From fccf7ff107a133695633bf7dd2c1e254002e8882 Mon Sep 17 00:00:00 2001 From: oreqizer Date: Fri, 2 Sep 2016 17:54:22 +0200 Subject: [PATCH] ESLintBear: Add filename context Adds information about current file location for ESLint. Aids in relative imports. Fixes https://github.com/coala-analyzer/coala-bears/issues/741 --- bears/js/ESLintBear.py | 9 ++++++++- package.json | 2 ++ tests/js/ESLintBearTest.py | 20 ++++++++++++++++++++ tests/js/test_files/eslintconfig_import.json | 8 ++++++++ tests/js/test_files/test.js | 3 +++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/js/test_files/eslintconfig_import.json create mode 100644 tests/js/test_files/test.js diff --git a/bears/js/ESLintBear.py b/bears/js/ESLintBear.py index 255df3d2d4..3bc02684d4 100644 --- a/bears/js/ESLintBear.py +++ b/bears/js/ESLintBear.py @@ -36,7 +36,14 @@ def create_arguments(filename, file, config_file, """ :param eslint_config: The location of the .eslintrc config file. """ - args = '--no-ignore', '--no-color', '-f=json', '--stdin' + args = ( + '--no-ignore', + '--no-color', + '-f=json', + '--stdin', + '--stdin-filename=' + filename, + ) + if eslint_config: args += ('--config', eslint_config) else: diff --git a/package.json b/package.json index 3d827f4387..69d1116a72 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,14 @@ "dependencies": { "alex": "~2", "autoprefixer": "~6", + "babel-eslint": "~6", "bootlint": "~0", "coffeelint": "~1", "complexity-report": "~2.0.0-alpha", "csslint": "~0", "dockerfile_lint": "~0", "eslint": "~2", + "eslint-plugin-import": "~1", "happiness":"~7.1.2", "jshint": "~2", "postcss-cli": "~2", diff --git a/tests/js/ESLintBearTest.py b/tests/js/ESLintBearTest.py index 2bacf4901b..fdd33df59c 100644 --- a/tests/js/ESLintBearTest.py +++ b/tests/js/ESLintBearTest.py @@ -24,6 +24,18 @@ }; """ +test_import_good = """ +import test from "./test"; + +test(); +""" + +test_import_bad = """ +import test from "../test"; + +test(); +""" + test_syntax_error = '{