Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --noglob cli option #4286

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions flow-typed/stylelint.js
Expand Up @@ -146,6 +146,7 @@ export type stylelint$standaloneOptions = {
ignorePattern?: RegExp,
reportNeedlessDisables?: boolean,
reportInvalidScopeDisables?: boolean,
noglob?: boolean,
maxWarnings?: number,
syntax?: stylelint$syntaxes,
customSyntax?: string,
Expand Down
13 changes: 13 additions & 0 deletions lib/cli.js
Expand Up @@ -124,6 +124,7 @@ const EXIT_CODE_ERROR = 2;
ignorePath: string,
ignorePattern: string,
maxWarnings: number,
noglob: boolean,
outputFile: string,
quiet: any,
reportNeedlessDisables: boolean,
Expand Down Expand Up @@ -156,6 +157,7 @@ const EXIT_CODE_ERROR = 2;
fix?: any,
ignoreDisables?: any,
ignorePath?: any,
noglob?: boolean,
outputFile?: string,
reportNeedlessDisables?: boolean,
reportInvalidScopeDisables?: boolean,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -361,6 +367,9 @@ const meowOptions /*: meowOptionsType*/ = {
'no-color': {
type: 'boolean',
},
noglob: {
type: 'boolean',
},
'output-file': {
alias: 'o',
type: 'string',
Expand Down Expand Up @@ -483,6 +492,10 @@ module.exports = (argv /*: string[]*/) /*: Promise<void>|void*/ => {
optionsBase.fix = cli.flags.fix;
}

if (cli.flags.noglob) {
optionsBase.noglob = true;
}

if (cli.flags.outputFile) {
optionsBase.outputFile = cli.flags.outputFile;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/standalone.js
Expand Up @@ -170,7 +170,7 @@ module.exports = function(
fileList = [fileList];
}

if (!options.disableDefaultIgnores) {
if (!options.disableDefaultIgnores && !options.noglob) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, ALWAYS_IGNORED_GLOBS is not working as expected with noglob, it is not good idea

fileList = fileList.concat(ALWAYS_IGNORED_GLOBS.map((glob) => '!' + glob));
}

Expand All @@ -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)));
Expand Down
1 change: 1 addition & 0 deletions system-tests/cli/A.css
@@ -0,0 +1 @@
div { display: none; }
1 change: 1 addition & 0 deletions system-tests/cli/B.css
@@ -0,0 +1 @@
div { display: none; }
1 change: 1 addition & 0 deletions system-tests/cli/[style].css
@@ -0,0 +1 @@
div { display: none; }
42 changes: 42 additions & 0 deletions system-tests/cli/cli.test.js
Expand Up @@ -114,4 +114,46 @@ describe('CLI', () => {
);
});
});

it('--noglob-enabled-right', () => {
vankop marked this conversation as resolved.
Show resolved Hide resolved
return Promise.resolve(
cli([
'--noglob',
'--config',
path.join(__dirname, 'config.json'),
path.join(__dirname, '[style].css'),
]),
).then(() => {
expect(process.exitCode).toBeUndefined();
});
});

it('--noglob-enabled-wrong', () => {
return Promise.resolve(
cli([
'--noglob',
'--config',
path.join(__dirname, 'config.json'),
path.join(__dirname, '[AB].css'),
]),
).then(() => {
expect(process.exitCode).toBe(1);
});
});

it('--noglob-disabled-right', () => {
return Promise.resolve(
cli(['--config', path.join(__dirname, 'config.json'), path.join(__dirname, '[AB].css')]),
).then(() => {
expect(process.exitCode).toBeUndefined();
});
});

it('--noglob-disabled-wrong', () => {
return Promise.resolve(
cli(['--config', path.join(__dirname, 'config.json'), path.join(__dirname, '[style].css')]),
).then(() => {
expect(process.exitCode).toBe(1);
});
});
});