Skip to content

Commit

Permalink
Add --no-globs parameter which ignores the "globs" property if presen…
Browse files Browse the repository at this point in the history
…t in the top-level options object (fixes #250).
  • Loading branch information
DavidAnson committed Jan 10, 2024
1 parent 7c084f1 commit 4ea8820
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 52 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ Dot-only glob:
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead
Optional parameters:
- --config specifies the path to a configuration file to define the base configuration
- --fix updates files to resolve fixable issues (can be overridden in configuration)
- --help writes this message to the console and exits without doing anything else
- --config specifies the path to a configuration file to define the base configuration
- --fix updates files to resolve fixable issues (can be overridden in configuration)
- --help writes this message to the console and exits without doing anything else
- --no-globs ignores the "globs" property if present in the top-level options object
Configuration via:
- .markdownlint-cli2.jsonc
Expand Down Expand Up @@ -290,6 +291,8 @@ of the rules within.
command-line arguments
- This setting can be used instead of (or in addition to) passing globs on
the command-line and offers identical performance
- This setting is ignored when the `--no-globs` parameter is passed on the
command-line
- This top-level setting is valid **only** in the directory from which
`markdownlint-cli2` is run
- `ignores`: `Array` of `String`s defining glob expressions to ignore when
Expand Down
14 changes: 10 additions & 4 deletions markdownlint-cli2.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,10 @@ Dot-only glob:
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead
Optional parameters:
- --config specifies the path to a configuration file to define the base configuration
- --fix updates files to resolve fixable issues (can be overridden in configuration)
- --help writes this message to the console and exits without doing anything else
- --config specifies the path to a configuration file to define the base configuration
- --fix updates files to resolve fixable issues (can be overridden in configuration)
- --help writes this message to the console and exits without doing anything else
- --no-globs ignores the "globs" property if present in the top-level options object
Configuration via:
- .markdownlint-cli2.jsonc
Expand Down Expand Up @@ -895,10 +896,12 @@ const main = async (params) => {
optionsOverride,
fileContents,
nonFileContents,
noGlobs,
noRequire,
name
} = params;
let {
noGlobs
} = params;
const logMessage = params.logMessage || noop;
const logError = params.logError || noop;
const fs = params.fs || require("node:fs");
Expand Down Expand Up @@ -929,6 +932,9 @@ const main = async (params) => {
} else if (arg === "--help") {
shouldShowHelp = true;
return false;
} else if (arg === "--no-globs") {
noGlobs = true;
return false;
}
return true;
});
Expand Down
14 changes: 14 additions & 0 deletions test/markdownlint-cli2-test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,20 @@ const testCases = ({
"exitCode": 1
});

testCase({
"name": "no-globs-and-args",
"args": [ "--no-globs", "dir/about.md", "dir/**/*.markdown" ],
"exitCode": 1,
"cwd": "globs-and-args"
});

testCase({
"name": "no-globs-and-empty-args",
"args": [ "--no-globs" ],
"exitCode": 2,
"cwd": "globs-and-args"
});

testCase({
"name": "globs-and-ignores",
"args": [],
Expand Down
131 changes: 110 additions & 21 deletions test/snapshots/markdownlint-cli2-test-exec.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ Generated by [AVA](https://avajs.dev).
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead␊
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --no-globs ignores the "globs" property if present in the top-level options object␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -89,9 +90,10 @@ Generated by [AVA](https://avajs.dev).
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead␊
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --no-globs ignores the "globs" property if present in the top-level options object␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -144,9 +146,10 @@ Generated by [AVA](https://avajs.dev).
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead␊
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --no-globs ignores the "globs" property if present in the top-level options object␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -199,9 +202,10 @@ Generated by [AVA](https://avajs.dev).
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead␊
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --no-globs ignores the "globs" property if present in the top-level options object␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -254,9 +258,10 @@ Generated by [AVA](https://avajs.dev).
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead␊
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --no-globs ignores the "globs" property if present in the top-level options object␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -309,9 +314,10 @@ Generated by [AVA](https://avajs.dev).
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead␊
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --no-globs ignores the "globs" property if present in the top-level options object␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -364,9 +370,10 @@ Generated by [AVA](https://avajs.dev).
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead␊
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --no-globs ignores the "globs" property if present in the top-level options object␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -805,6 +812,88 @@ Generated by [AVA](https://avajs.dev).
`,
}

## no-globs-and-args (exec)

> Snapshot 1
{
exitCode: 1,
formatterCodeQuality: '',
formatterJson: '',
formatterJunit: '',
formatterSarif: '',
stderr: `dir/about.md:1:1 MD021/no-multiple-space-closed-atx Multiple spaces inside hashes on closed atx style heading [Context: "# About #"]␊
dir/about.md:4 MD032/blanks-around-lists Lists should be surrounded by blank lines [Context: "1. List"]␊
dir/about.md:5:1 MD029/ol-prefix Ordered list item prefix [Expected: 2; Actual: 3; Style: 1/2/3]␊
dir/subdir/info.markdown:1 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]␊
dir/subdir/info.markdown:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## Information"]␊
dir/subdir/info.markdown:2:6 MD038/no-space-in-code Spaces inside code span elements [Context: "\` code1\`"]␊
dir/subdir/info.markdown:2:20 MD038/no-space-in-code Spaces inside code span elements [Context: "\`code2 \`"]␊
dir/subdir/info.markdown:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]␊
`,
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
Finding: dir/about.md dir/**/*.markdown␊
Linting: 2 file(s)␊
Summary: 8 error(s)␊
`,
}

## no-globs-and-empty-args (exec)

> Snapshot 1
{
exitCode: 2,
formatterCodeQuality: '',
formatterJson: '',
formatterJunit: '',
formatterSarif: '',
stderr: '',
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]␊
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
- ? matches a single character, but not /␊
- ** matches any number of characters, including /␊
- {} allows for a comma-separated list of "or" expressions␊
- ! or # at the beginning of a pattern negate the match␊
- : at the beginning identifies a literal file path␊
Dot-only glob:␊
- The command "markdownlint-cli2 ." would lint every file in the current directory tree which is probably not intended␊
- Instead, it is mapped to "markdownlint-cli2 *.{md,markdown}" which lints all Markdown files in the current directory␊
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead␊
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
- --no-globs ignores the "globs" property if present in the top-level options object␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
- .markdownlint-cli2.yaml␊
- .markdownlint-cli2.cjs or .markdownlint-cli2.mjs␊
- .markdownlint.jsonc or .markdownlint.json␊
- .markdownlint.yaml or .markdownlint.yml␊
- .markdownlint.cjs or .markdownlint.mjs␊
- package.json␊
Cross-platform compatibility:␊
- UNIX and Windows shells expand globs according to different rules; quoting arguments is recommended␊
- Some Windows shells don't handle single-quoted (') arguments well; double-quote (") is recommended␊
- Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊
- Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊
- The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊
The most compatible syntax for cross-platform support:␊
$ markdownlint-cli2 "**/*.md" "#node_modules"␊
`,
}

## globs-and-ignores (exec)

> Snapshot 1
Expand Down
Binary file modified test/snapshots/markdownlint-cli2-test-exec.js.snap
Binary file not shown.
Loading

0 comments on commit 4ea8820

Please sign in to comment.