-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(linter): use overrides in root eslint config (#3949)
* feat(linter): use overrides in root eslint config * feat(linter): update-root-eslint-config-to-use-overrides migration
- Loading branch information
1 parent
6b61a6c
commit 4f5fb0f
Showing
8 changed files
with
478 additions
and
26 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* This configuration is intended to be applied to ALL .js and .jsx files | ||
* within an Nx workspace. | ||
* | ||
* It should therefore NOT contain any rules or plugins which are specific | ||
* to one ecosystem, such as React, Angular, Node etc. | ||
* | ||
* We use @typescript-eslint/parser rather than the built in JS parser | ||
* because that is what Nx ESLint configs have always done and we don't | ||
* want to change too much all at once. | ||
* | ||
* TODO: Evaluate switching to the built-in JS parser (espree) in Nx v11, | ||
* it should yield a performance improvement but could introduce subtle | ||
* breaking changes - we should also look to replace all the @typescript-eslint | ||
* related plugins and rules below. | ||
*/ | ||
export default { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint'], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'prettier', | ||
'prettier/@typescript-eslint', | ||
], | ||
rules: { | ||
'@typescript-eslint/explicit-member-accessibility': 'off', | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/no-parameter-properties': '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
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
209 changes: 209 additions & 0 deletions
209
...es/linter/src/migrations/update-10-4-0/update-root-eslint-config-to-use-overrides.spec.ts
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,209 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { readJsonInTree } from '@nrwl/workspace'; | ||
import { createEmptyWorkspace } from '@nrwl/workspace/testing'; | ||
import { runMigration } from '../../utils/testing'; | ||
|
||
describe('Update root ESLint config to use overrides', () => { | ||
let tree: Tree; | ||
beforeEach(async () => { | ||
tree = Tree.empty(); | ||
tree = createEmptyWorkspace(tree); | ||
}); | ||
|
||
const testCases = [ | ||
{ | ||
// Most recent root ESLint config (before this change) with no modifications | ||
input: { | ||
root: true, | ||
ignorePatterns: ['**/*'], | ||
plugins: ['@nrwl/nx'], | ||
extends: ['plugin:@nrwl/nx/typescript'], | ||
rules: { | ||
'@nrwl/nx/enforce-module-boundaries': [ | ||
'error', | ||
{ | ||
enforceBuildableLibDependency: true, | ||
allow: [], | ||
depConstraints: [ | ||
{ sourceTag: '*', onlyDependOnLibsWithTags: ['*'] }, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
expected: { | ||
root: true, | ||
ignorePatterns: ['**/*'], | ||
plugins: ['@nrwl/nx'], | ||
overrides: [ | ||
{ | ||
files: ['*.ts', '*.tsx', '*.js', '*.jsx'], | ||
rules: { | ||
'@nrwl/nx/enforce-module-boundaries': [ | ||
'error', | ||
{ | ||
enforceBuildableLibDependency: true, | ||
allow: [], | ||
depConstraints: [ | ||
{ sourceTag: '*', onlyDependOnLibsWithTags: ['*'] }, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
files: ['*.ts', '*.tsx'], | ||
extends: ['plugin:@nrwl/nx/typescript'], | ||
parserOptions: { project: './tsconfig.*?.json' }, | ||
rules: {}, | ||
}, | ||
{ | ||
files: ['*.js', '*.jsx'], | ||
extends: ['plugin:@nrwl/nx/javascript'], | ||
rules: {}, | ||
}, | ||
], | ||
}, | ||
}, | ||
|
||
{ | ||
// Example using custom overrides already (should be a noop) | ||
input: { | ||
root: true, | ||
ignorePatterns: ['**/*'], | ||
plugins: ['@nrwl/nx'], | ||
extends: ['plugin:@nrwl/nx/typescript'], | ||
overrides: [ | ||
{ | ||
files: ['*.ts'], | ||
rules: { | ||
foo: 'error', | ||
}, | ||
}, | ||
], | ||
}, | ||
expected: { | ||
root: true, | ||
ignorePatterns: ['**/*'], | ||
plugins: ['@nrwl/nx'], | ||
extends: ['plugin:@nrwl/nx/typescript'], | ||
overrides: [ | ||
{ | ||
files: ['*.ts'], | ||
rules: { | ||
foo: 'error', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
|
||
{ | ||
// Example using custom rules and plugins at the top-level | ||
input: { | ||
root: true, | ||
ignorePatterns: ['**/*'], | ||
plugins: ['@nrwl/nx', 'plugin-a', 'plugin-b'], | ||
extends: ['plugin:@nrwl/nx/typescript'], | ||
rules: { | ||
bar: 'warn', | ||
'plugin-a/qux': ['error', { someConfig: true }], | ||
'plugin-b/baz': 'off', | ||
}, | ||
}, | ||
expected: { | ||
root: true, | ||
ignorePatterns: ['**/*'], | ||
plugins: ['@nrwl/nx'], | ||
overrides: [ | ||
{ | ||
files: ['*.ts', '*.tsx', '*.js', '*.jsx'], | ||
plugins: ['plugin-a', 'plugin-b'], | ||
rules: { | ||
bar: 'warn', | ||
'plugin-a/qux': ['error', { someConfig: true }], | ||
'plugin-b/baz': 'off', | ||
}, | ||
}, | ||
{ | ||
files: ['*.ts', '*.tsx'], | ||
extends: ['plugin:@nrwl/nx/typescript'], | ||
parserOptions: { project: './tsconfig.*?.json' }, | ||
rules: {}, | ||
}, | ||
{ | ||
files: ['*.js', '*.jsx'], | ||
extends: ['plugin:@nrwl/nx/javascript'], | ||
rules: {}, | ||
}, | ||
], | ||
}, | ||
}, | ||
|
||
{ | ||
// Example using other custom config at the top-level | ||
input: { | ||
root: true, | ||
ignorePatterns: ['**/*'], | ||
plugins: ['@nrwl/nx'], | ||
settings: { | ||
foo: 'bar', | ||
}, | ||
env: { | ||
browser: true, | ||
}, | ||
parser: 'some-custom-parser-value', | ||
parserOptions: { | ||
custom: 'option', | ||
}, | ||
extends: ['plugin:@nrwl/nx/typescript', 'custom-extends-config'], | ||
}, | ||
expected: { | ||
root: true, | ||
ignorePatterns: ['**/*'], | ||
plugins: ['@nrwl/nx'], | ||
overrides: [ | ||
{ | ||
files: ['*.ts', '*.tsx', '*.js', '*.jsx'], | ||
extends: ['custom-extends-config'], | ||
env: { | ||
browser: true, | ||
}, | ||
settings: { | ||
foo: 'bar', | ||
}, | ||
parser: 'some-custom-parser-value', | ||
parserOptions: { | ||
custom: 'option', | ||
}, | ||
rules: {}, | ||
}, | ||
{ | ||
files: ['*.ts', '*.tsx'], | ||
extends: ['plugin:@nrwl/nx/typescript'], | ||
parserOptions: { project: './tsconfig.*?.json' }, | ||
rules: {}, | ||
}, | ||
{ | ||
files: ['*.js', '*.jsx'], | ||
extends: ['plugin:@nrwl/nx/javascript'], | ||
rules: {}, | ||
}, | ||
], | ||
}, | ||
}, | ||
]; | ||
|
||
testCases.forEach((tc, i) => { | ||
it(`should update the existing root .eslintrc.json file to use overrides, CASE ${i}`, async () => { | ||
tree.create('.eslintrc.json', JSON.stringify(tc.input)); | ||
|
||
const result = await runMigration( | ||
'update-root-eslint-config-to-use-overrides', | ||
{}, | ||
tree | ||
); | ||
expect(readJsonInTree(result, '.eslintrc.json')).toEqual(tc.expected); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.