Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/lazy-dingos-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-config-prettier": patch
---

fix(cli): do not crash on no rules configured
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
11 changes: 11 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"use strict";

const childProcess = require("node:child_process");
const path = require("node:path");

const cli = require("../bin/cli");

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

test("empty config", (done) => {
childProcess.exec(
`node ${path.resolve("bin/cli.js")} index.js`,
{ cwd: path.resolve(__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.