diff --git a/.eslintrc.google.js b/.eslintrc.google.js new file mode 100644 index 0000000..1b9c384 --- /dev/null +++ b/.eslintrc.google.js @@ -0,0 +1,334 @@ +/** + * Copyright 2016 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +'use strict'; + +module.exports = { + rules: { + // The rules below are listed in the order they appear on the eslint + // rules page. All rules are listed to make it easier to keep in sync + // as new ESLint rules are added. + // http://eslint.org/docs/rules/ + // - Rules in the `eslint:recommended` ruleset that aren't specifically + // mentioned by the google styleguide are listed but commented out (so + // they don't override a base ruleset). + // - Rules that are recommended but contradict the Google styleguide + // are explicitely set to the Google styleguide value. + + // Possible Errors + // http://eslint.org/docs/rules/#possible-errors + // --------------------------------------------- + // 'for-direction': 0, + // 'no-await-in-loop': 0, + // 'no-compare-neg-zero': 2, // eslint:recommended + 'no-cond-assign': 0, // eslint:recommended + // 'no-console': 2, // eslint:recommended + // 'no-constant-condition': 2, // eslint:recommended + // 'no-control-regex': 2, // eslint:recommended + // 'no-debugger': 2, // eslint:recommended + // 'no-dupe-args': 2, // eslint:recommended + // 'no-dupe-keys': 2, // eslint:recommended + // 'no-duplicate-case': 2, // eslint:recommended + // 'no-empty': 2, // eslint:recommended + // 'no-empty-character-class': 2, // eslint:recommended + // 'no-ex-assign': 2, // eslint:recommended + // 'no-extra-boolean-cast': 2, // eslint:recommended + // 'no-extra-parens': 0, + // 'no-extra-semi': 2, // eslint:recommended + // 'no-func-assign': 2, // eslint:recommended + // 'no-inner-declarations': 2, // eslint:recommended + // 'no-invalid-regexp': 2, // eslint:recommended + 'no-irregular-whitespace': 2, // eslint:recommended + // 'no-obj-calls': 2, // eslint:recommended + // 'no-prototype-builtins': 0, + // 'no-regex-spaces': 2, // eslint:recommended + // 'no-sparse-arrays': 2, // eslint:recommended + // 'no-template-curly-in-string': 0, + 'no-unexpected-multiline': 2, // eslint:recommended + // 'no-unreachable': 2, // eslint:recommended + // 'no-unsafe-finally': 2, // eslint:recommended + // 'no-unsafe-negation': 0, + // 'use-isnan': 2 // eslint:recommended + 'valid-jsdoc': [2, { + requireParamDescription: false, + requireReturnDescription: false, + requireReturn: false, + prefer: {returns: 'return'}, + }], + // 'valid-typeof': 2 // eslint:recommended + + + // Best Practices + // http://eslint.org/docs/rules/#best-practices + // -------------------------------------------- + + // 'accessor-pairs': 0, + // 'array-callback-return': 0, + // 'block-scoped-var': 0, + // 'class-methods-use-this': 0, + // 'complexity': 0, + // 'consistent-return': 0 + 'curly': [2, 'multi-line'], // TODO(philipwalton): add an option to enforce + // braces with the exception of simple, + // single-line if statements. + // 'default-case': 0, + // 'dot-location': 0, + // 'dot-notation': 0, + // 'eqeqeq': 0, + 'guard-for-in': 2, + // 'no-alert': 0, + 'no-caller': 2, + // 'no-case-declarations': 2, // eslint:recommended + // 'no-div-regex': 0, + // 'no-else-return': 0, + // 'no-empty-function': 0, + // 'no-empty-pattern': 2, // eslint:recommended + // 'no-eq-null': 0, + // 'no-eval': 0, + 'no-extend-native': 2, + 'no-extra-bind': 2, + // 'no-extra-label': 0, + // 'no-fallthrough': 2, // eslint:recommended + // 'no-floating-decimal': 0, + // 'no-global-assign': 0, + // 'no-implicit-coercion': 0, + // 'no-implicit-globals': 0, + // 'no-implied-eval': 0, + 'no-invalid-this': 2, + // 'no-iterator': 0, + // 'no-labels': 0, + // 'no-lone-blocks': 0, + // 'no-loop-func': 0, + // 'no-magic-numbers': 0, + 'no-multi-spaces': 2, + 'no-multi-str': 2, + // 'no-new': 0, + // 'no-new-func': 0, + 'no-new-wrappers': 2, + // 'no-octal': 2, // eslint:recommended + // 'no-octal-escape': 0, + // 'no-param-reassign': 0, + // 'no-proto': 0, + // 'no-redeclare': 2, // eslint:recommended + // 'no-restricted-properties': 0, + // 'no-return-assign': 0, + // 'no-script-url': 0, + // 'no-self-assign': 2, // eslint:recommended + // 'no-self-compare': 0, + // 'no-sequences': 0, + 'no-throw-literal': 2, // eslint:recommended + // 'no-unmodified-loop-condition': 0, + // 'no-unused-expressions': 0, + // 'no-unused-labels': 2, // eslint:recommended + // 'no-useless-call': 0, + // 'no-useless-concat': 0, + // 'no-useless-escape': 0, + // 'no-void': 0, + // 'no-warning-comments': 0, + 'no-with': 2, + // 'prefer-promise-reject-errors': 0, + // 'radix': 0, + // 'require-await': 0, + // 'vars-on-top': 0, + // 'wrap-iife': 0, + // 'yoda': 0, + + // Strict Mode + // http://eslint.org/docs/rules/#strict-mode + // ----------------------------------------- + // 'strict': 0, + + // Variables + // http://eslint.org/docs/rules/#variables + // --------------------------------------- + // 'init-declarations': 0, + // 'no-catch-shadow': 0, + // 'no-delete-var': 2, // eslint:recommended + // 'no-label-var': 0, + // 'no-restricted-globals': 0, + // 'no-shadow': 0, + // 'no-shadow-restricted-names': 0, + // 'no-undef': 2, // eslint:recommended + // 'no-undef-init': 0, + // 'no-undefined': 0, + 'no-unused-vars': [2, {args: 'none'}], // eslint:recommended + // 'no-use-before-define': 0, + + // Node.js and CommonJS + // http://eslint.org/docs/rules/#nodejs-and-commonjs + // ------------------------------------------------- + // 'callback-return': 0, + // 'global-require': 0, + // 'handle-callback-err': 0, + // 'no-buffer-constructor': 0, + // 'no-mixed-requires': 0, + // 'no-new-require': 0, + // 'no-path-concat': 0, + // 'no-process-env': 0, + // 'no-process-exit': 0, + // 'no-restricted-modules': 0, + // 'no-sync': 0, + + // Stylistic Issues + // http://eslint.org/docs/rules/#stylistic-issues + // ---------------------------------------------- + 'array-bracket-newline': 0, // eslint:recommended + 'array-bracket-spacing': [2, 'never'], + 'array-element-newline': 0, // eslint:recommended + 'block-spacing': [2, 'never'], + 'brace-style': 2, + 'camelcase': [2, {properties: 'never'}], + // 'capitalized-comments': 0, + 'comma-dangle': [2, 'always-multiline'], + 'comma-spacing': 2, + 'comma-style': 2, + 'computed-property-spacing': 2, + // 'consistent-this': 0, + 'eol-last': 2, + 'func-call-spacing': 2, + // 'func-name-matching': 0, + // 'func-names': 0, + // 'func-style': 0, + // 'id-blacklist': 0, + // 'id-length': 0, + // 'id-match': 0, + // 'indent': 0, // TODO(philipwalton): this rule isn't compatible with + // Google's 4-space indent for line continuations. + // 'jsx-quotes': 0, + 'key-spacing': 2, + 'keyword-spacing': 2, + // 'line-comment-position': 0, + 'linebreak-style': 2, + // 'lines-around-comment': 0, + // 'max-depth': 0, + 'max-len': [2, { + code: 80, + tabWidth: 2, + ignoreUrls: true, + ignorePattern: '^goog\.(module|require)', + }], + // 'max-lines': 0, + // 'max-nested-callbacks': 0, + // 'max-params': 0, + // 'max-statements': 0, + // 'max-statements-per-line': 0, + // 'multiline-ternary': 0, // TODO(philipwalton): add a rule to enforce the + // operator appearing at the end of the line. + 'new-cap': 2, + // 'new-parens': 0, + // 'newline-per-chained-call': 0, + 'no-array-constructor': 2, + // 'no-bitwise': 0, + // 'no-continue': 0, + // 'no-inline-comments': 0, + // 'no-lonely-if': 0, + // 'no-mixed-operators': 0, + 'no-mixed-spaces-and-tabs': 2, // eslint:recommended + // 'no-multi-assign': 0, + 'no-multiple-empty-lines': [2, {max: 2}], + // 'no-negated-condition': 0, + // 'no-nested-ternary': 0, + 'no-new-object': 2, + // 'no-plusplus': 0, + // 'no-restricted-syntax': 0, + 'no-tabs': 2, + // 'no-ternary': 0, + 'no-trailing-spaces': 2, + // 'no-underscore-dangle': 0, + // 'no-unneeded-ternary': 0, + // 'no-whitespace-before-property': 0, + // 'nonblock-statement-body-position': 0, + // 'object-curly-newline': 0, + 'object-curly-spacing': 2, + // 'object-property-newline': 0, + 'one-var': [2, { + var: 'never', + let: 'never', + const: 'never', + }], + // 'one-var-declaration-per-line': 0, + // 'operator-assignment': 0, + // 'operator-linebreak': 0, + 'padded-blocks': [2, 'never'], + // 'padding-line-between-statements': 0, + 'quote-props': [2, 'consistent'], + 'quotes': [2, 'single', {allowTemplateLiterals: true}], + 'require-jsdoc': [2, { + require: { + FunctionDeclaration: true, + MethodDefinition: true, + ClassDeclaration: true, + }, + }], + 'semi': 2, + 'semi-spacing': 2, + // 'semi-style': 0, + // 'sort-keys': 0, + // 'sort-vars': 0, + 'space-before-blocks': 2, + 'space-before-function-paren': [2, { + asyncArrow: 'always', + anonymous: 'never', + named: 'never', + }], + // 'space-in-parens': 0, + // 'space-infix-ops': 0, + // 'space-unary-ops': 0, + 'spaced-comment': [2, 'always'], + // 'switch-colon-spacing': 2, + // 'template-tag-spacing': 0, + // 'unicode-bom': 0, + // 'wrap-regex': 0, + + // ECMAScript 6 + // http://eslint.org/docs/rules/#ecmascript-6 + // ------------------------------------------ + // 'arrow-body-style': 0, + 'arrow-parens': [2, 'always'], // TODO(philipwalton): technically arrow + // parens are optional but recommended. + // ESLint doesn't support a *consistent* + // setting so "always" is used. + // 'arrow-spacing': 0, + 'constructor-super': 2, // eslint:recommended + 'generator-star-spacing': [2, 'after'], + // 'no-class-assign': 0, + // 'no-confusing-arrow': 0, + // 'no-const-assign': 0, // eslint:recommended + // 'no-dupe-class-members': 0, // eslint:recommended + // 'no-duplicate-imports': 0, + 'no-new-symbol': 2, // eslint:recommended + // 'no-restricted-imports': 0, + 'no-this-before-super': 2, // eslint:recommended + // 'no-useless-computed-key': 0, + // 'no-useless-constructor': 0, + // 'no-useless-rename': 0, + 'no-var': 2, + // 'object-shorthand': 0, + // 'prefer-arrow-callback': 0, + // 'prefer-const': 0, + // 'prefer-destructuring': 0, + // 'prefer-numeric-literals': 0, + 'prefer-rest-params': 2, + 'prefer-spread': 2, + // 'prefer-template': 0, + // 'require-yield': 2, // eslint:recommended + 'rest-spread-spacing': 2, + // 'sort-imports': 0, + // 'symbol-description': 0, + // 'template-curly-spacing': 0, + 'yield-star-spacing': [2, 'after'], + }, +}; diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..33b6d56 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,63 @@ +module.exports = { + extends: './.eslintrc.google.js', + parserOptions: { + "ecmaVersion": 2017, + "sourceType": "module", + }, + env: { + es6: true, + }, + rules: { + 'arrow-parens': 0, + 'block-spacing': 0, + 'brace-style': 0, + 'camelcase': 0, + 'comma-dangle': 0, + 'comma-style': [2, 'last'], + 'curly': 0, + 'indent': [0, 4], + 'key-spacing': 0, + 'linebreak-style': 0, + 'linebreak-style': 2, + 'max-len': 0, + 'new-cap': 0, + 'no-invalid-this': 0, + 'no-multi-spaces': 0, + 'no-undef': 2, + 'no-unused-vars': 1, + 'object-curly-spacing': 0, + 'padded-blocks': [0, 'never'], + 'quote-props': 0, + 'quotes': 0, + 'require-jsdoc': 0, + 'semi': [1, 'always'], + 'space-before-function-paren': [0, {"anonymous": "never"}], + 'valid-jsdoc': 0, + }, + globals: { + // $: true, + _: true, + rdfstore: true, + FormData: true, + Backbone: true, + document: true, + require: true, + define: true, + console: true, + window: true, + process: true, + module: true, + Image: true, + exports: true, + parent: true, + setTimeout: true, + setInterval: true, + clearTimeout: true, + clearInterval: true, + __dirname: true, + GM_registerMenuCommand: true, + __filename: true, + Buffer: true, + fetch: true, + }, +} diff --git a/web/ocr-fileformat.js b/web/ocr-fileformat.js index 22fc143..26353f8 100644 --- a/web/ocr-fileformat.js +++ b/web/ocr-fileformat.js @@ -1,18 +1,20 @@ -var OcrFileformatAPI = function OcrFileformatAPI(endpoint) { +/* globals $ */ + +let OcrFileformatAPI = function OcrFileformatAPI(endpoint) { this.endpoint = endpoint; }; OcrFileformatAPI.prototype.urlFor = function urlFor(action, params) { params || (params = {}); - url = this.endpoint + '?do=' + action; - for (var paramName of Object.keys(params)) { + let url = this.endpoint + '?do=' + action; + for (let paramName of Object.keys(params)) { url += '&' + paramName + '=' + params[paramName]; } return url; }; OcrFileformatAPI.prototype.updateFormats = function updateFormats(cb) { - var self = this; + let self = this; this.request('list', null, null, function(err, formats) { self.formats = formats; cb(err); @@ -20,9 +22,9 @@ OcrFileformatAPI.prototype.updateFormats = function updateFormats(cb) { }; OcrFileformatAPI.prototype.request = function request(endpoint, query, formData, cb) { - ajaxCall = { + let ajaxCall = { type: 'GET', - url: api.urlFor(endpoint, query), + url: window.api.urlFor(endpoint, query), success: function(data) { cb(null, data); }, @@ -32,7 +34,7 @@ OcrFileformatAPI.prototype.request = function request(endpoint, query, formData, }; if (formData) { ajaxCall.type = 'POST'; - ajaxCall.data = formData + ajaxCall.data = formData; ajaxCall.processData = false; ajaxCall.contentType = false; } @@ -56,8 +58,7 @@ function onChangeFormat() { }); $("#transform-from").removeAttr('disabled'); } - var selectedFrom = $("#transform-from").val(); - var selectedTo = $("#transform-to").val(); + let selectedFrom = $("#transform-from").val(); $("#transform-to").attr('disabled', selectedFrom === null); if (selectedFrom) { $("#transform-to option").slice(1).remove(); @@ -73,48 +74,50 @@ function onChangeFormat() { } function submit(tabName, params) { - var pane = $("#" + tabName); - var input = pane.find(".input .active input"); + let pane = $("#" + tabName); + let input = pane.find(".input .active input"); + let formData; + let url = input.val(); if (input.attr('type') === 'file') { - var formData = new FormData(); + formData = new FormData(); formData.append('file', input.prop('files')[0]); } else { - var url = input.val(); params.url = url; } $("button .spinning", pane).removeClass('hidden'); - api.request(tabName, params, formData, function(err, data) { + window.api.request(tabName, params, formData, function(err, data) { pane.find("button .spinning").addClass('hidden'); - if (err) + if (err) { return $.notify(err, 'error'); + } if (url) { pane.find(".result a.download").attr('href', url); } pane.find(".result pre code").html(escapeHTML(data)); pane.find(".result").removeClass('hidden'); - /*global Prism*/ - Prism.highlightAll() + /* global Prism*/ + Prism.highlightAll(); }); } function maybeEnableSubmit() { - var el = $(".tab-pane.active") - var inputSet = !!$(".input .active input", el).val(); - var selects = $(".formats select", el); - var formatsSet = selects.length == selects.map(function() { return $(this).val(); }).length; + let el = $(".tab-pane.active"); + let inputSet = !!$(".input .active input", el).val(); + let selects = $(".formats select", el); + let formatsSet = selects.length == selects.map(function() { return $(this).val(); }).length; $("button", el).attr('disabled', !(inputSet && formatsSet)); } function hashRoute() { - var hash = window.location.hash; - var pageTab = hash.replace(/-.*/,''); + let hash = window.location.hash; + let pageTab = hash.replace(/-.*/, ''); $("a[data-toggle='tab'][href='" + pageTab + "']").tab('show'); $("a[data-toggle='tab'][href='" + hash + "']").tab('show'); } $(function() { $.notify.defaults({position: 'bottom right'}); - var api = window.api = new OcrFileformatAPI('ocr-fileformat.php'); + const api = window.api = new OcrFileformatAPI('ocr-fileformat.php'); $.notify("Loading formats", 'info'); api.updateFormats(function(err) { if (err) {