Skip to content

Commit 4e14024

Browse files
committed
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 4e14024

File tree

6 files changed

+89
-37
lines changed

6 files changed

+89
-37
lines changed

lib/config-utils.js

Lines changed: 15 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js

Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/config-utils.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.test.ts

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { getCachedCodeQL, setCodeQL } from "./codeql";
1010
import * as configUtils from "./config-utils";
1111
import { createFeatureFlags, FeatureFlag } from "./feature-flags";
1212
import { Language } from "./languages";
13-
import { getRunnerLogger } from "./logging";
13+
import { getRunnerLogger, Logger } from "./logging";
1414
import { setupTests } from "./testing-utils";
1515
import * as util from "./util";
1616

@@ -1424,7 +1424,12 @@ const parsePacksMacro = test.macro({
14241424
expected: Partial<Record<Language, string[]>>
14251425
) =>
14261426
t.deepEqual(
1427-
configUtils.parsePacksFromConfig(packsByLanguage, languages, "/a/b"),
1427+
configUtils.parsePacksFromConfig(
1428+
packsByLanguage,
1429+
languages,
1430+
"/a/b",
1431+
mockLogger
1432+
),
14281433
expected
14291434
),
14301435

@@ -1446,7 +1451,8 @@ const parsePacksErrorMacro = test.macro({
14461451
configUtils.parsePacksFromConfig(
14471452
packsByLanguage as string[] | Record<string, string[]>,
14481453
languages,
1449-
"/a/b"
1454+
"/a/b",
1455+
{} as Logger
14501456
),
14511457
{
14521458
message: expected,
@@ -1499,6 +1505,19 @@ test(
14991505
}
15001506
);
15011507

1508+
test(
1509+
"two packs with unused language in config",
1510+
parsePacksMacro,
1511+
{
1512+
[Language.cpp]: ["a/b", "c/d@1.2.3"],
1513+
[Language.java]: ["d/e", "f/g@1.2.3"],
1514+
},
1515+
[Language.cpp, Language.csharp],
1516+
{
1517+
[Language.cpp]: ["a/b", "c/d@1.2.3"],
1518+
}
1519+
);
1520+
15021521
test(
15031522
"packs with other valid names",
15041523
parsePacksMacro,
@@ -1544,13 +1563,6 @@ test(
15441563
[Language.java, Language.python],
15451564
/The configuration file "\/a\/b" is invalid: property "packs" must split packages by language/
15461565
);
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-
);
15541566
test(
15551567
"not an array",
15561568
parsePacksErrorMacro,
@@ -1583,13 +1595,25 @@ function parseInputAndConfigMacro(
15831595
expected
15841596
) {
15851597
t.deepEqual(
1586-
configUtils.parsePacks(packsFromConfig, packsFromInput, languages, "/a/b"),
1598+
configUtils.parsePacks(
1599+
packsFromConfig,
1600+
packsFromInput,
1601+
languages,
1602+
"/a/b",
1603+
mockLogger
1604+
),
15871605
expected
15881606
);
15891607
}
15901608
parseInputAndConfigMacro.title = (providedTitle: string) =>
15911609
`Parse Packs input and config: ${providedTitle}`;
15921610

1611+
const mockLogger = {
1612+
info: (message: string) => {
1613+
console.log(message);
1614+
},
1615+
} as Logger;
1616+
15931617
function parseInputAndConfigErrorMacro(
15941618
t: ExecutionContext<unknown>,
15951619
packsFromConfig: string[] | Record<string, string[]>,
@@ -1603,7 +1627,8 @@ function parseInputAndConfigErrorMacro(
16031627
packsFromConfig,
16041628
packsFromInput,
16051629
languages,
1606-
"/a/b"
1630+
"/a/b",
1631+
mockLogger
16071632
);
16081633
},
16091634
{

src/config-utils.ts

Lines changed: 20 additions & 10 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy