Skip to content

Commit 10c7ba7

Browse files
committed
include full content including frontmatter, and tweak some regexes
1 parent 1276f68 commit 10c7ba7

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

tests/content/lint-files.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const path = require('path')
22
const slash = require('slash')
33
const fs = require('fs')
44
const walk = require('walk-sync')
5-
const matter = require('@github-docs/frontmatter')
65
const { zip } = require('lodash')
76
const yaml = require('js-yaml')
87
const languages = require('../../lib/languages')
@@ -81,19 +80,19 @@ const versionLinkRegEx = /(?=^|[^\]]\s*)\[[^\]]+\](?::\n?[ \t]+|\s*\()(?:(?:http
8180
const domainLinkRegex = /(?=^|[^\]]\s*)\[[^\]]+\](?::\n?[ \t]+|\s*\()(?:https?:)?\/\/(?:help|docs|developer)\.github\.com(?!\/changes\/)[^)\s]*(?:\)|\s+|$)/gm
8281

8382
// {{ site.data.example.pizza }}
84-
const oldVariableRegex = /{{\s?site\.data\..*}}/g
83+
const oldVariableRegex = /{{\s*?site\.data\..*?}}/g
8584

8685
// - {{ octicon-plus }}
8786
// - {{ octicon-plus An example label }}
8887
//
89-
const oldOcticonRegex = /{{\s?octicon-([a-z-]+)(\s[\w\s\d-]+)?\s?}}/g
88+
const oldOcticonRegex = /{{\s*?octicon-([a-z-]+)(\s[\w\s\d-]+)?\s*?}}/g
9089

9190
// - {{#note}}
9291
// - {{/note}}
9392
// - {{ #warning }}
9493
// - {{ /pizza }}
9594
//
96-
const oldExtendedMarkdownRegex = /{{\s?[#/][a-z-]+\s?}}/g
95+
const oldExtendedMarkdownRegex = /{{\s*?[#/][a-z-]+\s*}}/g
9796

9897
const relativeArticleLinkErrorText = 'Found unexpected relative article links:'
9998
const languageLinkErrorText = 'Found article links with hard-coded language codes:'
@@ -125,10 +124,7 @@ describe('lint-files', () => {
125124
let content
126125

127126
beforeAll(async () => {
128-
const fileContents = await fs.promises.readFile(markdownAbsPath, 'utf8')
129-
const { content: bodyContent } = matter(fileContents)
130-
131-
content = bodyContent
127+
const content = await fs.promises.readFile(markdownAbsPath, 'utf8')
132128
})
133129

134130
test('relative URLs must start with "/"', async () => {
@@ -214,7 +210,7 @@ describe('lint-files', () => {
214210
const matches = (content.match(oldVariableRegex) || [])
215211
const matchesWithExample = matches.map(match => {
216212
const example = match
217-
.replace(/{{\s?site\.data\.([a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]+)+)\s*}}/g, '{% data $1 %}')
213+
.replace(/{{\s*?site\.data\.([a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]+)+)\s*?}}/g, '{% data $1 %}')
218214
return `${match} => ${example}`
219215
})
220216
const errorMessage = formatLinkError(oldVariableErrorText, matchesWithExample)
@@ -229,7 +225,7 @@ describe('lint-files', () => {
229225

230226
test('does not use old extended markdown syntax', async () => {
231227
Object.keys(tags).forEach(tag => {
232-
const reg = new RegExp(`{{\\s?[#|/]${tag}`, 'g')
228+
const reg = new RegExp(`{{\\s*?[#|/]${tag}`, 'g')
233229
if (reg.test(content)) {
234230
const matches = (content.match(oldExtendedMarkdownRegex)) || []
235231
const tagMessage = oldExtendedMarkdownErrorText
@@ -334,7 +330,7 @@ describe('lint-files', () => {
334330
if (valMatches.length > 0) {
335331
matches.push(...valMatches.map((match) => {
336332
const example = match
337-
.replace(/{{\s?site\.data\.([a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]+)+)\s*}}/g, '{% data $1 %}')
333+
.replace(/{{\s*?site\.data\.([a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]+)+)\s*?}}/g, '{% data $1 %}')
338334
return `Key "${key}": ${match} => ${example}`
339335
}))
340336
}

0 commit comments

Comments
 (0)