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

Use .jshintignore path as root for relative paths #516

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ const readFile = async filePath =>
});

export const isIgnored = async (filePath, ignorePath) => {
const fileDir = path.dirname(filePath);
const ignoreDir = path.dirname(ignorePath);
const rawIgnoreList = (await readFile(ignorePath)).split(/[\r\n]/);

// "Fix" the patterns in the same way JSHint does
const ignoreList = rawIgnoreList.filter(line => !!line.trim()).map((pattern) => {
if (pattern.startsWith('!')) {
return `!${path.resolve(fileDir, pattern.substr(1).trim())}`;
return `!${path.resolve(ignoreDir, pattern.substr(1).trim())}`;
}
return path.join(fileDir, pattern.trim());
return path.join(ignoreDir, pattern.trim());
});

// Check the modified patterns
Expand Down
21 changes: 10 additions & 11 deletions spec/linter-jshint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ describe('The JSHint provider for Linter', () => {
});

describe('handles .jshintignore files', () => {
const checkMessage = (message, filePath) => {
const checkMessages = (messages, filePath) => {
const expected = "W098 - 'foo' is defined but never used.";

expect(message.severity).toBe('warning');
expect(message.excerpt).toBe(expected);
expect(message.location.file).toBe(filePath);
expect(message.location.position).toEqual([[0, 4], [0, 7]]);
expect(messages.length).toBe(1);
expect(messages[0].severity).toBe('warning');
expect(messages[0].excerpt).toBe(expected);
expect(messages[0].location.file).toBe(filePath);
expect(messages[0].location.position).toEqual([[0, 4], [0, 7]]);
};

it('works when in the same directory', async () => {
Expand All @@ -106,11 +107,10 @@ describe('The JSHint provider for Linter', () => {
const ignoredPath = path.join(ignoreDir, 'ignored.js');
const checkEditor = await atom.workspace.open(checkedPath);
const ignoreEditor = await atom.workspace.open(ignoredPath);
const checkMessages = await lint(checkEditor);
const checkedMessages = await lint(checkEditor);
const ignoreMessages = await lint(ignoreEditor);

expect(checkMessages.length).toBe(1);
checkMessage(checkMessages[0], checkedPath);
checkMessages(checkedMessages, checkedPath);

expect(ignoreMessages.length).toBe(0);
});
Expand All @@ -121,11 +121,10 @@ describe('The JSHint provider for Linter', () => {
const ignoredPath = path.join(ignoreDir, 'ignored.js');
const checkEditor = await atom.workspace.open(checkedPath);
const ignoreEditor = await atom.workspace.open(ignoredPath);
const checkMessages = await lint(checkEditor);
const checkedMessages = await lint(checkEditor);
const ignoreMessages = await lint(ignoreEditor);

expect(checkMessages.length).toBe(1);
checkMessage(checkMessages[0], checkedPath);
checkMessages(checkedMessages, checkedPath);

expect(ignoreMessages.length).toBe(0);
});
Expand Down