From 96b64361b61d489558dc44b7581d8b0f6e3207c8 Mon Sep 17 00:00:00 2001 From: Landon Abney Date: Thu, 4 May 2017 16:10:26 -0700 Subject: [PATCH] Re-implement file ignoring Since JSHint can't handle `.jshintignore` files for content sent in via stdin, check this manually using `minimatch`. Also sets the CWD for better automatic resolution of the configuration, since that at least works within JSHint. --- decls/minimatch.js | 20 +++++++++++ lib/main.js | 87 +++++++++++++++++++++++++++++++--------------- package.json | 3 +- 3 files changed, 81 insertions(+), 29 deletions(-) create mode 100644 decls/minimatch.js diff --git a/decls/minimatch.js b/decls/minimatch.js new file mode 100644 index 0000000..9f07ba7 --- /dev/null +++ b/decls/minimatch.js @@ -0,0 +1,20 @@ +// @flow + +declare type MinimatchOptions = { + debug?: boolean, + nobrace?: boolean, + noglobstar?: boolean, + dot?: boolean, + noext?: boolean, + nocase?: boolean, + nonull?: boolean, + matchBase?: boolean, + nocomment?: boolean, + nonegate?: boolean, + flipNegate?: boolean, +} + +declare module 'minimatch' { + declare module.exports: + (path: string, pattern: string, options?: MinimatchOptions) => boolean; +} diff --git a/lib/main.js b/lib/main.js index 9208aab..dffc115 100644 --- a/lib/main.js +++ b/lib/main.js @@ -3,11 +3,24 @@ /* @flow */ import Path from 'path'; +import { readFile } from 'fs'; +import minimatch from 'minimatch'; /* eslint-disable import/extensions, import/no-extraneous-dependencies */ import { CompositeDisposable } from 'atom'; import type { TextEditor } from 'atom'; /* eslint-enable import/extensions, import/no-extraneous-dependencies */ +async function readIgnoreList(ignorePath) { + return new Promise((resolve, reject) => { + readFile(ignorePath, 'utf8', (err, data) => { + if (err) { + reject(err); + } + resolve(data.split(/[\r\n]/)); + }); + }); +} + module.exports = { config: { executablePath: { @@ -18,17 +31,22 @@ module.exports = { lintInlineJavaScript: { type: 'boolean', default: false, - description: 'Lint JavaScript inside `