Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6cc8292

Browse files
committedJun 22, 2022
Allow scans with packs for languages not being scanned
Previously, we were being too strict about checking that a pack's language was being scanned. It was a failure if a pack language was specified for a language not being scanned.
1 parent 2e0c6ca commit 6cc8292

6 files changed

+56
-28
lines changed
 

‎lib/config-utils.js

+15-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/config-utils.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/config-utils.test.js

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lib/config-utils.test.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/config-utils.test.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,19 @@ test(
14991499
}
15001500
);
15011501

1502+
test(
1503+
"two packs with unused language in config",
1504+
parsePacksMacro,
1505+
{
1506+
[Language.cpp]: ["a/b", "c/d@1.2.3"],
1507+
[Language.java]: ["d/e", "f/g@1.2.3"],
1508+
},
1509+
[Language.cpp, Language.csharp],
1510+
{
1511+
[Language.cpp]: ["a/b", "c/d@1.2.3"],
1512+
}
1513+
);
1514+
15021515
test(
15031516
"packs with other valid names",
15041517
parsePacksMacro,
@@ -1544,13 +1557,6 @@ test(
15441557
[Language.java, Language.python],
15451558
/The configuration file "\/a\/b" is invalid: property "packs" must split packages by language/
15461559
);
1547-
test(
1548-
"invalid language",
1549-
parsePacksErrorMacro,
1550-
{ [Language.java]: ["c/d"] },
1551-
[Language.cpp],
1552-
/The configuration file "\/a\/b" is invalid: property "packs" has "java", but it is not one of the languages to analyze/
1553-
);
15541560
test(
15551561
"not an array",
15561562
parsePacksErrorMacro,

‎src/config-utils.ts

+20-10
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,11 @@ export function getPathsInvalid(configFile: string): string {
629629
);
630630
}
631631

632-
export function getPacksRequireLanguage(
633-
lang: string,
634-
configFile: string
635-
): string {
632+
function getPacksRequireLanguage(lang: string, configFile: string): string {
636633
return getConfigFilePropertyError(
637634
configFile,
638635
PACKS_PROPERTY,
639-
`has "${lang}", but it is not one of the languages to analyze`
636+
`has "${lang}", but it is not a valid language.`
640637
);
641638
}
642639

@@ -1026,7 +1023,8 @@ async function loadConfig(
10261023
parsedYAML[PACKS_PROPERTY] ?? {},
10271024
packsInput,
10281025
languages,
1029-
configFile
1026+
configFile,
1027+
logger
10301028
);
10311029

10321030
// If queries were provided using `with` in the action configuration,
@@ -1146,7 +1144,8 @@ const PACK_IDENTIFIER_PATTERN = (function () {
11461144
export function parsePacksFromConfig(
11471145
packsByLanguage: string[] | Record<string, string[]>,
11481146
languages: Language[],
1149-
configFile: string
1147+
configFile: string,
1148+
logger: Logger
11501149
): Packs {
11511150
const packs = {};
11521151

@@ -1168,7 +1167,16 @@ export function parsePacksFromConfig(
11681167
throw new Error(getPacksInvalid(configFile));
11691168
}
11701169
if (!languages.includes(lang as Language)) {
1171-
throw new Error(getPacksRequireLanguage(lang, configFile));
1170+
// This particular language is not being analyzed in this run.
1171+
if (Language[lang as Language]) {
1172+
logger.info(
1173+
`Ignoring packs for ${lang} since this language is not being analyzed in this run.`
1174+
);
1175+
continue;
1176+
} else {
1177+
// This language is invalid, probably a misspelling
1178+
throw new Error(getPacksRequireLanguage(configFile, lang));
1179+
}
11721180
}
11731181
packs[lang] = [];
11741182
for (const packStr of packsArr) {
@@ -1296,13 +1304,15 @@ export function parsePacks(
12961304
rawPacksFromConfig: string[] | Record<string, string[]>,
12971305
rawPacksInput: string | undefined,
12981306
languages: Language[],
1299-
configFile: string
1307+
configFile: string,
1308+
logger: Logger
13001309
) {
13011310
const packsFromInput = parsePacksFromInput(rawPacksInput, languages);
13021311
const packsFomConfig = parsePacksFromConfig(
13031312
rawPacksFromConfig,
13041313
languages,
1305-
configFile
1314+
configFile,
1315+
logger
13061316
);
13071317

13081318
if (!packsFromInput) {

0 commit comments

Comments
 (0)
Please sign in to comment.