Skip to content

Commit c53c13a

Browse files
ByronDWallclaude
andcommitted
feat(eslint-configs): add runtime warnings for legacy .eslintrc usage
Surface migration guide when consumers haven't migrated to flat config: - Warn if loaded from a .eslintrc file (array export won't work there) - Warn if legacy .eslintrc files exist alongside flat config Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cb5fcb5 commit c53c13a

File tree

2 files changed

+84
-0
lines changed
  • packages-backend/eslint-config-node
  • packages/eslint-config-mc-app

2 files changed

+84
-0
lines changed

packages-backend/eslint-config-node/index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,45 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const migrationGuide =
5+
'node_modules/@commercetools-frontend/eslint-config-node/migrations/v27.md';
6+
7+
// Detect if loaded from a legacy .eslintrc file (the array export won't work there)
8+
const caller = module.parent?.filename || '';
9+
if (/\.eslintrc/.test(caller)) {
10+
console.error(
11+
'\n\u274c @commercetools-frontend/eslint-config-node v27 exports a flat config array.\n' +
12+
' It cannot be used in .eslintrc files. Migrate to eslint.config.js.\n' +
13+
' Guide: ' +
14+
migrationGuide +
15+
'\n'
16+
);
17+
}
18+
19+
// Detect leftover legacy config files and warn
20+
const projectRoot = process.cwd();
21+
const legacyPatterns = [
22+
'.eslintrc',
23+
'.eslintrc.js',
24+
'.eslintrc.cjs',
25+
'.eslintrc.json',
26+
'.eslintrc.yml',
27+
'.eslintrc.yaml',
28+
];
29+
const foundLegacy = legacyPatterns.filter((name) =>
30+
fs.existsSync(path.join(projectRoot, name))
31+
);
32+
if (foundLegacy.length > 0) {
33+
console.warn(
34+
'\n\u26a0\ufe0f @commercetools-frontend/eslint-config-node v27 uses ESLint 9 flat config.\n' +
35+
` Found legacy config file(s): ${foundLegacy.join(', ')}\n` +
36+
' These files are ignored by ESLint 9 and your subdirectory rules will not be applied.\n' +
37+
' Guide: ' +
38+
migrationGuide +
39+
'\n'
40+
);
41+
}
42+
143
const babelParser = require('@babel/eslint-parser');
244
const typescriptPlugin = require('@typescript-eslint/eslint-plugin');
345
const typescriptParser = require('@typescript-eslint/parser');

packages/eslint-config-mc-app/index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,48 @@
2828

2929
process.env.BABEL_ENV = 'production';
3030

31+
const fs = require('fs');
32+
const path = require('path');
33+
34+
const migrationGuide =
35+
'node_modules/@commercetools-frontend/eslint-config-mc-app/migrations/v27.md';
36+
37+
// Detect if loaded from a legacy .eslintrc file (the array export won't work there)
38+
const caller = module.parent?.filename || '';
39+
if (/\.eslintrc/.test(caller)) {
40+
console.error(
41+
'\n\u274c @commercetools-frontend/eslint-config-mc-app v27 exports a flat config array.\n' +
42+
' It cannot be used in .eslintrc files. Migrate to eslint.config.js.\n' +
43+
' Guide: ' +
44+
migrationGuide +
45+
'\n'
46+
);
47+
}
48+
49+
// Detect leftover legacy config files and warn
50+
const projectRoot = process.cwd();
51+
const legacyPatterns = [
52+
'.eslintrc',
53+
'.eslintrc.js',
54+
'.eslintrc.cjs',
55+
'.eslintrc.json',
56+
'.eslintrc.yml',
57+
'.eslintrc.yaml',
58+
];
59+
const foundLegacy = legacyPatterns.filter((name) =>
60+
fs.existsSync(path.join(projectRoot, name))
61+
);
62+
if (foundLegacy.length > 0) {
63+
console.warn(
64+
'\n\u26a0\ufe0f @commercetools-frontend/eslint-config-mc-app v27 uses ESLint 9 flat config.\n' +
65+
` Found legacy config file(s): ${foundLegacy.join(', ')}\n` +
66+
' These files are ignored by ESLint 9 and your subdirectory rules will not be applied.\n' +
67+
' Guide: ' +
68+
migrationGuide +
69+
'\n'
70+
);
71+
}
72+
3173
const babelParser = require('@babel/eslint-parser');
3274
const typescriptPlugin = require('@typescript-eslint/eslint-plugin');
3375
const typescriptParser = require('@typescript-eslint/parser');

0 commit comments

Comments
 (0)