Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Fix file import resolution #340

Merged
merged 1 commit into from
Nov 28, 2015
Merged
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
spec/files/bad.js
spec/eslintignore/ignored.js
10 changes: 8 additions & 2 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ Communication.on('JOB', function(job) {
} else process.env.NODE_PATH = ''
require('module').Module._initPaths()

process.chdir(params.fileDir)

if (params.global) {
if (params.nodePath === '' && prefixPath === null) {
Expand Down Expand Up @@ -102,7 +101,14 @@ Communication.on('JOB', function(job) {
}

job.Response = new Promise(function(resolve) {
const filePath = (eslintignoreDir) ? Path.relative(eslintignoreDir, params.filePath) : params.filePath
let filePath
if (eslintignoreDir) {
filePath = Path.relative(eslintignoreDir, params.filePath)
process.chdir(eslintignoreDir)
} else {
filePath = Path.basename(params.filePath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be nice to move this here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, completely missed that. Yes, indeed it would. One moment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, moved.

process.chdir(params.fileDir)
}
const argv = [
process.execPath,
eslintPath,
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
},
"devDependencies": {
"babel-eslint": "^4.1.5",
"eslint-plugin-react": "^3.10.0",
"eslint-config-airbnb": "latest",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alphabetising them? 😛

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm i --save-dev does this automatically, apparently.

"eslint-config-steelbrain": "latest",
"eslint-config-airbnb": "latest"
"eslint-plugin-import": "^0.11.0",
"eslint-plugin-react": "^3.10.0"
},
"package-deps": [
"linter"
Expand Down
8 changes: 8 additions & 0 deletions spec/eslintignore/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---

root: true

rules:
semi:
- 2
- never
1 change: 1 addition & 0 deletions spec/eslintignore/ignored.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var foo = 2;
11 changes: 11 additions & 0 deletions spec/import-resolution/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

root: true

parser: babel-eslint

plugins:
- import

rules:
import/no-unresolved: 2
1 change: 1 addition & 0 deletions spec/import-resolution/exporting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const meaning = 42
1 change: 1 addition & 0 deletions spec/import-resolution/nested/importing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { meaning } from '../exporting'
24 changes: 24 additions & 0 deletions spec/linter-eslint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,28 @@ describe('The eslint provider for Linter', () => {
});
})
});

describe('when resolving import paths using eslint-plugin-import', () => {
it('correctly resolves imports from parent', () => {
waitsForPromise(() => {
return atom.workspace.open(`${__dirname}/import-resolution/nested/importing.js`).then(editor => {
return lint(editor).then(messages => {
expect(messages.length).toEqual(0);
})
})
})
})
})

describe('when a file is specified in an .eslintignore file', () => {
it('will not give warnings for the file', () => {
waitsForPromise(() => {
return atom.workspace.open(`${__dirname}/eslintignore/ignored.js`).then(editor => {
return lint(editor).then(messages => {
expect(messages.length).toEqual(0);
})
})
})
})
})
});