Skip to content

Commit

Permalink
feat: avoid empty config warning (#153)
Browse files Browse the repository at this point in the history
* feat: avoid empty config warning

* env is always an array
  • Loading branch information
mdjermanovic authored Feb 12, 2025
1 parent a1d1417 commit 2a75349
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug
this.result.configContent = `${importContent}
${needCompatHelper ? helperContent : ""}
/** @type {import('eslint').Linter.Config[]} */
export default [\n${exportContent}];`;
export default [\n${exportContent || " {}\n"}];`; // defaults to `[{}]` to avoid empty config warning
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/__snapshots__/empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"configContent": "

/** @type {import('eslint').Linter.Config[]} */
export default [
{}
];",
"configFilename": "eslint.config.js",
"devDependencies": [
"eslint",
],
"installFlags": [
"-D",
],
}
12 changes: 12 additions & 0 deletions tests/config-snapshots.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ describe("generate config for esm projects", () => {
}
}

// add a combination that should produce an empty config
inputs.push({
name: "empty",
answers: {
purpose: "syntax",
moduleType: "esm",
framework: "none",
language: "javascript",
env: []
}
});

inputs.forEach(item => {
test(`${item.name}`, () => {
const generator = new ConfigGenerator({ cwd: esmProjectDir, answers: item.answers });
Expand Down

0 comments on commit 2a75349

Please sign in to comment.