Skip to content

Commit 8e897b2

Browse files
authored
Fix all no-shadow ESLint violations (#58234)
1 parent 23c9d95 commit 8e897b2

File tree

83 files changed

+374
-366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+374
-366
lines changed

eslint.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export default [
9797

9898
// Disabled rules to review
9999
'@typescript-eslint/ban-ts-comment': 'off', // 50+
100-
'no-shadow': 'off', // 150+
101100
'github/array-foreach': 'off', // 250+
102101
'no-console': 'off', // 800+
103102
'@typescript-eslint/no-explicit-any': 'off', // 1000+

next.config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ const config: NextConfig = {
4949
}
5050
})
5151
},
52-
webpack: (config) => {
53-
config.experiments = config.experiments || {}
54-
config.experiments.topLevelAwait = true
55-
config.resolve.fallback = { fs: false, async_hooks: false }
56-
return config
52+
webpack: (webpackConfig) => {
53+
webpackConfig.experiments = webpackConfig.experiments || {}
54+
webpackConfig.experiments.topLevelAwait = true
55+
webpackConfig.resolve.fallback = { fs: false, async_hooks: false }
56+
return webpackConfig
5757
},
5858

5959
// https://nextjs.org/docs/api-reference/next.config.js/compression

src/assets/middleware/dynamic-assets.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ export default async function dynamicAssets(
143143
const buffer = await image.webp({ effort }).toBuffer()
144144
assetCacheControl(res)
145145
return res.type('image/webp').send(buffer)
146-
} catch (error) {
147-
if (error instanceof Error && (error as any).code !== 'ENOENT') {
148-
throw error
146+
} catch (catchError) {
147+
if (catchError instanceof Error && (catchError as any).code !== 'ENOENT') {
148+
throw catchError
149149
}
150150
}
151151
}

src/assets/tests/static-assets.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ function getNextStaticAsset(directory: string) {
1616
return path.join(root, files[0])
1717
}
1818

19-
function mockRequest(path: string, { headers }: { headers?: Record<string, string> } = {}) {
19+
function mockRequest(requestPath: string, { headers }: { headers?: Record<string, string> } = {}) {
2020
const _headers = Object.fromEntries(
2121
Object.entries(headers || {}).map(([key, value]) => [key.toLowerCase(), value]),
2222
)
2323
return {
24-
path,
25-
url: path,
24+
path: requestPath,
25+
url: requestPath,
2626
get: (header: string) => {
2727
return _headers[header.toLowerCase()]
2828
},
@@ -74,8 +74,8 @@ const mockResponse = () => {
7474
if (typeof key === 'string') {
7575
res.headers[key.toLowerCase()] = value
7676
} else {
77-
for (const [k, value] of Object.entries(key)) {
78-
res.headers[k.toLowerCase()] = value
77+
for (const [k, v] of Object.entries(key)) {
78+
res.headers[k.toLowerCase()] = v
7979
}
8080
}
8181
}
@@ -319,9 +319,9 @@ describe('archived enterprise static assets', () => {
319319
},
320320
])(
321321
'should return $expectStatus for $name',
322-
({ name, path, referrer, expectStatus, shouldCallNext }) => {
322+
({ name, path: testPath, referrer, expectStatus, shouldCallNext }) => {
323323
test(name, async () => {
324-
const req = mockRequest(path, {
324+
const req = mockRequest(testPath, {
325325
headers: {
326326
Referrer: referrer,
327327
},
@@ -359,22 +359,25 @@ describe('archived enterprise static assets', () => {
359359
expectStatus: undefined,
360360
shouldCallNext: true,
361361
},
362-
])('should not suppress $name', ({ name, path, referrer, expectStatus, shouldCallNext }) => {
363-
test(name, async () => {
364-
const req = mockRequest(path, {
365-
headers: {
366-
Referrer: referrer,
367-
},
362+
])(
363+
'should not suppress $name',
364+
({ name, path: testPath, referrer, expectStatus, shouldCallNext }) => {
365+
test(name, async () => {
366+
const req = mockRequest(testPath, {
367+
headers: {
368+
Referrer: referrer,
369+
},
370+
})
371+
const res = mockResponse()
372+
let nexted = false
373+
const next = () => {
374+
nexted = true
375+
}
376+
setDefaultFastlySurrogateKey(req, res, () => {})
377+
await archivedEnterpriseVersionsAssets(req as any, res as any, next)
378+
expect(nexted).toBe(shouldCallNext)
379+
expect(res.statusCode).toBe(expectStatus)
368380
})
369-
const res = mockResponse()
370-
let nexted = false
371-
const next = () => {
372-
nexted = true
373-
}
374-
setDefaultFastlySurrogateKey(req, res, () => {})
375-
await archivedEnterpriseVersionsAssets(req as any, res as any, next)
376-
expect(nexted).toBe(shouldCallNext)
377-
expect(res.statusCode).toBe(expectStatus)
378-
})
379-
})
381+
},
382+
)
380383
})

src/codeql-cli/scripts/sync.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ async function setupEnvironment() {
8383

8484
// copy the raw rst files to the temp directory and convert them
8585
// to Markdownusing pandoc
86-
async function rstToMarkdown(sourceDirectory: string) {
87-
const sourceFiles = walk(sourceDirectory, {
86+
async function rstToMarkdown(rstSourceDirectory: string) {
87+
const sourceFiles = walk(rstSourceDirectory, {
8888
includeBasePath: true,
8989
globs: ['**/*.rst'],
9090
})

src/content-linter/lib/helpers/get-lintable-yml.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ export async function getLintableYml(dataFilePath: string): Promise<Record<strin
8080
// back to a file in the data directory.
8181
// The resulting key looks like:
8282
// 'data/variables/product.yml /pat_v1_caps'
83-
function addPathToKey(mdDict: Map<string, string>, dataFilePath: string): Map<string, string> {
84-
const keys = Array.from(mdDict.keys())
83+
function addPathToKey(mdDictMap: Map<string, string>, dataFilePath: string): Map<string, string> {
84+
const keys = Array.from(mdDictMap.keys())
8585
keys.forEach((key) => {
8686
const newKey = `${dataFilePath} ${key}`
87-
const value = mdDict.get(key)
87+
const value = mdDictMap.get(key)
8888
if (value !== undefined) {
89-
mdDict.delete(key)
90-
mdDict.set(newKey, value)
89+
mdDictMap.delete(key)
90+
mdDictMap.set(newKey, value)
9191
}
9292
})
93-
return mdDict
93+
return mdDictMap
9494
}

src/content-linter/lib/linting-rules/frontmatter-hero-image.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const frontmatterHeroImage: Rule = {
4545

4646
// Check if heroImage is an absolute path
4747
if (!heroImage.startsWith('/')) {
48-
const line = params.lines.find((line: string) => line.trim().startsWith('heroImage:'))
48+
const line = params.lines.find((ln: string) => ln.trim().startsWith('heroImage:'))
4949
const lineNumber = line ? params.lines.indexOf(line) + 1 : 1
5050
addError(
5151
onError,
@@ -59,7 +59,7 @@ export const frontmatterHeroImage: Rule = {
5959

6060
// Check if heroImage points to banner-images directory
6161
if (!heroImage.startsWith('/assets/images/banner-images/')) {
62-
const line = params.lines.find((line: string) => line.trim().startsWith('heroImage:'))
62+
const line = params.lines.find((ln: string) => ln.trim().startsWith('heroImage:'))
6363
const lineNumber = line ? params.lines.indexOf(line) + 1 : 1
6464
addError(
6565
onError,
@@ -74,7 +74,7 @@ export const frontmatterHeroImage: Rule = {
7474
// Check if the file actually exists
7575
const validHeroImages = getValidHeroImages()
7676
if (validHeroImages.length > 0 && !validHeroImages.includes(heroImage)) {
77-
const line = params.lines.find((line: string) => line.trim().startsWith('heroImage:'))
77+
const line = params.lines.find((ln: string) => ln.trim().startsWith('heroImage:'))
7878
const lineNumber = line ? params.lines.indexOf(line) + 1 : 1
7979
const availableImages = validHeroImages.join(', ')
8080
addError(

src/content-linter/lib/linting-rules/frontmatter-intro-links.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export const frontmatterIntroLinks: Rule = {
4848
for (const key of Object.keys(introLinks)) {
4949
if (!validKeys.includes(key)) {
5050
// Find the line with this key
51-
const line = params.lines.find((line: string) => {
52-
const trimmed = line.trim()
51+
const line = params.lines.find((ln: string) => {
52+
const trimmed = ln.trim()
5353
return trimmed.startsWith(`${key}:`) && !trimmed.startsWith('introLinks:')
5454
})
5555
const lineNumber = line ? params.lines.indexOf(line) + 1 : 1

src/content-linter/lib/linting-rules/frontmatter-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const frontmatterSchema: Rule = {
2424
for (const key of deprecatedKeys) {
2525
// Early access articles are allowed to have deprecated properties
2626
if (params.name.includes('early-access')) continue
27-
const line = params.lines.find((line: string) => line.trim().startsWith(key))
27+
const line = params.lines.find((ln: string) => ln.trim().startsWith(key))
2828
const lineNumber = params.lines.indexOf(line!) + 1
2929
addError(
3030
onError,

src/content-linter/scripts/lint-content.ts

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ async function main() {
262262
}
263263

264264
const fixableFiles = Object.entries(formattedResults)
265-
.filter(([, results]) => results.some((result) => result.fixable))
265+
.filter(([, fileResults]) => fileResults.some((flaw) => flaw.fixable))
266266
.map(([file]) => file)
267267
if (fixableFiles.length) {
268268
console.log('') // Just for some whitespace before the next message
@@ -302,7 +302,7 @@ function pluralize(things, word, pluralForm = null) {
302302
// (e.g., heading linters) so we need to separate the
303303
// list of data files from all other files to run
304304
// through markdownlint individually
305-
function getFilesToLint(paths) {
305+
function getFilesToLint(inputPaths) {
306306
const fileList = {
307307
length: 0,
308308
content: [],
@@ -316,7 +316,7 @@ function getFilesToLint(paths) {
316316
// The path passed to Markdownlint is what is displayed
317317
// in the error report, so we want to normalize it and
318318
// and make it relative if it's absolute.
319-
for (const rawPath of paths) {
319+
for (const rawPath of inputPaths) {
320320
const absPath = path.resolve(rawPath)
321321
if (fs.statSync(rawPath).isDirectory()) {
322322
if (isInDir(absPath, contentDir)) {
@@ -427,16 +427,16 @@ function reportSummaryByRule(results, config) {
427427
result. Results are sorted by severity per file, with errors
428428
listed first then warnings.
429429
*/
430-
function getFormattedResults(allResults, isPrecommit) {
430+
function getFormattedResults(allResults, isInPrecommitMode) {
431431
const output = {}
432432
Object.entries(allResults)
433433
// Each result key always has an array value, but it may be empty
434434
.filter(([, results]) => results.length)
435-
.forEach(([key, results]) => {
435+
.forEach(([key, fileResults]) => {
436436
if (verbose) {
437-
output[key] = [...results]
437+
output[key] = [...fileResults]
438438
} else {
439-
const formattedResults = results.map((flaw) => formatResult(flaw, isPrecommit))
439+
const formattedResults = fileResults.map((flaw) => formatResult(flaw, isInPrecommitMode))
440440

441441
// Only add the file to output if there are results after filtering
442442
if (formattedResults.length > 0) {
@@ -465,8 +465,8 @@ function getErrorCountByFile(results, fixed = false) {
465465
return getCountBySeverity(results, 'error', fixed)
466466
}
467467
function getCountBySeverity(results, severityLookup, fixed) {
468-
return Object.values(results).filter((results) =>
469-
results.some((result) => {
468+
return Object.values(results).filter((fileResults) =>
469+
fileResults.some((result) => {
470470
// If --fix was applied, we don't want to know about files that
471471
// no longer have errors or warnings.
472472
return result.severity === severityLookup && (!fixed || !result.fixable)
@@ -477,7 +477,7 @@ function getCountBySeverity(results, severityLookup, fixed) {
477477
// Removes null values and properties that are not relevant to content
478478
// writers, adds the severity to each result object, and transforms
479479
// some error and fix data into a more readable format.
480-
function formatResult(object, isPrecommit) {
480+
function formatResult(object, isInPrecommitMode) {
481481
const formattedResult = {}
482482

483483
// Add severity to each result object
@@ -486,7 +486,8 @@ function formatResult(object, isPrecommit) {
486486
throw new Error(`Rule not found in allConfig: '${ruleName}'`)
487487
}
488488
formattedResult.severity =
489-
allConfig[ruleName].severity || getSearchReplaceRuleSeverity(ruleName, object, isPrecommit)
489+
allConfig[ruleName].severity ||
490+
getSearchReplaceRuleSeverity(ruleName, object, isInPrecommitMode)
490491

491492
formattedResult.context = allConfig[ruleName].context || ''
492493

@@ -540,7 +541,7 @@ function listRules() {
540541
Rules that can't be run on partials have the property
541542
`partial-markdown-files` set to false.
542543
*/
543-
function getMarkdownLintConfig(errorsOnly, runRules) {
544+
function getMarkdownLintConfig(filterErrorsOnly, runRules) {
544545
const config = {
545546
content: structuredClone(defaultConfig),
546547
data: structuredClone(defaultConfig),
@@ -559,7 +560,7 @@ function getMarkdownLintConfig(errorsOnly, runRules) {
559560
// search-replace is handled differently than other rules because
560561
// it has nested metadata and rules.
561562
if (
562-
errorsOnly &&
563+
filterErrorsOnly &&
563564
getRuleSeverity(ruleConfig, isPrecommit) !== 'error' &&
564565
ruleName !== 'search-replace'
565566
) {
@@ -585,7 +586,7 @@ function getMarkdownLintConfig(errorsOnly, runRules) {
585586

586587
for (const searchRule of ruleConfig.rules) {
587588
const searchRuleSeverity = getRuleSeverity(searchRule, isPrecommit)
588-
if (errorsOnly && searchRuleSeverity !== 'error') continue
589+
if (filterErrorsOnly && searchRuleSeverity !== 'error') continue
589590
// Add search-replace rules to frontmatter configuration for rules that make sense in frontmatter
590591
// This ensures rules like TODOCS detection work in frontmatter
591592
// Rules with applyToFrontmatter should ONLY run in the frontmatter pass (which lints the entire file)
@@ -640,14 +641,16 @@ function getMarkdownLintConfig(errorsOnly, runRules) {
640641
// Return the severity value of a rule but keep in mind it could be
641642
// running as a precommit hook, which means the severity could be
642643
// deliberately different.
643-
function getRuleSeverity(rule, isPrecommit) {
644-
return isPrecommit ? rule.precommitSeverity || rule.severity : rule.severity
644+
function getRuleSeverity(ruleConfig, isInPrecommitMode) {
645+
return isInPrecommitMode
646+
? ruleConfig.precommitSeverity || ruleConfig.severity
647+
: ruleConfig.severity
645648
}
646649

647650
// Gets a custom rule function from the name of the rule
648651
// in the configuration file
649652
function getCustomRule(ruleName) {
650-
const rule = customRules.find((rule) => rule.names.includes(ruleName))
653+
const rule = customRules.find((r) => r.names.includes(ruleName))
651654
if (!rule)
652655
throw new Error(
653656
`A content-lint rule ('${ruleName}') is configured in the markdownlint config file but does not have a corresponding rule function.`,
@@ -696,24 +699,24 @@ export function shouldIncludeRule(ruleName, runRules) {
696699
fixInfo: null
697700
}
698701
*/
699-
function getSearchReplaceRuleSeverity(ruleName, object, isPrecommit) {
702+
function getSearchReplaceRuleSeverity(ruleName, object, isInPrecommitMode) {
700703
const pluginRuleName = object.errorDetail.split(':')[0].trim()
701-
const rule = allConfig[ruleName].rules.find((rule) => rule.name === pluginRuleName)
702-
return isPrecommit ? rule.precommitSeverity || rule.severity : rule.severity
704+
const rule = allConfig[ruleName].rules.find((r) => r.name === pluginRuleName)
705+
return isInPrecommitMode ? rule.precommitSeverity || rule.severity : rule.severity
703706
}
704707

705708
function isOptionsValid() {
706709
// paths should only contain existing files and directories
707-
const paths = program.opts().paths || []
708-
for (const path of paths) {
710+
const optionPaths = program.opts().paths || []
711+
for (const filePath of optionPaths) {
709712
try {
710-
fs.statSync(path)
713+
fs.statSync(filePath)
711714
} catch {
712-
if ('paths'.includes(path)) {
715+
if ('paths'.includes(filePath)) {
713716
console.log('error: did you mean --paths')
714717
} else {
715718
console.log(
716-
`error: invalid --paths (-p) option. The value '${path}' is not a valid file or directory`,
719+
`error: invalid --paths (-p) option. The value '${filePath}' is not a valid file or directory`,
717720
)
718721
}
719722
return false
@@ -722,14 +725,14 @@ function isOptionsValid() {
722725

723726
// rules should only contain existing, correctly spelled rules
724727
const allRulesList = [...allRules.map((rule) => rule.names).flat(), ...Object.keys(allConfig)]
725-
const rules = program.opts().rules || []
726-
for (const rule of rules) {
727-
if (!allRulesList.includes(rule)) {
728-
if ('rules'.includes(rule)) {
728+
const optionRules = program.opts().rules || []
729+
for (const ruleName of optionRules) {
730+
if (!allRulesList.includes(ruleName)) {
731+
if ('rules'.includes(ruleName)) {
729732
console.log('error: did you mean --rules')
730733
} else {
731734
console.log(
732-
`error: invalid --rules (-r) option. The value '${rule}' is not a valid rule name.`,
735+
`error: invalid --rules (-r) option. The value '${ruleName}' is not a valid rule name.`,
733736
)
734737
}
735738
return false

0 commit comments

Comments
 (0)