0
0
Fork 0
mirror of https://github.com/DavidAnson/markdownlint-cli2-action.git synced 2024-10-16 03:57:02 +02:00

Add "config" and "fix" inputs, deprecate "command" input.

This commit is contained in:
David Anson 2023-06-10 20:35:20 -07:00
parent 85978587f5
commit f70c069572
8 changed files with 1097 additions and 905 deletions

View file

@ -1,3 +1,5 @@
CommonMark
config
markdownlint-cli2-action
README
truthy

View file

@ -33,7 +33,7 @@ jobs:
- run: exit 1
if: steps.test.outcome != 'failure'
one-glob-pattern:
name: One glob (*.md, 0 errors)
name: One glob (README.md, 0 errors)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
@ -72,6 +72,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rm .markdownlint.json
- uses: ./
with:
command: config
@ -117,6 +118,7 @@ jobs:
- uses: ./
with:
command: fix
globs: 'test/*'
command-unsupported:
name: Command = unsupported (fails)
runs-on: ubuntu-latest
@ -129,3 +131,39 @@ jobs:
id: test
- run: exit 1
if: steps.test.outcome != 'failure'
config:
name: config (test/errors.md, 2 errors)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rm .markdownlint.json
- uses: ./
with:
config: 'config/test.markdownlint.jsonc'
globs: 'test/*'
continue-on-error: true
id: test
- run: exit 1
if: steps.test.outcome != 'failure'
config-invalid:
name: config (invalid configuration file, fails)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
with:
config: 'invalid.markdownlint.jsonc'
globs: 'test/*'
continue-on-error: true
id: test
- run: exit 1
if: steps.test.outcome != 'failure'
fix:
name: fix (test/errors.md, 0 errors)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
with:
fix: true
globs: 'test/*'

View file

@ -15,17 +15,32 @@ information.
### command (optional)
Command to run (unset, `fix`, or `config`)
> **Deprecated in favor of the "fix" and "config" inputs**
>
> Command to run (unset, `fix`, or `config`)
>
> If unspecified or `""`, the `markdownlint-cli2` command is run.
>
> If set to `fix`, the `markdownlint-cli2-fix` command is run and supported
> issues will be fixed automatically.
>
> If set to `config`, the `markdownlint-cli2-config` command is run and the
> first element of `globs` should specify a supported configuration file.
>
> For more detail: [documentation for `markdownlint-cli2`][command-line].
If unspecified or `""`, the `markdownlint-cli2` command is run.
### config (optional)
If set to `fix`, the `markdownlint-cli2-fix` command is run and supported issues
will be fixed automatically.
Path of a file to use for the base configuration object (defaults to none)
If set to `config`, the `markdownlint-cli2-config` command is run and the first
element of `globs` should specify a supported configuration file.
Equivalent to using the `--config` [command-line option][command-line] and
passing the specified configuration file.
For more detail: [documentation for `markdownlint-cli2`][command-line].
### fix (optional)
Whether to fix supported issues automatically (any truthy value enables)
Equivalent to specifying the `--fix` [command-line option][command-line].
### globs (optional)
@ -88,7 +103,7 @@ To fix supported issues when linting:
```yaml
- uses: DavidAnson/markdownlint-cli2-action@v10
with:
command: fix
fix: true
globs: '**/*.md'
```
@ -97,10 +112,8 @@ To specify a custom configuration file:
```yaml
- uses: DavidAnson/markdownlint-cli2-action@v10
with:
command: config
globs: |
config/custom.markdownlint.jsonc
**/*.md
config: 'config/custom.markdownlint.jsonc'
globs: '**/*.md'
```
To prevent linting issues from failing the workflow run:

View file

@ -7,6 +7,15 @@ branding:
inputs:
command:
description: Command to run (unset, "fix", or "config")
deprecationMessage: This input is deprecated in favor of the "fix" and "config" inputs
default: ''
required: false
config:
description: Path of a file to use for the base configuration object (defaults to none)
default: ''
required: false
fix:
description: Whether to fix supported issues automatically (any truthy value enables)
default: ''
required: false
globs:

View file

@ -1,18 +0,0 @@
{
"line-length": {
"strict": true,
"code_blocks": false
},
"proper-names": {
"code_blocks": false,
"names": [
"CommonMark",
"JavaScript",
"Markdown",
"markdown-it",
"markdownlint",
"markdownlint-cli2",
"Node.js"
]
}
}

1866
dist/index.js vendored

File diff suppressed because one or more lines are too long

View file

@ -52,13 +52,15 @@ const argv =
split(separator).
filter(String);
const parameters = {
argv,
logMessage,
"optionsOverride": {
"outputFormatters": [[outputFormatter]]
}
};
const config = core.getInput("config");
if (config) {
argv.push("--config", config);
}
const fix = Boolean(core.getInput("fix"));
if (fix) {
argv.push("--fix");
}
let invoke = true;
const command = core.getInput("command");
switch (command) {
@ -66,11 +68,10 @@ case "":
// Default behavior
break;
case "config":
parameters.name = "markdownlint-cli2-config";
argv.unshift("--config");
break;
case "fix":
parameters.name = "markdownlint-cli2-fix";
parameters.fixDefault = true;
argv.unshift("--fix");
break;
default:
core.setFailed(`Unsupported command: ${command}`);
@ -79,6 +80,13 @@ default:
}
if (invoke) {
const parameters = {
argv,
logMessage,
"optionsOverride": {
"outputFormatters": [[outputFormatter]]
}
};
markdownlintCli2(parameters).then(
(code) => code && core.setFailed(`Failed with exit code: ${code}`),
(error) => core.setFailed(`Failed due to error: ${error}`)

View file

@ -17,7 +17,7 @@
"build": "ncc build markdownlint-cli2-action.js",
"docker-npm-install": "docker run --rm --tty --name npm-install --volume $PWD:/home/workdir --workdir /home/workdir --user node node:16 npm install",
"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",
"lint": "eslint *.js && markdownlint-cli2-config ./config/.markdownlint.jsonc *.md",
"lint": "eslint *.js && markdownlint-cli2 *.md",
"test": "npm run lint && npm run build && git diff --exit-code ':(exclude)dist/index.js'",
"upgrade": "npx --yes npm-check-updates --upgrade"
},