From ae3237c0086f747e5ebda27c2b71a1321e6643b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Wed, 6 Dec 2017 14:35:33 +0100 Subject: [PATCH] feat: add new rules for best practices --- index.js | 56 ++++++++++++++++++++++++++++++++++++++++++-------- test/not-ok.js | 6 ++++++ test/ok.js | 6 ++++++ test/test.js | 14 +++++++------ 4 files changed, 68 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index be25df0..ec328bd 100644 --- a/index.js +++ b/index.js @@ -94,6 +94,54 @@ module.exports = { 'no-extra-bind': 'error', 'no-extra-label': 'error', 'no-fallthrough': 'error', + 'no-floating-decimal': 'error', + 'no-global-assign': 'error', + 'no-implicit-coercion': 'off', + 'no-implicit-globals': 'off', // only useful for browser scripts + 'no-implied-eval': 'error', + 'no-invalid-this': 'off', + 'no-iterator': 'error', + 'no-labels': 'off', // to enable on a case-by-case basis + 'no-lone-blocks': 'error', + 'no-loop-func': 'error', + 'no-magic-numbers': 'off', // todo: maybe warn later + 'no-multi-spaces': 'error', + 'no-multi-str': 'error', + 'no-new': 'error', + 'no-new-func': 'error', + 'no-new-wrappers': 'error', + 'no-octal': 'error', + 'no-octal-escape': 'error', + 'no-param-reassign': 'off', + 'no-proto': 'error', + 'no-redeclare': 'error', + 'no-restricted-properties': 'off', + 'no-return-assign': 'error', + 'no-return-await': 'error', + 'no-script-url': 'error', + 'no-self-assign': 'error', + 'no-self-compare': 'error', + 'no-sequences': 'error', + 'no-throw-literal': 'error', + 'no-unmodified-loop-condition': 'error', + 'no-unused-expressions': 'error', + 'no-unused-labels': 'error', + 'no-useless-call': 'error', + 'no-useless-concat': 'error', + 'no-useless-escape': 'error', + 'no-useless-return': 'error', + 'no-void': 'error', + 'no-warning-comments': 'warn', + 'no-with': 'error', + 'prefer-promise-reject-errors': 'error', + 'radix': 'warn', + 'require-await': 'error', + 'vars-on-top': 'off', // todo: maybe warn later + 'wrap-iife': 'error', + 'yoda': 'error', + + // Strict Mode (https://eslint.org/docs/rules/#strict-mode) + 'strict': ['error', 'global'], // todo continue the list @@ -112,21 +160,14 @@ module.exports = { 'no-array-constructor': 'error', 'no-delete-var': 'error', 'no-label-var': 'error', - 'no-lone-blocks': 'error', 'no-mixed-spaces-and-tabs': 'error', - 'no-multi-spaces': 'error', 'no-multiple-empty-lines': ['error', {max: 2, maxEOF: 1, maxBOF: 1}], 'no-new-object': 'error', - 'no-return-await': 'error', - 'no-new-wrappers': 'error', - 'no-redeclare': 'error', 'no-shadow-restricted-names': 'error', 'no-trailing-spaces': 'error', 'no-undef': 'error', 'no-undef-init': 'error', - 'no-unused-expressions': 'error', 'no-unused-vars': 'error', - 'no-with': 'error', 'object-curly-spacing': ['error', 'never'], 'one-var': ['error', {initialized: 'never'}], 'one-var-declaration-per-line': ['error', 'initializations'], @@ -139,7 +180,6 @@ module.exports = { 'space-in-parens': ['error', 'never'], 'space-infix-ops': ['error', {int32Hint: true}], 'space-unary-ops': 'error', - 'strict': ['error', 'global'], 'no-only-tests/no-only-tests': 'error' } diff --git a/test/not-ok.js b/test/not-ok.js index 824b443..7cacc90 100644 --- a/test/not-ok.js +++ b/test/not-ok.js @@ -14,6 +14,12 @@ x = { var y = 1, z; useIt(y, z); +function A() { + this.x = 1; +} + +new A(); + // use this function to mark a variable as used function useIt(...vals) { return vals; diff --git a/test/ok.js b/test/ok.js index b06b578..c0ddc24 100644 --- a/test/ok.js +++ b/test/ok.js @@ -11,6 +11,12 @@ b = 2; c = a + b; useIt(c); +function A() { + this.x = 1; +} + +useIt(new A()); + // use this function to mark a variable as used function useIt(...vals) { return vals; diff --git a/test/test.js b/test/test.js index 7b31232..702b4b0 100644 --- a/test/test.js +++ b/test/test.js @@ -17,14 +17,16 @@ const okResult = linter.verify(ok, config); assert.strictEqual(okResult.length, 0, 'ok.js should have no error: ' + util.format(okResult)); const notOkResult = linter.verify(notOk, config); -assert.deepStrictEqual(notOkResult.map(error => error.ruleId), [ - 'strict', +const errors = notOkResult.map(error => error.ruleId).sort(); +assert.deepStrictEqual(errors, [ 'no-console', - 'no-unused-vars', - 'quotes', + 'no-multiple-empty-lines', + 'no-new', 'no-redeclare', - 'quote-props', + 'no-unused-vars', 'one-var', 'one-var-declaration-per-line', - 'no-multiple-empty-lines' + 'quote-props', + 'quotes', + 'strict', ]);