Skip to content

Commit 3899ef0

Browse files
authored
Merge pull request github#28377 from github/repo-sync
Repo sync
2 parents bf58990 + dc3a073 commit 3899ef0

20 files changed

Lines changed: 211 additions & 30 deletions

content/actions/examples/using-concurrency-expressions-and-a-test-matrix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ layout: inline
1212
topics:
1313
- Workflows
1414
---
15-
15+
<!-- markdownlint-disable early-access-references -->
1616
{% data reusables.actions.enterprise-github-hosted-runners %}
1717

1818
## Example overview
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
export function testOptions(rule, module, strings) {
1+
export function testOptions(rule, module, { strings, files }) {
22
const config = {
33
default: false,
44
[rule]: true,
55
}
66

77
const options = {
8-
strings,
98
customRules: [module],
109
config,
1110
}
11+
if (strings) options.strings = strings
12+
if (files) options.files = files
1213
return options
1314
}

src/content-linter/lib/helpers/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,5 @@ export function filterTokensByOrder(tokens, tokenOrder) {
9494
}
9595
return matches
9696
}
97+
98+
export const docsDomains = ['docs.github.com', 'help.github.com', 'developer.github.com']

src/content-linter/lib/init-test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import markdownlint from 'markdownlint'
22

33
import { testOptions } from './default-markdownlint-options.js'
44

5-
export async function runRule(module, strings) {
6-
const options = testOptions(module.names[0], module, strings)
5+
export async function runRule(module, { strings, files } = {}) {
6+
if ((!strings && !files) || (strings && files))
7+
throw new Error('Must provide either Markdown strings or files to run a rule')
8+
9+
const options = testOptions(module.names[0], module, { strings, files })
710
return await markdownlint.promises.markdownlint(options)
811
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { addError } from 'markdownlint-rule-helpers'
2+
import yaml from 'js-yaml'
3+
4+
import frontmatter from '../../../../lib/read-frontmatter.js'
5+
import { getRange } from '../helpers/utils.js'
6+
7+
export const earlyAccessReferences = {
8+
names: ['GH035', 'early-access-references'],
9+
description:
10+
'Files that are not early access should not reference early-access or early-access files.',
11+
tags: ['early-access'],
12+
severity: 'error',
13+
information: new URL('https://github.com/github/docs/blob/main/src/content-linter/README.md'),
14+
function: function GH035(params, onError) {
15+
const filepath = params.name
16+
// Early access content is allowed to use early access references
17+
// There are several existing allowed references to `early access`
18+
// as a GitHub feature. This rule focuses on references to early
19+
// access pages.
20+
const isEarlyAccess = filepath.includes('early-access')
21+
if (isEarlyAccess) return
22+
23+
const earlyAccessRegex = /early-access/i
24+
const earlyAccessArticlesRegex = /-early-access-/
25+
26+
for (let i = 0; i < params.lines.length; i++) {
27+
const line = params.lines[i]
28+
const matches = line.match(earlyAccessRegex)
29+
if (matches && !earlyAccessArticlesRegex.test(line)) {
30+
addError(
31+
onError,
32+
i + 1,
33+
'An early access reference appears to be used in a non-early access doc. Remove early access references or disable this rule.',
34+
line,
35+
getRange(line, matches[0]),
36+
null, // No fix possible
37+
)
38+
}
39+
}
40+
41+
// The only Frontmatter property that is allowed to contain
42+
// early-access is the redirect_from property.
43+
// To get the list of frontmatter lines that are applicable
44+
// we can convert the frontmatter lines array to an object
45+
// remove the property then convert it back to strings.
46+
const frontmatterString = params.frontMatterLines.join('\n')
47+
const fm = frontmatter(frontmatterString).data
48+
delete fm.redirect_from
49+
// The landing page must link to early-access content so this
50+
// case is allowed.
51+
const isLandingPage = filepath === 'content/index.md'
52+
if (isLandingPage) delete fm.children
53+
const fmStrings = yaml.dump(fm).split('\n')
54+
55+
for (let i = 0; i < fmStrings.length; i++) {
56+
const fmLine = fmStrings[i]
57+
if (earlyAccessRegex.test(fmLine) && !earlyAccessArticlesRegex.test(fmLine)) {
58+
addError(
59+
onError,
60+
1,
61+
'Frontmatter: An early access reference appears to be used in a non-early access doc. Remove early access references or disable this rule.',
62+
fmLine,
63+
null,
64+
null, // No fix possible
65+
)
66+
}
67+
}
68+
},
69+
}

src/content-linter/lib/linting-rules/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { internalLinksSlash } from './internal-links-slash.js'
99
import { imageAltTextExcludeStartWords } from './image-alt-text-exclude-start-words.js'
1010
import { listFirstWordCapitalization } from './list-first-word-capitalization.js'
1111
import { internalLinkPunctuation } from './internal-link-punctuation.js'
12+
import { earlyAccessReferences } from './early-access-references.js'
1213

1314
export const gitHubDocsMarkdownlint = {
1415
rules: [
@@ -22,5 +23,6 @@ export const gitHubDocsMarkdownlint = {
2223
imageAltTextExcludeStartWords,
2324
listFirstWordCapitalization,
2425
internalLinkPunctuation,
26+
earlyAccessReferences,
2527
],
2628
}

src/content-linter/scripts/markdownlint.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ function formatResult(object) {
244244
delete acc.range
245245
return acc
246246
}
247+
if (key === 'lineNumber') {
248+
if (object.errorDetail.startsWith('Frontmatter:')) {
249+
delete acc.lineNumber
250+
acc.frontmatterError = true
251+
return acc
252+
}
253+
}
247254
acc[key] = value
248255
return acc
249256
}, formattedResult)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export const githubDocsConfig = {
4949
severity: 'error',
5050
'partial-markdown-files': true,
5151
},
52+
'early-access-references': {
53+
severity: 'error',
54+
'partial-markdown-files': true,
55+
},
5256
'search-replace': {
5357
severity: 'error',
5458
'severity-local-env': 'warning',
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: early-access secret
3+
descriptions: Early Access secret
4+
versions:
5+
fpt: '*'
6+
ghes: '*'
7+
ghae: '*'
8+
ghec: '*'
9+
---
10+
11+
Links that are not allowed:
12+
13+
- [link text](/early-access/github/blah)
14+
15+
[link text](https://docs.github.com/early-access/github/blah)
16+
[link-definition-ref][]
17+
18+
[link-definition-ref]: http://help.github.com/early-access/github/blah
19+
20+
Links that are allowed:
21+
[Node.js](https://example.org/early-access/)
22+
23+
Images that are not allowed:
24+
- ![image text](/assets/images/early-access/github/blah.gif)
25+
![image text] (https://docs.github.com/assets/images/early-access/github/blah.gif)
26+
[image-definition-ref]: http://help.github.com/assets/images/early-access/github/blah.gif
27+
![link text](/assets/images/early-access/github/blah.gif)
28+
29+
Images that are allowed:
30+
![Node.js](https://example.org/assets/images/early-access/blah.gif)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: early-access secret
3+
descriptions: Early-Access secret
4+
redirect_from:
5+
- /early-access/secret
6+
versions:
7+
fpt: '*'
8+
ghes: '*'
9+
ghae: '*'
10+
ghec: '*'
11+
---
12+
13+
Early-access
14+
path/to-about-early-access-at-github.md
15+
Early access is ok
16+
17+
- [link text](/early-access/github/blah)
18+
19+
[link text](https://docs.github.com/early-access/github/blah)
20+
[link-definition-ref][]
21+
22+
[Node.js](https://example.org/early-access/)<!-- markdownlint-disable-line early-access-references -->
23+
24+
- ![image text](/assets/images/early-access/github/blah.gif)
25+
![image text](https://docs.github.com/assets/images/early-access/github/blah.gif)
26+
27+
![image text](/assets/images/early-access/github/blah.gif)
28+
![image-definition-ref][]
29+
30+
![Node.js](https://example.org/assets/images/early-access/blah.gif)<!-- markdownlint-disable-line early-access-references -->
31+
32+
[link-definition-ref]: http://help.github.com/early-access/github/blah
33+
[image-definition-ref]: http://help.github.com/assets/images/early-access/github/blah.gif

0 commit comments

Comments
 (0)