fix(linter): add cjs, cts, mjs, and mts to the default extensions for the inference plugin (#29534)

## Current Behavior

On the default generated eslint on a ts reference workspace, the config
allows for linting of cjs and mjs files

```js
const nx = require('@nx/eslint-plugin');

module.exports = [
  ...nx.configs['flat/base'],
  ...nx.configs['flat/typescript'],
  ...nx.configs['flat/javascript'],
  {
    ignores: ['**/dist'],
  },
  {
    files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
    rules: {
      '@nx/enforce-module-boundaries': [
        'error',
        {
          enforceBuildableLibDependency: true,
          allow: ['^.*/eslint(\\.base)?\\.config\\.[cm]?js$'],
          depConstraints: [
            {
              sourceTag: '*',
              onlyDependOnLibsWithTags: ['*'],
            },
          ],
        },
      ],
    },
  },
  {
    files: [
      '**/*.ts',
      '**/*.tsx',
      '**/*.js',
      '**/*.jsx',
      '**/*.cjs',
      '**/*.mjs',
    ],
    // Override or add rules here
    rules: {},
  },
];

```


However, the default glob is not matching them

## Expected Behavior
All cjs and mjs files are included in the lint target detection

---------

Co-authored-by: Leosvel Pérez Espinosa <leosvel.perez.espinosa@gmail.com>
This commit is contained in:
Nicolas Beaussart 2025-01-29 12:24:35 +01:00 committed by GitHub
parent e2e9e6cb36
commit dfbfe3b786
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 1 deletions

View File

@ -158,6 +158,8 @@ export const getGlobalFlatEslintConfiguration = (
files: [
'**/*.ts',
'**/*.tsx',
'**/*.cts',
'**/*.mts',
'**/*.js',
'**/*.jsx',
'**/*.cjs',

View File

@ -327,6 +327,8 @@ describe('@nx/eslint:lint-project', () => {
files: [
"**/*.ts",
"**/*.tsx",
"**/*.cts",
"**/*.mts",
"**/*.js",
"**/*.jsx",
"**/*.cjs",
@ -396,6 +398,8 @@ describe('@nx/eslint:lint-project', () => {
files: [
"**/*.ts",
"**/*.tsx",
"**/*.cts",
"**/*.mts",
"**/*.js",
"**/*.jsx",
"**/*.cjs",

View File

@ -34,7 +34,18 @@ export interface EslintPluginOptions {
extensions?: string[];
}
const DEFAULT_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx', 'html', 'vue'];
const DEFAULT_EXTENSIONS = [
'ts',
'cts',
'mts',
'tsx',
'js',
'cjs',
'mjs',
'jsx',
'html',
'vue',
];
const PROJECT_CONFIG_FILENAMES = ['project.json', 'package.json'];
const ESLINT_CONFIG_GLOB_V1 = combineGlobPatterns(
ESLINT_CONFIG_FILENAMES.map((f) => `**/${f}`)