Skip to content

Commit 0238a03

Browse files
beaussanleosvelperez
authored andcommitted
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 <[email protected]> (cherry picked from commit dfbfe3b)
1 parent bddf35a commit 0238a03

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

packages/eslint/src/generators/init/global-eslint-config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ export const getGlobalFlatEslintConfiguration = (
158158
files: [
159159
'**/*.ts',
160160
'**/*.tsx',
161+
'**/*.cts',
162+
'**/*.mts',
161163
'**/*.js',
162164
'**/*.jsx',
163165
'**/*.cjs',

packages/eslint/src/generators/lint-project/lint-project.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ describe('@nx/eslint:lint-project', () => {
327327
files: [
328328
"**/*.ts",
329329
"**/*.tsx",
330+
"**/*.cts",
331+
"**/*.mts",
330332
"**/*.js",
331333
"**/*.jsx",
332334
"**/*.cjs",
@@ -396,6 +398,8 @@ describe('@nx/eslint:lint-project', () => {
396398
files: [
397399
"**/*.ts",
398400
"**/*.tsx",
401+
"**/*.cts",
402+
"**/*.mts",
399403
"**/*.js",
400404
"**/*.jsx",
401405
"**/*.cjs",

packages/eslint/src/plugins/plugin.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,18 @@ export interface EslintPluginOptions {
3434
extensions?: string[];
3535
}
3636

37-
const DEFAULT_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx', 'html', 'vue'];
37+
const DEFAULT_EXTENSIONS = [
38+
'ts',
39+
'cts',
40+
'mts',
41+
'tsx',
42+
'js',
43+
'cjs',
44+
'mjs',
45+
'jsx',
46+
'html',
47+
'vue',
48+
];
3849
const PROJECT_CONFIG_FILENAMES = ['project.json', 'package.json'];
3950
const ESLINT_CONFIG_GLOB_V1 = combineGlobPatterns(
4051
ESLINT_CONFIG_FILENAMES.map((f) => `**/${f}`)

0 commit comments

Comments
 (0)