mirror of
https://github.com/DavidAnson/markdownlint-cli2-action.git
synced 2025-03-24 17:46:24 +01:00
Add tests for custom rules (markdown-it and micromark) with no errors and errors.
This commit is contained in:
parent
51527aa3e5
commit
1d17f9bb81
5 changed files with 77 additions and 5 deletions
34
.github/workflows/test.yml
vendored
34
.github/workflows/test.yml
vendored
|
@ -51,7 +51,7 @@ jobs:
|
|||
with:
|
||||
globs: |
|
||||
*.md
|
||||
test/*
|
||||
test/*.md
|
||||
continue-on-error: true
|
||||
id: test
|
||||
- run: exit 1
|
||||
|
@ -63,7 +63,7 @@ jobs:
|
|||
- uses: actions/checkout@v4
|
||||
- uses: ./
|
||||
with:
|
||||
globs: '*.md,test/*'
|
||||
globs: '*.md,test/*.md'
|
||||
separator: ','
|
||||
continue-on-error: true
|
||||
id: test
|
||||
|
@ -78,7 +78,7 @@ jobs:
|
|||
- uses: ./
|
||||
with:
|
||||
config: 'config/test.markdownlint.jsonc'
|
||||
globs: 'test/*'
|
||||
globs: 'test/*.md'
|
||||
continue-on-error: true
|
||||
id: test
|
||||
- run: exit 1
|
||||
|
@ -91,7 +91,7 @@ jobs:
|
|||
- uses: ./
|
||||
with:
|
||||
config: 'invalid.markdownlint.jsonc'
|
||||
globs: 'test/*'
|
||||
globs: 'test/*.md'
|
||||
continue-on-error: true
|
||||
id: test
|
||||
- run: exit 1
|
||||
|
@ -104,4 +104,28 @@ jobs:
|
|||
- uses: ./
|
||||
with:
|
||||
fix: true
|
||||
globs: 'test/*'
|
||||
globs: 'test/*.md'
|
||||
rules-pass:
|
||||
name: custom rules (README.md, 0 errors)
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: rm .markdownlint.json
|
||||
- uses: ./
|
||||
with:
|
||||
config: 'config/custom-rules-pass.markdownlint-cli2.jsonc'
|
||||
globs: 'README.md'
|
||||
rules-fail:
|
||||
name: custom rules (README.md, 2 errors)
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: rm .markdownlint.json
|
||||
- uses: ./
|
||||
with:
|
||||
config: 'config/custom-rules-fail.markdownlint-cli2.jsonc'
|
||||
globs: 'README.md'
|
||||
continue-on-error: true
|
||||
id: test
|
||||
- run: exit 1
|
||||
if: steps.test.outcome != 'failure'
|
||||
|
|
14
config/custom-rules-fail.markdownlint-cli2.jsonc
Normal file
14
config/custom-rules-fail.markdownlint-cli2.jsonc
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"config": {
|
||||
"custom-rule-markdown-it": {
|
||||
"error": true
|
||||
},
|
||||
"custom-rule-micromark": {
|
||||
"error": true
|
||||
}
|
||||
},
|
||||
"customRules": [
|
||||
"../test/custom-rule-markdown-it.cjs",
|
||||
"../test/custom-rule-micromark.cjs"
|
||||
]
|
||||
}
|
6
config/custom-rules-pass.markdownlint-cli2.jsonc
Normal file
6
config/custom-rules-pass.markdownlint-cli2.jsonc
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"customRules": [
|
||||
"../test/custom-rule-markdown-it.cjs",
|
||||
"../test/custom-rule-micromark.cjs"
|
||||
]
|
||||
}
|
14
test/custom-rule-markdown-it.cjs
Normal file
14
test/custom-rule-markdown-it.cjs
Normal file
|
@ -0,0 +1,14 @@
|
|||
// @ts-check
|
||||
|
||||
/** @type {import("markdownlint").Rule} */
|
||||
module.exports = {
|
||||
"names": [ "custom-rule-markdown-it" ],
|
||||
"description": "Custom rule using markdown-it",
|
||||
"tags": [ "test" ],
|
||||
"parser": "markdownit",
|
||||
"function": (params, onError) => {
|
||||
if (params.config.error) {
|
||||
onError({ "lineNumber": 1 });
|
||||
}
|
||||
}
|
||||
}
|
14
test/custom-rule-micromark.cjs
Normal file
14
test/custom-rule-micromark.cjs
Normal file
|
@ -0,0 +1,14 @@
|
|||
// @ts-check
|
||||
|
||||
/** @type {import("markdownlint").Rule} */
|
||||
module.exports = {
|
||||
"names": [ "custom-rule-micromark" ],
|
||||
"description": "Custom rule using micromark",
|
||||
"tags": [ "test" ],
|
||||
"parser": "micromark",
|
||||
"function": (params, onError) => {
|
||||
if (params.config.error) {
|
||||
onError({ "lineNumber": 1 });
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue