| | import { describe, expect, test } from 'vitest' |
| | import markdownlint from 'markdownlint' |
| | import searchReplace from 'markdownlint-rule-search-replace' |
| |
|
| | import { searchReplaceConfig } from '../../style/github-docs' |
| |
|
| | describe('search-replace rule in frontmatter', () => { |
| | test('TODOCS placeholder in frontmatter is detected', async () => { |
| | const markdown = ['---', 'title: TODOCS', '---', '', 'Clean content.'].join('\n') |
| |
|
| | const result = await markdownlint.promises.markdownlint({ |
| | frontMatter: null, |
| | strings: { markdown }, |
| | config: { |
| | 'search-replace': searchReplaceConfig['search-replace'], |
| | }, |
| | customRules: [searchReplace], |
| | }) |
| |
|
| | const errors = result.markdown || [] |
| |
|
| | |
| | const todosErrors = errors.filter((e) => e.errorDetail && /TODOCS/.test(e.errorDetail)) |
| | expect(todosErrors.length).toBe(1) |
| | expect(todosErrors[0].lineNumber).toBe(2) |
| | }) |
| |
|
| | test('multiple TODOCS in frontmatter are all detected', async () => { |
| | const markdown = [ |
| | '---', |
| | 'title: TODOCS', |
| | 'shortTitle: TODOCS', |
| | 'intro: TODOCS', |
| | '---', |
| | '', |
| | 'Content without placeholder.', |
| | ].join('\n') |
| |
|
| | const result = await markdownlint.promises.markdownlint({ |
| | frontMatter: null, |
| | strings: { markdown }, |
| | config: { |
| | 'search-replace': searchReplaceConfig['search-replace'], |
| | }, |
| | customRules: [searchReplace], |
| | }) |
| |
|
| | const errors = result.markdown || [] |
| |
|
| | |
| | const todosErrors = errors.filter((e) => e.errorDetail && /TODOCS/.test(e.errorDetail)) |
| | expect(todosErrors.length).toBe(3) |
| | expect(todosErrors[0].lineNumber).toBe(2) |
| | expect(todosErrors[1].lineNumber).toBe(3) |
| | expect(todosErrors[2].lineNumber).toBe(4) |
| | }) |
| |
|
| | test('domain rules work in frontmatter', async () => { |
| | const markdown = [ |
| | '---', |
| | 'title: Check docs.github.com for info', |
| | 'shortTitle: Visit help.github.com', |
| | 'intro: See developer.github.com for API docs', |
| | '---', |
| | '', |
| | 'Content without domain references.', |
| | ].join('\n') |
| |
|
| | const result = await markdownlint.promises.markdownlint({ |
| | frontMatter: null, |
| | strings: { markdown }, |
| | config: { |
| | 'search-replace': searchReplaceConfig['search-replace'], |
| | }, |
| | customRules: [searchReplace], |
| | }) |
| |
|
| | const errors = result.markdown || [] |
| |
|
| | |
| | const domainErrors = errors.filter( |
| | (e) => e.errorDetail && /docs-domain|help-domain|developer-domain/.test(e.errorDetail), |
| | ) |
| | expect(domainErrors.length).toBe(3) |
| | expect(domainErrors[0].lineNumber).toBe(2) |
| | expect(domainErrors[1].lineNumber).toBe(3) |
| | expect(domainErrors[2].lineNumber).toBe(4) |
| | }) |
| |
|
| | test('deprecated liquid syntax in frontmatter is detected', async () => { |
| | const markdown = [ |
| | '---', |
| | 'title: "{{ site.data.variables.product.product_name }}"', |
| | 'intro: "Use {{ octicon-plus An icon }} here"', |
| | '---', |
| | '', |
| | 'Clean content.', |
| | ].join('\n') |
| |
|
| | const result = await markdownlint.promises.markdownlint({ |
| | frontMatter: null, |
| | strings: { markdown }, |
| | config: { |
| | 'search-replace': searchReplaceConfig['search-replace'], |
| | }, |
| | customRules: [searchReplace], |
| | }) |
| |
|
| | const errors = result.markdown || [] |
| |
|
| | |
| | const deprecatedErrors = errors.filter( |
| | (e) => e.errorDetail && /site\.data|octicon/.test(e.errorDetail), |
| | ) |
| | expect(deprecatedErrors.length).toBe(2) |
| | expect(deprecatedErrors[0].lineNumber).toBe(2) |
| | expect(deprecatedErrors[1].lineNumber).toBe(3) |
| | }) |
| | }) |
| |
|