Skip to content

Commit 59a4a1d

Browse files
committed
feat(cli): Show deprecation message for legacy eslint configs
1 parent 5fb4148 commit 59a4a1d

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

docs/docs/app-configuration-redwood-toml.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,19 @@ To run a Cedar app in a container or VM, you'll want to set both the web and api
194194

195195
You can also configure these values via `REDWOOD_WEB_HOST` and `REDWOOD_API_HOST`.
196196
And if you set `NODE_ENV` to production, these will be the defaults anyway.
197+
198+
## ESLint Configuration
199+
200+
| Key | Description | Default |
201+
| :-------------------------- | :---------------------------------------------------------------------------- | :------ |
202+
| `eslintLegacyConfigWarning` | Show deprecation warnings when legacy ESLint configuration files are detected | `true` |
203+
204+
The `eslintLegacyConfigWarning` option controls whether Cedar shows deprecation warnings when it detects legacy ESLint configuration files (like `.eslintrc.js`, `.eslintrc.json`, or `eslint` in `package.json`).
205+
206+
To disable these warnings, set it to `false`:
207+
208+
```toml title="redwood.toml"
209+
eslintLegacyConfigWarning = false
210+
```
211+
212+
This can be useful if you need to temporarily maintain legacy ESLint configurations while transitioning to the new flat config format.

packages/cli/src/commands/lint.js

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,83 @@
11
import fs from 'node:fs'
2+
import path from 'node:path'
23

34
import execa from 'execa'
45
import { terminalLink } from 'termi-link'
56

67
import { recordTelemetryAttributes } from '@cedarjs/cli-helpers'
78

8-
import { getPaths } from '../lib/index.js'
9+
import { getPaths, getConfig } from '../lib/index.js'
10+
11+
/**
12+
* Checks for legacy ESLint configuration files in the project root
13+
* @returns {string[]} Array of legacy config file names found
14+
*/
15+
function detectLegacyEslintConfig() {
16+
const projectRoot = getPaths().base
17+
const legacyConfigFiles = [
18+
'.eslintrc.js',
19+
'.eslintrc.cjs',
20+
'.eslintrc.json',
21+
'.eslintrc.yaml',
22+
'.eslintrc.yml',
23+
]
24+
25+
const foundLegacyFiles = []
26+
27+
// Check for .eslintrc.* files
28+
for (const configFile of legacyConfigFiles) {
29+
if (fs.existsSync(path.join(projectRoot, configFile))) {
30+
foundLegacyFiles.push(configFile)
31+
}
32+
}
33+
34+
// Check for eslint or eslintConfig fields in package.json
35+
const packageJsonPath = path.join(projectRoot, 'package.json')
36+
if (fs.existsSync(packageJsonPath)) {
37+
try {
38+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
39+
if (packageJson.eslintConfig) {
40+
foundLegacyFiles.push('package.json (eslintConfig field)')
41+
}
42+
if (packageJson.eslint) {
43+
foundLegacyFiles.push('package.json (eslint field)')
44+
}
45+
} catch (error) {
46+
// Ignore JSON parse errors
47+
}
48+
}
49+
50+
return foundLegacyFiles
51+
}
52+
53+
/**
54+
* Shows a deprecation warning for legacy ESLint configuration
55+
* @param {string[]} legacyFiles Array of legacy config file names
56+
*/
57+
function showLegacyEslintDeprecationWarning(legacyFiles) {
58+
console.warn('')
59+
console.warn('⚠️ DEPRECATION WARNING: Legacy ESLint Configuration Detected')
60+
console.warn('')
61+
console.warn(' The following legacy ESLint configuration files were found:')
62+
legacyFiles.forEach((file) => {
63+
console.warn(` - ${file}`)
64+
})
65+
console.warn('')
66+
console.warn(
67+
' Cedar has migrated to ESLint flat config format. Legacy configurations',
68+
)
69+
console.warn(
70+
' still work but are deprecated and will be removed in a future version.',
71+
)
72+
console.warn('')
73+
console.warn(' To migrate to the new format:')
74+
console.warn(' 1. Remove the legacy config file(s) listed above')
75+
console.warn(' 2. Create an eslint.config.mjs')
76+
console.warn(' 3. Use the flat config format with @cedarjs/eslint-config')
77+
console.warn('')
78+
console.warn(' See more here: https://github.com/cedarjs/cedar/pull/629')
79+
console.warn('')
80+
}
981

1082
export const command = 'lint [path..]'
1183
export const description = 'Lint your files'
@@ -37,6 +109,13 @@ export const builder = (yargs) => {
37109
export const handler = async ({ path, fix, format }) => {
38110
recordTelemetryAttributes({ command: 'lint', fix, format })
39111

112+
// Check for legacy ESLint configuration and show deprecation warning
113+
const config = getConfig()
114+
const legacyConfigFiles = detectLegacyEslintConfig()
115+
if (legacyConfigFiles.length > 0 && config.eslintLegacyConfigWarning) {
116+
showLegacyEslintDeprecationWarning(legacyConfigFiles)
117+
}
118+
40119
try {
41120
const pathString = path?.join(' ')
42121
const sbPath = getPaths().web.storybook

packages/project-config/src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export interface Config {
120120
lintOnly: boolean
121121
}
122122
}
123+
eslintLegacyConfigWarning: boolean
123124
}
124125

125126
export interface CLIPlugin {
@@ -206,6 +207,7 @@ const DEFAULT_CONFIG: Config = {
206207
lintOnly: false,
207208
},
208209
},
210+
eslintLegacyConfigWarning: true,
209211
}
210212

211213
/**

0 commit comments

Comments
 (0)