Skip to content

Commit

Permalink
Switch from yaml package to js-yaml (because bundle size is 39kB vs. …
Browse files Browse the repository at this point in the history
…102kB according to https://bundlephobia.com/).
  • Loading branch information
DavidAnson committed Feb 17, 2024
1 parent 5b38aa0 commit ecf25c2
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 72 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@
],
"dependencies": {
"globby": "14.0.1",
"js-yaml": "4.1.0",
"jsonc-parser": "3.2.1",
"markdownlint": "0.33.0",
"markdownlint-cli2-formatter-default": "0.0.4",
"micromatch": "4.0.5",
"yaml": "2.3.4"
"micromatch": "4.0.5"
},
"devDependencies": {
"@iktakahiro/markdown-it-katex": "4.0.1",
Expand Down
4 changes: 2 additions & 2 deletions parsers/yaml-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

"use strict";

const yaml = require("yaml");
const yaml = require("js-yaml");

/**
* Parses a YAML string, returning the corresponding object.
* @param {string} text String to parse as YAML.
* @returns {object} Corresponding object.
*/
const yamlParse = (text) => yaml.parse(text);
const yamlParse = (text) => yaml.load(text);

module.exports = yamlParse;
18 changes: 10 additions & 8 deletions test/markdownlint-cli2-test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ const testCases = ({
"name": "markdownlint-yaml-invalid",
"args": [ ".*" ],
"exitCode": 2,
"stderrRe": /'[^']*\.markdownlint\.yaml'.*Map keys must be unique/u
"stderrRe": /'[^']*\.markdownlint\.yaml'.*duplicated mapping key/u
});

testCase({
Expand Down Expand Up @@ -394,36 +394,38 @@ const testCases = ({
testCase({
"name": "markdownlint-cli2-yaml-mismatch",
"args": [ "viewme.md" ],
"exitCode": 1
"exitCode": 2,
"stderrRe": /'[^']*\.markdownlint-cli2\.yaml'.*missed comma between flow collection entries/u
});

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

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

testCase({
"name": "markdownlint-cli2-jsonc-mismatch-config",
"args": [ "--config", "../markdownlint-cli2-jsonc-mismatch/.markdownlint-cli2.jsonc", "viewme.md" ],
"exitCode": 2,
"stderrRe": /'[^']*\.markdownlint-cli2\.jsonc'.*Unable to parse JSONC content/u,
"cwd": "no-config",
"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",
"exitCode": 2,
"stderrRe": /'[^']*\.markdownlint-cli2\.yaml'.*missed comma between flow collection entries/u,
"cwd": "no-config"
});

testCase({
Expand Down Expand Up @@ -469,7 +471,7 @@ const testCases = ({
"name": "markdownlint-cli2-yaml-invalid",
"args": [ ".*" ],
"exitCode": 2,
"stderrRe": /'[^']*\.markdownlint-cli2\.yaml'.*Map keys must be unique/u
"stderrRe": /'[^']*\.markdownlint-cli2\.yaml'.*duplicated mapping key/u
});

testCase({
Expand Down
22 changes: 2 additions & 20 deletions test/snapshots/markdownlint-cli2-test-exec.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -1071,21 +1071,12 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
{
exitCode: 1,
exitCode: 2,
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)␊
`,
}

Expand Down Expand Up @@ -1144,21 +1135,12 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
{
exitCode: 1,
exitCode: 2,
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)␊
`,
}

Expand Down
Binary file modified test/snapshots/markdownlint-cli2-test-exec.js.snap
Binary file not shown.
22 changes: 2 additions & 20 deletions test/snapshots/markdownlint-cli2-test-fs.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -987,21 +987,12 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
{
exitCode: 1,
exitCode: 2,
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)␊
`,
}

Expand Down Expand Up @@ -1060,21 +1051,12 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
{
exitCode: 1,
exitCode: 2,
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)␊
`,
}

Expand Down
Binary file modified test/snapshots/markdownlint-cli2-test-fs.js.snap
Binary file not shown.
22 changes: 2 additions & 20 deletions test/snapshots/markdownlint-cli2-test-main.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -1071,21 +1071,12 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

{
exitCode: 1,
exitCode: 2,
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)␊
`,
}

Expand Down Expand Up @@ -1144,21 +1135,12 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1

{
exitCode: 1,
exitCode: 2,
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)␊
`,
}

Expand Down
Binary file modified test/snapshots/markdownlint-cli2-test-main.js.snap
Binary file not shown.

0 comments on commit ecf25c2

Please sign in to comment.