1
0
mirror of synced 2025-12-19 18:10:59 -05:00

Search replace linter bug (#43284)

This commit is contained in:
Rachael Sewell
2023-09-25 16:13:13 -07:00
committed by GitHub
parent a198af2c47
commit b8dfb50528
5 changed files with 21 additions and 7 deletions

View File

@@ -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:**
<!-- markdownlint-disable yaml-scheduled-jobs -->
```yaml
on:
schedule:
@@ -138,6 +139,7 @@ on:
schedule:
- cron: "40 19 * * *"
```
<!-- markdownlint-enable yaml-scheduled-jobs -->
### File names and directory names

View File

@@ -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 }

View File

@@ -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

View File

@@ -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 "<octicon-name>" aria-label="<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 }

View File

@@ -36,13 +36,14 @@ describe(searchReplace.names.join(' - '), () => {
'developer.github.com/changes/',
'developer.github.com/changes/changes',
'developer.github.com/enterprise/1',
'<https://docs.github.com/en/rest/reference/code-scanning#upload-an-analysis-as-sarif-data>',
].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 () => {