Skip to content

Commit e5e13f8

Browse files
authored
Update content linting report to only include errors and expired content warnings (#56479)
1 parent 0db9781 commit e5e13f8

File tree

4 files changed

+75
-7
lines changed

4 files changed

+75
-7
lines changed

.github/workflows/lint-entire-content-data-markdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
REPORT_AUTHOR: docs-bot
4242
REPORT_LABEL: broken content markdown report
4343
REPORT_REPOSITORY: github/docs-content
44-
run: npm run post-lints -- --path /tmp/lint-results.json
44+
run: npm run lint-report -- --path /tmp/lint-results.json
4545

4646
- uses: ./.github/actions/slack-alert
4747
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"move-content": "tsx src/content-render/scripts/move-content.js",
6767
"openapi-docs": "tsx src/rest/docs.js",
6868
"playwright-test": "playwright test --config src/fixtures/playwright.config.ts --project=\"Google Chrome\"",
69-
"post-lints": "tsx src/content-linter/scripts/post-lints.js",
69+
"lint-report": "tsx src/content-linter/scripts/lint-report.js",
7070
"postinstall": "cp package-lock.json .installed.package-lock.json && echo \"Updated .installed.package-lock.json\" # see husky/post-checkout and husky/post-merge",
7171
"precompute-pageinfo": "tsx src/article-api/scripts/precompute-pageinfo.ts",
7272
"prepare": "husky src/workflows/husky",

src/content-linter/scripts/post-lints.js renamed to src/content-linter/scripts/lint-report.js

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,47 @@ import coreLib from '@actions/core'
55
import github from '#src/workflows/github.ts'
66
import { getEnvInputs } from '#src/workflows/get-env-inputs.ts'
77
import { createReportIssue, linkReports } from '#src/workflows/issue-report.js'
8+
import { reportingConfig } from '#src/content-linter/style/github-docs.js'
89

910
// GitHub issue body size limit is ~65k characters, so we'll use 60k as a safe limit
1011
const MAX_ISSUE_BODY_SIZE = 60000
1112

13+
/**
14+
* Determines if a lint result should be included in the automated report
15+
* @param {Object} flaw - The lint result object
16+
* @param {string} flaw.severity - 'error' or 'warning'
17+
* @param {string[]} flaw.ruleNames - Array of rule names for this flaw
18+
* @returns {boolean} - True if this flaw should be included in the report
19+
*/
20+
function shouldIncludeInReport(flaw) {
21+
if (!flaw.ruleNames || !Array.isArray(flaw.ruleNames)) {
22+
return false
23+
}
24+
25+
// Check if any rule name is in the exclude list
26+
const hasExcludedRule = flaw.ruleNames.some((ruleName) =>
27+
reportingConfig.excludeRules.includes(ruleName),
28+
)
29+
if (hasExcludedRule) {
30+
return false
31+
}
32+
33+
// Check if severity should be included
34+
if (reportingConfig.includeSeverities.includes(flaw.severity)) {
35+
return true
36+
}
37+
38+
// Check if any rule name is in the include list
39+
const hasIncludedRule = flaw.ruleNames.some((ruleName) =>
40+
reportingConfig.includeRules.includes(ruleName),
41+
)
42+
if (hasIncludedRule) {
43+
return true
44+
}
45+
46+
return false
47+
}
48+
1249
// [start-readme]
1350
//
1451
// This script runs once a week via a scheduled GitHub Action to lint
@@ -46,15 +83,26 @@ async function main() {
4683
// or open an issue report, you might get cryptic error messages from Octokit.
4784
getEnvInputs(['GITHUB_TOKEN'])
4885

49-
core.info(`Creating issue for errors and warnings...`)
86+
core.info(`Creating issue for configured lint rules...`)
5087

5188
const parsedResults = JSON.parse(lintResults)
52-
const totalFiles = Object.keys(parsedResults).length
53-
let reportBody = 'The following files have markdown lint warnings/errors:\n\n'
89+
90+
// Filter results based on reporting configuration
91+
const filteredResults = {}
92+
for (const [file, flaws] of Object.entries(parsedResults)) {
93+
const filteredFlaws = flaws.filter(shouldIncludeInReport)
94+
95+
// Only include files that have remaining flaws after filtering
96+
if (filteredFlaws.length > 0) {
97+
filteredResults[file] = filteredFlaws
98+
}
99+
}
100+
const totalFiles = Object.keys(filteredResults).length
101+
let reportBody = 'The following files have markdown lint issues that require attention:\n\n'
54102
let filesIncluded = 0
55103
let truncated = false
56104

57-
for (const [file, flaws] of Object.entries(parsedResults)) {
105+
for (const [file, flaws] of Object.entries(filteredResults)) {
58106
const fileEntry = `File: \`${file}\`:\n\`\`\`json\n${JSON.stringify(flaws, null, 2)}\n\`\`\`\n`
59107

60108
// Check if adding this file would exceed the size limit
@@ -77,7 +125,7 @@ async function main() {
77125
const reportProps = {
78126
core,
79127
octokit,
80-
reportTitle: `Error(s) and warning(s) in content markdown file(s)`,
128+
reportTitle: `Content linting issues requiring attention`,
81129
reportBody,
82130
reportRepository: REPORT_REPOSITORY,
83131
reportLabel: REPORT_LABEL,

src/content-linter/style/github-docs.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
// Configuration for which rules should be included in automated weekly reports
2+
export const reportingConfig = {
3+
// Always include all rules with these severities
4+
includeSeverities: ['error'],
5+
6+
// Specific rules to include regardless of severity
7+
// Add rule names (short or long form) that should always be reported
8+
includeRules: [
9+
'GHD038', // expired-content - Content that has passed its expiration date
10+
'expired-content',
11+
],
12+
13+
// Specific rules to exclude from reports (overrides severity-based inclusion)
14+
// Add rule names here if you want to suppress them from reports
15+
excludeRules: [
16+
// Example: 'GHD030' // Uncomment to exclude code-fence-line-length warnings
17+
// Example: 'british-english-quotes' // Uncomment to exclude punctuation warnings
18+
],
19+
}
20+
121
const githubDocsConfig = {
222
'link-punctuation': {
323
// GHD001

0 commit comments

Comments
 (0)