Skip to content

Commit

Permalink
fix(core): restore tslint for next, clean up Linter enum usage (#4780)
Browse files Browse the repository at this point in the history
* fix(core): restore tslint for next

* fix(nextjs): type issue
  • Loading branch information
JamesHenry authored Feb 12, 2021
1 parent 4133c05 commit 4f758d4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 26 deletions.
67 changes: 50 additions & 17 deletions packages/next/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,25 +262,58 @@ describe('app', () => {
expect(appContent).not.toMatch(/extends Component/);
});

describe('--linter=eslint', () => {
it('should add .eslintrc.json and dependencies', async () => {
await applicationGenerator(tree, {
name: 'myApp',
style: 'css',
linter: Linter.EsLint,
describe('--linter', () => {
describe('default (eslint)', () => {
it('should add .eslintrc.json and dependencies', async () => {
await applicationGenerator(tree, {
name: 'myApp',
style: 'css',
});

const packageJson = readJson(tree, '/package.json');
expect(packageJson).toMatchObject({
devDependencies: {
'eslint-plugin-react': expect.anything(),
'eslint-plugin-react-hooks': expect.anything(),
},
});

const eslintJson = readJson(tree, '/apps/my-app/.eslintrc.json');
expect(eslintJson).toMatchInlineSnapshot(`
Object {
"extends": Array [
"plugin:@nrwl/nx/react",
"../../.eslintrc.json",
],
"ignorePatterns": Array [
"!**/*",
],
"rules": Object {},
}
`);
});
});

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

expect(eslintJson.extends).toEqual(
expect.arrayContaining(['plugin:@nrwl/nx/react'])
);
expect(packageJson).toMatchObject({
devDependencies: {
'eslint-plugin-react': expect.anything(),
'eslint-plugin-react-hooks': expect.anything(),
},
describe('tslint', () => {
it('should generate files', async () => {
await applicationGenerator(tree, {
name: 'myApp',
style: 'css',
linter: Linter.TsLint,
});

const tslintJson = readJson(tree, 'apps/my-app/tslint.json');
expect(tslintJson).toMatchInlineSnapshot(`
Object {
"extends": "../../tslint.json",
"linterOptions": Object {
"exclude": Array [
"!**/*",
],
},
"rules": Object {},
}
`);
});
});
});
Expand Down
28 changes: 19 additions & 9 deletions packages/next/src/generators/application/lib/add-linting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ import { NormalizedSchema } from './normalize-options';
export async function addLinting(host: Tree, options: NormalizedSchema) {
let installTask: GeneratorCallback;

/**
* TODO: Remove this use of any once we are consistent across the codebase
* in our use of the Linter enum. Currently we have one coming from linter
* and one from workspace and they do not match because one is a const enum
* and one is not.
*/
const linter: any = options.linter || Linter.EsLint;

await lintProjectGenerator(host, {
linter: Linter.EsLint,
linter,
project: options.projectName,
tsConfigPaths: [
joinPathFragments(options.appProjectRoot, 'tsconfig.app.json'),
Expand All @@ -22,14 +30,16 @@ export async function addLinting(host: Tree, options: NormalizedSchema) {
skipFormat: true,
});

updateJson(
host,
joinPathFragments(options.appProjectRoot, '.eslintrc.json'),
(json) => {
json.extends = [...reactEslintJson.extends, ...json.extends];
return json;
}
);
if (linter === Linter.EsLint) {
updateJson(
host,
joinPathFragments(options.appProjectRoot, '.eslintrc.json'),
(json) => {
json.extends = [...reactEslintJson.extends, ...json.extends];
return json;
}
);
}

installTask = await addDependenciesToPackageJson(
host,
Expand Down

0 comments on commit 4f758d4

Please sign in to comment.