Check that the set of queries is non-empty at init time

This commit is contained in:
Robert Brignull 2020-08-04 10:39:47 +01:00
parent 4896ba51da
commit dc366899d2
6 changed files with 35 additions and 6 deletions

8
lib/config-utils.js generated
View file

@ -439,6 +439,14 @@ async function loadConfig(configFile) {
paths.push(validateAndSanitisePath(path, PATHS_PROPERTY, configFile)); paths.push(validateAndSanitisePath(path, PATHS_PROPERTY, configFile));
}); });
} }
// 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].length === 0) {
throw new Error(`Did not detect any queries to analyze for ${language}. ` +
"Please make sure that the default queries are enabled, or you are specifying queries to run.");
}
}
return { return {
languages, languages,
queries, queries,

File diff suppressed because one or more lines are too long

View file

@ -200,7 +200,9 @@ ava_1.default("default queries are used", async (t) => {
resolveQueriesArgs.push({ queries, extraSearchPath }); resolveQueriesArgs.push({ queries, extraSearchPath });
return { return {
byLanguage: { byLanguage: {
'javascript': {}, 'javascript': {
'foo.ql': {},
},
}, },
noDeclaredLanguage: {}, noDeclaredLanguage: {},
multipleDeclaredLanguages: {}, multipleDeclaredLanguages: {},
@ -231,7 +233,11 @@ ava_1.default("API client used when reading remote config", async (t) => {
CodeQL.setCodeQL({ CodeQL.setCodeQL({
resolveQueries: async function () { resolveQueries: async function () {
return { return {
byLanguage: {}, byLanguage: {
'javascript': {
'foo.ql': {},
},
},
noDeclaredLanguage: {}, noDeclaredLanguage: {},
multipleDeclaredLanguages: {}, multipleDeclaredLanguages: {},
}; };

File diff suppressed because one or more lines are too long

View file

@ -224,7 +224,9 @@ test("default queries are used", async t => {
resolveQueriesArgs.push({queries, extraSearchPath}); resolveQueriesArgs.push({queries, extraSearchPath});
return { return {
byLanguage: { byLanguage: {
'javascript': {}, 'javascript': {
'foo.ql': {},
},
}, },
noDeclaredLanguage: {}, noDeclaredLanguage: {},
multipleDeclaredLanguages: {}, multipleDeclaredLanguages: {},
@ -262,7 +264,11 @@ test("API client used when reading remote config", async t => {
CodeQL.setCodeQL({ CodeQL.setCodeQL({
resolveQueries: async function() { resolveQueries: async function() {
return { return {
byLanguage: {}, byLanguage: {
'javascript': {
'foo.ql': {},
},
},
noDeclaredLanguage: {}, noDeclaredLanguage: {},
multipleDeclaredLanguages: {}, multipleDeclaredLanguages: {},
}; };

View file

@ -577,6 +577,15 @@ async function loadConfig(configFile: string): Promise<Config> {
}); });
} }
// 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].length === 0) {
throw new Error(`Did not detect any queries to analyze for ${language}. ` +
"Please make sure that the default queries are enabled, or you are specifying queries to run.");
}
}
return { return {
languages, languages,
queries, queries,