markdownlint-cli2
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -28,8 +28,16 @@ #!/usr/bin/env node | ||
// Negate a glob | ||
const negateGlob = (glob) => `!${glob}`; | ||
// Require a module ID with the specified directory in the path | ||
const requireResolve = (dir, id) => { | ||
const paths = [ dir, ...require.resolve.paths("") ]; | ||
const resolved = require.resolve(id, { paths }); | ||
return require(resolved); | ||
}; | ||
// Main function | ||
const main = async (argv, logMessage, logError) => { | ||
// Output help for missing arguments | ||
const globPatterns = | ||
argv. | ||
map((glob) => glob.replace(/^#/u, "!")); | ||
const globPatterns = argv.map((glob) => glob.replace(/^#/u, "!")); | ||
if (globPatterns.length === 0) { | ||
@@ -55,4 +63,8 @@ const { name, version, author, homepage } = require("./package.json"); | ||
Configuration: | ||
- Via .markdownlint-cli2.jsonc, .markdownlint.jsonc, .markdownlint.json, .markdownlint.yaml, or .markdownlint.yml | ||
Configuration via: | ||
- .markdownlint-cli2.jsonc | ||
- .markdownlint-cli2.js | ||
- .markdownlint.jsonc or .markdownlint.json | ||
- .markdownlint.yaml or .markdownlint.yml | ||
- .markdownlint.js | ||
@@ -66,4 +78,4 @@ Cross-platform compatibility: | ||
Therefore, the most compatible syntax for cross-platform support: | ||
${name} "**/*.md" "#node_modules"` | ||
Therefore, the most compatible glob syntax for cross-platform support: | ||
$ ${name} "**/*.md" "#node_modules"` | ||
); | ||
@@ -89,2 +101,10 @@ /* eslint-enable max-len */ | ||
}; | ||
const requireConfig = (dir, name, otherwise) => { | ||
const file = path.join(dir, name); | ||
return () => fs.access(file). | ||
then( | ||
() => requireResolve(dir, `./${name}`), | ||
otherwise | ||
); | ||
}; | ||
const getAndProcessDirInfo = (dir, func) => { | ||
@@ -106,3 +126,6 @@ let dirInfo = dirToDirInfo[dir]; | ||
() => fs.readFile(markdownlintCli2Jsonc, utf8).then(jsoncParse), | ||
() => null | ||
requireConfig( | ||
dir, | ||
".markdownlint-cli2.js", | ||
() => null) | ||
). | ||
@@ -126,3 +149,7 @@ then((options) => { | ||
".markdownlint.yml", | ||
() => null | ||
requireConfig( | ||
dir, | ||
".markdownlint.js", | ||
() => null | ||
) | ||
) | ||
@@ -149,3 +176,3 @@ ) | ||
const ignorePatterns = (baseMarkdownlintOptions.ignores || []). | ||
map((glob) => `!${glob}`); | ||
map(negateGlob); | ||
appendToArray(globPatterns, ignorePatterns); | ||
@@ -157,7 +184,14 @@ delete baseMarkdownlintOptions.ignores; | ||
// @ts-ignore | ||
let dir = path.dirname(file); | ||
let lastDir = dir; | ||
let lastDirInfo = getAndProcessDirInfo(dir, (dirInfo) => { | ||
const dir = path.dirname(file); | ||
getAndProcessDirInfo(dir, (dirInfo) => { | ||
dirInfo.files.push(file); | ||
}); | ||
} | ||
await Promise.all(tasks); | ||
tasks.length = 0; | ||
// Fill out directory info list with parent directories | ||
for (let lastDirInfo of Object.values(dirToDirInfo)) { | ||
let { dir } = lastDirInfo; | ||
let lastDir = dir; | ||
while ((dir = path.dirname(dir)) && (dir !== lastDir)) { | ||
@@ -202,10 +236,18 @@ lastDir = dir; | ||
// Verify dirInfos is simplified | ||
// if (dirInfos.filter((di) => !di.files.length).length) { | ||
// throw new Error("No files"); | ||
// if (dirInfos.filter((di) => !di.files.length).length > 0) { | ||
// throw new Error("Empty files"); | ||
// } | ||
// if (dirInfos.filter( | ||
// (di) => di.parent && !dirInfos.includes(di.parent)).length | ||
// (di) => di.parent && !dirInfos.includes(di.parent)).length > 0 | ||
// ) { | ||
// throw new Error("Extra parent"); | ||
// } | ||
// if ( | ||
// dirInfos.filter( | ||
// (di) => di.parent && | ||
// !((di.markdownlintConfig ? 1 : 0) ^ (di.markdownlintOptions ? 1 : 0)) | ||
// ).length > 0 | ||
// ) { | ||
// throw new Error("Missing object"); | ||
// } | ||
@@ -234,21 +276,8 @@ // Merge configuration by inheritance | ||
// Lint each list of files | ||
const requireIds = (dir, ids) => { | ||
let modules = undefined; | ||
if (ids) { | ||
const paths = [ ...require.resolve.paths(""), dir ]; | ||
modules = ids.map((ruleId) => { | ||
const resolved = require.resolve(ruleId, { paths }); | ||
return require(resolved); | ||
}); | ||
} | ||
return modules; | ||
}; | ||
const requireIds = (dir, ids) => ids.map((id) => requireResolve(dir, id)); | ||
const requireIdsAndParams = (dir, idsAndParams) => { | ||
let modulesAndParams = undefined; | ||
if (idsAndParams) { | ||
const ids = idsAndParams.map((entry) => entry[0]); | ||
const modules = requireIds(dir, ids); | ||
modulesAndParams = idsAndParams. | ||
map((entry, i) => [ modules[i], ...entry.slice(1) ]); | ||
} | ||
const ids = idsAndParams.map((entry) => entry[0]); | ||
const modules = requireIds(dir, ids); | ||
const modulesAndParams = idsAndParams. | ||
map((entry, i) => [ modules[i], ...entry.slice(1) ]); | ||
return modulesAndParams; | ||
@@ -260,3 +289,3 @@ }; | ||
if (markdownlintOptions.ignores) { | ||
const ignores = markdownlintOptions.ignores.map((glob) => `!${glob}`); | ||
const ignores = markdownlintOptions.ignores.map(negateGlob); | ||
const micromatch = require("micromatch"); | ||
@@ -273,3 +302,3 @@ filteredFiles = micromatch( | ||
"customRules": | ||
requireIds(dir, markdownlintOptions.customRules), | ||
requireIds(dir, markdownlintOptions.customRules || []), | ||
"frontMatter": markdownlintOptions.frontMatter | ||
@@ -280,3 +309,3 @@ ? new RegExp(markdownlintOptions.frontMatter, "u") | ||
"markdownItPlugins": | ||
requireIdsAndParams(dir, markdownlintOptions.markdownItPlugins), | ||
requireIdsAndParams(dir, markdownlintOptions.markdownItPlugins || []), | ||
"noInlineConfig": | ||
@@ -340,2 +369,3 @@ Boolean(markdownlintOptions.noInlineConfig), | ||
)); | ||
summary.forEach((result) => delete result.counter); | ||
@@ -342,0 +372,0 @@ // Output summary via formatters |
{ | ||
"name": "markdownlint-cli2", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "A fast, flexible, configuration-based command-line interface for linting Markdown/CommonMark files with the `markdownlint` library", | ||
@@ -48,3 +48,3 @@ "author": { | ||
"del": "~5.1.0", | ||
"eslint": "~7.7.0", | ||
"eslint": "~7.8.0", | ||
"eslint-plugin-node": "~11.1.0", | ||
@@ -54,2 +54,3 @@ "eslint-plugin-unicorn": "~21.0.0", | ||
"markdown-it-emoji": "~1.4.0", | ||
"markdown-it-for-inline": "~0.1.1", | ||
"markdownlint-cli2-formatter-json": "~0.0.1", | ||
@@ -56,0 +57,0 @@ "markdownlint-cli2-formatter-junit": "~0.0.1", |
110
README.md
@@ -12,3 +12,11 @@ # markdownlint-cli2 | ||
As a global CLI: | ||
```shell | ||
npm install markdownlint-cli2 --global | ||
``` | ||
As a development dependency of the current package: | ||
```shell | ||
npm install markdownlint-cli2 --save-dev | ||
@@ -26,9 +34,9 @@ ``` | ||
command-line interface for `markdownlint`. | ||
- `markdownlint-cli2` is configuration-based and prioritizes both speed and | ||
- `markdownlint-cli2` is configuration-based and prioritizes speed and | ||
simplicity. | ||
- `markdownlint-cli2` is mostly compatible with the features of | ||
`markdownlint-cli`. | ||
- `markdownlint-cli2` supports all the features of `markdownlint-cli` (sometimes | ||
a little differently). | ||
- [`vscode-markdownlint`][vscode-markdownlint] is a `markdownlint` extension for | ||
the [Visual Studio Code editor][vscode]. | ||
- `markdownlint-cli2` is meant to work well in conjunction with | ||
- `markdownlint-cli2` is designed to work well in conjunction with | ||
`vscode-markdownlint`. | ||
@@ -56,4 +64,8 @@ | ||
Configuration: | ||
- Via .markdownlint-cli2.jsonc, .markdownlint.jsonc, .markdownlint.json, .markdownlint.yaml, or .markdownlint.yml | ||
Configuration via: | ||
- .markdownlint-cli2.jsonc | ||
- .markdownlint-cli2.js | ||
- .markdownlint.jsonc or .markdownlint.json | ||
- .markdownlint.yaml or .markdownlint.yml | ||
- .markdownlint.js | ||
@@ -67,4 +79,4 @@ Cross-platform compatibility: | ||
Therefore, the most compatible syntax for cross-platform support: | ||
markdownlint-cli2 "**/*.md" "#node_modules" | ||
Therefore, the most compatible glob syntax for cross-platform support: | ||
$ markdownlint-cli2 "**/*.md" "#node_modules" | ||
``` | ||
@@ -81,3 +93,3 @@ | ||
- See the [Rules / Aliases][markdownlint-rules-aliases] and | ||
[Tags][markdownlint-tags] sections of the `markdownlint` documentation. | ||
[Tags][markdownlint-rules-tags] sections of the `markdownlint` documentation. | ||
@@ -92,3 +104,4 @@ ## Glob expressions | ||
- See the [Configuration][markdownlint-configuration] section of the | ||
`markdownlint` documentation for information about the inline comment syntax. | ||
`markdownlint` documentation for information about the inline comment syntax | ||
for enabling and disabling rules with HTML comments. | ||
@@ -102,4 +115,4 @@ ### `.markdownlint-cli2.jsonc` | ||
rules for this part of the directory tree | ||
- If a `jsonc`/`json`/`yaml`/`yml` file (see below) is present in the same | ||
directory, it overrides the value of this property | ||
- If a `.markdownlint.{jsonc,json,yaml,yml,js}` file (see below) is present | ||
in the same directory, it overrides the value of this property | ||
- `customRules`: `Array` of `Strings` of module names/paths of | ||
@@ -114,3 +127,3 @@ [custom rules][markdownlint-custom-rules] to load and use when linting | ||
- `frontMatter`: `String` defining the [`RegExp`][regexp] used to match and | ||
ignore any [front matter][front-matter] at the beginning of Markdown content | ||
ignore any [front matter][front-matter] at the beginning of a document | ||
- The `String` is passed as the `pattern` parameter to the | ||
@@ -134,2 +147,3 @@ [`RegExp` constructor][regexp-constructor] | ||
- Plugins can be used to add support for additional Markdown syntax | ||
- Relative paths are resolved based on the location of the `JSONC` file | ||
- For example: `[ [ "plugin-name", param_0, param_1, ... ], ... ]` | ||
@@ -144,14 +158,24 @@ - `noInlineConfig`: `Boolean` value to disable the support of | ||
scenarios | ||
- Relative paths are resolved based on the location of the `JSONC` file | ||
- For example: `[ [ "formatter-name", param_0, param_1, ... ], ... ]` | ||
- This setting affects all output, so is valid **only** in the directory | ||
from which `markdownlint-cli2` is run | ||
- This setting affects output for the entire pass, so is valid **only** in | ||
the directory from which `markdownlint-cli2` is run | ||
- Settings in this file apply to the directory it is in and all subdirectories. | ||
- Settings **merge with** those applied by any versions of this file in a parent | ||
directory. | ||
- For example: A [`.markdownlint-cli2.jsonc`][markdownlint-cli2-jsonc] with all | ||
- For example: [`.markdownlint-cli2.jsonc`][markdownlint-cli2-jsonc] with all | ||
properties set | ||
### `.markdownlint.jsonc` / `.markdownlint.json` | ||
### `.markdownlint-cli2.js` | ||
- The format of this file is a [JSON][json] or [JSONC][jsonc] object matching | ||
- The format of this file is a [CommonJS module][commonjs-module] that exports | ||
the `.markdownlint-cli2.jsonc` object described above. | ||
- Other details are the same as for `.markdownlint-cli2.jsonc` described above. | ||
- If a `.markdownlint-cli2.jsonc` file is present in the same directory, it | ||
takes precedence. | ||
- For example: [`.markdownlint-cli2.js`][markdownlint-cli2-js] | ||
### `.markdownlint.jsonc` or `.markdownlint.json` | ||
- The format of this file is a [JSONC][jsonc] or [JSON][json] object matching | ||
the [`markdownlint` `config` object][markdownlint-config]. | ||
@@ -161,18 +185,29 @@ - Settings in this file apply to the directory it is in and all subdirectories | ||
directory. | ||
- If both files are present in the same directory, the `jsonc` version takes | ||
precedence. | ||
- If `jsonc` and `json` files are present in the same directory, the `jsonc` | ||
version takes precedence. | ||
- To merge the settings of these files or share configuration, use the `extends` | ||
property (documented above). | ||
- Both extensions support comments in JSON. | ||
property (documented in the link above). | ||
- Both file types support comments in JSON. | ||
- For example: [`.markdownlint.jsonc`][markdownlint-jsonc] | ||
### `.markdownlint.yaml` / `.markdownlint.yml` | ||
### `.markdownlint.yaml` or `.markdownlint.yml` | ||
- The format of this file is a [YAML][yaml] object representing | ||
[`markdownlint`'s `config` object][markdownlint-config]. | ||
- The format of this file is a [YAML][yaml] object representing the | ||
[`markdownlint` `config` object][markdownlint-config]. | ||
- Other details are the same as for `jsonc`/`json` files described above. | ||
- If both files are present in the same directory, the `yaml` version takes | ||
- If `yaml` and `yml` files are present in the same directory, the `yaml` | ||
version takes precedence. | ||
- If a `jsonc` or `json` file is present in the same directory, it takes | ||
precedence. | ||
- If a `jsonc` or `json` file is present, it takes precedence according the | ||
rules above. | ||
- For example: [`.markdownlint.yaml`][markdownlint-yaml] | ||
### `.markdownlint.js` | ||
- The format of this file is a [CommonJS module][commonjs-module] that exports | ||
the [`markdownlint` `config` object][markdownlint-config]. | ||
- Other details are the same as for `jsonc`/`json` files described above. | ||
- If a `jsonc`, `json`, `yaml`, or `yml` file is present in the same directory, | ||
it takes precedence. | ||
- For example: [`.markdownlint.js`][markdownlint-js] | ||
## Compatibility | ||
@@ -182,11 +217,12 @@ | ||
- The glob implementation and handling of patterns is different. | ||
- The treatment of `.markdownlintignore` patterns is different. | ||
- Configuration files are supported in each directory (vs. one globally). | ||
- The `INI` config format and `.markdownlintrc` are not supported. | ||
- The glob implementation and handling of pattern matching is slightly | ||
different. | ||
- Configuration files are supported in every directory (vs. only one at the | ||
root). | ||
- The `INI` config format, `.markdownlintrc`, and `.markdownlintignore` are not | ||
supported. | ||
### `vscode-markdownlint` | ||
- The treatment of `.markdownlintignore` patterns is different. | ||
- `.markdownlintrc` is not supported as a configuration file. | ||
- `.markdownlintrc` and `.markdownlintignore` are not supported. | ||
@@ -200,2 +236,3 @@ ## History | ||
- 0.0.6 - Improve handling of very large directory trees | ||
- 0.0.7 - Support `.markdownlint-cli2.js` and `.markdownlint.js` | ||
@@ -207,2 +244,3 @@ <!-- markdownlint-disable line-length --> | ||
[commonmark]: https://commonmark.org/ | ||
[commonjs-module]: https://nodejs.org/api/modules.html#modules_modules_commonjs_modules | ||
[front-matter]: https://jekyllrb.com/docs/frontmatter/ | ||
@@ -228,3 +266,7 @@ [globby]: https://www.npmjs.com/package/globby | ||
[markdownlint-cli2-formatter]: https://www.npmjs.com/search?q=keywords:markdownlint-cli2-formatter | ||
[markdownlint-cli2-js]: test/markdownlint-cli2-js/.markdownlint-cli2.js | ||
[markdownlint-cli2-jsonc]: test/markdownlint-cli2-jsonc-example/.markdownlint-cli2.jsonc | ||
[markdownlint-js]: test/markdownlint-js/.markdownlint.js | ||
[markdownlint-jsonc]: test/markdownlint-jsonc/.markdownlint.jsonc | ||
[markdownlint-yaml]: test/markdownlint-yaml/.markdownlint.yaml | ||
[nodejs]: https://nodejs.org/ | ||
@@ -231,0 +273,0 @@ [nodejs-require]: https://nodejs.org/api/modules.html#modules_require_id |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
29194
390
266
15