markdownlint-cli2 0.7.1 → 0.8.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.
package/README.md CHANGED
@@ -67,9 +67,7 @@ As a [GitHub Action][github-action] via
67
67
  markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)
68
68
  https://github.com/DavidAnson/markdownlint-cli2
69
69
 
70
- Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN]
71
- markdownlint-cli2-fix glob0 [glob1] [...] [globN]
72
- markdownlint-cli2-config config-file glob0 [glob1] [...] [globN]
70
+ Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]
73
71
 
74
72
  Glob expressions (from the globby library):
75
73
  - * matches any number of characters, but not /
@@ -84,6 +82,10 @@ Dot-only glob:
84
82
  - Instead, it is mapped to "markdownlint-cli2 *.{md,markdown}" which lints all Markdown files in the current directory
85
83
  - To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead
86
84
 
85
+ Optional parameters:
86
+ - --config specifies the path to a configuration file to define the base configuration
87
+ - --fix updates files to resolve fixable issues (can be overridden in configuration)
88
+
87
89
  Configuration via:
88
90
  - .markdownlint-cli2.jsonc
89
91
  - .markdownlint-cli2.yaml
@@ -116,28 +118,47 @@ markdownlint-cli2 "**/*.md" "#node_modules"
116
118
  ```
117
119
 
118
120
  Because sharing the same configuration between "normal" and "fix" modes is
119
- common, the following command defaults the `fix` property (see below) to `true`:
121
+ common, the `--fix` argument can be used to default the `fix` property (see
122
+ below) to `true` (though it can still be overridden by a configuration file):
120
123
 
121
124
  ```bash
122
- markdownlint-cli2-fix "**/*.md" "#node_modules"
125
+ markdownlint-cli2 --fix "**/*.md" "#node_modules"
123
126
  ```
124
127
 
125
- Other than the default behavior of the `fix` property (which can be overridden),
126
- these two commands behave identically.
128
+ > **Deprecated**
129
+ >
130
+ > The following command behaves similarly, defaulting the `fix` property to
131
+ > `true`:
132
+ >
133
+ > ```bash
134
+ > markdownlint-cli2-fix "**/*.md" "#node_modules"
135
+ > ```
136
+ >
137
+ > Otherwise, `markdownlint-cli2-fix` behaves the same as `markdownlint-cli2`.
127
138
 
128
139
  In cases where it is not convenient to store a configuration file in the root
129
- of a project, the `markdownlint-cli2-config` command can be used. This command
130
- accepts a path to any supported configuration file as its first argument:
140
+ of a project, the `--config` argument can be used to provide a path to any
141
+ supported configuration file:
131
142
 
132
143
  ```bash
133
- markdownlint-cli2-config "config/.markdownlint-cli2.jsonc" "**/*.md" "#node_modules"
144
+ markdownlint-cli2 --config "config/.markdownlint-cli2.jsonc" "**/*.md" "#node_modules"
134
145
  ```
135
146
 
136
- The configuration file name must be (or end with) one of the supported types
147
+ The configuration file name must be (or end with) one of the supported names
137
148
  above. For example, `.markdownlint.json` or `example.markdownlint-cli2.jsonc`.
138
149
  The specified configuration file will be loaded, parsed, and applied as a base
139
150
  configuration for the current directory - which will then be handled normally.
140
- Otherwise, this command behaves identically to `markdownlint-cli2`.
151
+
152
+ > **Deprecated**
153
+ >
154
+ > The following command behaves similarly, accepting a base configuration file
155
+ > path as its first parameter:
156
+ >
157
+ > ```bash
158
+ > markdownlint-cli2-config "config/.markdownlint-cli2.jsonc" "**/*.md" "#node_modules"
159
+ > ```
160
+ >
161
+ > Otherwise, `markdownlint-cli2-config` behaves the same as `markdownlint-cli2`.
141
162
 
142
163
  ### Container Image
143
164
 
@@ -145,7 +166,7 @@ A container image [`davidanson/markdownlint-cli2`][docker-hub-markdownlint-cli2]
145
166
  can also be used (e.g., as part of a CI pipeline):
146
167
 
147
168
  ```bash
148
- docker run -v $PWD:/workdir davidanson/markdownlint-cli2:v0.7.1 "**/*.md" "#node_modules"
169
+ docker run -v $PWD:/workdir davidanson/markdownlint-cli2:v0.8.0 "**/*.md" "#node_modules"
149
170
  ```
150
171
 
151
172
  Notes:
@@ -162,15 +183,17 @@ Notes:
162
183
  - A custom working directory can be specified with Docker's `-w` flag:
163
184
 
164
185
  ```bash
165
- docker run -w /myfolder -v $PWD:/myfolder davidanson/markdownlint-cli2:v0.7.1 "**/*.md" "#node_modules"
186
+ docker run -w /myfolder -v $PWD:/myfolder davidanson/markdownlint-cli2:v0.8.0 "**/*.md" "#node_modules"
166
187
  ```
167
188
 
168
- To invoke the `markdownlint-cli2-config` or `markdownlint-cli2-fix` commands
169
- instead, use Docker's `--entrypoint` flag:
170
-
171
- ```bash
172
- docker run -v $PWD:/workdir --entrypoint="markdownlint-cli2-fix" davidanson/markdownlint-cli2:v0.7.1 "**/*.md" "#node_modules"
173
- ```
189
+ > **Deprecated**
190
+ >
191
+ > To invoke the `markdownlint-cli2-config` or `markdownlint-cli2-fix` commands
192
+ > instead, use Docker's `--entrypoint` flag:
193
+ >
194
+ > ```bash
195
+ > docker run -v $PWD:/workdir --entrypoint="markdownlint-cli2-fix" davidanson/markdownlint-cli2:v0.8.0 "**/*.md" "#node_modules"
196
+ > ```
174
197
 
175
198
  For convenience, the container image
176
199
  [`davidanson/markdownlint-cli2-rules`][docker-hub-markdownlint-cli2-rules]
@@ -378,7 +401,7 @@ reference to the `repos` list in that project's `.pre-commit-config.yaml` like:
378
401
 
379
402
  ```yaml
380
403
  - repo: https://github.com/DavidAnson/markdownlint-cli2
381
- rev: v0.7.1
404
+ rev: v0.8.0
382
405
  hooks:
383
406
  - id: markdownlint-cli2
384
407
  ```
@@ -6,6 +6,9 @@
6
6
 
7
7
  const { run } = require("./markdownlint-cli2");
8
8
 
9
- run({
10
- "name": "markdownlint-cli2-config"
11
- });
9
+ run(
10
+ {
11
+ "name": "markdownlint-cli2-config"
12
+ },
13
+ [ "--config" ]
14
+ );
@@ -6,7 +6,9 @@
6
6
 
7
7
  const { run } = require("./markdownlint-cli2");
8
8
 
9
- run({
10
- "fixDefault": true,
11
- "name": "markdownlint-cli2-fix"
12
- });
9
+ run(
10
+ {
11
+ "name": "markdownlint-cli2-fix"
12
+ },
13
+ [ "--fix" ]
14
+ );
@@ -25,7 +25,7 @@ const resolveAndRequire = require("./resolve-and-require");
25
25
 
26
26
  // Variables
27
27
  const packageName = "markdownlint-cli2";
28
- const packageVersion = "0.7.1";
28
+ const packageVersion = "0.8.0";
29
29
  const libraryName = "markdownlint";
30
30
  const libraryVersion = markdownlintLibrary.getVersion();
31
31
  const dotOnlySubstitute = "*.{md,markdown}";
@@ -87,8 +87,11 @@ const importOrRequireResolve = async (dir, id) => {
87
87
  } catch (error) {
88
88
  errors.push(error);
89
89
  }
90
- // Use AggregateError once available in Node 15+
91
- throw new Error(errors.map((error) => error.message).join(" / "));
90
+ // @ts-ignore
91
+ throw new AggregateError(
92
+ errors,
93
+ `Unable to require or import module '${id}'.`
94
+ );
92
95
  }
93
96
  return id;
94
97
  };
@@ -178,7 +181,7 @@ const removeIgnoredFiles = (dir, files, ignores) => {
178
181
 
179
182
  // Process/normalize command-line arguments and return glob patterns
180
183
  const processArgv = (argv) => {
181
- const globPatterns = (argv || []).map(
184
+ const globPatterns = argv.map(
182
185
  (glob) => {
183
186
  if (glob.startsWith(":")) {
184
187
  return glob;
@@ -205,9 +208,7 @@ const showHelp = (logMessage) => {
205
208
  /* eslint-disable max-len */
206
209
  logMessage(`https://github.com/DavidAnson/markdownlint-cli2
207
210
 
208
- Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN]
209
- markdownlint-cli2-fix glob0 [glob1] [...] [globN]
210
- markdownlint-cli2-config config-file glob0 [glob1] [...] [globN]
211
+ Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]
211
212
 
212
213
  Glob expressions (from the globby library):
213
214
  - * matches any number of characters, but not /
@@ -222,6 +223,10 @@ Dot-only glob:
222
223
  - Instead, it is mapped to "markdownlint-cli2 ${dotOnlySubstitute}" which lints all Markdown files in the current directory
223
224
  - To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead
224
225
 
226
+ Optional parameters:
227
+ - --config specifies the path to a configuration file to define the base configuration
228
+ - --fix updates files to resolve fixable issues (can be overridden in configuration)
229
+
225
230
  Configuration via:
226
231
  - .markdownlint-cli2.jsonc
227
232
  - .markdownlint-cli2.yaml
@@ -815,7 +820,6 @@ const main = async (params) => {
815
820
  argv,
816
821
  optionsDefault,
817
822
  optionsOverride,
818
- fixDefault,
819
823
  fileContents,
820
824
  nonFileContents,
821
825
  noErrors,
@@ -835,17 +839,33 @@ const main = async (params) => {
835
839
  // eslint-disable-next-line max-len
836
840
  `${name || packageName} v${packageVersion} (${libraryName} v${libraryVersion})`
837
841
  );
842
+ // Merge and process args/argv
843
+ let fixDefault = false;
844
+ // eslint-disable-next-line unicorn/no-useless-undefined
845
+ let configPath = undefined;
846
+ const argvFiltered = (argv || []).filter((arg) => {
847
+ if (configPath === null) {
848
+ configPath = arg;
849
+ return false;
850
+ } else if (arg === "--config") {
851
+ configPath = null;
852
+ return false;
853
+ } else if (arg === "--fix") {
854
+ fixDefault = true;
855
+ return false;
856
+ }
857
+ return true;
858
+ });
838
859
  // Read argv configuration file (if relevant and present)
839
860
  let optionsArgv = null;
840
861
  let relativeDir = null;
841
- const [ configPath ] = (argv || []);
842
- if ((name === "markdownlint-cli2-config") && configPath) {
862
+ if (configPath) {
843
863
  optionsArgv =
844
864
  await readOptionsOrConfig(configPath, fs, noRequire);
845
865
  relativeDir = path.dirname(configPath);
846
866
  }
847
867
  // Process arguments and get base options
848
- const globPatterns = processArgv(optionsArgv ? argv.slice(1) : argv);
868
+ const globPatterns = processArgv(argvFiltered);
849
869
  const { baseMarkdownlintOptions, dirToDirInfo } =
850
870
  await getBaseOptions(
851
871
  fs,
@@ -859,7 +879,7 @@ const main = async (params) => {
859
879
  );
860
880
  if ((globPatterns.length === 0) && !nonFileContents) {
861
881
  showHelp(logMessage);
862
- return 1;
882
+ return 2;
863
883
  }
864
884
  // Include any file overrides or non-file content
865
885
  const resolvedFileContents = {};
@@ -918,11 +938,13 @@ const main = async (params) => {
918
938
  };
919
939
 
920
940
  // Run function
921
- const run = (overrides) => {
941
+ const run = (overrides, args) => {
922
942
  (async () => {
943
+ const argsAndArgv = args || [];
944
+ appendToArray(argsAndArgv, process.argv.slice(2));
923
945
  try {
924
946
  const defaultParams = {
925
- "argv": process.argv.slice(2),
947
+ "argv": argsAndArgv,
926
948
  "logMessage": console.log,
927
949
  "logError": console.error
928
950
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdownlint-cli2",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "A fast, flexible, configuration-based command-line interface for linting Markdown/CommonMark files with the `markdownlint` library",
5
5
  "author": {
6
6
  "name": "David Anson",
@@ -29,8 +29,8 @@
29
29
  "build-docker-image": "VERSION=$(node -e \"process.stdout.write(require('./package.json').version)\") && docker build -t davidanson/markdownlint-cli2:v$VERSION -f docker/Dockerfile --label org.opencontainers.image.version=v$VERSION .",
30
30
  "build-docker-image-rules": "VERSION=$(node -e \"process.stdout.write(require('./package.json').version)\") && docker build -t davidanson/markdownlint-cli2-rules:v$VERSION -f docker/Dockerfile-rules --build-arg VERSION=v$VERSION --label org.opencontainers.image.version=v$VERSION .",
31
31
  "ci": "npm-run-all --continue-on-error --parallel test-cover lint",
32
- "docker-npm-install": "docker run --rm --tty --name npm-install --volume $PWD:/home/workdir --workdir /home/workdir --user node node:16 npm install",
33
- "docker-npm-run-upgrade": "docker run --rm --tty --name npm-run-upgrade --volume $PWD:/home/workdir --workdir /home/workdir --user node node:16 npm run upgrade",
32
+ "docker-npm-install": "docker run --rm --tty --name npm-install --volume $PWD:/home/workdir --workdir /home/workdir --user node node:latest npm install",
33
+ "docker-npm-run-upgrade": "docker run --rm --tty --name npm-run-upgrade --volume $PWD:/home/workdir --workdir /home/workdir --user node node:latest npm run upgrade",
34
34
  "lint": "eslint --max-warnings 0 .",
35
35
  "lint-dockerfile": "docker run --rm -i hadolint/hadolint:latest-alpine < docker/Dockerfile",
36
36
  "lint-watch": "git ls-files | entr npm run lint",
@@ -48,7 +48,7 @@
48
48
  "webworker-install": "npm run docker-npm-install -- --no-save path-browserify process setimmediate stream-browserify url util webpack-cli"
49
49
  },
50
50
  "engines": {
51
- "node": ">=14.18.0"
51
+ "node": ">=16"
52
52
  },
53
53
  "files": [
54
54
  "append-to-array.js",
@@ -62,21 +62,21 @@
62
62
  ],
63
63
  "dependencies": {
64
64
  "globby": "13.1.4",
65
- "markdownlint": "0.28.2",
65
+ "markdownlint": "0.29.0",
66
66
  "markdownlint-cli2-formatter-default": "0.0.4",
67
67
  "micromatch": "4.0.5",
68
68
  "strip-json-comments": "5.0.0",
69
- "yaml": "2.2.2"
69
+ "yaml": "2.3.1"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@iktakahiro/markdown-it-katex": "4.0.1",
73
- "ava": "5.2.0",
74
- "c8": "7.13.0",
75
- "cpy": "9.0.1",
73
+ "ava": "5.3.0",
74
+ "c8": "7.14.0",
75
+ "cpy": "10.1.0",
76
76
  "del": "7.0.0",
77
- "eslint": "8.39.0",
78
- "eslint-plugin-n": "15.7.0",
79
- "eslint-plugin-unicorn": "46.0.0",
77
+ "eslint": "8.42.0",
78
+ "eslint-plugin-n": "16.0.0",
79
+ "eslint-plugin-unicorn": "47.0.0",
80
80
  "execa": "7.1.1",
81
81
  "markdown-it-emoji": "2.0.2",
82
82
  "markdown-it-for-inline": "0.1.1",