Skip to content

Commit

Permalink
feat(linter): default lintFilePatterns to {projectRoot} (#20313)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav authored Nov 27, 2023
1 parent 98883bb commit ff5d1be
Show file tree
Hide file tree
Showing 78 changed files with 343 additions and 597 deletions.
3 changes: 1 addition & 2 deletions docs/generated/packages/eslint/executors/lint.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"lintFilePatterns": {
"type": "array",
"description": "One or more files/dirs/globs to pass directly to ESLint's `lintFiles()` method.",
"default": [],
"default": ["{projectRoot}"],
"items": { "type": "string" }
},
"format": {
Expand Down Expand Up @@ -140,7 +140,6 @@
"default": true
}
},
"required": ["lintFilePatterns"],
"examplesFile": "Linter can be configured in multiple ways. The basic way is to provide only `lintFilePatterns`, which is a mandatory property. This tells us where to look for files to lint.\n\n`project.json`:\n\n```json\n\"lint\": {\n \"executor\": \"@nx/eslint:lint\",\n \"options\": {\n \"lintFilePatterns\": [\"apps/frontend/**/*.ts\"]\n }\n}\n```\n\n## Examples\n\n{% tabs %}\n{% tab label=\"Fixing linter issues\" %}\n\nLinter provides an automated way of fixing known issues. To ensure that those changes are properly cached, we need to add an `outputs` property to the `lint` target. Omitting the `outputs` property would produce an invalid cache record. Both of these properties are set by default when scaffolding a new project.\n\n```json\n\"lint\": {\n \"executor\": \"@nx/eslint:lint\",\n \"outputs\": [\"{options.outputFile}\"],\n \"options\": {\n \"lintFilePatterns\": [\"apps/frontend/**/*.ts\"]\n }\n}\n```\n\nWith these settings, we can run the command with a `--fix` flag:\n\n```bash\nnx run frontend:lint --fix\n```\n\nWe can also set this flag via project configuration to always fix files when running lint:\n\n```json\n\"lint\": {\n \"executor\": \"@nx/eslint:lint\",\n \"outputs\": [\"{options.outputFile}\"],\n \"options\": {\n \"lintFilePatterns\": [\"apps/frontend/**/*.ts\"],\n \"fix\": true\n }\n}\n```\n\n{% /tab %}\n{% tab label=\"Custom output format\" %}\n\nESLint executor uses the `stylish` output format by default. You can change this by specifying the `format` property:\n\n```json\n\"lint\": {\n \"executor\": \"@nx/eslint:lint\",\n \"outputs\": [\"{options.outputFile}\"],\n \"options\": {\n \"lintFilePatterns\": [\"apps/frontend/**/*.ts\"],\n \"format\": \"compact\"\n }\n}\n```\n\n{% /tab %}\n{% tab label=\"Silence warnings\" %}\n\nMigrated or legacy projects tend to have an overwhelming amount of lint errors. We might want to change those temporarily to be warnings so they don't block the development. But they would still clutter the report. We can run the command with `--quiet` to hide warning (errors would still break the lint):\n\n```bash\nnx run frontend:lint --quiet\n```\n\nWe can also set this via project configuration as a default option.\n\n```json\n\"lint\": {\n \"executor\": \"@nx/eslint:lint\",\n \"outputs\": [\"{options.outputFile}\"],\n \"options\": {\n \"lintFilePatterns\": [\"apps/frontend/**/*.ts\"],\n \"quiet\": true\n }\n}\n```\n\n{% /tab %}\n{% tab label=\"Flat Config file\" %}\n\n`ESLint` provides several ways of specifying the configuration. The default one is using `.eslintrc.json` but you can override it by setting the `eslintConfig` flag. The new `Flat Config` is now also supported:\n\n```json\n\"lint\": {\n \"executor\": \"@nx/eslint:lint\",\n \"outputs\": [\"{options.outputFile}\"],\n \"options\": {\n \"lintFilePatterns\": [\"apps/frontend/**/*.ts\"],\n \"eslintConfig\": \"eslint.config.js\"\n }\n}\n```\n\n**Note:** In contrast to other configuration formats, the `Flat Config` requires that all configuration files are converted to `eslint.config.js`. Built-in migrations and generators support only `.eslintrc.json` at the moment.\n\n{% /tab %}\n{% /tabs %}\n\n---\n",
"presets": []
},
Expand Down
4 changes: 1 addition & 3 deletions docs/shared/node-server-tutorial/affected-project-graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": { "lintFilePatterns": ["auth/**/*.ts"] },
"configurations": {}
},
"test": {
Expand Down Expand Up @@ -155,7 +154,6 @@
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": { "lintFilePatterns": ["e2e/**/*.{js,ts}"] },
"configurations": {}
}
}
Expand Down Expand Up @@ -324,7 +322,7 @@
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": { "lintFilePatterns": ["./**/*.ts"] },
"options": { "lintFilePatterns": ["./src"] },
"configurations": {}
}
}
Expand Down
2 changes: 0 additions & 2 deletions docs/shared/node-server-tutorial/final-project-graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": { "lintFilePatterns": ["auth/**/*.ts"] },
"configurations": {}
},
"test": {
Expand Down Expand Up @@ -137,7 +136,6 @@
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": { "lintFilePatterns": ["e2e/**/*.{js,ts}"] },
"configurations": {}
}
}
Expand Down
5 changes: 2 additions & 3 deletions docs/shared/node-server-tutorial/initial-project-graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": { "lintFilePatterns": ["auth/**/*.ts"] },

"configurations": {}
},
"test": {
Expand Down Expand Up @@ -137,7 +137,6 @@
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": { "lintFilePatterns": ["e2e/**/*.{js,ts}"] },
"configurations": {}
}
}
Expand Down Expand Up @@ -305,7 +304,7 @@
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": { "lintFilePatterns": ["./**/*.ts"] },
"options": { "lintFilePatterns": ["./src"] },
"configurations": {}
}
}
Expand Down
13 changes: 2 additions & 11 deletions e2e/angular-core/src/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,7 @@ const angularV1Json = (appName: string) => `{
}
},
"lint": {
"builder": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"${appName}/src/**/*.ts",
"${appName}/src/**/*.html"
]
}
"builder": "@nx/eslint:lint"
},
"test": {
"builder": "@nx/jest:jest",
Expand Down Expand Up @@ -159,10 +153,7 @@ const angularV1Json = (appName: string) => `{
},
"lint": {
"builder": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["${appName}-e2e/**/*.{js,ts}"]
}
"outputs": ["{options.outputFile}"]
}
},
"tags": [],
Expand Down
6 changes: 0 additions & 6 deletions e2e/angular-core/src/ng-add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,6 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
const projectConfig = readJson(`apps/${project}/project.json`);
expect(projectConfig.targets.lint).toStrictEqual({
executor: '@nx/eslint:lint',
options: {
lintFilePatterns: [
`apps/${project}/src/**/*.ts`,
`apps/${project}/src/**/*.html`,
],
},
});

let output = runCLI(`lint ${project}`);
Expand Down
8 changes: 0 additions & 8 deletions e2e/eslint/src/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,6 @@ describe('Linter', () => {
];
return json;
});
updateJson(`libs/${mylib}/project.json`, (json) => {
json.targets.lint.options.lintFilePatterns = [
`libs/${mylib}/**/*.ts`,
`libs/${mylib}/project.json`,
`libs/${mylib}/package.json`,
];
return json;
});
});

it('should report dependency check issues', () => {
Expand Down
21 changes: 0 additions & 21 deletions e2e/nx-misc/src/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,6 @@ describe('Workspace Tests', () => {
const project = readJson(join(newPath, 'project.json'));
expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.targets.lint.options.lintFilePatterns).toEqual([
`shared/${lib1}/data-access/**/*.ts`,
`shared/${lib1}/data-access/package.json`,
]);

/**
* Check that the import in lib2 has been updated
Expand Down Expand Up @@ -343,11 +339,6 @@ describe('Workspace Tests', () => {
const lib3Config = readJson(join(lib3, 'project.json'));
expect(lib3Config.implicitDependencies).toEqual([newName]);

expect(project.targets.lint.options.lintFilePatterns).toEqual([
`shared/${lib1}/data-access/**/*.ts`,
`shared/${lib1}/data-access/package.json`,
]);

/**
* Check that the import in lib2 has been updated
*/
Expand Down Expand Up @@ -479,10 +470,6 @@ describe('Workspace Tests', () => {
const project = readJson(join(newPath, 'project.json'));
expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.targets.lint.options.lintFilePatterns).toEqual([
`packages/shared/${lib1}/data-access/**/*.ts`,
`packages/shared/${lib1}/data-access/package.json`,
]);
expect(project.tags).toEqual([]);

/**
Expand Down Expand Up @@ -615,10 +602,6 @@ describe('Workspace Tests', () => {
const project = readJson(join(newPath, 'project.json'));
expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.targets.lint.options.lintFilePatterns).toEqual([
`${lib1}/data-access/**/*.ts`,
`${lib1}/data-access/package.json`,
]);

/**
* Check that the import in lib2 has been updated
Expand Down Expand Up @@ -736,10 +719,6 @@ describe('Workspace Tests', () => {
const project = readJson(join(newPath, 'project.json'));
expect(project).toBeTruthy();
expect(project.sourceRoot).toBe(`${newPath}/src`);
expect(project.targets.lint.options.lintFilePatterns).toEqual([
`shared/${lib1}/data-access/**/*.ts`,
`shared/${lib1}/data-access/package.json`,
]);

/**
* Check that the import in lib2 has been updated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ describe('addLinting generator', () => {
const project = readProjectConfiguration(tree, appProjectName);
expect(project.targets.lint).toEqual({
executor: '@nx/eslint:lint',
options: {
lintFilePatterns: [
`${appProjectRoot}/**/*.ts`,
`${appProjectRoot}/**/*.html`,
],
},
outputs: ['{options.outputFile}'],
});
});
Expand Down
5 changes: 0 additions & 5 deletions packages/angular/src/generators/add-linting/add-linting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
Tree,
} from '@nx/devkit';
import { Linter, lintProjectGenerator } from '@nx/eslint';
import { mapLintPattern } from '@nx/eslint/src/generators/lint-project/lint-project';
import { addAngularEsLintDependencies } from './lib/add-angular-eslint-dependencies';
import type { AddLintingGeneratorSchema } from './schema';
import {
Expand All @@ -30,10 +29,6 @@ export async function addLintingGenerator(
joinPathFragments(options.projectRoot, 'tsconfig.app.json'),
],
unitTestRunner: options.unitTestRunner,
eslintFilePatterns: [
mapLintPattern(options.projectRoot, 'ts', rootProject),
mapLintPattern(options.projectRoot, 'html', rootProject),
],
setParserOptionsProject: options.setParserOptionsProject,
skipFormat: true,
rootProject: rootProject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,6 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
},
"lint": {
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"apps/my-dir/my-app/**/*.ts",
"apps/my-dir/my-app/**/*.html",
],
},
"outputs": [
"{options.outputFile}",
],
Expand Down Expand Up @@ -339,11 +333,6 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
},
"lint": {
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"apps/my-dir/my-app-e2e/**/*.{js,ts}",
],
},
"outputs": [
"{options.outputFile}",
],
Expand Down Expand Up @@ -503,12 +492,6 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
},
"lint": {
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"apps/my-app/**/*.ts",
"apps/my-app/**/*.html",
],
},
"outputs": [
"{options.outputFile}",
],
Expand Down Expand Up @@ -575,11 +558,6 @@ exports[`app --project-name-and-root-format=derived should generate correctly wh
},
"lint": {
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"apps/my-app-e2e/**/*.{js,ts}",
],
},
"outputs": [
"{options.outputFile}",
],
Expand Down Expand Up @@ -963,12 +941,6 @@ exports[`app nested should create project configs 1`] = `
},
"lint": {
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"my-dir/my-app/**/*.ts",
"my-dir/my-app/**/*.html",
],
},
"outputs": [
"{options.outputFile}",
],
Expand Down Expand Up @@ -1035,11 +1007,6 @@ exports[`app nested should create project configs 2`] = `
},
"lint": {
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"my-dir/my-app-e2e/**/*.{js,ts}",
],
},
"outputs": [
"{options.outputFile}",
],
Expand Down Expand Up @@ -1112,12 +1079,6 @@ exports[`app not nested should create project configs 1`] = `
},
"lint": {
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"my-app/**/*.ts",
"my-app/**/*.html",
],
},
"outputs": [
"{options.outputFile}",
],
Expand Down Expand Up @@ -1184,11 +1145,6 @@ exports[`app not nested should create project configs 2`] = `
},
"lint": {
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"my-app-e2e/**/*.{js,ts}",
],
},
"outputs": [
"{options.outputFile}",
],
Expand Down
11 changes: 0 additions & 11 deletions packages/angular/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,6 @@ describe('app', () => {
.toMatchInlineSnapshot(`
{
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"my-app/**/*.ts",
"my-app/**/*.html",
],
},
"outputs": [
"{options.outputFile}",
],
Expand All @@ -521,11 +515,6 @@ describe('app', () => {
.toMatchInlineSnapshot(`
{
"executor": "@nx/eslint:lint",
"options": {
"lintFilePatterns": [
"my-app-e2e/**/*.{js,ts}",
],
},
"outputs": [
"{options.outputFile}",
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './add-files';
export * from './add-path-mapping';
export * from './normalize-options';
export * from './update-linting-file-patterns';
export * from './update-tsconfig-included-files';

This file was deleted.

Loading

1 comment on commit ff5d1be

@vercel
Copy link

@vercel vercel bot commented on ff5d1be Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.