Skip to content

Commit

Permalink
ESLintBear: Handle corner case if eslint fails
Browse files Browse the repository at this point in the history
If eslint fails to run, for example if it gets an invalid config file it
does not know how to handle, earlier the bear would throw a JSON
Decoding error because it wouldn't know how to parse "" (an empty
string). Now this case is handled, and it gracefull doesn't try to
create results in such cases.

Fixes #727
  • Loading branch information
AbdealiLoKo committed Sep 3, 2016
1 parent 430d67c commit 0a681b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bears/js/ESLintBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def generate_config(filename, file):
return '{"extends": "eslint:recommended"}'

def process_output(self, output, filename, file):
if not file:
if not file or not output:
return

output = json.loads(output)
Expand Down
8 changes: 8 additions & 0 deletions tests/js/ESLintBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@
ESLintBear,
valid_files=(test_good, ''),
invalid_files=(test_syntax_error, test_bad))

# If there is an invalid config file, the results cannot be found. So, no
# file gives a result.
ESLintBearWithUnloadablePluginTest = verify_local_bear(
ESLintBear,
valid_files=(test_bad, test_good),
invalid_files=(),
settings={"eslint_config": os.path.join(test_dir, "eslintconfig2.json")})
14 changes: 14 additions & 0 deletions tests/js/test_files/eslintconfig2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "eslint:recommended",
"plugins": ["invalid_plugin_should_throw_error"],
"rules": {
"consistent-return": 2,
"indent" : [1, 4],
"no-else-return" : 1,
"semi" : [1, "always"],
"space-unary-ops" : [2, {
"words": true,
"nonwords": true
}]
}
}

0 comments on commit 0a681b2

Please sign in to comment.