Fix logic for calculating if there are queries to run

During the analyze phase.
This commit is contained in:
Andrew Eisenberg 2021-06-04 13:12:49 -07:00
parent 6cee818bf3
commit 9b5753ab00
6 changed files with 21 additions and 18 deletions

9
lib/analyze.js generated
View file

@ -77,6 +77,7 @@ async function finalizeDatabaseCreation(config, threadsFlag, logger) {
}
// Runs queries and creates sarif files in the given folder
async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag, automationDetailsId, config, logger) {
var _a, _b;
const statusReport = {};
// count the number of lines in the background
const locPromise = count_loc_1.countLoc(path.resolve(),
@ -88,8 +89,10 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
logger.startGroup(`Analyzing ${language}`);
const queries = config.queries[language];
const packsWithVersion = config.packs[language] || [];
if (queries === undefined ||
(queries.builtin.length === 0 && queries.custom.length === 0)) {
const hasBuiltinQueries = ((_a = queries) === null || _a === void 0 ? void 0 : _a.builtin.length) > 0;
const hasCustomQueries = ((_b = queries) === null || _b === void 0 ? void 0 : _b.custom.length) > 0;
const hasPackWithCustomQueries = packsWithVersion.length > 0;
if (!hasBuiltinQueries && !hasCustomQueries && !hasPackWithCustomQueries) {
throw new Error(`Unable to analyse ${language} as no queries were selected for this language`);
}
try {
@ -176,7 +179,7 @@ function createPackSuiteContents(packsWithVersion) {
function packWithVersionToQuerySuiteEntry(pack) {
let text = `- qlpack: ${pack.packName}`;
if (pack.version) {
text += `${"\n"} version: ${pack.version}`;
text += `${"\n"} version: ${pack.version.format()}`;
}
return text;
}

File diff suppressed because one or more lines are too long

8
lib/config-utils.js generated
View file

@ -625,10 +625,10 @@ async function initConfig(languagesInput, queriesInput, configFile, dbLocation,
// 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) {
const hasPacks = ((_a = config.packs[language]) === null || _a === void 0 ? void 0 : _a.length) > 0;
const hasQueries = ((_b = config.queries[language]) === null || _b === void 0 ? void 0 : _b.builtin.length) > 0 ||
((_c = config.queries[language]) === null || _c === void 0 ? void 0 : _c.custom.length) > 0;
if (!hasPacks && !hasQueries) {
const hasBuiltinQueries = ((_a = config.queries[language]) === null || _a === void 0 ? void 0 : _a.builtin.length) > 0;
const hasCustomQueries = ((_b = config.queries[language]) === null || _b === void 0 ? void 0 : _b.custom.length) > 0;
const hasPacks = ((_c = config.packs[language]) === null || _c === void 0 ? void 0 : _c.length) > 0;
if (!hasPacks && !hasBuiltinQueries && !hasCustomQueries) {
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.");
}

File diff suppressed because one or more lines are too long

View file

@ -167,10 +167,11 @@ export async function runQueries(
const queries = config.queries[language];
const packsWithVersion = config.packs[language] || [];
if (
queries === undefined ||
(queries.builtin.length === 0 && queries.custom.length === 0)
) {
const hasBuiltinQueries = queries?.builtin.length > 0;
const hasCustomQueries = queries?.custom.length > 0;
const hasPackWithCustomQueries = packsWithVersion.length > 0;
if (!hasBuiltinQueries && !hasCustomQueries && !hasPackWithCustomQueries) {
throw new Error(
`Unable to analyse ${language} as no queries were selected for this language`
);
@ -317,7 +318,7 @@ function packWithVersionToQuerySuiteEntry(
): string {
let text = `- qlpack: ${pack.packName}`;
if (pack.version) {
text += `${"\n"} version: ${pack.version}`;
text += `${"\n"} version: ${pack.version.format()}`;
}
return text;
}

View file

@ -1156,11 +1156,10 @@ 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) {
const hasBuiltinQueries = config.queries[language]?.builtin.length > 0;
const hasCustomQueries = config.queries[language]?.custom.length > 0;
const hasPacks = config.packs[language]?.length > 0;
const hasQueries =
config.queries[language]?.builtin.length > 0 ||
config.queries[language]?.custom.length > 0;
if (!hasPacks && !hasQueries) {
if (!hasPacks && !hasBuiltinQueries && !hasCustomQueries) {
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."