forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request github#28566 from github/repo-sync
Repo sync
- Loading branch information
Showing
22 changed files
with
276 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/content-linter/lib/linting-rules/github-owned-action-references.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { addError, ellipsify } from 'markdownlint-rule-helpers' | ||
|
||
import { getRange } from '../helpers/utils.js' | ||
/* | ||
This rule currently only checks for one hardcoded string but | ||
can be generalized in the future to check for strings that | ||
have data reusables. | ||
*/ | ||
export const githubOwnedActionReferences = { | ||
names: ['GHD013', 'github-owned-action-references'], | ||
description: | ||
'Strings that have a data reusable should use the reusable instead of the hardcoded string.', | ||
tags: ['actions'], | ||
information: new URL('https://github.com/github/docs/blob/main/src/content-linter/README.md'), | ||
function: function GHD013(params, onError) { | ||
const filepath = params.name | ||
if (filepath.startsWith('data/reusables/actions/action-')) return | ||
|
||
const regex = | ||
/(actions\/(checkout|delete-package-versions|download-artifact|upload-artifact|github-script|setup-dotnet|setup-go|setup-java|setup-node|setup-python|stale|cache)|github\/codeql-action[/a-zA-Z-]*)@v\d+/g | ||
|
||
for (let i = 0; i < params.lines.length; i++) { | ||
const line = params.lines[i] | ||
const matches = line.match(regex) | ||
if (!matches) continue | ||
|
||
for (const match of matches) { | ||
const lineNumber = i + 1 | ||
const range = getRange(line, match) | ||
addError( | ||
onError, | ||
lineNumber, | ||
`The string ${match} is using hardcoding a reference to a GitHub-owned action. You should use the reusables for the action. e.g {% data reusables.actions.action-checkout %}.`, | ||
ellipsify(line), | ||
range, | ||
null, // No fix possible | ||
) | ||
} | ||
} | ||
}, | ||
} |
41 changes: 41 additions & 0 deletions
41
src/content-linter/lib/linting-rules/hardcoded-data-variable.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { addError, ellipsify } from 'markdownlint-rule-helpers' | ||
|
||
import { getRange } from '../helpers/utils.js' | ||
import frontmatter from '../../../../lib/read-frontmatter.js' | ||
|
||
/* | ||
This rule currently only checks for one hardcoded string but | ||
can be generalized in the future to check for strings that | ||
have data variables. | ||
*/ | ||
export const hardcodedDataVariable = { | ||
names: ['GHD012', 'hardcoded-data-variable'], | ||
description: | ||
'Strings that have a data reusable should use the reusable instead of the hardcoded string.', | ||
tags: ['single-source'], | ||
information: new URL('https://github.com/github/docs/blob/main/src/content-linter/README.md'), | ||
function: function GHD012(params, onError) { | ||
const frontmatterString = params.frontMatterLines.join('\n') | ||
const fm = frontmatter(frontmatterString).data | ||
if (fm.autogenerated) return | ||
for (let i = 0; i < params.lines.length; i++) { | ||
const line = params.lines[i] | ||
const regex = /personal access tokens?/gi | ||
const matches = line.match(regex) | ||
if (!matches) continue | ||
|
||
for (const match of matches) { | ||
const lineNumber = i + 1 | ||
const range = getRange(line, match) | ||
addError( | ||
onError, | ||
lineNumber, | ||
`The string ${match} can be replaced with a variable. You should use one of the variables from data/variables/product.yml instead of the literal phrase(s):`, | ||
ellipsify(line), | ||
range, | ||
null, // No fix possible | ||
) | ||
} | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/content-linter/lib/linting-rules/internal-links-old-version.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { filterTokens, addError } from 'markdownlint-rule-helpers' | ||
import { getRange } from '../helpers/utils.js' | ||
|
||
export const internalLinksOldVersion = { | ||
names: ['GHD010', 'internal-links-old-version'], | ||
description: 'Internal links must not have a hardcoded version using old versioning patterns', | ||
tags: ['links', 'url'], | ||
information: new URL('https://github.com/github/docs/blob/main/src/content-linter/README.md'), | ||
function: function GHD010(params, onError) { | ||
filterTokens(params, 'inline', (token) => { | ||
if ( | ||
params.name.endsWith('migrating-from-github-enterprise-1110x-to-2123.md') || | ||
params.name.endsWith('all-releases.md') | ||
) | ||
return | ||
for (const child of token.children) { | ||
if (child.type !== 'link_open') continue | ||
// Things matched by this RegExp: | ||
// - /enterprise/2.19/admin/blah | ||
// - https://docs.github.com/enterprise/11.10.340/admin/blah | ||
// - http://help.github.com/enterprise/2.8/admin/blah | ||
// | ||
// Things intentionally NOT matched by this RegExp: | ||
// - https://someservice.com/enterprise/1.0/blah | ||
// - /github/site-policy/enterprise/2.2/admin/blah | ||
const versionLinkRegEx = | ||
/(?:(?:https?:\/\/(?:help|docs|developer)\.github\.com)(?:\/enterprise\/\d+(\.\d+)+\/[^)\s]*)?|^\/enterprise\/\d+(\.\d+)+\/[^)\s]*)(?=\s|$)/gm | ||
// Example child.attrs: | ||
// [ | ||
// ['href', 'get-started'], ['target', '_blank'], | ||
// ['rel', 'canonical'], | ||
// ] | ||
const hrefsMissingSlashes = child.attrs | ||
// The attribute could also be `target` or `rel` | ||
.filter((attr) => attr[0] === 'href') | ||
.filter((attr) => attr[1].startsWith('/') || !attr[1].startsWith('//')) | ||
// Filter out link paths that matches the version link regex | ||
.filter((attr) => attr[1].match(versionLinkRegEx)) | ||
// Get the link path from the attribute | ||
.map((attr) => attr[1]) | ||
|
||
// Create errors for each link path that includes a hardcoded version | ||
for (const linkPath of hrefsMissingSlashes) { | ||
const range = getRange(child.line, linkPath) | ||
addError( | ||
onError, | ||
child.lineNumber, | ||
`There looks to be a hardcoded version in this link: ${linkPath}`, | ||
linkPath, | ||
range, | ||
null, // No fix possible | ||
) | ||
} | ||
} | ||
}) | ||
}, | ||
} |
Oops, something went wrong.