Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ if (module === require.main) {
})
)
.then((configs) => {
const rules = configs.flatMap(({ rules }, index) =>
Object.entries(rules).map((entry) => [...entry, args[index]])
const rules = configs.flatMap(
(
// Initializing config and rules for files that aren't included in the flat config,
// which is a very unlikely scenario, but should still be treated as a success
{ rules = {} } = {},
index
) => Object.entries(rules).map((entry) => [...entry, args[index]])
);
const result = processRules(rules);
if (result.stderr) {
Expand Down
10 changes: 10 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

const childProcess = require("child_process");
const path = require("path");
const cli = require("../bin/cli");

const offPatterns = [0, "off", [0], ["off"], ["off", "never"]];
Expand Down Expand Up @@ -76,6 +78,14 @@ test("no results", () => {
`);
});

test("empty config", (done) => {
childProcess.exec(
`node ${path.join(process.cwd(), "bin/cli.js")} index.js`,
{ cwd: path.join(__dirname, "fixtures/empty-config") },
done
);
});

test("conflicting options", () => {
const rules = ["strict", ["curly", "multi-line"]];
expect(cli.processRules(createRules(rules, "error"))).toMatchInlineSnapshot(`
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/empty-config/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default [{}];
Empty file.