Skip to content

Commit 50f166f

Browse files
authored
ignore automated test files in linter (github#35632)
1 parent 4246f6b commit 50f166f

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/codeql-cli/lib/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
},
1919
"targetDirectory": "content/code-security/code-scanning/codeql-cli-manual",
2020
"sourceDirectory": "semmle-code/documentation/restructuredtext/codeql-cli/manual",
21-
"removeKeywords": ["[Plumbing]"]
21+
"removeKeywords": ["[Plumbing]"],
22+
"linterIgnore": ["content/code-security/code-scanning/codeql-cli-manual"]
2223
}

tests/linting/lint-files.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import addFormats from 'ajv-formats'
1010
import { fromMarkdown } from 'mdast-util-from-markdown'
1111
import { visit } from 'unist-util-visit'
1212
import fs from 'fs/promises'
13+
import { existsSync } from 'fs'
1314
import semver from 'semver'
1415
import { frontmatter, deprecatedProperties } from '../../lib/frontmatter.js'
1516
import languages from '../../lib/languages.js'
@@ -236,7 +237,53 @@ let mdToLint, ymlToLint, ghesReleaseNotesToLint, ghaeReleaseNotesToLint, learnin
236237

237238
const contentMarkdownAbsPaths = walk(contentDir, mdWalkOptions).sort()
238239
const contentMarkdownRelPaths = contentMarkdownAbsPaths.map((p) => slash(path.relative(rootDir, p)))
239-
const contentMarkdownTuples = zip(contentMarkdownRelPaths, contentMarkdownAbsPaths)
240+
241+
// Get the list of config files for automated pipelines
242+
const automatedConfigFiles = walk(`src`, { includeBasePath: true, globs: ['**/lib/config.json'] })
243+
// Get a list of Markdown files to ignore during Markdown linting
244+
const automatedIgnorePaths = (
245+
await Promise.all(
246+
automatedConfigFiles.map(async (p) => {
247+
return JSON.parse(await fs.readFile(p, 'utf8')).linterIgnore
248+
})
249+
)
250+
)
251+
.flat()
252+
.filter(Boolean)
253+
console.log(automatedIgnorePaths)
254+
// For each linterIgnore directory, walk the files in the directory and add
255+
// to the ignore list.
256+
const ignoreMarkdownFilesAbsPath = new Set(
257+
automatedIgnorePaths
258+
.filter((p) => {
259+
const exists = existsSync(p)
260+
if (!exists) {
261+
console.warn(
262+
`WARNING: Ignored path ${p} defined in an automation pipeline does not exist. This may be expected, but if not, remove the defined path from the pipeline config.`
263+
)
264+
}
265+
return exists
266+
})
267+
.map((p) =>
268+
walk(p, {
269+
includeBasePath: true,
270+
globs: ['**/*.md'],
271+
})
272+
)
273+
.flat()
274+
)
275+
276+
// Difference between contentMarkdownAbsPaths & automatedIgnorePaths
277+
const contentMarkdownNoAutomated = [...contentMarkdownRelPaths].filter(
278+
(p) => !ignoreMarkdownFilesAbsPath.has(p)
279+
)
280+
// We also need to go back and get the difference between the
281+
// absolute paths list
282+
const contentMarkdownAbsPathNoAutomated = [...contentMarkdownAbsPaths].filter(
283+
(p) => !ignoreMarkdownFilesAbsPath.has(slash(path.relative(rootDir, p)))
284+
)
285+
286+
const contentMarkdownTuples = zip(contentMarkdownNoAutomated, contentMarkdownAbsPathNoAutomated)
240287

241288
const reusableMarkdownAbsPaths = walk(reusablesDir, mdWalkOptions).sort()
242289
const reusableMarkdownRelPaths = reusableMarkdownAbsPaths.map((p) =>

0 commit comments

Comments
 (0)