Skip to content

Commit 319e0b1

Browse files
author
Josh Goldberg
authored
Switched no-console output from blacklist to whitelist (#235)
1 parent bd694e7 commit 319e0b1

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/rules/converters/no-console.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ export const convertNoConsole: RuleConverter = tslintRule => {
55
rules: [
66
{
77
...(tslintRule.ruleArguments.length !== 0 && {
8-
ruleArguments: [{ allow: tslintRule.ruleArguments }],
8+
notices: ["Custom console methods, if they exist, will no longer be allowed."],
9+
ruleArguments: [
10+
{
11+
allow: Object.keys(console).filter(
12+
method => !tslintRule.ruleArguments.includes(method),
13+
),
14+
},
15+
],
916
}),
1017
ruleName: "no-console",
1118
},

src/rules/converters/tests/no-console.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import { convertNoConsole } from "../no-console";
22

3+
const consoleKeysExcluding = (...keys: string[]) => {
4+
const knownConsoleKeys = new Set(Object.keys(console));
5+
6+
for (const key of keys) {
7+
knownConsoleKeys.delete(key);
8+
}
9+
10+
return Array.from(knownConsoleKeys);
11+
};
12+
313
describe(convertNoConsole, () => {
414
test("conversion without arguments", () => {
515
const result = convertNoConsole({
@@ -23,7 +33,8 @@ describe(convertNoConsole, () => {
2333
expect(result).toEqual({
2434
rules: [
2535
{
26-
ruleArguments: [{ allow: ["info", "log"] }],
36+
notices: ["Custom console methods, if they exist, will no longer be allowed."],
37+
ruleArguments: [{ allow: consoleKeysExcluding("info", "log") }],
2738
ruleName: "no-console",
2839
},
2940
],

0 commit comments

Comments
 (0)