Nx converter to ESLint's flat config breaks linting
Asked Answered
A

0

6

Problem

After using nx g @nx/eslint:convert-to-flat-config described here I got automatically generated config files like this (example for a library named "not-found"):

const { FlatCompat } = require('@eslint/eslintrc');
const baseConfig = require('../../eslint.config.js');
const js = require('@eslint/js');
const compat = new FlatCompat({
  baseDirectory: __dirname,
  recommendedConfig: js.configs.recommended,
});
module.exports = [
  ...baseConfig,
  ...compat
    .config({
      extends: [
        'plugin:@nx/angular',
        'plugin:@angular-eslint/template/process-inline-templates',
      ],
    })
    .map((config) => ({
      ...config,
      files: ['libs/not-found/**/*.ts'],
      rules: {
        '@angular-eslint/directive-selector': [
          'error',
          {
            type: 'attribute',
            prefix: 'npp',
            style: 'camelCase',
          },
        ],
        '@angular-eslint/component-selector': [
          'error',
          {
            type: 'element',
            prefix: 'npp',
            style: 'kebab-case',
          },
        ],
      },
    })),
  ...compat
    .config({
      plugins: ['deprecation'],
      parserOptions: { project: 'libs/not-found/tsconfig.*?.json' },
    })
    .map((config) => ({
      ...config,
      files: ['libs/not-found/**/*.ts'],
      rules: { 'deprecation/deprecation': 'warn' },
    })),
  ...compat
    .config({ extends: ['plugin:@nx/angular-template'] })
    .map((config) => ({
      ...config,
      files: ['libs/not-found/**/*.html'],
      rules: {},
    })),
];

Now executing the command nx run not-found:lint produces following error:

Linting "not-found"...

Error: You have attempted to use the lint rule deprecation/deprecation which requires the full TypeScript type-checker to be available, but you do not have `parserOptions.project` configured to point at your project tsconfig.json files in the relevant TypeScript file "overrides" block of your project ESLint config /path/to/my/monorepo/libs/not-found/eslint.config.js

Please see https://nx.dev/guides/eslint for full guidance on how to resolve this issue.

This problem occurs to all apps and libs inside the monorepo now. There is no working-scenario, with which i could compare.

Investigation

I visited the referenced link, but the docs there refer to the old eslintrc config format.

I am confused as to why the error message mentions a 'relevant TypeScript file "overrides" block'. The Nx docs say that overrides are no longer used:

use a flat cascading of rules (instead of a mix of rules and overrides)

The referenced official migration guide supports this impression.

I googled the error message, but the only solutions I found referred to the old eslintrc format and suggested adding the parserOptions.project property in the overrides block. But this was already there in my configs and is still there after the conversion, as you can see in the source-code i posted.

enter image description here

Question

What steps do i have to take, to complete the conversion to a flat config format and have the nx lint command working again?

Aikens answered 26/3 at 9:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.