Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add error mssg in bin/eslint (fixes #9011) #9041

Merged
merged 3 commits into from
Aug 1, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ process.once("uncaughtException", err => {
console.error("\nOops! Something went wrong! :(");
console.error(`\n${template(err.messageData || {})}`);
} else {

console.error(err.message);
console.error(err.stack);
}

Expand Down
17 changes: 14 additions & 3 deletions tests/bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,28 @@ describe("bin/eslint.js", () => {
});

describe("handling crashes", () => {
it("prints the error message exactly once to stderr in the event of a crash", () => {
it("prints the error message to stderr in the event of a crash", () => {
const child = runESLint(["--rule=no-restricted-syntax:[error, 'Invalid Selector [[[']", "Makefile.js"]);
const exitCodeAssertion = assertExitCode(child, 1);
const outputAssertion = getOutput(child).then(output => {
const expectedSubstring = "Syntax error in selector";

assert.strictEqual(output.stdout, "");
assert.include(output.stderr, expectedSubstring);
});

// The message should appear exactly once in stderr
assert.strictEqual(output.stderr.indexOf(expectedSubstring), output.stderr.lastIndexOf(expectedSubstring));
return Promise.all([exitCodeAssertion, outputAssertion]);
});

it("prints the error message pointing to line of code", () => {
const invalidConfig = `${__dirname}/../fixtures/bin/.eslintrc.yml`;
const child = runESLint(["--no-ignore", invalidConfig]);
const exitCodeAssertion = assertExitCode(child, 1);
const outputAssertion = getOutput(child).then(output => {
const expectedSubstring = "Error: bad indentation of a mapping entry at line";

assert.strictEqual(output.stdout, "");
assert.include(output.stderr, expectedSubstring);
});

return Promise.all([exitCodeAssertion, outputAssertion]);
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/bin/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# intentionally invalid YML
rules:
semi: error
yoda: error
quotes: error