diff --git a/content/contributing/writing-for-github-docs/style-guide.md b/content/contributing/writing-for-github-docs/style-guide.md index 836c311879..9bd92c5d25 100644 --- a/content/contributing/writing-for-github-docs/style-guide.md +++ b/content/contributing/writing-for-github-docs/style-guide.md @@ -126,6 +126,7 @@ Avoid inline links in command names. When code examples refer to a larger file, show the relevant section of the file, so that users understand how to edit their own code in context. - **Use:** + ```yaml on: schedule: @@ -138,6 +139,7 @@ on: schedule: - cron: "40 19 * * *" ``` + ### File names and directory names diff --git a/src/content-linter/lib/helpers/get-rules.js b/src/content-linter/lib/helpers/get-rules.js index 7bfee336f4..06d8df8551 100644 --- a/src/content-linter/lib/helpers/get-rules.js +++ b/src/content-linter/lib/helpers/get-rules.js @@ -1,8 +1,8 @@ import rules from '../../../../node_modules/markdownlint/lib/rules.js' import { gitHubDocsMarkdownlint } from '../linting-rules/index.js' import { baseConfig } from '../../style/base.js' -import { githubDocsConfig, searchReplaceConfig } from '../../style/github-docs.js' +import { customConfig } from '../../style/github-docs.js' export const customRules = gitHubDocsMarkdownlint.rules export const allRules = [...rules, ...gitHubDocsMarkdownlint.rules] -export const allConfig = { ...baseConfig, ...githubDocsConfig, ...searchReplaceConfig } +export const allConfig = { ...baseConfig, ...customConfig } diff --git a/src/content-linter/scripts/lint-content.js b/src/content-linter/scripts/lint-content.js index f6e65f8c69..40dab64efa 100755 --- a/src/content-linter/scripts/lint-content.js +++ b/src/content-linter/scripts/lint-content.js @@ -9,7 +9,7 @@ import { execSync } from 'child_process' import walkFiles from '../../../script/helpers/walk-files.js' import { allConfig, allRules, customRules } from '../lib/helpers/get-rules.js' -import { githubDocsConfig } from '../style/github-docs.js' +import { customConfig } from '../style/github-docs.js' program .description('Run GitHub Docs Markdownlint rules.') @@ -308,7 +308,7 @@ function listRules() { Rules that can't be run on partials have the property `partial-markdown-files` set to false. */ -function getMarkdownLintConfig(errorsOnly, runRules, customRules) { +function getMarkdownLintConfig(errorsOnly, runRules) { const config = { content: { default: false, // By default, don't turn on all markdownlint rules @@ -323,12 +323,13 @@ function getMarkdownLintConfig(errorsOnly, runRules, customRules) { } for (const [ruleName, ruleConfig] of Object.entries(allConfig)) { - const customRule = githubDocsConfig[ruleName] && getCustomRule(ruleName) + const customRule = customConfig[ruleName] && getCustomRule(ruleName) // search-replace is handled differently than other rules because // it has nested metadata and rules. if (errorsOnly && getRuleSeverity(ruleConfig) !== 'error' && ruleName !== 'search-replace') continue + if (runRules && !runRules.includes(ruleName)) continue // Handle the special case of the search-replace rule diff --git a/src/content-linter/style/github-docs.js b/src/content-linter/style/github-docs.js index ac77e933e9..d7ee01043f 100644 --- a/src/content-linter/style/github-docs.js +++ b/src/content-linter/style/github-docs.js @@ -72,7 +72,7 @@ export const searchReplaceConfig = { message: 'Catch occurrences of docs.gitub.com domain.', search: 'docs.github.com', searchScope: 'all', - severity: 'error', + severity: 'warning', 'partial-markdown-files': true, }, { @@ -110,6 +110,8 @@ export const searchReplaceConfig = { message: 'Catch occurrences of deprecated liquid data syntax.', searchPattern: '/{{\\s*?site\\.data\\.([a-zA-Z0-9-_]+(?:\\.[a-zA-Z0-9-_]+)+)\\s*?}}/g', replace: '{% data $1 %}', + severity: 'error', + 'partial-markdown-files': true, }, { // Catches usage of old octicon variable syntax. For example: @@ -119,6 +121,8 @@ export const searchReplaceConfig = { message: 'The octicon liquid syntax used is deprecated. Use this format instead {% octicon "" aria-label="" %}', searchPattern: '/{{\\s*?octicon-([a-z-]+)(\\s[\\w\\s\\d-]+)?\\s*?}}/g', + severity: 'error', + 'partial-markdown-files': true, }, { // Catches usage of string personal access token, which should @@ -127,6 +131,8 @@ export const searchReplaceConfig = { message: 'The string "personal access token" can be replaced with a variable. You should use one of the variables from data/variables/product.yml instead of the literal phrase(s):', searchPattern: '/personal access tokens?/gi', + severity: 'warning', + 'partial-markdown-files': true, }, { // Catches usage of GitHub-owned actions that don't use a @@ -156,7 +162,11 @@ export const searchReplaceConfig = { 'A GitHub-owned action is referenced, but should be replaced with a reusable from data/reusables/actions.', searchPattern: '/(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-]*)/g', + severity: 'warning', + 'partial-markdown-files': true, }, ], }, } + +export const customConfig = { ...searchReplaceConfig, ...githubDocsConfig } diff --git a/src/content-linter/tests/unit/search-replace.js b/src/content-linter/tests/unit/search-replace.js index 9542c46dd2..337c01d9b9 100644 --- a/src/content-linter/tests/unit/search-replace.js +++ b/src/content-linter/tests/unit/search-replace.js @@ -36,13 +36,14 @@ describe(searchReplace.names.join(' - '), () => { 'developer.github.com/changes/', 'developer.github.com/changes/changes', 'developer.github.com/enterprise/1', + '', ].join('\n') const result = await runRule(searchReplace, { strings: { markdown }, testConfig: searchReplaceConfig['search-replace'], }) const errors = result.markdown - expect(errors.length).toBe(9) + expect(errors.length).toBe(10) }) test('Deprecated Liquid syntax causes error', async () => {