Omit Autofix column if no row has it (#49872)
This commit is contained in:
@@ -55,8 +55,8 @@ import chalk from 'chalk'
|
||||
import { program } from 'commander'
|
||||
// We don't want to introduce a global dependency on @github/cocofix, so we install it by hand
|
||||
// as described above and suppress the import warning.
|
||||
import { getSupportedQueries } from '@github/cocofix/dist/querySuites' // eslint-disable-line import/no-unresolved
|
||||
import { type Language } from '@github/cocofix/dist/codeql' // eslint-disable-line import/no-unresolved
|
||||
import { getSupportedQueries } from '@github/cocofix/dist/querySuites' // eslint-disable-line import/no-extraneous-dependencies
|
||||
import { type Language } from '@github/cocofix/dist/codeql' // eslint-disable-line import/no-extraneous-dependencies
|
||||
|
||||
program
|
||||
.description('Generate a reusable Markdown for for a code scanning query language')
|
||||
@@ -164,14 +164,24 @@ async function main(options: Options, language: string) {
|
||||
|
||||
const entries = Object.values(queries)
|
||||
entries.sort((a, b) => a.name.localeCompare(b.name))
|
||||
printQueries(options, entries)
|
||||
|
||||
// At the moment, our chosen business logic is that we omit the Autofix
|
||||
// column if there are no queries that support it.
|
||||
// In a future rendition we might revisit this to make it configurable
|
||||
// instead.
|
||||
const includeAutofix = entries.some((query) => query.autofixSupport !== 'none')
|
||||
console.warn(`${includeAutofix ? 'Including' : 'Excluding'} 'Autofix' column for ${language}`)
|
||||
printQueries(options, entries, includeAutofix)
|
||||
}
|
||||
|
||||
function printQueries(options: Options, queries: Query[]) {
|
||||
function printQueries(options: Options, queries: Query[], includeAutofix: boolean) {
|
||||
const markdown = []
|
||||
markdown.push('{% rowheaders %}')
|
||||
markdown.push('') // blank line
|
||||
const header = ['Query name', 'Related CWEs', 'Default', 'Extended', 'Autofix']
|
||||
const header = ['Query name', 'Related CWEs', 'Default', 'Extended']
|
||||
if (includeAutofix) {
|
||||
header.push('Autofix')
|
||||
}
|
||||
markdown.push(`| ${header.join(' | ')} |`)
|
||||
markdown.push(`| ${header.map(() => '---').join(' | ')} |`)
|
||||
|
||||
@@ -192,9 +202,11 @@ function printQueries(options: Options, queries: Query[]) {
|
||||
if (query.autofixSupport === 'default') {
|
||||
autofixIcon = includedOcticon
|
||||
}
|
||||
markdown.push(
|
||||
`| ${markdownLink} | ${query.cwes.join(', ')} | ${defaultIcon} | ${extendedIcon} | ${autofixIcon} |`,
|
||||
)
|
||||
const row = [markdownLink, query.cwes.join(', '), defaultIcon, extendedIcon]
|
||||
if (includeAutofix) {
|
||||
row.push(autofixIcon)
|
||||
}
|
||||
markdown.push(`| ${row.join(' | ')} |`)
|
||||
}
|
||||
markdown.push('') // blank line
|
||||
markdown.push('{% endrowheaders %}')
|
||||
|
||||
Reference in New Issue
Block a user