Skip to content

Commit 2a75349

Browse files
authored
feat: avoid empty config warning (#153)
* feat: avoid empty config warning * env is always an array
1 parent a1d1417 commit 2a75349

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

lib/config-generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug
231231
this.result.configContent = `${importContent}
232232
${needCompatHelper ? helperContent : ""}
233233
/** @type {import('eslint').Linter.Config[]} */
234-
export default [\n${exportContent}];`;
234+
export default [\n${exportContent || " {}\n"}];`; // defaults to `[{}]` to avoid empty config warning
235235
}
236236

237237
/**

tests/__snapshots__/empty

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"configContent": "
3+
4+
/** @type {import('eslint').Linter.Config[]} */
5+
export default [
6+
{}
7+
];",
8+
"configFilename": "eslint.config.js",
9+
"devDependencies": [
10+
"eslint",
11+
],
12+
"installFlags": [
13+
"-D",
14+
],
15+
}

tests/config-snapshots.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ describe("generate config for esm projects", () => {
4545
}
4646
}
4747

48+
// add a combination that should produce an empty config
49+
inputs.push({
50+
name: "empty",
51+
answers: {
52+
purpose: "syntax",
53+
moduleType: "esm",
54+
framework: "none",
55+
language: "javascript",
56+
env: []
57+
}
58+
});
59+
4860
inputs.forEach(item => {
4961
test(`${item.name}`, () => {
5062
const generator = new ConfigGenerator({ cwd: esmProjectDir, answers: item.answers });

0 commit comments

Comments
 (0)