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

Commit

Permalink
Add a spec checking for .jshintignore handling
Browse files Browse the repository at this point in the history
Adds a spec that checks whether any .jshintignore file is being properly
handled.
  • Loading branch information
Arcanemagus committed May 4, 2017
1 parent cbf4171 commit 5360103
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions spec/fixtures/ignore/.jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/ignored.js
3 changes: 3 additions & 0 deletions spec/fixtures/ignore/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"unused": true
}
1 change: 1 addition & 0 deletions spec/fixtures/ignore/checked.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var foo = 42;
1 change: 1 addition & 0 deletions spec/fixtures/ignore/ignored.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var foo = 42;
28 changes: 25 additions & 3 deletions spec/linter-jshint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@ import * as path from 'path';
import linter from '../lib/main';

const bitwisePath = path.join(__dirname, 'fixtures', 'bitwise', 'bitwise.js');
const emptyPath = path.join(__dirname, 'fixtures', 'empty.js');
const goodPath = path.join(__dirname, 'fixtures', 'good.js');

describe('The JSHint provider for Linter', () => {
const lint = linter.provideLinter().lint;

beforeEach(async () => {
await atom.packages.activatePackage('linter-jshint');
await atom.packages.activatePackage('language-javascript');
await atom.workspace.open(bitwisePath);
});

it('should be in the packages list', () =>
Expand Down Expand Up @@ -46,12 +43,14 @@ describe('The JSHint provider for Linter', () => {
});

it('finds nothing wrong with an empty file', async () => {
const emptyPath = path.join(__dirname, 'fixtures', 'empty.js');
const editor = await atom.workspace.open(emptyPath);
const messages = await lint(editor);
expect(messages.length).toBe(0);
});

it('finds nothing wrong with a valid file', async () => {
const goodPath = path.join(__dirname, 'fixtures', 'good.js');
const editor = await atom.workspace.open(goodPath);
const messages = await lint(editor);
expect(messages.length).toBe(0);
Expand All @@ -75,4 +74,27 @@ describe('The JSHint provider for Linter', () => {
expect(messages[0].range).toEqual([[0, 10], [0, 11]]);
});
});

describe('handles .jshintignore files', () => {
const ignoreDir = path.join(__dirname, 'fixtures', 'ignore');
const checkedPath = path.join(ignoreDir, 'checked.js');
const ignoredPath = path.join(ignoreDir, 'ignored.js');

it('works when in the same directory', async () => {
const checkEditor = await atom.workspace.open(checkedPath);
const ignoreEditor = await atom.workspace.open(ignoredPath);
const checkMessages = await lint(checkEditor);
const ignoreMessages = await lint(ignoreEditor);
const expected = "W098 - 'foo' is defined but never used.";

expect(checkMessages.length).toBe(1);
expect(checkMessages[0].type).toBe('Warning');
expect(checkMessages[0].html).not.toBeDefined();
expect(checkMessages[0].text).toBe(expected);
expect(checkMessages[0].filePath).toBe(checkedPath);
expect(checkMessages[0].range).toEqual([[0, 4], [0, 7]]);

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

0 comments on commit 5360103

Please sign in to comment.