diff --git a/spec/fixtures/ignore/.jshintignore b/spec/fixtures/ignore/.jshintignore new file mode 100644 index 0000000..6dc7684 --- /dev/null +++ b/spec/fixtures/ignore/.jshintignore @@ -0,0 +1 @@ +**/ignored.js diff --git a/spec/fixtures/ignore/.jshintrc b/spec/fixtures/ignore/.jshintrc new file mode 100644 index 0000000..6182be0 --- /dev/null +++ b/spec/fixtures/ignore/.jshintrc @@ -0,0 +1,3 @@ +{ + "unused": true +} diff --git a/spec/fixtures/ignore/checked.js b/spec/fixtures/ignore/checked.js new file mode 100644 index 0000000..be92fda --- /dev/null +++ b/spec/fixtures/ignore/checked.js @@ -0,0 +1 @@ +var foo = 42; diff --git a/spec/fixtures/ignore/ignored.js b/spec/fixtures/ignore/ignored.js new file mode 100644 index 0000000..be92fda --- /dev/null +++ b/spec/fixtures/ignore/ignored.js @@ -0,0 +1 @@ +var foo = 42; diff --git a/spec/linter-jshint-spec.js b/spec/linter-jshint-spec.js index 374991b..1c5d57f 100644 --- a/spec/linter-jshint-spec.js +++ b/spec/linter-jshint-spec.js @@ -6,8 +6,6 @@ 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; @@ -15,7 +13,6 @@ describe('The JSHint provider for Linter', () => { 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', () => @@ -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); @@ -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); + }); + }); });