I'm using ESLint for the first time. I installed it in my Angular project using ng add @angular-eslint/schematics
per https://github.com/angular-eslint/angular-eslint/blob/main/README.md.
The eslint.config.mjs
file created by the installation looked like this:
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
export default [
{files: ["**/*.{js,mjs,cjs,ts}"]},
{files: ["**/*.js"], languageOptions: {sourceType: "script"}},
{languageOptions: { globals: globals.browser }},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
];
Running ESLint with no adjustment to this configuration, using ng lint
, I received the report "628 problems (621 errors, 7 warnings)". Many of these violations are of a couple of rules that aren't of concern to me right now, so I want to turn them off. One of them is prefer-const
, so I tried this, based on examples from https://eslint.org/docs/latest/use/configure/rules (in case anyone notices, it's Prettier that's changing double quotes to single quotes on save):
import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
export default [
{ files: ['**/*.{js,mjs,cjs,ts}'], rules: { 'prefer-const': 'off' } },
{ files: ['**/*.js'], languageOptions: { sourceType: 'script' } },
{ languageOptions: { globals: globals.browser } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
];
Running ESLint, I got the same result as the first time. Going further in stages, I wound up in overdrive:
import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
export default [
{ files: ['**/*.{js,mjs,cjs,ts}'], rules: { 'prefer-const': 'off' } },
{ files: ['**/*.js'], languageOptions: { sourceType: 'script' }, rules: { 'prefer-const': 'off' } },
{ rules: { 'prefer-const': 'off' } },
{ languageOptions: { globals: globals.browser } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{ rules: { 'prefer-const': 'off' } },
];
Still, no change in the outcome. Can anyone see what's wrong?
UPDATE: I pared the config file down to
export default [];
and got the same result. So I have no idea what it's looking at!
The problem turned out to be that even though the eslint.config.mjs
file was installed, a .eslintrc.json
file, which I thought was supposed to be deprecated, was also installed, and ESLint was using that. I removed it to see if the linter would pick up on the .mjs
file but I got an error that way. So I restored .eslintrc.json
, added my rule exceptions to that file, and it worked as expected. Shaking my head.