2929 *
3030 * /Users/peterbe/.local/share/gh/extensions/gh-codeql/dist/nightly/codeql-bundle-20231204/codeql
3131 *
32+ * Finally, you need to install `@github/cocofix`. This is a private package,
33+ * so you first need to get the `DOCS_BOT_PAT_WORKFLOW` PAT from the vault and
34+ * store it in the environment variable `DOCS_BOT_PAT_WORKFLOW`.
35+ * Then run the following command from the root of this repo:
36+ *
37+ * ```sh
38+ * npm i --no-save '--@github:registry=https://npm.pkg.github.com' '--//npm.pkg.github.com/:_authToken=${DOCS_BOT_PAT_WORKFLOW}' @github/cocofix
39+ * ```
40+ *
3241 * If you've git cloned github/codeql in /tmp/ now you can execute this script.
3342 * For example, to generate the Markdown
3443 * for Python:
@@ -44,6 +53,10 @@ import { execFileSync } from 'child_process'
4453
4554import chalk from 'chalk'
4655import { program } from 'commander'
56+ // We don't want to introduce a global dependency on @github/cocofix, so we install it by hand
57+ // as described above and suppress the import warning.
58+ import { getSupportedQueries } from '@github/cocofix/dist/querySuites' // eslint-disable-line import/no-unresolved
59+ import { type Language } from '@github/cocofix/dist/codeql' // eslint-disable-line import/no-unresolved
4760
4861program
4962 . description ( 'Generate a reusable Markdown for for a code scanning query language' )
@@ -74,6 +87,7 @@ type Query = {
7487 url : string
7588 packs : string [ ]
7689 cwes : string [ ]
90+ autofixSupport : 'none' | 'default'
7791}
7892
7993const opts = program . opts ( )
@@ -105,6 +119,12 @@ async function main(options: Options, language: string) {
105119 [ id : string ] : Query
106120 } = { }
107121
122+ const autofixSupportedQueryIds = await getSupportedQueries (
123+ 'default' ,
124+ language as Language ,
125+ 'CodeQL' ,
126+ )
127+
108128 for ( const pack of options . packs ) {
109129 const languagePack = `${language } - $ { pack} . qls `
110130 if (options.verbose) console.log(chalk.dim(` Searching for queries in $ { languagePack} `))
@@ -123,12 +143,13 @@ async function main(options: Options, language: string) {
123143 if (id && name) {
124144 const cwes = getCWEs(tags || '')
125145 const url = getDocsLink(language, id)
146+ const autofixSupport = autofixSupportedQueryIds.includes(id) ? 'default' : 'none'
126147
127148 // Only include queries that have CWEs, since the other queries deal with code scanning
128149 // metadata and metrics (e.g. counting lines of code or number of files) and have no docs link
129150 if (cwes.length) {
130151 if (!(id in queries)) {
131- queries [ id ] = { url, name, packs : [ ] , cwes }
152+ queries[id] = { url, name, packs: [], cwes, autofixSupport }
132153 }
133154 queries[id].packs.push(pack)
134155 } else {
@@ -150,7 +171,7 @@ function printQueries(options: Options, queries: Query[]) {
150171 const markdown = []
151172 markdown.push('{% rowheaders %}')
152173 markdown.push('') // blank line
153- const header = [ 'Query name' , 'Related CWEs' , 'Default' , 'Extended' ]
174+ const header = ['Query name', 'Related CWEs', 'Default', 'Extended', 'Autofix' ]
154175 markdown.push(` | $ { header . join ( ' | ' ) } | `)
155176 markdown.push(` | $ { header . map ( ( ) => '---' ) . join ( ' | ' ) } | `)
156177
@@ -161,14 +182,18 @@ function printQueries(options: Options, queries: Query[]) {
161182 const markdownLink = ` [ $ { query . name } ] ( $ { query . url } ) `
162183 let defaultIcon = notIncludedOcticon
163184 let extendedIcon = notIncludedOcticon
185+ let autofixIcon = notIncludedOcticon
164186 if (query.packs.includes('code-scanning')) {
165187 defaultIcon = includedOcticon
166188 }
167189 if (query.packs.includes('security-extended')) {
168190 extendedIcon = includedOcticon
169191 }
192+ if (query.autofixSupport === 'default') {
193+ autofixIcon = includedOcticon
194+ }
170195 markdown.push(
171- `| ${ markdownLink } | ${ query . cwes . join ( ', ' ) } | ${ defaultIcon } | ${ extendedIcon } |` ,
196+ ` | $ { markdownLink} | $ { query . cwes . join ( ', ' ) } | $ { defaultIcon} | $ { extendedIcon} | $ { autofixIcon } | `,
172197 )
173198 }
174199 markdown.push('') // blank line
0 commit comments