Skip to content

Commit

Permalink
feat: add new rules for best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Dec 6, 2017
1 parent 1b589e8 commit ae3237c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 14 deletions.
56 changes: 48 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'],
Expand All @@ -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'
}
Expand Down
6 changes: 6 additions & 0 deletions test/not-ok.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions test/ok.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);

0 comments on commit ae3237c

Please sign in to comment.