From 0a49405962bee2abfc735f3d131801e6eeff208c Mon Sep 17 00:00:00 2001 From: Biliana Date: Mon, 25 Feb 2019 16:02:21 +0100 Subject: [PATCH 01/17] Throw error on non-existent files unless allow-empty-input is enabled --- lib/__tests__/standalone.test.js | 18 +++++++++++++++++- lib/cli.js | 8 ++++++++ lib/standalone.js | 7 +++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/__tests__/standalone.test.js b/lib/__tests__/standalone.test.js index 263b5c801a..f8158b426b 100644 --- a/lib/__tests__/standalone.test.js +++ b/lib/__tests__/standalone.test.js @@ -114,10 +114,26 @@ it("standalone without input css and file(s) should throw error", () => { ); }); -it("standalone with non-existent-file quietly exits", () => { +it("standalone with non-existent-file throws an error", () => { + const expectedError = new Error( + "The specified `files` glob returns no results" + ); + return standalone({ files: `${fixturesPath}/non-existent-file.css`, config: configBlockNoEmpty + }).then(() => { + throw new Error("should not have succeeded"); + }).catch((actualError) => { + expect(actualError).toEqual(expectedError) + }); +}); + +it("standalone with non-existent-file and allowEmptyInput enabled quietly exits", () => { + return standalone({ + files: `${fixturesPath}/non-existent-file.css`, + config: configBlockNoEmpty, + allowEmptyInput: true, }).then(linted => { expect(typeof linted.output).toBe("string"); expect(linted.results).toHaveLength(0); diff --git a/lib/cli.js b/lib/cli.js index 8aa69ea6b1..3ed2f059f5 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -278,6 +278,10 @@ const meowOptions /*: meowOptionsType*/ = { --version, -v Show the currently installed version of stylelint. + + --alow-empty-input + + When glob pattern matches no files, the process will exit without throwing an error. `, flags: { cache: { @@ -478,6 +482,10 @@ module.exports = (argv /*: string[]*/) /*: Promise|void*/ => { return; } + if (cli.flags.allowEmptyInput) { + optionsBase.allowEmptyInput = cli.flags.allowEmptyInput; + } + return Promise.resolve() .then(() => { // Add input/code into options diff --git a/lib/standalone.js b/lib/standalone.js index 37da535903..e4ff6d47b0 100644 --- a/lib/standalone.js +++ b/lib/standalone.js @@ -42,6 +42,7 @@ module.exports = function( const reportNeedlessDisables = options.reportNeedlessDisables; const maxWarnings = options.maxWarnings; const syntax = options.syntax; + const allowEmptyInput = options.allowEmptyInput; const useCache = options.cache || false; let fileCache; const startTime = Date.now(); @@ -198,6 +199,12 @@ module.exports = function( ); if (!filePaths.length) { + if (!allowEmptyInput) { + throw new Error( + "The specified `files` glob returns no results" + ); + } + return Promise.all([]); } From acd69245387183bcc706936bcfe518405b492328 Mon Sep 17 00:00:00 2001 From: Biliana Date: Mon, 25 Feb 2019 18:09:01 +0100 Subject: [PATCH 02/17] Remove trailing comma --- lib/__tests__/standalone.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/__tests__/standalone.test.js b/lib/__tests__/standalone.test.js index f8158b426b..0f6db2741b 100644 --- a/lib/__tests__/standalone.test.js +++ b/lib/__tests__/standalone.test.js @@ -133,7 +133,7 @@ it("standalone with non-existent-file and allowEmptyInput enabled quietly exits" return standalone({ files: `${fixturesPath}/non-existent-file.css`, config: configBlockNoEmpty, - allowEmptyInput: true, + allowEmptyInput: true }).then(linted => { expect(typeof linted.output).toBe("string"); expect(linted.results).toHaveLength(0); From 898494c1008dd2c6c1a71f808999962e9f9fbc18 Mon Sep 17 00:00:00 2001 From: Biliana Date: Mon, 25 Feb 2019 18:09:23 +0100 Subject: [PATCH 03/17] Set allow-empty-input option to false by default --- lib/standalone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/standalone.js b/lib/standalone.js index e4ff6d47b0..36a5524bd5 100644 --- a/lib/standalone.js +++ b/lib/standalone.js @@ -42,7 +42,7 @@ module.exports = function( const reportNeedlessDisables = options.reportNeedlessDisables; const maxWarnings = options.maxWarnings; const syntax = options.syntax; - const allowEmptyInput = options.allowEmptyInput; + const allowEmptyInput = options.allowEmptyInput || false; const useCache = options.cache || false; let fileCache; const startTime = Date.now(); From 2947db4152b73c2a5620fce942cced10e30940a3 Mon Sep 17 00:00:00 2001 From: Biliana Date: Mon, 25 Feb 2019 18:09:29 +0100 Subject: [PATCH 04/17] Fix failing tests --- lib/__tests__/ignore.test.js | 57 ++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/lib/__tests__/ignore.test.js b/lib/__tests__/ignore.test.js index b5822bad00..bb7b47d96c 100644 --- a/lib/__tests__/ignore.test.js +++ b/lib/__tests__/ignore.test.js @@ -191,8 +191,12 @@ describe("extending config with ignoreFiles glob ignoring one by negation", () = }); describe("specified `ignorePath` file ignoring one file", () => { + const noFilesErrorMessage = new Error( + "The specified `files` glob returns no results" + ); let results; let actualCwd; + let errorMessage; beforeAll(() => { actualCwd = process.cwd(); @@ -212,17 +216,24 @@ describe("specified `ignorePath` file ignoring one file", () => { } }, ignorePath: path.join(__dirname, "fixtures/ignore.txt") - }).then(data => (results = data.results)); + }).then(data => (results = data.results)) + .catch((actualError) => { + errorMessage = actualError; + }); }); it("no files read", () => { - expect(results).toHaveLength(0); + expect(errorMessage).toEqual(noFilesErrorMessage); }); }); describe("specified `ignorePattern` file ignoring one file", () => { + const noFilesErrorMessage = new Error( + "The specified `files` glob returns no results" + ); let results; let actualCwd; + let errorMessage; beforeAll(() => { actualCwd = process.cwd(); @@ -242,17 +253,24 @@ describe("specified `ignorePattern` file ignoring one file", () => { } }, ignorePattern: "fixtures/empty-block.css" - }).then(data => (results = data.results)); + }).then(data => (results = data.results)) + .catch((actualError) => { + errorMessage = actualError; + }); }); it("no files read", () => { - expect(results).toHaveLength(0); + expect(errorMessage).toEqual(noFilesErrorMessage); }); }); describe("specified `ignorePattern` file ignoring two files", () => { + const noFilesErrorMessage = new Error( + "The specified `files` glob returns no results" + ); let results; let actualCwd; + let errorMessage; beforeAll(() => { actualCwd = process.cwd(); @@ -278,11 +296,14 @@ describe("specified `ignorePattern` file ignoring two files", () => { "fixtures/empty-block.css", "fixtures/no-syntax-error.css" ] - }).then(data => (results = data.results)); + }).then(data => (results = data.results)) + .catch((actualError) => { + errorMessage = actualError; + }); }); it("no files read", () => { - expect(results).toHaveLength(0); + expect(errorMessage).toEqual(noFilesErrorMessage); }); }); @@ -416,6 +437,9 @@ describe("using codeFilename and ignoreFiles with configBasedir", () => { }); describe("file in node_modules", () => { + const noFilesErrorMessage = new Error( + "The specified `files` glob returns no results" + ); const lint = () => standalone({ files: [`${fixturesPath}/node_modules/test.css`], @@ -427,13 +451,19 @@ describe("file in node_modules", () => { }); it("is ignored", () => { - return lint().then(output => { - expect(output.results).toHaveLength(0); - }); + return lint() + .then(() => { + throw new Error("should not have succeeded"); + }).catch((actualError) => { + expect(actualError).toEqual(noFilesErrorMessage) + }); }); }); describe("file in bower_components", () => { + const noFilesErrorMessage = new Error( + "The specified `files` glob returns no results" + ); const lint = () => standalone({ files: [`${fixturesPath}/bower_components/test.css`], @@ -445,9 +475,12 @@ describe("file in bower_components", () => { }); it("is ignored", () => { - return lint().then(output => { - expect(output.results).toHaveLength(0); - }); + return lint() + .then(() => { + throw new Error("should not have succeeded"); + }).catch((actualError) => { + expect(actualError).toEqual(noFilesErrorMessage) + }); }); }); From 2a70cc14205921ac448a06aec0b3c315a8942137 Mon Sep 17 00:00:00 2001 From: Biliana Date: Mon, 25 Feb 2019 18:18:39 +0100 Subject: [PATCH 05/17] Remove unused variables --- lib/__tests__/ignore.test.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/__tests__/ignore.test.js b/lib/__tests__/ignore.test.js index bb7b47d96c..619d84781d 100644 --- a/lib/__tests__/ignore.test.js +++ b/lib/__tests__/ignore.test.js @@ -194,7 +194,6 @@ describe("specified `ignorePath` file ignoring one file", () => { const noFilesErrorMessage = new Error( "The specified `files` glob returns no results" ); - let results; let actualCwd; let errorMessage; @@ -216,7 +215,7 @@ describe("specified `ignorePath` file ignoring one file", () => { } }, ignorePath: path.join(__dirname, "fixtures/ignore.txt") - }).then(data => (results = data.results)) + }).then(() => { throw new Error("should not have succeeded") }) .catch((actualError) => { errorMessage = actualError; }); @@ -231,7 +230,6 @@ describe("specified `ignorePattern` file ignoring one file", () => { const noFilesErrorMessage = new Error( "The specified `files` glob returns no results" ); - let results; let actualCwd; let errorMessage; @@ -253,7 +251,7 @@ describe("specified `ignorePattern` file ignoring one file", () => { } }, ignorePattern: "fixtures/empty-block.css" - }).then(data => (results = data.results)) + }).then(() => { throw new Error("should not have succeeded") }) .catch((actualError) => { errorMessage = actualError; }); @@ -268,7 +266,6 @@ describe("specified `ignorePattern` file ignoring two files", () => { const noFilesErrorMessage = new Error( "The specified `files` glob returns no results" ); - let results; let actualCwd; let errorMessage; @@ -296,7 +293,7 @@ describe("specified `ignorePattern` file ignoring two files", () => { "fixtures/empty-block.css", "fixtures/no-syntax-error.css" ] - }).then(data => (results = data.results)) + }).then(() => { throw new Error("should not have succeeded") }) .catch((actualError) => { errorMessage = actualError; }); From 2c0e3f749942ed373526067b249165e95a749b29 Mon Sep 17 00:00:00 2001 From: Biliana Date: Mon, 25 Feb 2019 18:22:04 +0100 Subject: [PATCH 06/17] Fix empty space --- lib/standalone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/standalone.js b/lib/standalone.js index 36a5524bd5..f336a5aa41 100644 --- a/lib/standalone.js +++ b/lib/standalone.js @@ -42,7 +42,7 @@ module.exports = function( const reportNeedlessDisables = options.reportNeedlessDisables; const maxWarnings = options.maxWarnings; const syntax = options.syntax; - const allowEmptyInput = options.allowEmptyInput || false; + const allowEmptyInput = options.allowEmptyInput || false; const useCache = options.cache || false; let fileCache; const startTime = Date.now(); From 651156de298deb8c7b103244d2028570a1aaa88f Mon Sep 17 00:00:00 2001 From: Biliana Date: Mon, 25 Feb 2019 18:27:35 +0100 Subject: [PATCH 07/17] Add missing object type --- lib/cli.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cli.js b/lib/cli.js index 3ed2f059f5..2011aada8c 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -125,7 +125,8 @@ const EXIT_CODE_ERROR = 2; stdinFilename: any, syntax: any, v: string, - version: string + version: string, + allowEmptyInput: boolean }, input: any, help: any, From 8d44521b1d6941a7b25aa3cc5856753ed101ba93 Mon Sep 17 00:00:00 2001 From: Biliana Date: Mon, 25 Feb 2019 18:36:38 +0100 Subject: [PATCH 08/17] Add missing allowEmptyInput in type definitions --- flow-typed/stylelint.js | 3 ++- lib/cli.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/flow-typed/stylelint.js b/flow-typed/stylelint.js index 4e2f2764fc..826bbf3886 100644 --- a/flow-typed/stylelint.js +++ b/flow-typed/stylelint.js @@ -147,5 +147,6 @@ export type stylelint$standaloneOptions = { customSyntax?: string, formatter?: "compact" | "json" | "string" | "unix" | "verbose" | Function, disableDefaultIgnores?: boolean, - fix?: boolean + fix?: boolean, + allowEmptyInput: boolean }; diff --git a/lib/cli.js b/lib/cli.js index 2011aada8c..5c60625fb6 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -154,7 +154,8 @@ const EXIT_CODE_ERROR = 2; maxWarnings?: any, syntax?: any, disableDefaultIgnores?: any, - ignorePattern?: any + ignorePattern?: any, + allowEmptyInput?: boolean }*/ const meowOptions /*: meowOptionsType*/ = { From 71112d3dae14fc63f92fd1544842cbdc0aac747b Mon Sep 17 00:00:00 2001 From: Biliana Date: Mon, 25 Feb 2019 18:42:30 +0100 Subject: [PATCH 09/17] Fix codestyle with prettier --- lib/__tests__/ignore.test.js | 31 +++++++++++++++++++++---------- lib/__tests__/standalone.test.js | 12 +++++++----- lib/standalone.js | 4 +--- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/lib/__tests__/ignore.test.js b/lib/__tests__/ignore.test.js index 619d84781d..2b8e2b79dd 100644 --- a/lib/__tests__/ignore.test.js +++ b/lib/__tests__/ignore.test.js @@ -215,8 +215,11 @@ describe("specified `ignorePath` file ignoring one file", () => { } }, ignorePath: path.join(__dirname, "fixtures/ignore.txt") - }).then(() => { throw new Error("should not have succeeded") }) - .catch((actualError) => { + }) + .then(() => { + throw new Error("should not have succeeded"); + }) + .catch(actualError => { errorMessage = actualError; }); }); @@ -251,8 +254,11 @@ describe("specified `ignorePattern` file ignoring one file", () => { } }, ignorePattern: "fixtures/empty-block.css" - }).then(() => { throw new Error("should not have succeeded") }) - .catch((actualError) => { + }) + .then(() => { + throw new Error("should not have succeeded"); + }) + .catch(actualError => { errorMessage = actualError; }); }); @@ -293,8 +299,11 @@ describe("specified `ignorePattern` file ignoring two files", () => { "fixtures/empty-block.css", "fixtures/no-syntax-error.css" ] - }).then(() => { throw new Error("should not have succeeded") }) - .catch((actualError) => { + }) + .then(() => { + throw new Error("should not have succeeded"); + }) + .catch(actualError => { errorMessage = actualError; }); }); @@ -451,8 +460,9 @@ describe("file in node_modules", () => { return lint() .then(() => { throw new Error("should not have succeeded"); - }).catch((actualError) => { - expect(actualError).toEqual(noFilesErrorMessage) + }) + .catch(actualError => { + expect(actualError).toEqual(noFilesErrorMessage); }); }); }); @@ -475,8 +485,9 @@ describe("file in bower_components", () => { return lint() .then(() => { throw new Error("should not have succeeded"); - }).catch((actualError) => { - expect(actualError).toEqual(noFilesErrorMessage) + }) + .catch(actualError => { + expect(actualError).toEqual(noFilesErrorMessage); }); }); }); diff --git a/lib/__tests__/standalone.test.js b/lib/__tests__/standalone.test.js index 0f6db2741b..39aa29f0a6 100644 --- a/lib/__tests__/standalone.test.js +++ b/lib/__tests__/standalone.test.js @@ -122,11 +122,13 @@ it("standalone with non-existent-file throws an error", () => { return standalone({ files: `${fixturesPath}/non-existent-file.css`, config: configBlockNoEmpty - }).then(() => { - throw new Error("should not have succeeded"); - }).catch((actualError) => { - expect(actualError).toEqual(expectedError) - }); + }) + .then(() => { + throw new Error("should not have succeeded"); + }) + .catch(actualError => { + expect(actualError).toEqual(expectedError); + }); }); it("standalone with non-existent-file and allowEmptyInput enabled quietly exits", () => { diff --git a/lib/standalone.js b/lib/standalone.js index f336a5aa41..bbd05b158f 100644 --- a/lib/standalone.js +++ b/lib/standalone.js @@ -200,9 +200,7 @@ module.exports = function( if (!filePaths.length) { if (!allowEmptyInput) { - throw new Error( - "The specified `files` glob returns no results" - ); + throw new Error("The specified `files` glob returns no results"); } return Promise.all([]); From 3200db032adb6ed4c3668a9e6a253c924dd205a5 Mon Sep 17 00:00:00 2001 From: Biliana Date: Wed, 27 Feb 2019 17:26:43 +0100 Subject: [PATCH 10/17] Update error message to use glob pattern specified by user --- lib/__tests__/ignore.test.js | 43 +++++++++++++----------------- lib/__tests__/standalone.test.js | 8 +++--- lib/standalone.js | 3 ++- lib/testUtils/noFilesFoundError.js | 13 +++++++++ 4 files changed, 38 insertions(+), 29 deletions(-) create mode 100644 lib/testUtils/noFilesFoundError.js diff --git a/lib/__tests__/ignore.test.js b/lib/__tests__/ignore.test.js index 2b8e2b79dd..e73cb5ff86 100644 --- a/lib/__tests__/ignore.test.js +++ b/lib/__tests__/ignore.test.js @@ -2,7 +2,7 @@ const path = require("path"); const standalone = require("../standalone"); - +const NoFilesFoundError = require("../testUtils/NoFilesFoundError"); const fixturesPath = path.join(__dirname, "fixtures"); describe("extending config and ignoreFiles glob ignoring single glob", () => { @@ -191,9 +191,8 @@ describe("extending config with ignoreFiles glob ignoring one by negation", () = }); describe("specified `ignorePath` file ignoring one file", () => { - const noFilesErrorMessage = new Error( - "The specified `files` glob returns no results" - ); + const files = [`${fixturesPath}/empty-block.css`]; + const noFilesErrorMessage = new NoFilesFoundError(files); let actualCwd; let errorMessage; @@ -208,7 +207,7 @@ describe("specified `ignorePath` file ignoring one file", () => { beforeEach(() => { return standalone({ - files: [`${fixturesPath}/empty-block.css`], + files, config: { rules: { "block-no-empty": true @@ -230,9 +229,8 @@ describe("specified `ignorePath` file ignoring one file", () => { }); describe("specified `ignorePattern` file ignoring one file", () => { - const noFilesErrorMessage = new Error( - "The specified `files` glob returns no results" - ); + const files = [`${fixturesPath}/empty-block.css`]; + const noFilesErrorMessage = new NoFilesFoundError(files); let actualCwd; let errorMessage; @@ -247,7 +245,7 @@ describe("specified `ignorePattern` file ignoring one file", () => { beforeEach(() => { return standalone({ - files: [`${fixturesPath}/empty-block.css`], + files, config: { rules: { "block-no-empty": true @@ -269,9 +267,11 @@ describe("specified `ignorePattern` file ignoring one file", () => { }); describe("specified `ignorePattern` file ignoring two files", () => { - const noFilesErrorMessage = new Error( - "The specified `files` glob returns no results" - ); + const files = [ + `${fixturesPath}/empty-block.css`, + `${fixturesPath}/no-syntax-error.css` + ]; + const noFilesErrorMessage = new NoFilesFoundError(files); let actualCwd; let errorMessage; @@ -286,10 +286,7 @@ describe("specified `ignorePattern` file ignoring two files", () => { beforeEach(() => { return standalone({ - files: [ - `${fixturesPath}/empty-block.css`, - `${fixturesPath}/no-syntax-error.css` - ], + files, config: { rules: { "block-no-empty": true @@ -443,12 +440,11 @@ describe("using codeFilename and ignoreFiles with configBasedir", () => { }); describe("file in node_modules", () => { - const noFilesErrorMessage = new Error( - "The specified `files` glob returns no results" - ); + const files = [`${fixturesPath}/node_modules/test.css`]; + const noFilesErrorMessage = new NoFilesFoundError(files); const lint = () => standalone({ - files: [`${fixturesPath}/node_modules/test.css`], + files, config: { rules: { "block-no-empty": true @@ -468,12 +464,11 @@ describe("file in node_modules", () => { }); describe("file in bower_components", () => { - const noFilesErrorMessage = new Error( - "The specified `files` glob returns no results" - ); + const files = [`${fixturesPath}/bower_components/test.css`]; + const noFilesErrorMessage = new NoFilesFoundError(files); const lint = () => standalone({ - files: [`${fixturesPath}/bower_components/test.css`], + files, config: { rules: { "block-no-empty": true diff --git a/lib/__tests__/standalone.test.js b/lib/__tests__/standalone.test.js index 39aa29f0a6..5c2fb1bf61 100644 --- a/lib/__tests__/standalone.test.js +++ b/lib/__tests__/standalone.test.js @@ -3,6 +3,7 @@ const configBlockNoEmpty = require("./fixtures/config-block-no-empty"); const path = require("path"); const standalone = require("../standalone"); +const NoFilesFoundError = require("../testUtils/NoFilesFoundError"); const fixturesPath = path.join(__dirname, "fixtures"); @@ -115,12 +116,11 @@ it("standalone without input css and file(s) should throw error", () => { }); it("standalone with non-existent-file throws an error", () => { - const expectedError = new Error( - "The specified `files` glob returns no results" - ); + const files = `${fixturesPath}/non-existent-file.css`; + const expectedError = new NoFilesFoundError(files); return standalone({ - files: `${fixturesPath}/non-existent-file.css`, + files, config: configBlockNoEmpty }) .then(() => { diff --git a/lib/standalone.js b/lib/standalone.js index bbd05b158f..9cfb6c6313 100644 --- a/lib/standalone.js +++ b/lib/standalone.js @@ -10,6 +10,7 @@ const filterFilePaths = require("./utils/filterFilePaths"); const formatters = require("./formatters"); const fs = require("fs"); const getFormatterOptionsText = require("./utils/getFormatterOptionsText"); +const NoFilesFoundError = require("./testUtils/NoFilesFoundError"); const globby /*: Function*/ = require("globby"); const hash = require("./utils/hash"); const ignore = require("ignore"); @@ -200,7 +201,7 @@ module.exports = function( if (!filePaths.length) { if (!allowEmptyInput) { - throw new Error("The specified `files` glob returns no results"); + throw new NoFilesFoundError(fileList); } return Promise.all([]); diff --git a/lib/testUtils/noFilesFoundError.js b/lib/testUtils/noFilesFoundError.js new file mode 100644 index 0000000000..d42fa64c5a --- /dev/null +++ b/lib/testUtils/noFilesFoundError.js @@ -0,0 +1,13 @@ +class NoFilesFoundError extends Error { + constructor(fileList) { + super(); + + if (typeof fileList === "string") { + fileList = [fileList]; + } + const pattern = fileList.filter(i => !i.startsWith("!")).join(", "); + this.message = `No files matching the pattern "${pattern}" were found.`; + } +} + +module.exports = NoFilesFoundError; From 22958291027bc5cc7a13a57cc7c1fc5d596f51a0 Mon Sep 17 00:00:00 2001 From: Biliana Date: Wed, 27 Feb 2019 17:41:11 +0100 Subject: [PATCH 11/17] Fix errors --- lib/__tests__/ignore.test.js | 3 ++- lib/__tests__/standalone.test.js | 2 +- lib/standalone.js | 2 +- lib/testUtils/noFilesFoundError.js | 4 ++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/__tests__/ignore.test.js b/lib/__tests__/ignore.test.js index e73cb5ff86..8cce2601ee 100644 --- a/lib/__tests__/ignore.test.js +++ b/lib/__tests__/ignore.test.js @@ -1,8 +1,9 @@ "use strict"; const path = require("path"); +const NoFilesFoundError = require("../testUtils/noFilesFoundError"); const standalone = require("../standalone"); -const NoFilesFoundError = require("../testUtils/NoFilesFoundError"); + const fixturesPath = path.join(__dirname, "fixtures"); describe("extending config and ignoreFiles glob ignoring single glob", () => { diff --git a/lib/__tests__/standalone.test.js b/lib/__tests__/standalone.test.js index 5c2fb1bf61..8e326d5c1a 100644 --- a/lib/__tests__/standalone.test.js +++ b/lib/__tests__/standalone.test.js @@ -1,9 +1,9 @@ "use strict"; const configBlockNoEmpty = require("./fixtures/config-block-no-empty"); +const NoFilesFoundError = require("../testUtils/noFilesFoundError"); const path = require("path"); const standalone = require("../standalone"); -const NoFilesFoundError = require("../testUtils/NoFilesFoundError"); const fixturesPath = path.join(__dirname, "fixtures"); diff --git a/lib/standalone.js b/lib/standalone.js index 9cfb6c6313..958c41ac05 100644 --- a/lib/standalone.js +++ b/lib/standalone.js @@ -10,11 +10,11 @@ const filterFilePaths = require("./utils/filterFilePaths"); const formatters = require("./formatters"); const fs = require("fs"); const getFormatterOptionsText = require("./utils/getFormatterOptionsText"); -const NoFilesFoundError = require("./testUtils/NoFilesFoundError"); const globby /*: Function*/ = require("globby"); const hash = require("./utils/hash"); const ignore = require("ignore"); const needlessDisables /*: Function*/ = require("./needlessDisables"); +const NoFilesFoundError = require("./testUtils/noFilesFoundError"); const path = require("path"); const pify = require("pify"); const pkg = require("../package.json"); diff --git a/lib/testUtils/noFilesFoundError.js b/lib/testUtils/noFilesFoundError.js index d42fa64c5a..a91eb26515 100644 --- a/lib/testUtils/noFilesFoundError.js +++ b/lib/testUtils/noFilesFoundError.js @@ -1,3 +1,5 @@ +"use strict"; + class NoFilesFoundError extends Error { constructor(fileList) { super(); @@ -5,7 +7,9 @@ class NoFilesFoundError extends Error { if (typeof fileList === "string") { fileList = [fileList]; } + const pattern = fileList.filter(i => !i.startsWith("!")).join(", "); + this.message = `No files matching the pattern "${pattern}" were found.`; } } From 2d086cc2ada1dcbc364ffb3524c7d564bbe88e7a Mon Sep 17 00:00:00 2001 From: Biliana Date: Wed, 27 Feb 2019 17:55:49 +0100 Subject: [PATCH 12/17] Fix requires order --- lib/__tests__/ignore.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/__tests__/ignore.test.js b/lib/__tests__/ignore.test.js index 8cce2601ee..3237ead10d 100644 --- a/lib/__tests__/ignore.test.js +++ b/lib/__tests__/ignore.test.js @@ -1,7 +1,7 @@ "use strict"; -const path = require("path"); const NoFilesFoundError = require("../testUtils/noFilesFoundError"); +const path = require("path"); const standalone = require("../standalone"); const fixturesPath = path.join(__dirname, "fixtures"); From 5db668960ba79232828a4e8c3ad1c5eba5e2fe7b Mon Sep 17 00:00:00 2001 From: Aleks Hudochenkov Date: Thu, 11 Apr 2019 22:27:00 +0200 Subject: [PATCH 13/17] Fix typo in lib/cli.js Co-Authored-By: Bilie --- lib/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli.js b/lib/cli.js index 5c60625fb6..a00537f4b2 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -281,7 +281,7 @@ const meowOptions /*: meowOptionsType*/ = { Show the currently installed version of stylelint. - --alow-empty-input + --allow-empty-input When glob pattern matches no files, the process will exit without throwing an error. `, From 4ed2ee934f031a07842a86ba508e60ef61d0efaa Mon Sep 17 00:00:00 2001 From: Bilie Date: Thu, 11 Apr 2019 22:48:37 +0200 Subject: [PATCH 14/17] Move noFilesFoundError to utils folder --- lib/__tests__/ignore.test.js | 2 +- lib/__tests__/standalone.test.js | 2 +- lib/standalone.js | 2 +- lib/{testUtils => utils}/noFilesFoundError.js | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename lib/{testUtils => utils}/noFilesFoundError.js (100%) diff --git a/lib/__tests__/ignore.test.js b/lib/__tests__/ignore.test.js index 3237ead10d..ef3b88952f 100644 --- a/lib/__tests__/ignore.test.js +++ b/lib/__tests__/ignore.test.js @@ -1,6 +1,6 @@ "use strict"; -const NoFilesFoundError = require("../testUtils/noFilesFoundError"); +const NoFilesFoundError = require("../utils/noFilesFoundError"); const path = require("path"); const standalone = require("../standalone"); diff --git a/lib/__tests__/standalone.test.js b/lib/__tests__/standalone.test.js index 8e326d5c1a..ebe22e35af 100644 --- a/lib/__tests__/standalone.test.js +++ b/lib/__tests__/standalone.test.js @@ -1,7 +1,7 @@ "use strict"; const configBlockNoEmpty = require("./fixtures/config-block-no-empty"); -const NoFilesFoundError = require("../testUtils/noFilesFoundError"); +const NoFilesFoundError = require("../utils/noFilesFoundError"); const path = require("path"); const standalone = require("../standalone"); diff --git a/lib/standalone.js b/lib/standalone.js index 958c41ac05..a4f8f06555 100644 --- a/lib/standalone.js +++ b/lib/standalone.js @@ -14,7 +14,7 @@ const globby /*: Function*/ = require("globby"); const hash = require("./utils/hash"); const ignore = require("ignore"); const needlessDisables /*: Function*/ = require("./needlessDisables"); -const NoFilesFoundError = require("./testUtils/noFilesFoundError"); +const NoFilesFoundError = require("./utils/noFilesFoundError"); const path = require("path"); const pify = require("pify"); const pkg = require("../package.json"); diff --git a/lib/testUtils/noFilesFoundError.js b/lib/utils/noFilesFoundError.js similarity index 100% rename from lib/testUtils/noFilesFoundError.js rename to lib/utils/noFilesFoundError.js From 7b662723aa0ca44f6abbd09fffe435bb3f122955 Mon Sep 17 00:00:00 2001 From: Bilie Date: Thu, 11 Apr 2019 22:57:37 +0200 Subject: [PATCH 15/17] Remove not necessary error in test --- lib/__tests__/standalone.test.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/__tests__/standalone.test.js b/lib/__tests__/standalone.test.js index ebe22e35af..bb143b08cf 100644 --- a/lib/__tests__/standalone.test.js +++ b/lib/__tests__/standalone.test.js @@ -122,13 +122,9 @@ it("standalone with non-existent-file throws an error", () => { return standalone({ files, config: configBlockNoEmpty - }) - .then(() => { - throw new Error("should not have succeeded"); - }) - .catch(actualError => { - expect(actualError).toEqual(expectedError); - }); + }).catch(actualError => { + expect(actualError).toEqual(expectedError); + }); }); it("standalone with non-existent-file and allowEmptyInput enabled quietly exits", () => { From 47b3d61cf8a4d47b4247bd02d5ceff8a45deab5d Mon Sep 17 00:00:00 2001 From: Biliana Date: Fri, 12 Apr 2019 10:13:30 +0200 Subject: [PATCH 16/17] Remove not necessary error in test --- lib/__tests__/ignore.test.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lib/__tests__/ignore.test.js b/lib/__tests__/ignore.test.js index ef3b88952f..358cc4e0e5 100644 --- a/lib/__tests__/ignore.test.js +++ b/lib/__tests__/ignore.test.js @@ -216,9 +216,6 @@ describe("specified `ignorePath` file ignoring one file", () => { }, ignorePath: path.join(__dirname, "fixtures/ignore.txt") }) - .then(() => { - throw new Error("should not have succeeded"); - }) .catch(actualError => { errorMessage = actualError; }); @@ -254,9 +251,6 @@ describe("specified `ignorePattern` file ignoring one file", () => { }, ignorePattern: "fixtures/empty-block.css" }) - .then(() => { - throw new Error("should not have succeeded"); - }) .catch(actualError => { errorMessage = actualError; }); @@ -298,9 +292,6 @@ describe("specified `ignorePattern` file ignoring two files", () => { "fixtures/no-syntax-error.css" ] }) - .then(() => { - throw new Error("should not have succeeded"); - }) .catch(actualError => { errorMessage = actualError; }); @@ -455,9 +446,6 @@ describe("file in node_modules", () => { it("is ignored", () => { return lint() - .then(() => { - throw new Error("should not have succeeded"); - }) .catch(actualError => { expect(actualError).toEqual(noFilesErrorMessage); }); @@ -479,9 +467,6 @@ describe("file in bower_components", () => { it("is ignored", () => { return lint() - .then(() => { - throw new Error("should not have succeeded"); - }) .catch(actualError => { expect(actualError).toEqual(noFilesErrorMessage); }); From 903080ba4e8b41effefc2b046763ebc1a89a1936 Mon Sep 17 00:00:00 2001 From: Biliana Date: Fri, 12 Apr 2019 17:36:07 +0200 Subject: [PATCH 17/17] Fix linting errors --- lib/__tests__/ignore.test.js | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/lib/__tests__/ignore.test.js b/lib/__tests__/ignore.test.js index 358cc4e0e5..f6f68aa66c 100644 --- a/lib/__tests__/ignore.test.js +++ b/lib/__tests__/ignore.test.js @@ -215,10 +215,9 @@ describe("specified `ignorePath` file ignoring one file", () => { } }, ignorePath: path.join(__dirname, "fixtures/ignore.txt") - }) - .catch(actualError => { - errorMessage = actualError; - }); + }).catch(actualError => { + errorMessage = actualError; + }); }); it("no files read", () => { @@ -250,10 +249,9 @@ describe("specified `ignorePattern` file ignoring one file", () => { } }, ignorePattern: "fixtures/empty-block.css" - }) - .catch(actualError => { - errorMessage = actualError; - }); + }).catch(actualError => { + errorMessage = actualError; + }); }); it("no files read", () => { @@ -291,10 +289,9 @@ describe("specified `ignorePattern` file ignoring two files", () => { "fixtures/empty-block.css", "fixtures/no-syntax-error.css" ] - }) - .catch(actualError => { - errorMessage = actualError; - }); + }).catch(actualError => { + errorMessage = actualError; + }); }); it("no files read", () => { @@ -445,10 +442,9 @@ describe("file in node_modules", () => { }); it("is ignored", () => { - return lint() - .catch(actualError => { - expect(actualError).toEqual(noFilesErrorMessage); - }); + return lint().catch(actualError => { + expect(actualError).toEqual(noFilesErrorMessage); + }); }); }); @@ -466,10 +462,9 @@ describe("file in bower_components", () => { }); it("is ignored", () => { - return lint() - .catch(actualError => { - expect(actualError).toEqual(noFilesErrorMessage); - }); + return lint().catch(actualError => { + expect(actualError).toEqual(noFilesErrorMessage); + }); }); });