From 0a681b23d6b7824a7ec5d055888dda6a4476c2f3 Mon Sep 17 00:00:00 2001 From: AbdealiJK Date: Fri, 2 Sep 2016 20:31:42 +0530 Subject: [PATCH] ESLintBear: Handle corner case if eslint fails 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 https://github.com/coala-analyzer/coala-bears/issues/727 --- bears/js/ESLintBear.py | 2 +- tests/js/ESLintBearTest.py | 8 ++++++++ tests/js/test_files/eslintconfig2.json | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/js/test_files/eslintconfig2.json diff --git a/bears/js/ESLintBear.py b/bears/js/ESLintBear.py index a8075e6df2..1704f8f7e4 100644 --- a/bears/js/ESLintBear.py +++ b/bears/js/ESLintBear.py @@ -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) diff --git a/tests/js/ESLintBearTest.py b/tests/js/ESLintBearTest.py index bd4766a760..f1b7a4a42f 100644 --- a/tests/js/ESLintBearTest.py +++ b/tests/js/ESLintBearTest.py @@ -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")}) diff --git a/tests/js/test_files/eslintconfig2.json b/tests/js/test_files/eslintconfig2.json new file mode 100644 index 0000000000..868c9786c3 --- /dev/null +++ b/tests/js/test_files/eslintconfig2.json @@ -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 + }] + } +}