Skip to content

Commit

Permalink
ESLintBear: Add filename context
Browse files Browse the repository at this point in the history
Adds information about current file location for ESLint.
Aids in relative imports.

Fixes #741
  • Loading branch information
oreqizer authored and sils committed Sep 11, 2016
1 parent f25f760 commit fccf7ff
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
9 changes: 8 additions & 1 deletion bears/js/ESLintBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions tests/js/ESLintBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
};
"""

test_import_good = """
import test from "./test";
test();
"""

test_import_bad = """
import test from "../test";
test();
"""

test_syntax_error = '{<!@3@^ yeah!/\n'

test_dir = os.path.join(os.path.dirname(__file__), "test_files")
Expand All @@ -47,3 +59,11 @@
invalid_files=(),
settings={"eslint_config": os.path.join(test_dir,
"eslintconfig_badplugin.json")})
ESLintBearImportTest = verify_local_bear(
ESLintBear,
valid_files=(test_import_good, ),
invalid_files=(test_import_bad, ),
filename=os.path.join(test_dir, 'test.js'),
create_tempfile=False,
settings={"eslint_config": os.path.join(test_dir,
"eslintconfig_import.json")})
8 changes: 8 additions & 0 deletions tests/js/test_files/eslintconfig_import.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "eslint:recommended",
"parser": "babel-eslint",
"plugins": ["import"],
"rules": {
"import/no-unresolved": ["error"]
}
}
3 changes: 3 additions & 0 deletions tests/js/test_files/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function test() {
return true;
}

0 comments on commit fccf7ff

Please sign in to comment.