Skip to content
Permalink
Browse files

Fix: improve error message on --print-config (fixes #11874) (#11885)

  • Loading branch information...
mysticatea authored and not-an-aardvark committed Jun 25, 2019
1 parent 056c2aa commit 13f041897ee31982808a57b4d06450b57c9b27dc
@@ -45,7 +45,7 @@ process.once("uncaughtException", err => {
const pkg = require("../package.json");

console.error("\nOops! Something went wrong! :(");
console.error(`\nESLint: ${pkg.version}.\n${template(err.messageData || {})}`);
console.error(`\nESLint: ${pkg.version}.\n\n${template(err.messageData || {})}`);
} else {

console.error(err.stack);
@@ -904,6 +904,13 @@ class CLIEngine {
const { configArrayFactory, options } = internalSlotsMap.get(this);
const absolutePath = path.resolve(options.cwd, filePath);

if (directoryExists(absolutePath)) {
throw Object.assign(
new Error("'filePath' should not be a directory path."),
{ messageTemplate: "print-config-with-directory-path" }
);
}

return configArrayFactory
.getConfigArrayForFile(absolutePath)
.extractConfig(absolutePath)
@@ -0,0 +1,2 @@
The '--print-config' CLI option requires a path to a source code file rather than a directory.
See also: https://eslint.org/docs/user-guide/command-line-interface#--print-config
@@ -3459,6 +3459,17 @@ describe("CLIEngine", () => {
assert.deepStrictEqual(actualConfig, expectedConfig);
});

it("should throw an error if a directory path was given.", () => {
const engine = new CLIEngine();

try {
engine.getConfigForFile(".");
} catch (error) {
assert.strictEqual(error.messageTemplate, "print-config-with-directory-path");
return;
}
assert.fail("should throw an error");
});
});

describe("isPathIgnored", () => {
@@ -1084,7 +1084,7 @@ describe("cli", () => {

describe("when passing --print-config", () => {
it("should print out the configuration", () => {
const filePath = getFixturePath("files");
const filePath = getFixturePath("xxxx");

const exitCode = cli.execute(`--print-config ${filePath}`);

0 comments on commit 13f0418

Please sign in to comment.
You can’t perform that action at this time.