Is this a properly-configured eslint.config.js file for an Angular project?

Discussão em 'Angular' iniciado por hairbo, Fevereiro 11, 2025.

  1. hairbo

    hairbo Guest

    I've had a hard time finding a good example of a well-configured eslint.config.js file for an Angular project. Through some trial and error, I managed to put this together. The right thing appears to happen when ng lint runs, but an earlier version of my config file also ran properly (against ESLint 8.57.0), and that thing was objectively a mess.

    This is running against Angular 19 and ESLint 9.20.0. Any advice is appreciated. I'm a bit less interested in which rules I should have enabled or disabled, and mostly interested in whether the structure is "right".

    Thanks in advance!

    // @ts-check
    import eslint from '@eslint/js';
    import rxjs from '@smarttools/eslint-plugin-rxjs';
    import angular from 'angular-eslint';
    import tseslint from 'typescript-eslint';

    export default tseslint.config(
    {
    languageOptions: {
    parserOptions: {
    projectService: true,
    tsconfigRootDir: import.meta.dirname,
    },
    },
    files: ['**/*.ts'],
    plugins: { rxjs },
    extends: [
    eslint.configs.recommended,
    ...tseslint.configs.recommended,
    ...tseslint.configs.stylistic,
    ...angular.configs.tsRecommended,
    ],
    processor: angular.processInlineTemplates,
    rules: {
    'accessor-pairs': 'off',
    'no-prototype-builtins': 'off',
    '@typescript-eslint/no-unused-vars': 'off',
    '@typescript-eslint/no-explicit-any': 'off',
    '@typescript-eslint/consistent-type-definitions': 'off',
    '@typescript-eslint/consistent-indexed-object-style': 'off',
    '@typescript-eslint/consistent-generic-constructors': 'off',
    'rxjs/no-async-subscribe': 'warn',
    'rxjs/no-create': 'warn',
    'rxjs/no-index': 'warn',
    'rxjs/no-ignored-replay-buffer': 'warn',
    'rxjs/no-ignored-takewhile-value': 'warn',
    'rxjs/no-internal': 'warn',
    'rxjs/no-nested-subscribe': 'warn',
    'rxjs/no-redundant-notify': 'warn',
    'rxjs/no-subject-unsubscribe': 'warn',
    'rxjs/no-unbound-methods': 'warn',
    'rxjs/no-unsafe-subject-next': 'warn',
    },
    },
    {
    files: ['**/*.html'],
    ignores: ['**/dev_index.html'],
    extends: [
    ...angular.configs.templateRecommended,
    ...angular.configs.templateAccessibility,
    ],
    rules: {
    '@angular-eslint/template/label-has-associated-control': 'off',
    '@angular-eslint/template/valid-aria': 'off',
    '@angular-eslint/template/alt-text': 'error',
    '@angular-eslint/template/no-autofocus': 'off',
    '@angular-eslint/template/no-distracting-elements': 'error',
    '@angular-eslint/template/use-track-by-function': 'error',
    '@angular-eslint/template/prefer-self-closing-tags': 'error',
    '@angular-eslint/template/click-events-have-key-events': 'off',
    '@angular-eslint/template/interactive-supports-focus': 'off',
    },
    },
    );

    Continue reading...

Compartilhe esta Página