Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Breaking] Add config for Jest (#211)
- Loading branch information
1 parent
8fda131
commit 43367b2
Showing
10 changed files
with
282 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,120 +1,15 @@ | ||
'use strict'; | ||
|
||
// eslint-disable-next-line no-undef -- Keep backward compatibility with CommonJS. | ||
module.exports = { | ||
parserOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: 'module', | ||
}, | ||
env: { | ||
es6: true, | ||
node: true, | ||
}, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:node/recommended-module', | ||
'plugin:jest/recommended', | ||
'plugin:jest/style', | ||
'plugin:regexp/recommended', | ||
'prettier', | ||
], | ||
rules: { | ||
'array-callback-return': 'error', | ||
'dot-notation': 'error', | ||
eqeqeq: ['error', 'smart'], | ||
'func-name-matching': 'error', | ||
'func-names': ['error', 'as-needed'], | ||
'guard-for-in': 'error', | ||
'no-confusing-arrow': [ | ||
'error', | ||
{ | ||
allowParens: false, | ||
}, | ||
], | ||
'no-console': [ | ||
'error', | ||
{ | ||
allow: ['warn', 'error'], | ||
}, | ||
], | ||
'no-else-return': [ | ||
'error', | ||
{ | ||
allowElseIf: false, | ||
}, | ||
], | ||
'no-implicit-coercion': 'error', | ||
'no-lonely-if': 'error', | ||
'no-shadow': 'error', | ||
'no-unneeded-ternary': 'error', | ||
'no-unused-vars': [ | ||
'error', | ||
{ | ||
ignoreRestSiblings: true, | ||
}, | ||
], | ||
'no-use-before-define': ['error', 'nofunc'], | ||
'no-useless-return': 'error', | ||
'no-var': 'error', | ||
'node/no-unsupported-features/es-builtins': 'error', | ||
'node/no-unsupported-features/es-syntax': 'error', | ||
'node/no-unsupported-features/node-builtins': 'error', | ||
'object-shorthand': 'error', | ||
'one-var': ['error', 'never'], | ||
'operator-assignment': 'error', | ||
'padding-line-between-statements': [ | ||
'error', | ||
// Require blank lines after all directive prologues (e. g. 'use strict') | ||
{ | ||
blankLine: 'always', | ||
prev: 'directive', | ||
next: '*', | ||
}, | ||
// Disallow blank lines between all directive prologues (e. g. 'use strict') | ||
{ | ||
blankLine: 'never', | ||
prev: 'directive', | ||
next: 'directive', | ||
}, | ||
// Require blank lines after every sequence of variable declarations | ||
{ | ||
blankLine: 'always', | ||
prev: ['const', 'let', 'var'], | ||
next: '*', | ||
}, | ||
// Blank lines could be between variable declarations | ||
{ | ||
blankLine: 'any', | ||
prev: ['const', 'let', 'var'], | ||
next: ['const', 'let', 'var'], | ||
}, | ||
// Require blank lines before all return statements | ||
{ | ||
blankLine: 'always', | ||
prev: '*', | ||
next: 'return', | ||
}, | ||
// Require blank lines before and after all following statements | ||
{ | ||
blankLine: 'always', | ||
prev: '*', | ||
next: ['for', 'function', 'if', 'switch', 'try'], | ||
}, | ||
{ | ||
blankLine: 'always', | ||
prev: ['for', 'function', 'if', 'switch', 'try'], | ||
next: '*', | ||
}, | ||
], | ||
'prefer-arrow-callback': 'error', | ||
'prefer-object-spread': 'error', | ||
'prefer-regex-literals': 'error', | ||
'prefer-rest-params': 'error', | ||
'prefer-spread': 'error', | ||
'prefer-template': 'error', | ||
'sort-imports': ['error', { allowSeparatedGroups: true }], | ||
root: true, | ||
|
||
// Prefer code readability, e.g. `[0-9A-Za-z]`. | ||
'regexp/prefer-d': 'off', | ||
extends: ['./index.js', './jest.js'], | ||
|
||
// TODO: Keep backward compatibility with CommonJS. We may delete after ESM migration. | ||
globals: { | ||
module: true, | ||
require: true, | ||
}, | ||
|
||
reportUnusedDisableDirectives: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
function isObject(obj) { | ||
return typeof obj === 'object' && obj !== null; | ||
} | ||
|
||
module.exports = { isObject }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,20 @@ | ||
'use strict'; | ||
|
||
// eslint-disable-next-line no-undef -- Keep backward compatibility with CommonJS. | ||
const { ESLint } = require('eslint'); | ||
|
||
// eslint-disable-next-line no-undef -- Keep backward compatibility with CommonJS. | ||
const config = require('../index'); | ||
const { isObject } = require('./helper'); | ||
|
||
it('test basic properties of config', () => { | ||
test('basic properties of config', () => { | ||
expect(isObject(config.parserOptions)).toBeTruthy(); | ||
expect(isObject(config.env)).toBeTruthy(); | ||
expect(isObject(config.rules)).toBeTruthy(); | ||
expect(Array.isArray(config.extends)).toBeTruthy(); | ||
}); | ||
|
||
it('load config in ESLint to validate all rule syntax is correct', async () => { | ||
const eslint = new ESLint({}); | ||
|
||
test('load config in ESLint to validate all rule syntax is correct', async () => { | ||
const eslint = new ESLint({ baseConfig: config, useEslintrc: false }); | ||
const results = await eslint.lintText('var foo\n'); | ||
|
||
expect(results).toBeTruthy(); | ||
}); | ||
|
||
function isObject(obj) { | ||
return typeof obj === 'object' && obj !== null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
const { ESLint } = require('eslint'); | ||
|
||
const config = require('../jest'); | ||
const { isObject } = require('./helper'); | ||
|
||
test('basic properties of config', () => { | ||
expect(isObject(config.extends)).toBeTruthy(); | ||
}); | ||
|
||
test('load config in ESLint to validate all rule syntax is correct', async () => { | ||
const eslint = new ESLint({ baseConfig: config, useEslintrc: false }); | ||
const results = await eslint.lintText('test("foo");'); | ||
|
||
expect(results).toBeTruthy(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,117 @@ | ||
'use strict'; | ||
|
||
// eslint-disable-next-line no-undef -- Keep backward compatibility with CommonJS. | ||
module.exports = require('./.eslintrc.js'); | ||
module.exports = { | ||
parserOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: 'module', | ||
}, | ||
env: { | ||
es6: true, | ||
node: true, | ||
}, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:node/recommended-module', | ||
'plugin:regexp/recommended', | ||
'prettier', | ||
], | ||
rules: { | ||
'array-callback-return': 'error', | ||
'dot-notation': 'error', | ||
eqeqeq: ['error', 'smart'], | ||
'func-name-matching': 'error', | ||
'func-names': ['error', 'as-needed'], | ||
'guard-for-in': 'error', | ||
'no-confusing-arrow': [ | ||
'error', | ||
{ | ||
allowParens: false, | ||
}, | ||
], | ||
'no-console': [ | ||
'error', | ||
{ | ||
allow: ['warn', 'error'], | ||
}, | ||
], | ||
'no-else-return': [ | ||
'error', | ||
{ | ||
allowElseIf: false, | ||
}, | ||
], | ||
'no-implicit-coercion': 'error', | ||
'no-lonely-if': 'error', | ||
'no-shadow': 'error', | ||
'no-unneeded-ternary': 'error', | ||
'no-unused-vars': [ | ||
'error', | ||
{ | ||
ignoreRestSiblings: true, | ||
}, | ||
], | ||
'no-use-before-define': ['error', 'nofunc'], | ||
'no-useless-return': 'error', | ||
'no-var': 'error', | ||
'node/no-unsupported-features/es-builtins': 'error', | ||
'node/no-unsupported-features/es-syntax': 'error', | ||
'node/no-unsupported-features/node-builtins': 'error', | ||
'object-shorthand': 'error', | ||
'one-var': ['error', 'never'], | ||
'operator-assignment': 'error', | ||
'padding-line-between-statements': [ | ||
'error', | ||
// Require blank lines after all directive prologues (e. g. 'use strict') | ||
{ | ||
blankLine: 'always', | ||
prev: 'directive', | ||
next: '*', | ||
}, | ||
// Disallow blank lines between all directive prologues (e. g. 'use strict') | ||
{ | ||
blankLine: 'never', | ||
prev: 'directive', | ||
next: 'directive', | ||
}, | ||
// Require blank lines after every sequence of variable declarations | ||
{ | ||
blankLine: 'always', | ||
prev: ['const', 'let', 'var'], | ||
next: '*', | ||
}, | ||
// Blank lines could be between variable declarations | ||
{ | ||
blankLine: 'any', | ||
prev: ['const', 'let', 'var'], | ||
next: ['const', 'let', 'var'], | ||
}, | ||
// Require blank lines before all return statements | ||
{ | ||
blankLine: 'always', | ||
prev: '*', | ||
next: 'return', | ||
}, | ||
// Require blank lines before and after all following statements | ||
{ | ||
blankLine: 'always', | ||
prev: '*', | ||
next: ['for', 'function', 'if', 'switch', 'try'], | ||
}, | ||
{ | ||
blankLine: 'always', | ||
prev: ['for', 'function', 'if', 'switch', 'try'], | ||
next: '*', | ||
}, | ||
], | ||
'prefer-arrow-callback': 'error', | ||
'prefer-object-spread': 'error', | ||
'prefer-regex-literals': 'error', | ||
'prefer-rest-params': 'error', | ||
'prefer-spread': 'error', | ||
'prefer-template': 'error', | ||
'sort-imports': ['error', { allowSeparatedGroups: true }], | ||
|
||
// Prefer code readability, e.g. `[0-9A-Za-z]`. | ||
'regexp/prefer-d': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
extends: ['plugin:jest/recommended', 'plugin:jest/style'], | ||
}; |
Oops, something went wrong.