You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-14Lines changed: 38 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,11 @@ Install the package for your corresponding language as a development dependency:
49
49
50
50
## Configuration
51
51
52
-
After installing the lint configuration packages, follow the configuration instructions for your project language:
52
+
After installing the lint configuration packages, determine if the project is using CommonJS or ES modules by default. ES modules will specify ["type": "module"](https://nodejs.org/api/packages.html#type) in`package.json`. The following configuration examples are ES modules. Use the file extension `mjs`forES modulesin CommonJS projects, e.g. `eslint.config.mjs` will be common for Angular.
53
+
54
+
With flat configuration, the `files` declaration must use a glob to match files in subdirectories. See [Glob-Based Configs](https://eslint.org/docs/latest/use/configure/migration-guide#glob-based-configs).
55
+
56
+
Follow the instructions for your project's language:
53
57
54
58
### JavaScript configuration
55
59
@@ -66,7 +70,7 @@ export default defineConfig([
66
70
67
71
### TypeScript configuration
68
72
69
-
Use `@ni/eslint-config-typescript` configurations in the [ESLint flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new) (`eslint.config.js`). Set the `parserOptions.project` to the project's TypeScript configuration to correctly enable [linting with type information](https://typescript-eslint.io/getting-started/typed-linting).
73
+
Use `@ni/eslint-config-typescript` configurations in the [ESLint flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new) (`eslint.config.js`). Set the `languageOptions.parserOptions.project` to the project's TypeScript configuration to correctly enable [linting with type information](https://typescript-eslint.io/getting-started/typed-linting).
70
74
71
75
```js
72
76
import { defineConfig } from 'eslint/config';
@@ -79,7 +83,7 @@ export default defineConfig([
79
83
languageOptions: {
80
84
parserOptions: {
81
85
project: ['./tsconfig.json'],
82
-
tsConfigRootDir: import.meta.dirname,
86
+
tsconfigRootDir: import.meta.dirname,
83
87
},
84
88
},
85
89
},
@@ -90,38 +94,58 @@ export default defineConfig([
90
94
91
95
ESLint support for Angular is provided by [`angular-eslint`](https://github.com/angular-eslint/angular-eslint#readme).
92
96
93
-
1. **For single and multi-project workspaces**, [add angular-eslint](https://github.com/angular-eslint/angular-eslint#quick-start). Remove the `angular-eslint` and `eslint` dependencies from `package.json`.
97
+
1. **For single and multi-project workspaces**, [add angular-eslint](https://github.com/angular-eslint/angular-eslint#quick-start).
94
98
```bash
95
99
ng add angular-eslint
96
100
```
97
-
2. **For multi-project workspaces**, [configure each project](https://github.com/angular-eslint/angular-eslint#adding-eslint-configuration-to-an-existing-angular-cli-project-which-has-no-existing-linter), and then enable future generated projects to be configured as well.
101
+
2. Remove the `angular-eslint`, `typescript-eslint`, and `eslint` development dependencies from `package.json`.
102
+
3. **For multi-project workspaces**, [configure each project](https://github.com/angular-eslint/angular-eslint#adding-eslint-configuration-to-an-existing-angular-cli-project-which-has-no-existing-linter), and thenenable future generated projects to be configured as well.
98
103
```bash
99
104
> ng g angular-eslint:add-eslint-to-project <PROJECT NAME>
100
105
> ng config cli.schematicCollections "[\"angular-eslint\"]"
101
106
```
102
-
3. Use the NI configured rules for Angular TypeScript code and Angular templates in the [ESLint flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new) (`eslint.config.js`). Set the `parserOptions.project` configuration to the project's TypeScript configuration to correctly enable [linting with type information](https://typescript-eslint.io/getting-started/typed-linting)..
107
+
4. Replace `eslint.config.js` with the following `eslint.config.mjs` [flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new) of rules for Typescript, Angular templates, and JavaScript.
103
108
```js
104
109
import { defineConfig } from 'eslint/config';
105
110
import { angularTypescriptConfig, angularTemplateConfig } from '@ni/eslint-config-angular';
111
+
import { javascriptConfig } from '@ni/eslint-config-javascript';
106
112
107
113
export default defineConfig([
114
+
{
115
+
// JavaScript rules fail to parse the HTML files that are added below. Therefore, the JavaScript
116
+
// configuration must now match the correct files to avoid an error.
117
+
files: ['**/*.js'],
118
+
extends: javascriptConfig
119
+
},
108
120
{
109
121
files: ['**/*.ts'],
110
122
extends: angularTypescriptConfig,
111
123
languageOptions: {
112
124
parserOptions: {
113
-
project: ['./tsconfig.json'],
114
-
tsConfigRootDir: import.meta.dirname,
115
-
},
116
-
},
125
+
// The `languageOptions.parserOptions.projectService` option is recommended but does not identify
126
+
// tsconfig.*.json files. Use the older `project` configuration instead. The general `tsconfig.json` is
127
+
// declared last in the hope that the application and test configurations will apply to their
4. Evaluate the [project specific rule groups](#evaluate-project-specific-rule-groups) to manually add to your lint configuration. For Angular applications in particular, consider enabling the [`[application-prefix]`](#application-prefix) rule group.
147
+
5. Evaluate the [project specific rule groups](#evaluate-project-specific-rule-groups) to manually add to your lint configuration. For Angular applications in particular, consider enabling the [`[application-prefix]`](#application-prefix) rule group.
148
+
6. With flat configurations, configurations forsubdirectories must be defined at the root except for projects which are already root configurations. ESLint loads only one flat configuration resolved relative to the working directory (e.g. root). Support for defining configurationsin subdirectories is experimental behind an active feature flag. The angular-eslint builder does not support this feature flag. See ESLint [issue #18385](https://github.com/eslint/eslint/issues/18385).
125
149
126
150
### Playwright configuration
127
151
@@ -140,7 +164,7 @@ export default defineConfig([
140
164
languageOptions: {
141
165
parserOptions: {
142
166
project: ['./tsconfig.json'],
143
-
tsConfigRootDir: import.meta.dirname,
167
+
tsconfigRootDir: import.meta.dirname,
144
168
},
145
169
}
146
170
}
@@ -314,7 +338,7 @@ Instead of using the `extends` property, import the configuration packages you n
0 commit comments