Skip to content

Commit

Permalink
Add tests for JSON-in-YAML and YAML-in-JSON configuration file mismat…
Browse files Browse the repository at this point in the history
…ches. Note that mismatch is an error for ".markdownlint-cli2.*" files becaused they are parsed directly, but NOT an error for ".markdownlint.*" because the markdownlint helpers use the parsers[] argument to handle nested "extends". (closes #244)
  • Loading branch information
DavidAnson committed Dec 3, 2023
1 parent 5e86bf6 commit bf7a2a8
Show file tree
Hide file tree
Showing 16 changed files with 565 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config:
default: false
14 changes: 14 additions & 0 deletions test/markdownlint-cli2-jsonc-mismatch/viewme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Title

> Tagline

# Description

Text text text
Text text text
Text text text

## Summary

Text text text
60 changes: 56 additions & 4 deletions test/markdownlint-cli2-test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,60 @@ const testCases = ({
"usesRequire": true
});

testCase({
"name": "markdownlint-json-mismatch",
"args": [ "viewme.md" ],
"exitCode": 0
});

testCase({
"name": "markdownlint-yaml-mismatch",
"args": [ "viewme.md" ],
"exitCode": 0
});

testCase({
"name": "markdownlint-cli2-jsonc-mismatch",
"args": [ "viewme.md" ],
"exitCode": 2,
"stderrRe": /Unexpected token/u
});

testCase({
"name": "markdownlint-cli2-yaml-mismatch",
"args": [ "viewme.md" ],
"exitCode": 1
});

testCase({
"name": "markdownlint-json-mismatch-config",
"args": [ "--config", "../markdownlint-json-mismatch/.markdownlint.json", "viewme.md" ],
"exitCode": 0,
"cwd": "no-config",
});

testCase({
"name": "markdownlint-yaml-mismatch-config",
"args": [ "--config", "../markdownlint-yaml-mismatch/.markdownlint.yaml", "viewme.md" ],
"exitCode": 0,
"cwd": "no-config",
});

testCase({
"name": "markdownlint-cli2-jsonc-mismatch-config",
"args": [ "--config", "../markdownlint-cli2-jsonc-mismatch/.markdownlint-cli2.jsonc", "viewme.md" ],
"exitCode": 2,
"stderrRe": /Unexpected token/u,
"cwd": "no-config",
});

testCase({
"name": "markdownlint-cli2-yaml-mismatch-config",
"args": [ "--config", "../markdownlint-cli2-yaml-mismatch/.markdownlint-cli2.yaml", "viewme.md" ],
"exitCode": 1,
"cwd": "no-config",
});

testCase({
"name": "markdownlint-cli2-jsonc",
"args": [ "**/*.md" ],
Expand Down Expand Up @@ -472,8 +526,7 @@ const testCases = ({
"configs/.markdownlint-cli2.jsonc",
"viewme.md"
],
"exitCode": 0,
"cwd": "config-option-extends"
"exitCode": 0
});

testCase({
Expand Down Expand Up @@ -1010,8 +1063,7 @@ const testCases = ({
testCase({
"name": "nested-directories",
"args": [ "**", "!a", "a/b", "#a/b/c", "a/b/c/d" ],
"exitCode": 1,
"cwd": "nested-directories"
"exitCode": 1
});

testCase({
Expand Down
2 changes: 2 additions & 0 deletions test/markdownlint-cli2-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ test("validateMarkdownlintConfigSchema", async (t) => {
"**/*.markdownlint.(json|jsonc)",
"!node_modules/**",
"!**/*-copy-*/**",
"!**/*mismatch*/**",
"!**/*invalid*/**",
"!**/invalid*"
],
Expand Down Expand Up @@ -127,6 +128,7 @@ test("validateMarkdownlintCli2ConfigSchema", async (t) => {
"**/*.markdownlint-cli2.(json|jsonc)",
"!node_modules/**",
"!**/*-copy-*/**",
"!**/*mismatch*/**",
"!**/*invalid*/**",
"!**/invalid*",
"!test/customRules/dir/subdir2/.markdownlint-cli2.jsonc"
Expand Down
6 changes: 6 additions & 0 deletions test/markdownlint-cli2-yaml-mismatch/.markdownlint-cli2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"config": {
// Comment
"default": false
}
}
14 changes: 14 additions & 0 deletions test/markdownlint-cli2-yaml-mismatch/viewme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Title

> Tagline

# Description

Text text text
Text text text
Text text text

## Summary

Text text text
1 change: 1 addition & 0 deletions test/markdownlint-json-mismatch/.markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default: false
14 changes: 14 additions & 0 deletions test/markdownlint-json-mismatch/viewme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Title

> Tagline

# Description

Text text text
Text text text
Text text text

## Summary

Text text text
4 changes: 4 additions & 0 deletions test/markdownlint-yaml-mismatch/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// Comment
"default": false
}
14 changes: 14 additions & 0 deletions test/markdownlint-yaml-mismatch/viewme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Title

> Tagline

# Description

Text text text
Text text text
Text text text

## Summary

Text text text
146 changes: 146 additions & 0 deletions test/snapshots/markdownlint-cli2-test-exec.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,152 @@ Generated by [AVA](https://avajs.dev).
`,
}

## markdownlint-json-mismatch (exec)

> Snapshot 1
{
exitCode: 0,
formatterCodeQuality: '',
formatterJson: '',
formatterJunit: '',
formatterSarif: '',
stderr: '',
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
Finding: viewme.md␊
Linting: 1 file(s)␊
Summary: 0 error(s)␊
`,
}

## markdownlint-yaml-mismatch (exec)

> Snapshot 1
{
exitCode: 0,
formatterCodeQuality: '',
formatterJson: '',
formatterJunit: '',
formatterSarif: '',
stderr: '',
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
Finding: viewme.md␊
Linting: 1 file(s)␊
Summary: 0 error(s)␊
`,
}

## markdownlint-cli2-jsonc-mismatch (exec)

> Snapshot 1
{
exitCode: 2,
formatterCodeQuality: '',
formatterJson: '',
formatterJunit: '',
formatterSarif: '',
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
`,
}

## markdownlint-cli2-yaml-mismatch (exec)

> Snapshot 1
{
exitCode: 1,
formatterCodeQuality: '',
formatterJson: '',
formatterJunit: '',
formatterSarif: '',
stderr: `viewme.md:3:10 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]␊
viewme.md:5 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]␊
viewme.md:6 MD025/single-title/single-h1 Multiple top-level headings in the same document [Context: "# Description"]␊
viewme.md:12:1 MD019/no-multiple-space-atx Multiple spaces after hash on atx style heading [Context: "## Summary"]␊
viewme.md:14:14 MD047/single-trailing-newline Files should end with a single newline character␊
`,
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
Finding: viewme.md␊
Linting: 1 file(s)␊
Summary: 5 error(s)␊
`,
}

## markdownlint-json-mismatch-config (exec)

> Snapshot 1
{
exitCode: 0,
formatterCodeQuality: '',
formatterJson: '',
formatterJunit: '',
formatterSarif: '',
stderr: '',
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
Finding: viewme.md␊
Linting: 1 file(s)␊
Summary: 0 error(s)␊
`,
}

## markdownlint-yaml-mismatch-config (exec)

> Snapshot 1
{
exitCode: 0,
formatterCodeQuality: '',
formatterJson: '',
formatterJunit: '',
formatterSarif: '',
stderr: '',
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
Finding: viewme.md␊
Linting: 1 file(s)␊
Summary: 0 error(s)␊
`,
}

## markdownlint-cli2-jsonc-mismatch-config (exec)

> Snapshot 1
{
exitCode: 2,
formatterCodeQuality: '',
formatterJson: '',
formatterJunit: '',
formatterSarif: '',
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
`,
}

## markdownlint-cli2-yaml-mismatch-config (exec)

> Snapshot 1
{
exitCode: 1,
formatterCodeQuality: '',
formatterJson: '',
formatterJunit: '',
formatterSarif: '',
stderr: `viewme.md:3:10 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]␊
viewme.md:5 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]␊
viewme.md:6 MD025/single-title/single-h1 Multiple top-level headings in the same document [Context: "# Description"]␊
viewme.md:12:1 MD019/no-multiple-space-atx Multiple spaces after hash on atx style heading [Context: "## Summary"]␊
viewme.md:14:14 MD047/single-trailing-newline Files should end with a single newline character␊
`,
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
Finding: viewme.md␊
Linting: 1 file(s)␊
Summary: 5 error(s)␊
`,
}

## markdownlint-cli2-jsonc (exec)

> Snapshot 1
Expand Down
Binary file modified test/snapshots/markdownlint-cli2-test-exec.js.snap
Binary file not shown.
Loading

0 comments on commit bf7a2a8

Please sign in to comment.