Skip to content

Commit

Permalink
Add tests for custom rules (markdown-it and micromark) with no errors…
Browse files Browse the repository at this point in the history
… and errors.
  • Loading branch information
DavidAnson committed Jan 19, 2025
1 parent 51527aa commit 1d17f9b
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
34 changes: 29 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
with:
globs: |
*.md
test/*
test/*.md
continue-on-error: true
id: test
- run: exit 1
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 changes: 14 additions & 0 deletions config/custom-rules-fail.markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions config/custom-rules-pass.markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"customRules": [
"../test/custom-rule-markdown-it.cjs",
"../test/custom-rule-micromark.cjs"
]
}
14 changes: 14 additions & 0 deletions test/custom-rule-markdown-it.cjs
Original file line number Diff line number Diff line change
@@ -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 changes: 14 additions & 0 deletions test/custom-rule-micromark.cjs
Original file line number Diff line number Diff line change
@@ -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 });
}
}
}

0 comments on commit 1d17f9b

Please sign in to comment.