Merge branch 'main' into aibaars-additional-packs

This commit is contained in:
Andrew Eisenberg 2021-05-21 09:21:54 -07:00 committed by GitHub
commit c3e0f887ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 74 additions and 34 deletions

View file

@ -162,7 +162,10 @@ export async function runQueries(
logger.startGroup(`Analyzing ${language}`);
const queries = config.queries[language];
if (queries.builtin.length === 0 && queries.custom.length === 0) {
if (
queries === undefined ||
(queries.builtin.length === 0 && queries.custom.length === 0)
) {
throw new Error(
`Unable to analyse ${language} as no queries were selected for this language`
);

View file

@ -68,7 +68,10 @@ test("load empty config", async (t) => {
const codeQL = setCodeQL({
async resolveQueries() {
return {
byLanguage: {},
byLanguage: {
javascript: { queries: ["query1.ql"] },
python: { queries: ["query2.ql"] },
},
noDeclaredLanguage: {},
multipleDeclaredLanguages: {},
};
@ -116,7 +119,10 @@ test("loading config saves config", async (t) => {
const codeQL = setCodeQL({
async resolveQueries() {
return {
byLanguage: {},
byLanguage: {
javascript: { queries: ["query1.ql"] },
python: { queries: ["query2.ql"] },
},
noDeclaredLanguage: {},
multipleDeclaredLanguages: {},
};

View file

@ -760,6 +760,12 @@ export async function getDefaultConfig(
logger
);
const queries: Queries = {};
for (const language of languages) {
queries[language] = {
builtin: [],
custom: [],
};
}
await addDefaultQueries(codeQL, languages, queries);
if (queriesInput) {
await addQueriesFromWorkflow(
@ -834,6 +840,12 @@ async function loadConfig(
);
const queries: Queries = {};
for (const language of languages) {
queries[language] = {
builtin: [],
custom: [],
};
}
const pathsIgnore: string[] = [];
const paths: string[] = [];
@ -925,21 +937,6 @@ async function loadConfig(
}
}
// The list of queries should not be empty for any language. If it is then
// it is a user configuration error.
for (const language of languages) {
if (
queries[language] === undefined ||
(queries[language].builtin.length === 0 &&
queries[language].custom.length === 0)
) {
throw new Error(
`Did not detect any queries to run for ${language}. ` +
"Please make sure that the default queries are enabled, or you are specifying queries to run."
);
}
}
return {
languages,
queries,
@ -1016,6 +1013,21 @@ export async function initConfig(
);
}
// The list of queries should not be empty for any language. If it is then
// it is a user configuration error.
for (const language of config.languages) {
if (
config.queries[language] === undefined ||
(config.queries[language].builtin.length === 0 &&
config.queries[language].custom.length === 0)
) {
throw new Error(
`Did not detect any queries to run for ${language}. ` +
"Please make sure that the default queries are enabled, or you are specifying queries to run."
);
}
}
// Save the config so we can easily access it again in the future
await saveConfig(config, logger);
return config;