Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed Apr 28, 2024
1 parent 899e6a8 commit 062b447
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@ markdownlint --help
MarkdownLint Command Line Interface

Options:
-V, --version output the version number
-c, --config [configFile] configuration file (JSON, JSONC, JS, YAML, or TOML)
-d, --dot include files/folders with a dot (for example `.github`)
-f, --fix fix basic errors (does not work with STDIN)
-i, --ignore [file|directory|glob] file(s) to ignore/exclude (default: [])
-j, --json write issues in json format
-o, --output [outputFile] write issues to file (no console)
-p, --ignore-path [file] path to file with ignore pattern(s)
-q, --quiet do not write issues to STDOUT
-r, --rules [file|directory|glob|package] include custom rule files (default: [])
-s, --stdin read from STDIN (does not work with files)
--enable [rules...] Enable certain rules, e.g. --enable MD013 MD041 --
--disable [rules...] Disable certain rules, e.g. --disable MD013 MD041 --
-h, --help display help for command
```

Or run using [Docker](https://www.docker.com) and [GitHub Packages](https://github.com/features/packages):
Expand Down Expand Up @@ -113,6 +99,9 @@ JS configuration files contain JavaScript code, must have the `.js` or `.cjs` fi
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**.
A JS configuration file may internally `require` one or more npm packages as a way of reusing configuration across projects.

The `--configPointer` argument allows the use of [JSON Pointer][json-pointer] syntax to identify a sub-object within the configuration file specified via `--config`.
This works for any configuration file format and makes it possible to nest a configuration object within a more expansive file that (ex: `package.json` or `pyproject.toml`).

`--enable` and `--disable` override configuration files; if a configuration file disables `MD123` and you pass `--enable MD123`, it will be enabled.
If a rule is passed to both `--enable` and `--disable`, it will be disabled.

Expand Down Expand Up @@ -156,6 +145,7 @@ MIT © Igor Shubovych
[actions-badge]: https://github.com/igorshubovych/markdownlint-cli/workflows/CI/badge.svg?branch=master
[actions-url]: https://github.com/igorshubovych/markdownlint-cli/actions?query=workflow%3ACI
[commander-variadic]: https://github.com/tj/commander.js#variadic-option
[json-pointer]: https://datatracker.ietf.org/doc/html/rfc6901
[markdownlint]: https://github.com/DavidAnson/markdownlint
[markdownlint-cli2]: https://github.com/DavidAnson/markdownlint-cli2
[markdownlint-jsonc]: https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.jsonc
Expand Down
7 changes: 5 additions & 2 deletions markdownlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const glob = require('glob');
const markdownlint = require('markdownlint');
const rc = require('run-con');
const minimatch = require('minimatch');
const jsonpointer = require('jsonpointer');
const pkg = require('./package.json');

const options = program.opts();
Expand Down Expand Up @@ -200,14 +201,15 @@ program
.description(pkg.description)
.usage('[options] <files|directories|globs>')
.option('-c, --config <configFile>', 'configuration file (JSON, JSONC, JS, or YAML)')
.option('--configPointer <pointer>', 'JSON Pointer to object within configuration file', '')
.option('-d, --dot', 'include files/folders with a dot (for example `.github`)')
.option('-f, --fix', 'fix basic errors (does not work with STDIN)')
.option('-i, --ignore <file|directory|glob>', 'file(s) to ignore/exclude', concatArray, [])
.option('-j, --json', 'write issues in json format')
.option('-o, --output <outputFile>', 'write issues to file (no console)')
.option('-p, --ignore-path <file>', 'path to file with ignore pattern(s)')
.option('-q, --quiet', 'do not write issues to STDOUT')
.option('-r, --rules <file|directory|glob|package>', 'include custom rule files', concatArray, [])
.option('-r, --rules <file|directory|glob|package>', 'include custom rule files', concatArray, [])
.option('-s, --stdin', 'read from STDIN (does not work with files)')
.option('--enable <rules...>', 'Enable certain rules, e.g. --enable MD013 MD041 --')
.option('--disable <rules...>', 'Disable certain rules, e.g. --disable MD013 MD041 --');
Expand Down Expand Up @@ -276,7 +278,8 @@ const diff = files.filter(file => !ignores.some(ignore => ignore.absolute === fi

function lintAndPrint(stdin, files) {
files ||= [];
const config = readConfiguration(options.config);
const configuration = readConfiguration(options.config);
const config = jsonpointer.get(configuration, options.configPointer);

for (const rule of options.enable || []) {
// Leave default values in place if rule is an object
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"ignore": "~5.3.1",
"js-yaml": "^4.1.0",
"jsonc-parser": "~3.2.1",
"jsonpointer": "5.0.1",
"markdownlint": "~0.34.0",
"minimatch": "~9.0.4",
"run-con": "~1.3.2",
Expand Down

0 comments on commit 062b447

Please sign in to comment.