Skip to content

Commit 6a94b2d

Browse files
author
Peter Bengtsson
authored
Check that content-liter-rules.md stays up-to-date (#49389)
1 parent 437c920 commit 6a94b2d

File tree

6 files changed

+98
-8
lines changed

6 files changed

+98
-8
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: 'Check content-linter rules docs'
2+
3+
# **What it does**: Makes sure the content-linter-rules.md is up-to-date.
4+
# **Why we have it**: So what's automated doesn't fall behind
5+
# **Who does it impact**: Docs content.
6+
7+
on:
8+
workflow_dispatch:
9+
pull_request:
10+
paths:
11+
- 'src/content-linter/**'
12+
# In case imported markdownlint rules are updated
13+
- package-lock.json
14+
# In case manual changes are made to the content-linter-rules.md file
15+
- data/reusables/contributing/content-linter-rules.md
16+
# Self-test
17+
- .github/workflows/content-linter-rules-docs.yml
18+
19+
permissions:
20+
contents: read
21+
22+
jobs:
23+
check-content-linter-rules-docs:
24+
runs-on: ${{ fromJSON('["ubuntu-latest", "ubuntu-20.04-xl"]')[github.repository == 'github/docs-internal'] }}
25+
if: github.repository == 'github/docs-internal' || github.repository == 'github/docs'
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
29+
30+
- uses: ./.github/actions/node-npm-setup
31+
32+
- name: Check that content-linter-rules.md is up-to-date
33+
run: npm run generate-content-linter-docs
34+
35+
- name: Fail if it isn't up-to-date
36+
run: |
37+
if [ -n "$(git status --porcelain)" ]; then
38+
git status
39+
git diff
40+
41+
# Some whitespace for the sake of the message below
42+
echo ""
43+
echo ""
44+
45+
echo "content-linter-rules.md is out of date."
46+
echo "Please run 'npm run generate-content-linter-docs' and commit the changes."
47+
exit 1;
48+
fi

data/reusables/contributing/content-linter-rules.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
| [MD049](https://github.com/DavidAnson/markdownlint/blob/v0.28.2/doc/md049.md) | emphasis-style | Emphasis style should be consistent | error | emphasis |
2626
| [MD050](https://github.com/DavidAnson/markdownlint/blob/v0.28.2/doc/md050.md) | strong-style | Strong style should be consistent | error | emphasis |
2727
| [search-replace](https://github.com/OnkarRuikar/markdownlint-rule-search-replace) | todocs-placeholder | Catch occurrences of TODOCS placeholder. | error | |
28-
| [search-replace](https://github.com/OnkarRuikar/markdownlint-rule-search-replace) | docs-domain | Catch occurrences of docs.gitub.com domain. | warning | |
28+
| [search-replace](https://github.com/OnkarRuikar/markdownlint-rule-search-replace) | docs-domain | Catch occurrences of docs.gitub.com domain. | error | |
2929
| [search-replace](https://github.com/OnkarRuikar/markdownlint-rule-search-replace) | help-domain | Catch occurrences of help.github.com domain. | error | |
3030
| [search-replace](https://github.com/OnkarRuikar/markdownlint-rule-search-replace) | preview-domain | Catch occurrences of preview.ghdocs.com domain. | error | |
3131
| [search-replace](https://github.com/OnkarRuikar/markdownlint-rule-search-replace) | developer-domain | Catch occurrences of developer.github.com domain. | error | |
@@ -58,4 +58,6 @@
5858
| GHD017 | frontmatter-liquid-syntax | Frontmatter properties must use valid Liquid | error | liquid, frontmatter |
5959
| GHD018 | liquid-syntax | Markdown content must use valid Liquid | error | liquid |
6060
| GHD019 | liquid-if-tags | Liquid `ifversion` tags should be used instead of `if` tags when the argument is a valid version | error | liquid, versioning |
61-
| GHD020 | liquid-ifversion-tags | Liquid `ifversion` tags should contain valid version names as arguments | error | liquid, versioning |
61+
| GHD020 | liquid-ifversion-tags | Liquid `ifversion` tags should contain valid version names as arguments | error | liquid, versioning |
62+
| GHD035 | rai-reusable-usage | RAI articles and reusables can only reference reusable content in the data/reusables/rai directory | error | feature, rai |
63+
| GHD036 | image-no-gif | Image must not be a gif, styleguide reference: contributing/style-guide-and-content-model/style-guide.md#images | error | images |

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"lint-content": "node src/content-linter/scripts/lint-content.js",
3535
"lint-translation": "cross-env NODE_OPTIONS=--experimental-vm-modules jest src/content-linter/tests/lint-files.js",
3636
"generate-code-scanning-query-list": "tsx src/code-scanning/scripts/generate-code-scanning-query-list.ts",
37+
"generate-content-linter-docs": "tsx src/content-linter/scripts/generate-docs.ts",
3738
"move-content": "node src/content-render/scripts/move-content.js",
3839
"openapi-docs": "node src/rest/docs.js",
3940
"playwright-test": "playwright test --config src/fixtures/playwright.config.ts --project=\"Google Chrome\"",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// get-rules.d.ts
2+
// This is a declaration file for get-rules.js
3+
4+
import type { Rule, RuleConfig } from '../../types.ts'
5+
6+
export const customRules: Rule[]
7+
export const allRules: Rule[]
8+
export const allConfig: RuleConfig

src/content-linter/scripts/generate-docs.js renamed to src/content-linter/scripts/generate-docs.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22
import { writeFileSync } from 'fs'
3+
import type { Rule, Config } from '../types.ts'
34
import { allRules, allConfig } from '../lib/helpers/get-rules.js'
45

56
main()
@@ -13,11 +14,12 @@ function main() {
1314
)
1415
markdown.push('| Rule ID | Rule Name(s) | Description | Severity | Tags |')
1516
markdown.push('| ------- | ------------ | ----------- | -------- | ---- |')
16-
for (const rule of allRules) {
17-
const ruleName = rule.names.find((name) => allConfig[name] !== undefined)
18-
if (allConfig[ruleName] === undefined) continue
17+
18+
for (const rule of allRules as Rule[]) {
19+
const ruleName = rule.names.find((name) => name in allConfig)
20+
if (!ruleName) continue
1921
if (rule.names.includes('search-replace')) {
20-
markdown.push(...getSearchRepolaceRules(rule, allConfig[ruleName]))
22+
markdown.push(...getSearchReplaceRules(rule, allConfig[ruleName]))
2123
continue
2224
}
2325
const row = []
@@ -34,10 +36,10 @@ function main() {
3436

3537
// The search-replace rule configures multiple psuedo-rules
3638
// under the rules key.
37-
function getSearchRepolaceRules(srRule, ruleConfig) {
39+
function getSearchReplaceRules(srRule: Rule, ruleConfig: Config) {
3840
const name = srRule.information ? `[search-replace](${srRule.information})` : 'search-replace'
3941
const markdown = []
40-
for (const rule of ruleConfig.rules) {
42+
for (const rule of ruleConfig.rules || []) {
4143
const row = []
4244
row.push(name)
4345
row.push(rule.name)

src/content-linter/types.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export type Rule = {
2+
names: string[]
3+
description: string
4+
tags: string[]
5+
information?: URL
6+
function: Function[]
7+
}
8+
9+
type RuleDetail = Rule & {
10+
name: string
11+
'partial-markdown-files': boolean
12+
message: string
13+
severity: string
14+
searchPattern: string
15+
searchScope: string
16+
precommitSeverity?: string
17+
}
18+
19+
export type Config = {
20+
severity: string
21+
'partial-markdown-files': boolean
22+
allowed_languages?: string[]
23+
style?: string
24+
rules?: RuleDetail[]
25+
}
26+
27+
export type RuleConfig = {
28+
[name: string]: Config
29+
}

0 commit comments

Comments
 (0)