Angular-ESLint rule exclusion and eslint.config.mjs in Angular project

Discussão em 'Angular' iniciado por Green Grasso Holm, Outubro 29, 2024.

  1. 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?

    Continue reading...

Compartilhe esta Página