Skip to content

Commit bdf9be5

Browse files
authored
refactor markdownlint tests (github#42200)
1 parent e61e105 commit bdf9be5

21 files changed

+245
-169
lines changed

src/content-linter/lib/default-markdownlint-options.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
export function testOptions(rule, module, fixtureFile) {
1+
export function testOptions(rule, module, strings) {
22
const config = {
33
default: false,
44
[rule]: true,
55
}
66

77
const options = {
8-
files: [fixtureFile],
8+
strings,
99
customRules: [module],
1010
config,
1111
}

src/content-linter/lib/helpers/utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ export function getRange(line, content) {
99
const startColumnIndex = line.indexOf(content)
1010
return startColumnIndex !== -1 ? [startColumnIndex + 1, content.length] : null
1111
}
12+
13+
export function isStringQuoted(text) {
14+
// String starts with either a single or double quote
15+
// ends with either a single or double quote
16+
// and optionally ends with a question mark or exclamation point
17+
// because that punctuation can exist outside of the quoted string
18+
const regex = /^['"].*['"][?!]?$/
19+
return text.match(regex)
20+
}

src/content-linter/lib/init-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import markdownlint from 'markdownlint'
22

33
import { testOptions } from './default-markdownlint-options.js'
44

5-
export async function runRule(module, fixtureFile) {
6-
const options = testOptions(module.names[0], module, fixtureFile)
5+
export async function runRule(module, strings) {
6+
const options = testOptions(module.names[0], module, strings)
77
return await markdownlint.promises.markdownlint(options)
88
}

src/content-linter/lib/linting-rules/image-alt-text-end-punctuation.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { forEachInlineChild } from 'markdownlint-rule-helpers'
22

3-
import { addFixErrorDetail, getRange } from '../helpers/utils.js'
3+
import { addFixErrorDetail, getRange, isStringQuoted } from '../helpers/utils.js'
44

55
export const imageAltTextEndPunctuation = {
66
names: ['GHD002', 'image-alt-text-end-punctuation'],
@@ -20,7 +20,9 @@ export const imageAltTextEndPunctuation = {
2020
) {
2121
addFixErrorDetail(onError, token.lineNumber, imageAltText + '.', imageAltText, range, {
2222
lineNumber: token.lineNumber,
23-
editColumn: token.line.indexOf(']') + 1,
23+
editColumn: isStringQuoted(imageAltText)
24+
? token.line.indexOf(']')
25+
: token.line.indexOf(']') + 1,
2426
deleteCount: 0,
2527
insertText: '.',
2628
})

src/content-linter/lib/linting-rules/internal-links-lang.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { filterTokens } from 'markdownlint-rule-helpers'
2-
32
import { addFixErrorDetail, getRange } from '../helpers/utils.js'
4-
import { languageKeys } from '#src/languages/lib/languages.js'
3+
import { allLanguageKeys } from '#src/languages/lib/languages.js'
54

65
export const internalLinksLang = {
76
names: ['GHD005', 'internal-links-lang'],
@@ -24,7 +23,7 @@ export const internalLinksLang = {
2423
.filter((attr) => attr[0] === 'href')
2524
.filter((attr) => attr[1].startsWith('/') || !attr[1].startsWith('//'))
2625
// Filter out link paths that start with language code
27-
.filter((attr) => languageKeys.some((lang) => attr[1].split('/')[1] === lang))
26+
.filter((attr) => allLanguageKeys.some((lang) => attr[1].split('/')[1] === lang))
2827
// Get the link path from the attribute
2928
.map((attr) => attr[1])
3029
// Create errors for each link path that includes a language code

src/content-linter/scripts/markdownlint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ main()
4646
async function main() {
4747
// If paths has not been specified, lint all files
4848
const files = getFilesToLint((summaryByRule && ALL_CONTENT_DIR) || paths || getChangedFiles())
49-
const spinner = ora({ text: 'Running content linter', spinner: 'simpleDots' })
49+
const spinner = ora({ text: 'Running content linter\n\n', spinner: 'simpleDots' })
5050

5151
if (!files.length) {
5252
spinner.succeed('No files to lint')

src/content-linter/tests/fixtures/code-fence-line-length.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/content-linter/tests/fixtures/image-alt-text-end-punctuation.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/content-linter/tests/fixtures/image-alt-text-exclude-start-words.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/content-linter/tests/fixtures/image-alt-text-length.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)