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 --globby-options flag #6437

Merged
merged 18 commits into from Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
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
4 changes: 4 additions & 0 deletions docs/user-guide/usage/cli.md
Expand Up @@ -68,6 +68,10 @@ Automatically fix, where possible, problems reported by rules. [More info](optio

Specify the formatter to format your results. [More info](options.md#formatter).

## `--globbyOptions, --go`

Options in JSON format passed to [globby](https://github.com/sindresorhus/globby). [More info](options.md#globbyoptions).

### `--ignore-disables, --id`

Ignore `stylelint-disable` (e.g. `/* stylelint-disable block-no-empty */`) comments. [More info](options.md#ignoredisables).
Expand Down
6 changes: 6 additions & 0 deletions docs/user-guide/usage/options.md
Expand Up @@ -139,6 +139,12 @@ CLI flags: `--disable-default-ignores, --di`

Disable the default ignores. Stylelint will not automatically ignore the contents of `node_modules`.

## `globbyOptions`

CLI flags: `--globby-options, --go`

Options passed to [globby](https://github.com/sindresorhus/globby). [More info](node-api.md#globbyoptions).

## `ignorePath`

CLI flags: `--ignore-path, -i`
Expand Down
184 changes: 94 additions & 90 deletions lib/__tests__/__snapshots__/cli.test.js.snap
Expand Up @@ -4,150 +4,154 @@ exports[`CLI --help 1`] = `
"
A mighty, modern CSS linter.

Usage: stylelint [input] [options]
Usage: stylelint [input] [options]

Input: Files(s), glob(s), or nothing to use stdin.
Input: Files(s), glob(s), or nothing to use stdin.

If an input argument is wrapped in quotation marks, it will be passed to
globby for cross-platform glob support. node_modules are always ignored.
You can also pass no input and use stdin, instead.
If an input argument is wrapped in quotation marks, it will be passed to
globby for cross-platform glob support. node_modules are always ignored.
You can also pass no input and use stdin, instead.

Options:
Options:

--config
--config

Path to a specific configuration file (JSON, YAML, or CommonJS), or the
name of a module in node_modules that points to one. If no --config
argument is provided, stylelint will search for configuration files in
the following places, in this order:
- a stylelint property in package.json
- a .stylelintrc file (with or without filename extension:
.json, .yaml, .yml, and .js are available)
- a stylelint.config.js file exporting a JS object
The search will begin in the working directory and move up the directory
tree until a configuration file is found.
Path to a specific configuration file (JSON, YAML, or CommonJS), or the
name of a module in node_modules that points to one. If no --config
argument is provided, stylelint will search for configuration files in
the following places, in this order:
- a stylelint property in package.json
- a .stylelintrc file (with or without filename extension:
.json, .yaml, .yml, and .js are available)
- a stylelint.config.js file exporting a JS object
The search will begin in the working directory and move up the directory
tree until a configuration file is found.

--config-basedir
--config-basedir

An absolute path to the directory that relative paths defining \\"extends\\"
and \\"plugins\\" are *relative to*. Only necessary if these values are
relative paths.
An absolute path to the directory that relative paths defining \\"extends\\"
and \\"plugins\\" are *relative to*. Only necessary if these values are
relative paths.

--print-config
--print-config

Print the configuration for the given path.
Print the configuration for the given path.

--ignore-path, -i
--ignore-path, -i

Path to a file containing patterns that describe files to ignore. The
path can be absolute or relative to process.cwd(). You can repeat the
option to provide multiple paths. By default, Stylelint looks for
.stylelintignore in process.cwd().
Path to a file containing patterns that describe files to ignore. The
path can be absolute or relative to process.cwd(). You can repeat the
option to provide multiple paths. By default, Stylelint looks for
.stylelintignore in process.cwd().

--ignore-pattern, --ip
--ignore-pattern, --ip

Pattern of files to ignore (in addition to those in .stylelintignore)
Pattern of files to ignore (in addition to those in .stylelintignore)

--fix
--fix

Automatically fix problems of certain rules.
Automatically fix problems of certain rules.

--custom-syntax
--custom-syntax

Module name or path to a JS file exporting a PostCSS-compatible syntax.
Module name or path to a JS file exporting a PostCSS-compatible syntax.

--stdin
--stdin

Accept stdin input even if it is empty.
Accept stdin input even if it is empty.

--stdin-filename
--stdin-filename

A filename to assign stdin input.
A filename to assign stdin input.

--ignore-disables, --id
--ignore-disables, --id

Ignore stylelint-disable comments.
Ignore stylelint-disable comments.

--disable-default-ignores, --di
--disable-default-ignores, --di

Allow linting of node_modules.
Allow linting of node_modules.

--cache [default: false]
--cache [default: false]

Store the info about processed files in order to only operate on the
changed ones the next time you run stylelint. By default, the cache
is stored in \\"./.stylelintcache\\". To adjust this, use --cache-location.
Store the info about processed files in order to only operate on the
changed ones the next time you run stylelint. By default, the cache
is stored in \\"./.stylelintcache\\". To adjust this, use --cache-location.

--cache-location [default: '.stylelintcache']
--cache-location [default: '.stylelintcache']

Path to a file or directory to be used for the cache location.
Default is \\"./.stylelintcache\\". If a directory is specified, a cache
file will be created inside the specified folder, with a name derived
from a hash of the current working directory.
Path to a file or directory to be used for the cache location.
Default is \\"./.stylelintcache\\". If a directory is specified, a cache
file will be created inside the specified folder, with a name derived
from a hash of the current working directory.

If the directory for the cache does not exist, make sure you add a trailing \\"/\\"
on *nix systems or \\"\\\\\\" on Windows. Otherwise the path will be assumed to be a file.
If the directory for the cache does not exist, make sure you add a trailing \\"/\\"
on *nix systems or \\"\\\\\\" on Windows. Otherwise the path will be assumed to be a file.

--cache-strategy [default: \\"metadata\\"]
--cache-strategy [default: \\"metadata\\"]

Strategy for the cache to use for detecting changed files. Can be either
\\"metadata\\" or \\"content\\".
Strategy for the cache to use for detecting changed files. Can be either
\\"metadata\\" or \\"content\\".

The \\"content\\" strategy can be useful in cases where the modification time of
your files changes even if their contents have not. For example, this can happen
during git operations like \\"git clone\\" because git does not track file modification
time.
The \\"content\\" strategy can be useful in cases where the modification time of
your files changes even if their contents have not. For example, this can happen
during git operations like \\"git clone\\" because git does not track file modification
time.

--formatter, -f [default: \\"string\\"]
--formatter, -f [default: \\"string\\"]

The output formatter: \\"compact\\", \\"github\\", \\"json\\", \\"string\\", \\"tap\\", \\"unix\\" or \\"verbose\\".
The output formatter: \\"compact\\", \\"github\\", \\"json\\", \\"string\\", \\"tap\\", \\"unix\\" or \\"verbose\\".

--custom-formatter
--custom-formatter

Path to a JS file exporting a custom formatting function.
The file can either be a filesystem path, a module name, or a file to load from a dependency.
Path to a JS file exporting a custom formatting function.
The file can either be a filesystem path, a module name, or a file to load from a dependency.

--quiet, -q
--quiet, -q

Only register problems for rules with an \\"error\\"-level severity (ignore
\\"warning\\"-level).
Only register problems for rules with an \\"error\\"-level severity (ignore
\\"warning\\"-level).

--color
--no-color
--color
--no-color

Force enabling/disabling of color.
Force enabling/disabling of color.

--report-needless-disables, --rd
--report-needless-disables, --rd

Also report errors for stylelint-disable comments that are not blocking a lint warning.
The process will exit with code 2 if needless disables are found.
Also report errors for stylelint-disable comments that are not blocking a lint warning.
The process will exit with code 2 if needless disables are found.

--report-invalid-scope-disables, --risd
--report-invalid-scope-disables, --risd

Report stylelint-disable comments that used for rules that don't exist within the configuration object.
The process will exit with code 2 if invalid scope disables are found.
Report stylelint-disable comments that used for rules that don't exist within the configuration object.
The process will exit with code 2 if invalid scope disables are found.

--report-descriptionless-disables, --rdd
--report-descriptionless-disables, --rdd

Report stylelint-disable comments without a description.
The process will exit with code 2 if descriptionless disables are found.
Report stylelint-disable comments without a description.
The process will exit with code 2 if descriptionless disables are found.

--max-warnings, --mw
--max-warnings, --mw

Number of warnings above which the process will exit with code 2.
Useful when setting \\"defaultSeverity\\" to \\"warning\\" and expecting the
process to fail on warnings (e.g. CI build).
Number of warnings above which the process will exit with code 2.
Useful when setting \\"defaultSeverity\\" to \\"warning\\" and expecting the
process to fail on warnings (e.g. CI build).

--output-file, -o
--output-file, -o

Path of file to write report.
Path of file to write report.

--version, -v
--version, -v

Show the currently installed version of stylelint.
Show the currently installed version of stylelint.

--allow-empty-input, --aei
--allow-empty-input, --aei

When glob pattern matches no files, the process will exit without throwing an error.
When glob pattern matches no files, the process will exit without throwing an error.

--globby-options, --go

Options in JSON format passed to globby.
"
`;
28 changes: 28 additions & 0 deletions lib/__tests__/cli.test.js
Expand Up @@ -50,6 +50,11 @@ describe('buildCLI', () => {
expect(buildCLI(['--cache-location=foo']).flags.cacheLocation).toBe('foo');
});

it('flags.globbyOptions', () => {
expect(buildCLI(['--globby-options={"dot":true}']).flags.globbyOptions).toBe('{"dot":true}');
expect(buildCLI(['--go={"dot":true}']).flags.globbyOptions).toBe('{"dot":true}');
});

it('flags.cacheStrategy', () => {
expect(buildCLI(['--cache-strategy=content']).flags.cacheStrategy).toBe('content');
expect(buildCLI(['--cache-strategy=metadata']).flags.cacheStrategy).toBe('metadata');
Expand Down Expand Up @@ -361,6 +366,29 @@ describe('CLI', () => {
expect(output).toBe('Custom formatter reports 1 warning(s).');
});

it('output a message when wrong --globby-options provided', async () => {
await cli(['--globby-options=wrong']);

expect(process.exitCode).toBe(2);
expect(process.stdout.write).toHaveBeenCalledTimes(0);
expect(process.stderr.write).toHaveBeenCalledTimes(1);
expect(stripAnsi(process.stderr.write.mock.calls[0][0])).toContain(
'Invalid option "--globby-options". The value "wrong" is not valid JSON object.',
);
});
ybiquitous marked this conversation as resolved.
Show resolved Hide resolved

it('--globby-options', async () => {
await cli([
'--globby-options={"dot":true}',
'--config',
fixturesPath('config-block-no-empty.json'),
fixturesPath('globby-options'),
]);

expect(process.stdout.write).toHaveBeenCalledTimes(1);
expect(process.stdout.write).toHaveBeenCalledWith(expect.stringMatching(/block-no-empty/));
});

ybiquitous marked this conversation as resolved.
Show resolved Hide resolved
it('--custom-formatter with node module', async () => {
await cli([
`--custom-formatter=stylelint-test-custom-formatter`,
Expand Down
1 change: 1 addition & 0 deletions lib/__tests__/fixtures/globby-options/.dot/empty-block.css
@@ -0,0 +1 @@
a {}