Merge pull request #518 from github/aibaars-no-queries
Ensure queries[language] objects are initialized
This commit is contained in:
commit
1ad5a6c1be
9 changed files with 74 additions and 34 deletions
3
lib/analyze.js
generated
3
lib/analyze.js
generated
|
|
@ -87,7 +87,8 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
|
||||||
for (const language of config.languages) {
|
for (const language of config.languages) {
|
||||||
logger.startGroup(`Analyzing ${language}`);
|
logger.startGroup(`Analyzing ${language}`);
|
||||||
const queries = config.queries[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`);
|
throw new Error(`Unable to analyse ${language} as no queries were selected for this language`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
32
lib/config-utils.js
generated
32
lib/config-utils.js
generated
|
|
@ -394,6 +394,12 @@ function shouldAddConfigFileQueries(queriesInput) {
|
||||||
async function getDefaultConfig(languagesInput, queriesInput, dbLocation, repository, tempDir, toolCacheDir, codeQL, checkoutPath, gitHubVersion, apiDetails, logger) {
|
async function getDefaultConfig(languagesInput, queriesInput, dbLocation, repository, tempDir, toolCacheDir, codeQL, checkoutPath, gitHubVersion, apiDetails, logger) {
|
||||||
const languages = await getLanguages(languagesInput, repository, apiDetails, logger);
|
const languages = await getLanguages(languagesInput, repository, apiDetails, logger);
|
||||||
const queries = {};
|
const queries = {};
|
||||||
|
for (const language of languages) {
|
||||||
|
queries[language] = {
|
||||||
|
builtin: [],
|
||||||
|
custom: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
await addDefaultQueries(codeQL, languages, queries);
|
await addDefaultQueries(codeQL, languages, queries);
|
||||||
if (queriesInput) {
|
if (queriesInput) {
|
||||||
await addQueriesFromWorkflow(codeQL, queriesInput, languages, queries, tempDir, checkoutPath, apiDetails, logger);
|
await addQueriesFromWorkflow(codeQL, queriesInput, languages, queries, tempDir, checkoutPath, apiDetails, logger);
|
||||||
|
|
@ -437,6 +443,12 @@ async function loadConfig(languagesInput, queriesInput, configFile, dbLocation,
|
||||||
}
|
}
|
||||||
const languages = await getLanguages(languagesInput, repository, apiDetails, logger);
|
const languages = await getLanguages(languagesInput, repository, apiDetails, logger);
|
||||||
const queries = {};
|
const queries = {};
|
||||||
|
for (const language of languages) {
|
||||||
|
queries[language] = {
|
||||||
|
builtin: [],
|
||||||
|
custom: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
const pathsIgnore = [];
|
const pathsIgnore = [];
|
||||||
const paths = [];
|
const paths = [];
|
||||||
let disableDefaultQueries = false;
|
let disableDefaultQueries = false;
|
||||||
|
|
@ -491,16 +503,6 @@ async function loadConfig(languagesInput, queriesInput, configFile, dbLocation,
|
||||||
paths.push(validateAndSanitisePath(includePath, PATHS_PROPERTY, configFile, logger));
|
paths.push(validateAndSanitisePath(includePath, PATHS_PROPERTY, configFile, logger));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 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 {
|
return {
|
||||||
languages,
|
languages,
|
||||||
queries,
|
queries,
|
||||||
|
|
@ -533,6 +535,16 @@ async function initConfig(languagesInput, queriesInput, configFile, dbLocation,
|
||||||
else {
|
else {
|
||||||
config = await loadConfig(languagesInput, queriesInput, configFile, dbLocation, repository, tempDir, toolCacheDir, codeQL, checkoutPath, gitHubVersion, apiDetails, logger);
|
config = await loadConfig(languagesInput, queriesInput, configFile, dbLocation, repository, tempDir, toolCacheDir, codeQL, checkoutPath, gitHubVersion, apiDetails, logger);
|
||||||
}
|
}
|
||||||
|
// 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
|
// Save the config so we can easily access it again in the future
|
||||||
await saveConfig(config, logger);
|
await saveConfig(config, logger);
|
||||||
return config;
|
return config;
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
10
lib/config-utils.test.js
generated
10
lib/config-utils.test.js
generated
|
|
@ -66,7 +66,10 @@ ava_1.default("load empty config", async (t) => {
|
||||||
const codeQL = codeql_1.setCodeQL({
|
const codeQL = codeql_1.setCodeQL({
|
||||||
async resolveQueries() {
|
async resolveQueries() {
|
||||||
return {
|
return {
|
||||||
byLanguage: {},
|
byLanguage: {
|
||||||
|
javascript: { queries: ["query1.ql"] },
|
||||||
|
python: { queries: ["query2.ql"] },
|
||||||
|
},
|
||||||
noDeclaredLanguage: {},
|
noDeclaredLanguage: {},
|
||||||
multipleDeclaredLanguages: {},
|
multipleDeclaredLanguages: {},
|
||||||
};
|
};
|
||||||
|
|
@ -82,7 +85,10 @@ ava_1.default("loading config saves config", async (t) => {
|
||||||
const codeQL = codeql_1.setCodeQL({
|
const codeQL = codeql_1.setCodeQL({
|
||||||
async resolveQueries() {
|
async resolveQueries() {
|
||||||
return {
|
return {
|
||||||
byLanguage: {},
|
byLanguage: {
|
||||||
|
javascript: { queries: ["query1.ql"] },
|
||||||
|
python: { queries: ["query2.ql"] },
|
||||||
|
},
|
||||||
noDeclaredLanguage: {},
|
noDeclaredLanguage: {},
|
||||||
multipleDeclaredLanguages: {},
|
multipleDeclaredLanguages: {},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -162,7 +162,10 @@ export async function runQueries(
|
||||||
logger.startGroup(`Analyzing ${language}`);
|
logger.startGroup(`Analyzing ${language}`);
|
||||||
|
|
||||||
const queries = config.queries[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(
|
throw new Error(
|
||||||
`Unable to analyse ${language} as no queries were selected for this language`
|
`Unable to analyse ${language} as no queries were selected for this language`
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,10 @@ test("load empty config", async (t) => {
|
||||||
const codeQL = setCodeQL({
|
const codeQL = setCodeQL({
|
||||||
async resolveQueries() {
|
async resolveQueries() {
|
||||||
return {
|
return {
|
||||||
byLanguage: {},
|
byLanguage: {
|
||||||
|
javascript: { queries: ["query1.ql"] },
|
||||||
|
python: { queries: ["query2.ql"] },
|
||||||
|
},
|
||||||
noDeclaredLanguage: {},
|
noDeclaredLanguage: {},
|
||||||
multipleDeclaredLanguages: {},
|
multipleDeclaredLanguages: {},
|
||||||
};
|
};
|
||||||
|
|
@ -116,7 +119,10 @@ test("loading config saves config", async (t) => {
|
||||||
const codeQL = setCodeQL({
|
const codeQL = setCodeQL({
|
||||||
async resolveQueries() {
|
async resolveQueries() {
|
||||||
return {
|
return {
|
||||||
byLanguage: {},
|
byLanguage: {
|
||||||
|
javascript: { queries: ["query1.ql"] },
|
||||||
|
python: { queries: ["query2.ql"] },
|
||||||
|
},
|
||||||
noDeclaredLanguage: {},
|
noDeclaredLanguage: {},
|
||||||
multipleDeclaredLanguages: {},
|
multipleDeclaredLanguages: {},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -760,6 +760,12 @@ export async function getDefaultConfig(
|
||||||
logger
|
logger
|
||||||
);
|
);
|
||||||
const queries: Queries = {};
|
const queries: Queries = {};
|
||||||
|
for (const language of languages) {
|
||||||
|
queries[language] = {
|
||||||
|
builtin: [],
|
||||||
|
custom: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
await addDefaultQueries(codeQL, languages, queries);
|
await addDefaultQueries(codeQL, languages, queries);
|
||||||
if (queriesInput) {
|
if (queriesInput) {
|
||||||
await addQueriesFromWorkflow(
|
await addQueriesFromWorkflow(
|
||||||
|
|
@ -834,6 +840,12 @@ async function loadConfig(
|
||||||
);
|
);
|
||||||
|
|
||||||
const queries: Queries = {};
|
const queries: Queries = {};
|
||||||
|
for (const language of languages) {
|
||||||
|
queries[language] = {
|
||||||
|
builtin: [],
|
||||||
|
custom: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
const pathsIgnore: string[] = [];
|
const pathsIgnore: string[] = [];
|
||||||
const paths: 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 {
|
return {
|
||||||
languages,
|
languages,
|
||||||
queries,
|
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
|
// Save the config so we can easily access it again in the future
|
||||||
await saveConfig(config, logger);
|
await saveConfig(config, logger);
|
||||||
return config;
|
return config;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue