Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Resolving alerts from secret scanning
intro: 'After reviewing the details of a secret scanning alert, you should fix and then close the alert.'
permissions: 'Repository owners, organization owners, security managers, commit authors, and users with the **admin** role'
permissions: 'Repository owners, organization owners, security managers, users assigned to {% data variables.secret-scanning.alerts %}, commit authors, and users with the **admin** role'
versions:
fpt: '*'
ghes: '*'
Expand Down
32 changes: 22 additions & 10 deletions src/content-linter/scripts/lint-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ program

const {
fix,
paths,
errorsOnly,
rules,
summaryByRule,
Expand All @@ -144,8 +143,13 @@ main()
async function main() {
if (!isOptionsValid()) return

// Get the updated paths after validation (invalid paths will have been filtered out)
const validatedPaths = program.opts().paths

// If paths has not been specified, lint all files
const files = getFilesToLint((summaryByRule && ALL_CONTENT_DIR) || paths || getChangedFiles())
const files = getFilesToLint(
(summaryByRule && ALL_CONTENT_DIR) || validatedPaths || getChangedFiles(),
)

if (new Set(files.data).size !== files.data.length) throw new Error('Duplicate data files')
if (new Set(files.content).size !== files.content.length)
Expand All @@ -162,7 +166,7 @@ async function main() {
const start = Date.now()

// Initializes the config to pass to markdownlint based on the input options
const { config, configuredRules } = getMarkdownLintConfig(errorsOnly, rules || [])
const { config, configuredRules } = getMarkdownLintConfig(errorsOnly, rules)

// Run Markdownlint for content directory
const resultContent = (await markdownlint.promises.markdownlint({
Expand Down Expand Up @@ -619,7 +623,7 @@ function listRules() {
*/
function getMarkdownLintConfig(
filterErrorsOnly: boolean,
runRules: string[],
runRules: string[] | undefined,
): MarkdownLintConfigResult {
const config = {
content: structuredClone(defaultConfig),
Expand Down Expand Up @@ -793,21 +797,27 @@ function getSearchReplaceRuleSeverity(
function isOptionsValid() {
// paths should only contain existing files and directories
const optionPaths = program.opts().paths || []
const validPaths = []

for (const filePath of optionPaths) {
try {
fs.statSync(filePath)
validPaths.push(filePath) // Keep track of valid paths
} catch {
if ('paths'.includes(filePath)) {
console.log('error: did you mean --paths')
console.warn('warning: did you mean --paths')
} else {
console.log(
`error: invalid --paths (-p) option. The value '${filePath}' is not a valid file or directory`,
)
console.warn(`warning: the value '${filePath}' was not found. Skipping this path.`)
}
return false
// Continue processing - don't return false here
}
}

// Update the program options to only include valid paths
if (optionPaths.length > 0) {
program.setOptionValue('paths', validPaths)
}

// rules should only contain existing, correctly spelled rules
const allRulesList = [...allRules.map((rule) => rule.names).flat(), ...Object.keys(allConfig)]
const optionRules = program.opts().rules || []
Expand All @@ -823,7 +833,9 @@ function isOptionsValid() {
return false
}
}
return true

// Only return false if paths were specified but none are valid
return optionPaths.length === 0 || validPaths.length > 0
}

function isAFixtureMdFile(filePath: string): boolean {
Expand Down
Loading