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

Improve clarity of ESLint failure reports #252

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions mustache_lint/mustache_lint.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
// When we have no example context, parse errors are common because
// there are missing variables in the js, thus we ignore them.
$ignoreparseerrors = empty($example) ? true : false;
print_message('INFO', 'ESLint reported JavaScript errors');
print_eslint_problems($eslintproblems, $ignoreparseerrors);
}

Expand Down Expand Up @@ -260,8 +261,18 @@ function print_eslint_problems($problems, $ignoreparseerrors) {
} else {
$severity = 'warning';
}
$message = "ESLint {$severity} [{$problem->ruleId}]: {$problem->message} ( {$problem->source} ), Line: {$problem->line} Column: {$problem->column}";
print_problem('WARNING', $message);
if ($problem->linesource) {
$message = "ESLint {$severity} [{$problem->ruleId}]: {$problem->message}, Line: {$problem->line} Column: {$problem->column}";
print_problem('WARNING', $message);
print_problem('WARNING', rtrim($problem->linesource));

if ($problem->column !== null) {
print_problem('WARNING', str_pad(' ', $problem->column - 1) . '^');
}
} else {
$message = "ESLint {$severity} [{$problem->ruleId}]: {$problem->message} ( {$problem->source} ), Line: {$problem->line} Column: {$problem->column}";
print_problem('WARNING', $message);
}
}
}

Expand Down
11 changes: 9 additions & 2 deletions tests/1-mustache_lint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ setup () {
# Assert result
assert_failure
assert_output --partial "lib/templates/js_test.mustache - WARNING: ESLint warning [camelcase]: Identifier 'my_message' is not in camel case"
assert_output --partial "lib/templates/js_test.mustache - WARNING: ESLint warning [no-alert]: Unexpected alert. ( alert(my_message); )"
assert_output --partial "lib/templates/js_test.mustache - WARNING: var my_message = 'Hello World!';"
assert_output --partial "lib/templates/js_test.mustache - WARNING: ^"
assert_output --partial "lib/templates/js_test.mustache - WARNING: ESLint warning [no-alert]: Unexpected alert."
assert_output --partial "lib/templates/js_test.mustache - WARNING: alert(my_message);"
assert_output --partial "lib/templates/js_test.mustache - WARNING: ^"
}

@test "mustache_lint: Test eslint handles parsing failures safely" {
Expand All @@ -195,7 +199,10 @@ setup () {

# Assert result
assert_failure
assert_output --partial "lib/templates/js_token_test.mustache - WARNING: ESLint error []: Parsing error: Unexpected token bar ( var foo bar baz = 'bum'; )"
assert_output --partial "lib/templates/js_token_test.mustache - INFO: ESLint reported JavaScript errors"
assert_output --partial "lib/templates/js_token_test.mustache - WARNING: ESLint error []: Parsing error: Unexpected token bar, Line: 2 Column: 13"
assert_output --partial "lib/templates/js_token_test.mustache - WARNING: var foo bar baz = 'bum';"
assert_output --partial "lib/templates/js_token_test.mustache - WARNING: ^"
}

@test "mustache_lint: Test eslint runs ok when invoked from any directory" {
Expand Down