Skip to content

Commit

Permalink
Merge pull request #2080 from github/henrymercer/fix-unconditional-wa…
Browse files Browse the repository at this point in the history
…rning

Fix `paths`/`paths-ignore` warning that would appear unconditionally
  • Loading branch information
henrymercer authored Jan 11, 2024
2 parents cd94990 + 30597e3 commit eb14aeb
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/init.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/init.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions lib/init.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/init.test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/init.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
9 changes: 6 additions & 3 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?.length !== 0 ||
config.originalUserInput["paths-ignore"]?.length !== 0) &&
(config.originalUserInput.paths?.length ||
config.originalUserInput["paths-ignore"]?.length) &&
!config.languages.every(isScannedLanguage)
) {
logger.warning(
Expand Down

0 comments on commit eb14aeb

Please sign in to comment.