diff --git a/flow-typed/stylelint.js b/flow-typed/stylelint.js index d8f117195d..f1ea6bfad6 100644 --- a/flow-typed/stylelint.js +++ b/flow-typed/stylelint.js @@ -146,6 +146,7 @@ export type stylelint$standaloneOptions = { ignorePattern?: RegExp, reportNeedlessDisables?: boolean, reportInvalidScopeDisables?: boolean, + noglob?: boolean, maxWarnings?: number, syntax?: stylelint$syntaxes, customSyntax?: string, diff --git a/lib/cli.js b/lib/cli.js index 01561d8598..e8474563aa 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -124,6 +124,7 @@ const EXIT_CODE_ERROR = 2; ignorePath: string, ignorePattern: string, maxWarnings: number, + noglob: boolean, outputFile: string, quiet: any, reportNeedlessDisables: boolean, @@ -156,6 +157,7 @@ const EXIT_CODE_ERROR = 2; fix?: any, ignoreDisables?: any, ignorePath?: any, + noglob?: boolean, outputFile?: string, reportNeedlessDisables?: boolean, reportInvalidScopeDisables?: boolean, @@ -290,6 +292,10 @@ const meowOptions /*: meowOptionsType*/ = { Useful when setting "defaultSeverity" to "warning" and expecting the process to fail on warnings (e.g. CI build). + --noglob + + Use filenames exactly from parameters, without glob matching. + --output-file, -o Path of file to write report. @@ -361,6 +367,9 @@ const meowOptions /*: meowOptionsType*/ = { 'no-color': { type: 'boolean', }, + noglob: { + type: 'boolean', + }, 'output-file': { alias: 'o', type: 'string', @@ -483,6 +492,10 @@ module.exports = (argv /*: string[]*/) /*: Promise|void*/ => { optionsBase.fix = cli.flags.fix; } + if (cli.flags.noglob) { + optionsBase.noglob = true; + } + if (cli.flags.outputFile) { optionsBase.outputFile = cli.flags.outputFile; } diff --git a/lib/standalone.js b/lib/standalone.js index 42d2fb46ee..8bd54d7b46 100644 --- a/lib/standalone.js +++ b/lib/standalone.js @@ -170,7 +170,7 @@ module.exports = function( fileList = [fileList]; } - if (!options.disableDefaultIgnores) { + if (!options.disableDefaultIgnores && !options.noglob) { fileList = fileList.concat(ALWAYS_IGNORED_GLOBS.map((glob) => '!' + glob)); } @@ -186,7 +186,7 @@ module.exports = function( fileCache.destroy(); } - return globby(fileList, globbyOptions) + return (options.noglob ? Promise.resolve(fileList) : globby(fileList, globbyOptions)) .then((filePaths) => { // The ignorer filter needs to check paths relative to cwd filePaths = filterFilePaths(ignorer, filePaths.map((p) => path.relative(process.cwd(), p))); diff --git a/system-tests/cli/A.css b/system-tests/cli/A.css new file mode 100644 index 0000000000..38845a2211 --- /dev/null +++ b/system-tests/cli/A.css @@ -0,0 +1 @@ +div { display: none; } \ No newline at end of file diff --git a/system-tests/cli/B.css b/system-tests/cli/B.css new file mode 100644 index 0000000000..38845a2211 --- /dev/null +++ b/system-tests/cli/B.css @@ -0,0 +1 @@ +div { display: none; } \ No newline at end of file diff --git a/system-tests/cli/[style].css b/system-tests/cli/[style].css new file mode 100644 index 0000000000..38845a2211 --- /dev/null +++ b/system-tests/cli/[style].css @@ -0,0 +1 @@ +div { display: none; } \ No newline at end of file diff --git a/system-tests/cli/cli.test.js b/system-tests/cli/cli.test.js index 74c6723279..5fbc1f2b00 100644 --- a/system-tests/cli/cli.test.js +++ b/system-tests/cli/cli.test.js @@ -114,4 +114,48 @@ describe('CLI', () => { ); }); }); + + describe('--noglob', () => { + it('enabled. file exists', () => { + return Promise.resolve( + cli([ + '--noglob', + '--config', + path.join(__dirname, 'config.json'), + path.join(__dirname, '[style].css'), + ]), + ).then(() => { + expect(process.exitCode).toBeUndefined(); + }); + }); + + it('enabled. file does not exist', () => { + return Promise.resolve( + cli([ + '--noglob', + '--config', + path.join(__dirname, 'config.json'), + path.join(__dirname, '[AB].css'), + ]), + ).then(() => { + expect(process.exitCode).toBe(1); + }); + }); + + it('disable. match files exist', () => { + return Promise.resolve( + cli(['--config', path.join(__dirname, 'config.json'), path.join(__dirname, '[AB].css')]), + ).then(() => { + expect(process.exitCode).toBeUndefined(); + }); + }); + + it('disable. match files do not exist', () => { + return Promise.resolve( + cli(['--config', path.join(__dirname, 'config.json'), path.join(__dirname, '[style].css')]), + ).then(() => { + expect(process.exitCode).toBe(1); + }); + }); + }); });