Skip to content

Commit

Permalink
feat(react): add react-specific eslint configuration (#1727)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo authored Aug 15, 2019
1 parent ff1de5b commit 13e7b69
Show file tree
Hide file tree
Showing 11 changed files with 566 additions and 370 deletions.
5 changes: 5 additions & 0 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ export function copyMissingPackages(): void {
'babel-loader',
'babel-plugin-macros',

'eslint-plugin-import',
'eslint-plugin-jsx-a11y',
'eslint-plugin-react',
'eslint-plugin-react-hooks',

'document-register-element'
];
modulesToCopy.forEach(m => copyNodeModule(m));
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"codelyzer": "~5.0.1",
"commitizen": "^4.0.3",
"conventional-changelog-cli": "^2.0.23",
"confusing-browser-globals": "^1.0.8",
"copy-webpack-plugin": "5.0.3",
"cosmiconfig": "^4.0.0",
"cypress": "3.4.1",
Expand All @@ -87,6 +88,10 @@
"express": "4.17.1",
"eslint": "6.1.0",
"eslint-config-prettier": "6.0.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-react-hooks": "^1.7.0",
"fork-ts-checker-webpack-plugin": "^0.4.9",
"fs-extra": "7.0.1",
"graphviz": "^0.0.9",
Expand All @@ -108,6 +113,7 @@
"karma-jasmine-html-reporter": "^0.2.2",
"karma-webpack": "2.0.4",
"license-webpack-plugin": "^1.4.0",
"mime": "2.4.4",
"ng-packagr": "5.3.0",
"ngrx-store-freeze": "0.2.4",
"npm-run-all": "^4.1.5",
Expand Down Expand Up @@ -139,8 +145,7 @@
"webpack-node-externals": "^1.7.2",
"yargs": "^11.0.0",
"yargs-parser": "10.0.0",
"zone.js": "^0.9.0",
"mime": "2.4.4"
"zone.js": "^0.9.0"
},
"author": "Victor Savkin",
"license": "MIT",
Expand Down
4 changes: 3 additions & 1 deletion packages/angular/src/schematics/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ export default function(schema: Schema): Rule {
...options,
skipFormat: true
}),
addLintFiles(options.appProjectRoot, options.linter, true),
addLintFiles(options.appProjectRoot, options.linter, {
onlyGlobal: true
}),
externalSchematic('@schematics/angular', 'application', {
name: options.name,
inlineStyle: options.inlineStyle,
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/schematics/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ export default function(schema: Schema): Rule {
}

return chain([
addLintFiles(options.projectRoot, Linter.TsLint, true),
addLintFiles(options.projectRoot, Linter.TsLint, { onlyGlobal: true }),
addUnitTestRunner(options),
externalSchematic('@schematics/angular', 'library', {
name: options.name,
Expand Down
23 changes: 23 additions & 0 deletions packages/react/src/schematics/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,4 +528,27 @@ describe('app', () => {
});
});
});

describe('--linter=eslint', () => {
it('should add .eslintrc and dependencies', async () => {
const tree = await runSchematic(
'app',
{ name: 'myApp', linter: 'eslint' },
appTree
);

const eslintJson = readJsonInTree(tree, '/apps/my-app/.eslintrc');
const packageJson = readJsonInTree(tree, '/package.json');

expect(eslintJson.plugins).toEqual(
expect.arrayContaining(['react', 'react-hooks'])
);
expect(packageJson).toMatchObject({
devDependencies: {
'eslint-plugin-react': expect.anything(),
'eslint-plugin-react-hooks': expect.anything()
}
});
});
});
});
8 changes: 7 additions & 1 deletion packages/react/src/schematics/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
regeneratorVersion
} from '../../utils/versions';
import { assertValidStyle } from '../../utils/assertion';
import { extraEslintDependencies, reactEslintJson } from '../../utils/lint';

interface NormalizedSchema extends Schema {
projectName: string;
Expand All @@ -68,7 +69,10 @@ export default function(schema: Schema): Rule {
ngAdd({
skipFormat: true
}),
addLintFiles(options.appProjectRoot, options.linter),
addLintFiles(options.appProjectRoot, options.linter, {
localConfig: reactEslintJson,
extraPackageDeps: extraEslintDependencies
}),
createApplicationFiles(options),
updateNxJson(options),
addProject(options),
Expand Down Expand Up @@ -320,6 +324,7 @@ function setDefaults(options: NormalizedSchema): Rule {
application: {
babel: options.babel,
style: options.style,
linter: options.linter,
...jsonIdentity(prev.application)
},
component: {
Expand All @@ -328,6 +333,7 @@ function setDefaults(options: NormalizedSchema): Rule {
},
library: {
style: options.style,
linter: options.linter,
...jsonIdentity(prev.library)
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/react/src/schematics/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
} from '../../utils/ast-utils';
import { reactRouterVersion } from '../../utils/versions';
import { assertValidStyle } from '../../utils/assertion';
import { extraEslintDependencies, reactEslintJson } from '../../utils/lint';

export interface NormalizedSchema extends Schema {
name: string;
Expand All @@ -57,7 +58,10 @@ export default function(schema: Schema): Rule {
const options = normalizeOptions(host, schema, context);

return chain([
addLintFiles(options.projectRoot, options.linter),
addLintFiles(options.projectRoot, options.linter, {
localConfig: reactEslintJson,
extraPackageDeps: extraEslintDependencies
}),
createFiles(options),
!options.skipTsConfig ? updateTsConfig(options) : noop(),
addProject(options),
Expand Down
Loading

0 comments on commit 13e7b69

Please sign in to comment.