mirror of
https://github.com/github/codeql-action.git
synced 2026-01-04 13:40:23 +08:00
Handle empty lists as well as undefined ones
This commit is contained in:
32
src/init.test.ts
Normal file
32
src/init.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import test from "ava";
|
||||
|
||||
import { Config } from "./config-utils";
|
||||
import { printPathFiltersWarning } from "./init";
|
||||
import { Language } from "./languages";
|
||||
import { LoggedMessage, getRecordingLogger, setupTests } from "./testing-utils";
|
||||
|
||||
setupTests(test);
|
||||
|
||||
test("printPathFiltersWarning does not trigger when 'paths' and 'paths-ignore' are undefined", async (t) => {
|
||||
const messages: LoggedMessage[] = [];
|
||||
printPathFiltersWarning(
|
||||
{
|
||||
languages: [Language.cpp],
|
||||
originalUserInput: {},
|
||||
} as Partial<Config> as Config,
|
||||
getRecordingLogger(messages),
|
||||
);
|
||||
t.is(messages.length, 0);
|
||||
});
|
||||
|
||||
test("printPathFiltersWarning does not trigger when 'paths' and 'paths-ignore' are empty", async (t) => {
|
||||
const messages: LoggedMessage[] = [];
|
||||
printPathFiltersWarning(
|
||||
{
|
||||
languages: [Language.cpp],
|
||||
originalUserInput: { paths: [], "paths-ignore": [] },
|
||||
} as Partial<Config> as Config,
|
||||
getRecordingLogger(messages),
|
||||
);
|
||||
t.is(messages.length, 0);
|
||||
});
|
||||
@@ -127,12 +127,15 @@ export async function runInit(
|
||||
return await getCombinedTracerConfig(config);
|
||||
}
|
||||
|
||||
function printPathFiltersWarning(config: configUtils.Config, logger: Logger) {
|
||||
export function printPathFiltersWarning(
|
||||
config: configUtils.Config,
|
||||
logger: Logger,
|
||||
) {
|
||||
// Index include/exclude/filters only work in javascript/python/ruby.
|
||||
// If any other languages are detected/configured then show a warning.
|
||||
if (
|
||||
(config.originalUserInput.paths ||
|
||||
config.originalUserInput["paths-ignore"]) &&
|
||||
(config.originalUserInput.paths?.length ||
|
||||
config.originalUserInput["paths-ignore"]?.length) &&
|
||||
!config.languages.every(isScannedLanguage)
|
||||
) {
|
||||
logger.warning(
|
||||
|
||||
Reference in New Issue
Block a user