Skip to content

Commit 3e6f0dc

Browse files
committed
Update tests to account for deprecation of MD002, MD006, and "header" aliases, fix new prettier issues.
1 parent 75b959d commit 3e6f0dc

File tree

4 files changed

+27
-38
lines changed

4 files changed

+27
-38
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ JS configuration files contain JavaScript code, must have the `.js` or `.cjs` fi
113113
If your workspace _(project)_ is [ESM-only] _(`"type": "module"` set in the root `package.json` file)_, then the configuration file **should end with `.cjs` file extension**.
114114
A JS configuration file may internally `require` one or more npm packages as a way of reusing configuration across projects.
115115

116-
`--enable` and `--disable` override configuration files; if a configuration file disables `MD002` and you pass `--enable MD002`, it will be enabled.
116+
`--enable` and `--disable` override configuration files; if a configuration file disables `MD123` and you pass `--enable MD123`, it will be enabled.
117117
If a rule is passed to both `--enable` and `--disable`, it will be disabled.
118118

119119
> JS configuration files must be provided via the `--config` argument; they are not automatically loaded because running untrusted code is a security concern.

test/md043-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MD012: false
22
MD043:
3-
headers:
3+
headings:
44
- "# First"
55
- "## Second"
66
- "### Third"

test/test-config.json

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"extends": "base-config.json",
33

4-
"MD002": true,
54
"MD007": { "indent": 4 },
65
"MD013": { "line_length": 200 }
76
}

test/test.js

+25-35
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ test('linting of incorrect Markdown file fails', async t => {
8383
t.fail();
8484
} catch (error) {
8585
t.is(error.stdout, '');
86-
t.is(error.stderr.match(errorPattern).length, 8);
86+
t.is(error.stderr.match(errorPattern).length, 7);
8787
t.is(error.exitCode, 1);
8888
}
8989
});
@@ -95,19 +95,19 @@ test('linting of incorrect Markdown file fails prints issues as json', async t =
9595
} catch (error) {
9696
t.is(error.stdout, '');
9797
const issues = JSON.parse(error.stderr);
98-
t.is(issues.length, 8);
99-
// RuleInformation changes with version so that field just check not null and present
98+
t.is(issues.length, 7);
10099
const issue = issues[0];
100+
// Property "ruleInformation" changes with library version
101101
t.true(issue.ruleInformation.length > 0);
102102
issue.ruleInformation = null;
103103
const expected = {
104104
fileName: 'incorrect.md',
105105
lineNumber: 1,
106-
ruleNames: ['MD002', 'first-heading-h1', 'first-header-h1'],
107-
ruleDescription: 'First heading should be a top-level heading',
106+
ruleNames: ['MD041', 'first-line-heading', 'first-line-h1'],
107+
ruleDescription: 'First line in a file should be a top-level heading',
108108
ruleInformation: null,
109-
errorContext: null,
110-
errorDetail: 'Expected: h1; Actual: h2',
109+
errorContext: '## header 2',
110+
errorDetail: null,
111111
errorRange: null,
112112
fixInfo: null
113113
};
@@ -122,7 +122,7 @@ test('linting of incorrect Markdown file fails with absolute path', async t => {
122122
t.fail();
123123
} catch (error) {
124124
t.is(error.stdout, '');
125-
t.is(error.stderr.match(errorPattern).length, 8);
125+
t.is(error.stderr.match(errorPattern).length, 7);
126126
t.is(error.exitCode, 1);
127127
}
128128
});
@@ -163,7 +163,7 @@ test('glob linting works with failing files', async t => {
163163
t.fail();
164164
} catch (error) {
165165
t.is(error.stdout, '');
166-
t.is(error.stderr.match(errorPattern).length, 17);
166+
t.is(error.stderr.match(errorPattern).length, 15);
167167
t.is(error.exitCode, 1);
168168
}
169169
});
@@ -181,7 +181,7 @@ test('dir linting works with failing .markdown files', async t => {
181181
t.fail();
182182
} catch (error) {
183183
t.is(error.stdout, '');
184-
t.is(error.stderr.match(errorPattern).length, 10);
184+
t.is(error.stderr.match(errorPattern).length, 9);
185185
t.is(error.exitCode, 1);
186186
}
187187
});
@@ -192,7 +192,7 @@ test('dir linting works with failing .markdown files and absolute path', async t
192192
t.fail();
193193
} catch (error) {
194194
t.is(error.stdout, '');
195-
t.is(error.stderr.match(errorPattern).length, 10);
195+
t.is(error.stderr.match(errorPattern).length, 9);
196196
t.is(error.exitCode, 1);
197197
}
198198
});
@@ -217,7 +217,7 @@ test('glob linting with failing files has fewer errors when ignored by dir', asy
217217
t.fail();
218218
} catch (error) {
219219
t.is(error.stdout, '');
220-
t.is(error.stderr.match(errorPattern).length, 9);
220+
t.is(error.stderr.match(errorPattern).length, 8);
221221
t.is(error.exitCode, 1);
222222
}
223223
});
@@ -228,7 +228,7 @@ test('glob linting with failing files has fewer errors when ignored by dir and a
228228
t.fail();
229229
} catch (error) {
230230
t.is(error.stdout, '');
231-
t.is(error.stderr.match(errorPattern).length, 9);
231+
t.is(error.stderr.match(errorPattern).length, 8);
232232
t.is(error.exitCode, 1);
233233
}
234234
});
@@ -267,17 +267,7 @@ test('linting results are sorted by file/line/names/description', async t => {
267267
await execa('../markdownlint.js', ['--config', 'test-config.json', 'incorrect.md'], {stripFinalNewline: false});
268268
t.fail();
269269
} catch (error) {
270-
const expected = [
271-
'incorrect.md:1 MD002/first-heading-h1/first-header-h1 First heading should be a top-level heading [Expected: h1; Actual: h2]',
272-
'incorrect.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## header 2"]',
273-
'incorrect.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]',
274-
'incorrect.md:2 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "# header"]',
275-
'incorrect.md:5:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]',
276-
'incorrect.md:11:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]',
277-
'incorrect.md:17:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]',
278-
'incorrect.md:23:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]',
279-
''
280-
].join('\n');
270+
const expected = ['incorrect.md:1 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## header 2"]', 'incorrect.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]', 'incorrect.md:2 MD022/blanks-around-headings Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "# header"]', 'incorrect.md:5:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]', 'incorrect.md:11:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]', 'incorrect.md:17:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]', 'incorrect.md:23:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ code"]', ''].join('\n');
281271
t.is(error.stdout, '');
282272
t.is(error.stderr, expected);
283273
t.is(error.exitCode, 1);
@@ -591,7 +581,7 @@ test('fixing errors in a file yields fewer errors', async t => {
591581
await execa('../markdownlint.js', ['--fix', '--config', 'test-config.json', fixFileA], {stripFinalNewline: false});
592582
t.fail();
593583
} catch (error) {
594-
const expected = [fixFileA + ':1 MD002/first-heading-h1/first-header-h1 First heading should be a top-level heading [Expected: h1; Actual: h2]', fixFileA + ':1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]', ''].join('\n');
584+
const expected = [fixFileA + ':1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]', ''].join('\n');
595585
t.is(error.stdout, '');
596586
t.is(error.stderr, expected);
597587
t.is(error.exitCode, 1);
@@ -607,7 +597,7 @@ test('fixing errors in a file with absolute path yields fewer errors', async t =
607597
t.fail();
608598
} catch (error) {
609599
t.is(error.stdout, '');
610-
t.is(error.stderr.match(errorPattern).length, 2);
600+
t.is(error.stderr.match(errorPattern).length, 1);
611601
t.is(error.exitCode, 1);
612602
fs.unlinkSync(fixFileB);
613603
}
@@ -624,7 +614,7 @@ test('fixing errors with a glob yields fewer errors', async t => {
624614
t.fail();
625615
} catch (error) {
626616
t.is(error.stdout, '');
627-
t.is(error.stderr.match(errorPattern).length, 4);
617+
t.is(error.stderr.match(errorPattern).length, 2);
628618
t.is(error.exitCode, 1);
629619
fs.unlinkSync(fixFileC);
630620
fs.unlinkSync(fixSubFileC);
@@ -724,7 +714,7 @@ test('--dot option to include folders/files with a dot', async t => {
724714
t.fail();
725715
} catch (error) {
726716
t.is(error.stdout, '');
727-
t.is(error.stderr.match(errorPattern).length, 13);
717+
t.is(error.stderr.match(errorPattern).length, 11);
728718
t.is(error.exitCode, 1);
729719
}
730720
});
@@ -749,11 +739,11 @@ test('with --quiet option does not print to stdout or stderr', async t => {
749739

750740
test('--enable flag', async t => {
751741
try {
752-
await execa('../markdownlint.js', ['--enable', 'MD002', '--config', 'default-false-config.yml', 'incorrect.md'], {stripFinalNewline: false});
742+
await execa('../markdownlint.js', ['--enable', 'MD041', '--config', 'default-false-config.yml', 'incorrect.md'], {stripFinalNewline: false});
753743
t.fail();
754744
} catch (error) {
755745
t.is(error.stdout, '');
756-
t.is(error.stderr, 'incorrect.md:1 MD002/first-heading-h1/first-header-h1 First heading should be a top-level heading [Expected: h1; Actual: h2]\n');
746+
t.is(error.stderr, 'incorrect.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]\n');
757747
t.is(error.exitCode, 1);
758748
}
759749
});
@@ -764,24 +754,24 @@ test('--enable flag does not modify already enabled rules', async t => {
764754
t.fail();
765755
} catch (error) {
766756
t.is(error.stdout, '');
767-
t.is(error.stderr, 'correct.md:1 MD043/required-headings/required-headers Required heading structure [Expected: # First; Actual: # header]\n');
757+
t.is(error.stderr, 'correct.md:1 MD043/required-headings Required heading structure [Expected: # First; Actual: # header]\n');
768758
t.is(error.exitCode, 1);
769759
}
770760
});
771761

772762
test('--enable flag accepts rule alias', async t => {
773763
try {
774-
await execa('../markdownlint.js', ['--enable', 'first-header-h1', '--config', 'default-false-config.yml', 'incorrect.md'], {stripFinalNewline: false});
764+
await execa('../markdownlint.js', ['--enable', 'first-line-heading', '--config', 'default-false-config.yml', 'incorrect.md'], {stripFinalNewline: false});
775765
t.fail();
776766
} catch (error) {
777767
t.is(error.stdout, '');
778-
t.is(error.stderr, 'incorrect.md:1 MD002/first-heading-h1/first-header-h1 First heading should be a top-level heading [Expected: h1; Actual: h2]\n');
768+
t.is(error.stderr, 'incorrect.md:1 MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "## header 2"]\n');
779769
t.is(error.exitCode, 1);
780770
}
781771
});
782772

783773
test('--disable flag', async t => {
784-
const result = await execa('../markdownlint.js', ['--disable', 'MD002', 'MD014', 'MD022', 'MD041', '--', 'incorrect.md'], {stripFinalNewline: false});
774+
const result = await execa('../markdownlint.js', ['--disable', 'MD014', 'MD022', 'MD041', '--', 'incorrect.md'], {stripFinalNewline: false});
785775

786776
t.is(result.stdout, '');
787777
t.is(result.stderr, '');
@@ -798,7 +788,7 @@ test('--disable flag', async t => {
798788
});
799789

800790
test('--disable flag overrides --enable flag', async t => {
801-
const result = await execa('../markdownlint.js', ['--disable', 'MD002', '--enable', 'MD002', '--config', 'default-false-config.yml', 'incorrect.md'], {stripFinalNewline: false});
791+
const result = await execa('../markdownlint.js', ['--disable', 'MD041', '--enable', 'MD041', '--config', 'default-false-config.yml', 'incorrect.md'], {stripFinalNewline: false});
802792
t.is(result.stdout, '');
803793
t.is(result.stderr, '');
804794
t.is(result.exitCode, 0);

0 commit comments

Comments
 (0)