From efd759bec5c56a0f9f6d43e7a199947da46743d5 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 16 Jun 2020 17:46:48 +0200 Subject: [PATCH] Add code linting using ESLint Add ESLint as a dev dependency and configure it to match the preferred style for the project. The config options set to warn are tentative and may not be sensible as they haven't been fully investigated yet. --- .eslintrc.js | 253 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 + 2 files changed, 255 insertions(+) create mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..e518c29a --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,253 @@ +"use strict"; +module.exports = { + "env": { + "node": true, + "browser": true, + "commonjs": true, + "es6": true, + }, + "parserOptions": { + "ecmaVersion": 11, + }, + + "overrides": [ + { + "files": ["test/**/*.js", "plugins/*/test/**/*.js"], + "env": { + "mocha": "true", + }, + "rules": { + "prefer-arrow-callback": "off", + }, + }, + ], + + "rules": { + "accessor-pairs": "error", + "array-bracket-newline": "off", + "array-bracket-spacing": ["error", "never"], + "array-callback-return": "error", + "array-element-newline": "off", + "arrow-body-style": "error", + "arrow-parens": "off", + "arrow-spacing": ["error", { "after": true, "before": true }], + "block-scoped-var": "error", + "block-spacing": "error", + "brace-style": ["warn", "1tbs", { "allowSingleLine": true }], + "callback-return": "off", + "camelcase": "off", + "capitalized-comments": "off", + "class-methods-use-this": "off", + "comma-dangle": [ + "error", + { + "arrays": "always-multiline", + "objects": "always-multiline", + "functions": "only-multiline", + }, + ], + "comma-spacing": "warn", + "comma-style": ["error", "last"], + "complexity": "warn", + "computed-property-spacing": ["error", "never"], + "consistent-return": "error", + "consistent-this": "error", + "curly": "warn", + "default-case": "error", + "default-case-last": "error", + "default-param-last": "error", + "dot-location": ["error", "property"], + "dot-notation": ["warn", { "allowKeywords": true }], + "eol-last": "error", + "eqeqeq": "warn", + "func-call-spacing": "error", + "func-name-matching": "error", + "func-names": "off", + "func-style": ["error", "declaration"], + "function-call-argument-newline": "off", + "function-paren-newline": "off", + "generator-star-spacing": ["error", { "before": false, "after": true }], + "global-require": "warn", + "grouped-accessor-pairs": "error", + "guard-for-in": "error", + "handle-callback-err": "error", + "id-blacklist": "error", + "id-length": "off", + "id-match": "error", + "implicit-arrow-linebreak": "error", + "indent": ["error", "tab", { "SwitchCase": 1 }], + "indent-legacy": "off", + "init-declarations": "off", + "jsx-quotes": "error", + "key-spacing": "error", + "keyword-spacing": "warn", + "line-comment-position": "off", + "linebreak-style": ["error", "unix"], + "lines-around-comment": "off", + "lines-around-directive": "off", + "lines-between-class-members": ["error", "always"], + "max-classes-per-file": "off", + "max-depth": "warn", + "max-len": ["warn", { "code": 120 }], + "max-lines": "off", + "max-lines-per-function": "off", + "max-nested-callbacks": "error", + "max-params": "off", + "max-statements": "off", + "max-statements-per-line": "off", + "multiline-comment-style": ["warn", "separate-lines"], + "multiline-ternary": "warn", + "new-cap": "warn", + "new-parens": "error", + "newline-after-var": "off", + "newline-before-return": "off", + "newline-per-chained-call": "off", + "no-alert": "error", + "no-array-constructor": "error", + "no-await-in-loop": "off", + "no-bitwise": "off", + "no-buffer-constructor": "error", + "no-caller": "error", + "no-catch-shadow": "error", + "no-confusing-arrow": "error", + "no-console": "off", + "no-constant-condition": ["error", { "checkLoops": false }], + "no-constructor-return": "error", + "no-continue": "off", + "no-div-regex": "error", + "no-duplicate-imports": "error", + "no-else-return": "warn", + "no-empty-function": "off", + "no-eq-null": "error", + "no-eval": "error", + "no-extend-native": "error", + "no-extra-bind": "error", + "no-extra-label": "error", + "no-extra-parens": "off", + "no-floating-decimal": "error", + "no-implicit-coercion": "error", + "no-implicit-globals": "error", + "no-implied-eval": "error", + "no-inline-comments": "off", + "no-invalid-this": "warn", + "no-iterator": "error", + "no-label-var": "error", + "no-lone-blocks": "error", + "no-lonely-if": "error", + "no-loop-func": "error", + "no-magic-numbers": "off", + "no-mixed-operators": "warn", + "no-mixed-requires": "error", + "no-multi-assign": "error", + "no-multi-spaces": "error", + "no-multi-str": "error", + "no-multiple-empty-lines": "error", + "no-native-reassign": "error", + "no-negated-condition": "off", + "no-negated-in-lhs": "error", + "no-nested-ternary": "error", + "no-new": "error", + "no-new-func": "error", + "no-new-object": "error", + "no-new-require": "error", + "no-new-wrappers": "error", + "no-octal-escape": "error", + "no-param-reassign": "off", + "no-path-concat": "error", + "no-plusplus": ["warn", { "allowForLoopAfterthoughts": true }], + "no-process-env": "error", + "no-process-exit": "warn", + "no-proto": "error", + "no-restricted-exports": "error", + "no-restricted-globals": "error", + "no-restricted-imports": "error", + "no-restricted-modules": "error", + "no-restricted-properties": "error", + "no-restricted-syntax": "error", + "no-return-assign": "error", + "no-return-await": "off", + "no-script-url": "error", + "no-self-compare": "error", + "no-sequences": "error", + "no-shadow": "warn", + "no-spaced-func": "error", + "no-sync": "error", + "no-tabs": ["error", { "allowIndentationTabs": true }], + "no-template-curly-in-string": "error", + "no-ternary": "off", + "no-throw-literal": "error", + "no-trailing-spaces": "error", + "no-undef-init": "error", + "no-undefined": "off", + "no-unmodified-loop-condition": "error", + "no-unneeded-ternary": "error", + "no-unused-expressions": "error", + "no-use-before-define": "warn", + "no-useless-backreference": "error", + "no-useless-call": "error", + "no-useless-computed-key": "error", + "no-useless-concat": "error", + "no-useless-constructor": "error", + "no-useless-rename": "error", + "no-useless-return": "error", + "no-var": "warn", + "no-void": "error", + "no-warning-comments": "off", + "no-whitespace-before-property": "error", + "nonblock-statement-body-position": "error", + "object-curly-newline": "error", + "object-curly-spacing": "off", + "object-shorthand": "off", + "one-var": "off", + "one-var-declaration-per-line": "error", + "operator-assignment": "off", + "operator-linebreak": "warn", + "padded-blocks": "off", + "padding-line-between-statements": "error", + "prefer-arrow-callback": "warn", + "prefer-const": "off", + "prefer-destructuring": "off", + "prefer-exponentiation-operator": "error", + "prefer-named-capture-group": "off", + "prefer-numeric-literals": "error", + "prefer-object-spread": "error", + "prefer-promise-reject-errors": "error", + "prefer-reflect": "off", + "prefer-regex-literals": "error", + "prefer-rest-params": "error", + "prefer-spread": "error", + "prefer-template": "warn", + "quote-props": "off", + "quotes": ["error", "double", { "avoidEscape": true }], + "radix": ["error", "always"], + "require-atomic-updates": "off", // XXX Not sure why this triggers on process.title = ... + "require-await": "off", + "require-jsdoc": "off", + "require-unicode-regexp": "off", + "rest-spread-spacing": ["error", "never"], + "semi": "error", + "semi-spacing": "error", + "semi-style": "off", + "sort-imports": "error", + "sort-keys": "off", + "sort-vars": "error", + "space-before-blocks": "warn", + "space-before-function-paren": "off", + "space-in-parens": ["error", "never"], + "space-infix-ops": "off", + "space-unary-ops": "error", + "spaced-comment": ["warn", "always"], + "strict": "error", + "switch-colon-spacing": "error", + "symbol-description": "error", + "template-curly-spacing": ["error", "never"], + "template-tag-spacing": "error", + "unicode-bom": ["error", "never"], + "valid-jsdoc": ["error", { "requireReturn": false }], + "vars-on-top": "warn", + "wrap-iife": "error", + "wrap-regex": "off", + "yield-star-spacing": "error", + "yoda": ["error", "never", { "exceptRange": true }], + }, +}; diff --git a/package.json b/package.json index fc2842fb..ee0d7b5c 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "cover": "nyc npm test", "fast-cover": "FAST_TEST=y nyc npm test", "ci-cover": "nyc --reporter=lcovonly npm run-script test", + "lint": "eslint \"*.js\" lib plugins test", "docs": "jsdoc --configure docs/jsdoc.json", "install": "node lib/npmPostinstall", "bundle-dependencies": "bundle-dependencies" @@ -70,6 +71,7 @@ "yargs": "^14.2.0" }, "devDependencies": { + "eslint": "^7.2.0", "html5-validator": "^1.2.1", "jsdoc": "^3.6.3", "klaw": "^3.0.0",