markdownlint-cli 0.39.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +24 -18
  2. package/markdownlint.js +28 -22
  3. package/package.json +12 -10
package/README.md CHANGED
@@ -26,20 +26,21 @@ markdownlint --help
26
26
  MarkdownLint Command Line Interface
27
27
 
28
28
  Options:
29
- -V, --version output the version number
30
- -c, --config [configFile] configuration file (JSON, JSONC, JS, or YAML)
31
- -d, --dot include files/folders with a dot (for example `.github`)
32
- -f, --fix fix basic errors (does not work with STDIN)
33
- -i, --ignore [file|directory|glob] file(s) to ignore/exclude (default: [])
34
- -j, --json write issues in json format
35
- -o, --output [outputFile] write issues to file (no console)
36
- -p, --ignore-path [file] path to file with ignore pattern(s)
37
- -q, --quiet do not write issues to STDOUT
38
- -r, --rules [file|directory|glob|package] include custom rule files (default: [])
39
- -s, --stdin read from STDIN (does not work with files)
40
- --enable [rules...] Enable certain rules, e.g. --enable MD013 MD041 --
41
- --disable [rules...] Disable certain rules, e.g. --disable MD013 MD041 --
42
- -h, --help display help for command
29
+ -V, --version output the version number
30
+ -c, --config <configFile> configuration file (JSON, JSONC, JS, YAML, or TOML)
31
+ --configPointer <pointer> JSON Pointer to object within configuration file (default: "")
32
+ -d, --dot include files/folders with a dot (for example `.github`)
33
+ -f, --fix fix basic errors (does not work with STDIN)
34
+ -i, --ignore <file|directory|glob> file(s) to ignore/exclude (default: [])
35
+ -j, --json write issues in json format
36
+ -o, --output <outputFile> write issues to file (no console)
37
+ -p, --ignore-path <file> path to file with ignore pattern(s)
38
+ -q, --quiet do not write issues to STDOUT
39
+ -r, --rules <file|directory|glob|package> include custom rule files (default: [])
40
+ -s, --stdin read from STDIN (does not work with files)
41
+ --enable <rules...> Enable certain rules, e.g. --enable MD013 MD041 --
42
+ --disable <rules...> Disable certain rules, e.g. --disable MD013 MD041 --
43
+ -h, --help display help for command
43
44
  ```
44
45
 
45
46
  Or run using [Docker](https://www.docker.com) and [GitHub Packages](https://github.com/features/packages):
@@ -88,7 +89,7 @@ Because this option makes changes to the input files, it is good to make a backu
88
89
 
89
90
  `markdownlint-cli` reuses [the rules][rules] from `markdownlint` package.
90
91
 
91
- Configuration is stored in JSON, JSONC, YAML, or INI files in the same [config format][config].
92
+ Configuration is stored in JSON, JSONC, YAML, INI, or TOML files in the same [config format][config].
92
93
 
93
94
  A sample configuration file:
94
95
 
@@ -102,7 +103,7 @@ A sample configuration file:
102
103
  }
103
104
  ```
104
105
 
105
- For more examples, see [.markdownlint.jsonc][markdownlint-jsonc], [.markdownlint.yaml][markdownlint-yaml], or the [style folder][style-folder].
106
+ For more examples, see [.markdownlint.jsonc][markdownlint-jsonc], [.markdownlint.yaml][markdownlint-yaml], [test-config.toml](test/test-config.toml) or the [style folder][style-folder].
106
107
 
107
108
  The CLI argument `--config` is not required.
108
109
  If it is not provided, `markdownlint-cli` looks for the file `.markdownlint.jsonc`/`.markdownlint.json`/`.markdownlint.yaml`/`.markdownlint.yml` in current folder, or for the file `.markdownlintrc` in the current or all parent folders.
@@ -113,10 +114,14 @@ JS configuration files contain JavaScript code, must have the `.js` or `.cjs` fi
113
114
  If your workspace _(project)_ is [ESM-only] _(`"type": "module"` set in the root `package.json` file)_, then the configuration file **should end with `.cjs` file extension**.
114
115
  A JS configuration file may internally `require` one or more npm packages as a way of reusing configuration across projects.
115
116
 
117
+ The `--configPointer` argument allows the use of [JSON Pointer][json-pointer] syntax to identify a sub-object within the configuration object (per above).
118
+ This argument can be used with any configuration file type and makes it possible to nest a configuration object within another file like `package.json` or `pyproject.toml` (e.g., via `/key` or `/key/subkey`).
119
+
116
120
  `--enable` and `--disable` override configuration files; if a configuration file disables `MD123` and you pass `--enable MD123`, it will be enabled.
117
121
  If a rule is passed to both `--enable` and `--disable`, it will be disabled.
118
122
 
119
- > JS configuration files must be provided via the `--config` argument; they are not automatically loaded because running untrusted code is a security concern.
123
+ > - JS configuration files must be provided via the `--config` argument; they are not automatically loaded because running untrusted code is a security concern.
124
+ > - TOML configuration files must be provided via the `--config` argument; they are not automatically loaded.
120
125
 
121
126
  ## Exit codes
122
127
 
@@ -134,7 +139,7 @@ To run `markdownlint-cli` as part of a [pre-commit][pre-commit] workflow, add so
134
139
 
135
140
  ```yaml
136
141
  - repo: https://github.com/igorshubovych/markdownlint-cli
137
- rev: v0.39.0
142
+ rev: v0.41.0
138
143
  hooks:
139
144
  - id: markdownlint
140
145
  ```
@@ -155,6 +160,7 @@ MIT © Igor Shubovych
155
160
  [actions-badge]: https://github.com/igorshubovych/markdownlint-cli/workflows/CI/badge.svg?branch=master
156
161
  [actions-url]: https://github.com/igorshubovych/markdownlint-cli/actions?query=workflow%3ACI
157
162
  [commander-variadic]: https://github.com/tj/commander.js#variadic-option
163
+ [json-pointer]: https://datatracker.ietf.org/doc/html/rfc6901
158
164
  [markdownlint]: https://github.com/DavidAnson/markdownlint
159
165
  [markdownlint-cli2]: https://github.com/DavidAnson/markdownlint-cli2
160
166
  [markdownlint-jsonc]: https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.jsonc
package/markdownlint.js CHANGED
@@ -7,11 +7,12 @@ const path = require('node:path');
7
7
  const Module = require('node:module');
8
8
  const os = require('node:os');
9
9
  const process = require('node:process');
10
- const program = require('commander');
10
+ const {program} = require('commander');
11
11
  const glob = require('glob');
12
12
  const markdownlint = require('markdownlint');
13
13
  const rc = require('run-con');
14
14
  const minimatch = require('minimatch');
15
+ const jsonpointer = require('jsonpointer');
15
16
  const pkg = require('./package.json');
16
17
 
17
18
  const options = program.opts();
@@ -36,6 +37,10 @@ function yamlParse(text) {
36
37
  return require('js-yaml').load(text);
37
38
  }
38
39
 
40
+ function tomlParse(text) {
41
+ return require('smol-toml').parse(text);
42
+ }
43
+
39
44
  const exitCodes = {
40
45
  lintFindings: 1,
41
46
  failedToWriteOutputFile: 2,
@@ -44,13 +49,12 @@ const exitCodes = {
44
49
  };
45
50
 
46
51
  const projectConfigFiles = ['.markdownlint.jsonc', '.markdownlint.json', '.markdownlint.yaml', '.markdownlint.yml'];
47
- const configParsers = [jsoncParse, yamlParse];
52
+ // TOML files can be (incorrectly) read by yamlParse (but not vice versa), so tomlParse needs to go before yamlParse
53
+ const configParsers = [jsoncParse, tomlParse, yamlParse];
48
54
  const fsOptions = {encoding: 'utf8'};
49
55
  const processCwd = process.cwd();
50
56
 
51
57
  function readConfiguration(userConfigFile) {
52
- const jsConfigFile = /\.c?js$/i.test(userConfigFile);
53
-
54
58
  // Load from well-known config files
55
59
  let config = rc('markdownlint', {});
56
60
  for (const projectConfigFile of projectConfigFiles) {
@@ -65,9 +69,10 @@ function readConfiguration(userConfigFile) {
65
69
  }
66
70
 
67
71
  // Normally parsing this file is not needed, because it is already parsed by rc package.
68
- // However I have to do it to overwrite configuration from .markdownlint.{json,yaml,yml}.
72
+ // However I have to do it to overwrite configuration from .markdownlint.{jsonc,json,yaml,yml}.
69
73
  if (userConfigFile) {
70
74
  try {
75
+ const jsConfigFile = /\.c?js$/i.test(userConfigFile);
71
76
  const userConfig = jsConfigFile ? require(path.resolve(processCwd, userConfigFile)) : markdownlint.readConfigSync(userConfigFile, configParsers);
72
77
  config = require('deep-extend')(config, userConfig);
73
78
  } catch (error) {
@@ -85,7 +90,10 @@ function prepareFileList(files, fileExtensions, previousResults) {
85
90
  nodir: true
86
91
  };
87
92
  let extensionGlobPart = '*.';
88
- if (fileExtensions.length === 1) {
93
+ if (!fileExtensions) {
94
+ // Match everything
95
+ extensionGlobPart = '';
96
+ } else if (fileExtensions.length === 1) {
89
97
  // Glob seems not to match patterns like 'foo.{js}'
90
98
  extensionGlobPart += fileExtensions[0];
91
99
  } else {
@@ -190,18 +198,19 @@ program
190
198
  .version(pkg.version)
191
199
  .description(pkg.description)
192
200
  .usage('[options] <files|directories|globs>')
193
- .option('-c, --config [configFile]', 'configuration file (JSON, JSONC, JS, or YAML)')
201
+ .option('-c, --config <configFile>', 'configuration file (JSON, JSONC, JS, YAML, or TOML)')
202
+ .option('--configPointer <pointer>', 'JSON Pointer to object within configuration file', '')
194
203
  .option('-d, --dot', 'include files/folders with a dot (for example `.github`)')
195
204
  .option('-f, --fix', 'fix basic errors (does not work with STDIN)')
196
- .option('-i, --ignore [file|directory|glob]', 'file(s) to ignore/exclude', concatArray, [])
205
+ .option('-i, --ignore <file|directory|glob>', 'file(s) to ignore/exclude', concatArray, [])
197
206
  .option('-j, --json', 'write issues in json format')
198
- .option('-o, --output [outputFile]', 'write issues to file (no console)')
199
- .option('-p, --ignore-path [file]', 'path to file with ignore pattern(s)')
207
+ .option('-o, --output <outputFile>', 'write issues to file (no console)')
208
+ .option('-p, --ignore-path <file>', 'path to file with ignore pattern(s)')
200
209
  .option('-q, --quiet', 'do not write issues to STDOUT')
201
- .option('-r, --rules [file|directory|glob|package]', 'include custom rule files', concatArray, [])
210
+ .option('-r, --rules <file|directory|glob|package>', 'include custom rule files', concatArray, [])
202
211
  .option('-s, --stdin', 'read from STDIN (does not work with files)')
203
- .option('--enable [rules...]', 'Enable certain rules, e.g. --enable MD013 MD041 --')
204
- .option('--disable [rules...]', 'Disable certain rules, e.g. --disable MD013 MD041 --');
212
+ .option('--enable <rules...>', 'Enable certain rules, e.g. --enable MD013 MD041 --')
213
+ .option('--disable <rules...>', 'Disable certain rules, e.g. --disable MD013 MD041 --');
205
214
 
206
215
  program.parse(process.argv);
207
216
 
@@ -261,19 +270,18 @@ if (existsSync(ignorePath)) {
261
270
  }
262
271
 
263
272
  const files = prepareFileList(program.args, ['md', 'markdown']).filter(value => ignoreFilter(value));
264
- const ignores = prepareFileList(options.ignore, ['md', 'markdown'], files);
273
+ const ignores = prepareFileList(options.ignore, null, files);
265
274
  const customRules = loadCustomRules(options.rules);
266
275
  const diff = files.filter(file => !ignores.some(ignore => ignore.absolute === file.absolute)).map(paths => paths.original);
267
276
 
268
277
  function lintAndPrint(stdin, files) {
269
- files = files || [];
270
- const config = readConfiguration(options.config);
278
+ files ||= [];
279
+ const configuration = readConfiguration(options.config);
280
+ const config = jsonpointer.get(configuration, options.configPointer) || {};
271
281
 
272
282
  for (const rule of options.enable || []) {
273
283
  // Leave default values in place if rule is an object
274
- if (!config[rule]) {
275
- config[rule] = true;
276
- }
284
+ config[rule] ||= true;
277
285
  }
278
286
 
279
287
  for (const rule of options.disable || []) {
@@ -324,9 +332,7 @@ try {
324
332
  if (files.length > 0 && !options.stdin) {
325
333
  lintAndPrint(null, diff);
326
334
  } else if (files.length === 0 && options.stdin && !options.fix) {
327
- import('get-stdin')
328
- .then(module => module.default())
329
- .then(lintAndPrint);
335
+ import('get-stdin').then(module => module.default()).then(lintAndPrint);
330
336
  } else {
331
337
  program.help();
332
338
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdownlint-cli",
3
- "version": "0.39.0",
3
+ "version": "0.41.0",
4
4
  "description": "MarkdownLint Command Line Interface",
5
5
  "main": "markdownlint.js",
6
6
  "bin": {
@@ -37,21 +37,23 @@
37
37
  },
38
38
  "homepage": "https://github.com/igorshubovych/markdownlint-cli#readme",
39
39
  "dependencies": {
40
- "commander": "~11.1.0",
40
+ "commander": "~12.1.0",
41
41
  "get-stdin": "~9.0.0",
42
- "glob": "~10.3.10",
43
- "ignore": "~5.3.0",
42
+ "glob": "~10.4.1",
43
+ "ignore": "~5.3.1",
44
44
  "js-yaml": "^4.1.0",
45
45
  "jsonc-parser": "~3.2.1",
46
- "markdownlint": "~0.33.0",
47
- "minimatch": "~9.0.3",
48
- "run-con": "~1.3.2"
46
+ "jsonpointer": "5.0.1",
47
+ "markdownlint": "~0.34.0",
48
+ "minimatch": "~9.0.4",
49
+ "run-con": "~1.3.2",
50
+ "smol-toml": "~1.2.0"
49
51
  },
50
52
  "devDependencies": {
51
- "ava": "^6.1.0",
52
- "execa": "^8.0.1",
53
+ "ava": "^6.1.3",
54
+ "execa": "^9.1.0",
53
55
  "markdownlint-cli-local-test-rule": "./test/custom-rules/markdownlint-cli-local-test-rule",
54
- "xo": "^0.56.0"
56
+ "xo": "^0.58.0"
55
57
  },
56
58
  "xo": {
57
59
  "prettier": true,