Search replace linter bug (#43284)
This commit is contained in:
@@ -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.
|
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:**
|
- **Use:**
|
||||||
|
|
||||||
|
<!-- markdownlint-disable yaml-scheduled-jobs -->
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
@@ -138,6 +139,7 @@ on:
|
|||||||
schedule:
|
schedule:
|
||||||
- cron: "40 19 * * *"
|
- cron: "40 19 * * *"
|
||||||
```
|
```
|
||||||
|
<!-- markdownlint-enable yaml-scheduled-jobs -->
|
||||||
|
|
||||||
### File names and directory names
|
### File names and directory names
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import rules from '../../../../node_modules/markdownlint/lib/rules.js'
|
import rules from '../../../../node_modules/markdownlint/lib/rules.js'
|
||||||
import { gitHubDocsMarkdownlint } from '../linting-rules/index.js'
|
import { gitHubDocsMarkdownlint } from '../linting-rules/index.js'
|
||||||
import { baseConfig } from '../../style/base.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 customRules = gitHubDocsMarkdownlint.rules
|
||||||
export const allRules = [...rules, ...gitHubDocsMarkdownlint.rules]
|
export const allRules = [...rules, ...gitHubDocsMarkdownlint.rules]
|
||||||
export const allConfig = { ...baseConfig, ...githubDocsConfig, ...searchReplaceConfig }
|
export const allConfig = { ...baseConfig, ...customConfig }
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { execSync } from 'child_process'
|
|||||||
|
|
||||||
import walkFiles from '../../../script/helpers/walk-files.js'
|
import walkFiles from '../../../script/helpers/walk-files.js'
|
||||||
import { allConfig, allRules, customRules } from '../lib/helpers/get-rules.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
|
program
|
||||||
.description('Run GitHub Docs Markdownlint rules.')
|
.description('Run GitHub Docs Markdownlint rules.')
|
||||||
@@ -308,7 +308,7 @@ function listRules() {
|
|||||||
Rules that can't be run on partials have the property
|
Rules that can't be run on partials have the property
|
||||||
`partial-markdown-files` set to false.
|
`partial-markdown-files` set to false.
|
||||||
*/
|
*/
|
||||||
function getMarkdownLintConfig(errorsOnly, runRules, customRules) {
|
function getMarkdownLintConfig(errorsOnly, runRules) {
|
||||||
const config = {
|
const config = {
|
||||||
content: {
|
content: {
|
||||||
default: false, // By default, don't turn on all markdownlint rules
|
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)) {
|
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
|
// search-replace is handled differently than other rules because
|
||||||
// it has nested metadata and rules.
|
// it has nested metadata and rules.
|
||||||
if (errorsOnly && getRuleSeverity(ruleConfig) !== 'error' && ruleName !== 'search-replace')
|
if (errorsOnly && getRuleSeverity(ruleConfig) !== 'error' && ruleName !== 'search-replace')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if (runRules && !runRules.includes(ruleName)) continue
|
if (runRules && !runRules.includes(ruleName)) continue
|
||||||
|
|
||||||
// Handle the special case of the search-replace rule
|
// Handle the special case of the search-replace rule
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export const searchReplaceConfig = {
|
|||||||
message: 'Catch occurrences of docs.gitub.com domain.',
|
message: 'Catch occurrences of docs.gitub.com domain.',
|
||||||
search: 'docs.github.com',
|
search: 'docs.github.com',
|
||||||
searchScope: 'all',
|
searchScope: 'all',
|
||||||
severity: 'error',
|
severity: 'warning',
|
||||||
'partial-markdown-files': true,
|
'partial-markdown-files': true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -110,6 +110,8 @@ export const searchReplaceConfig = {
|
|||||||
message: 'Catch occurrences of deprecated liquid data syntax.',
|
message: 'Catch occurrences of deprecated liquid data syntax.',
|
||||||
searchPattern: '/{{\\s*?site\\.data\\.([a-zA-Z0-9-_]+(?:\\.[a-zA-Z0-9-_]+)+)\\s*?}}/g',
|
searchPattern: '/{{\\s*?site\\.data\\.([a-zA-Z0-9-_]+(?:\\.[a-zA-Z0-9-_]+)+)\\s*?}}/g',
|
||||||
replace: '{% data $1 %}',
|
replace: '{% data $1 %}',
|
||||||
|
severity: 'error',
|
||||||
|
'partial-markdown-files': true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Catches usage of old octicon variable syntax. For example:
|
// Catches usage of old octicon variable syntax. For example:
|
||||||
@@ -119,6 +121,8 @@ export const searchReplaceConfig = {
|
|||||||
message:
|
message:
|
||||||
'The octicon liquid syntax used is deprecated. Use this format instead {% octicon "<octicon-name>" aria-label="<Octicon aria label>" %}',
|
'The octicon liquid syntax used is deprecated. Use this format instead {% octicon "<octicon-name>" aria-label="<Octicon aria label>" %}',
|
||||||
searchPattern: '/{{\\s*?octicon-([a-z-]+)(\\s[\\w\\s\\d-]+)?\\s*?}}/g',
|
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
|
// Catches usage of string personal access token, which should
|
||||||
@@ -127,6 +131,8 @@ export const searchReplaceConfig = {
|
|||||||
message:
|
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):',
|
'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',
|
searchPattern: '/personal access tokens?/gi',
|
||||||
|
severity: 'warning',
|
||||||
|
'partial-markdown-files': true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// Catches usage of GitHub-owned actions that don't use a
|
// 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.',
|
'A GitHub-owned action is referenced, but should be replaced with a reusable from data/reusables/actions.',
|
||||||
searchPattern:
|
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',
|
'/(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 }
|
||||||
|
|||||||
@@ -36,13 +36,14 @@ describe(searchReplace.names.join(' - '), () => {
|
|||||||
'developer.github.com/changes/',
|
'developer.github.com/changes/',
|
||||||
'developer.github.com/changes/changes',
|
'developer.github.com/changes/changes',
|
||||||
'developer.github.com/enterprise/1',
|
'developer.github.com/enterprise/1',
|
||||||
|
'<https://docs.github.com/en/rest/reference/code-scanning#upload-an-analysis-as-sarif-data>',
|
||||||
].join('\n')
|
].join('\n')
|
||||||
const result = await runRule(searchReplace, {
|
const result = await runRule(searchReplace, {
|
||||||
strings: { markdown },
|
strings: { markdown },
|
||||||
testConfig: searchReplaceConfig['search-replace'],
|
testConfig: searchReplaceConfig['search-replace'],
|
||||||
})
|
})
|
||||||
const errors = result.markdown
|
const errors = result.markdown
|
||||||
expect(errors.length).toBe(9)
|
expect(errors.length).toBe(10)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Deprecated Liquid syntax causes error', async () => {
|
test('Deprecated Liquid syntax causes error', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user