Skip to content

Commit

Permalink
Switched no-console output from blacklist to whitelist (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Goldberg authored Oct 10, 2019
1 parent bd694e7 commit 319e0b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/rules/converters/no-console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ export const convertNoConsole: RuleConverter = tslintRule => {
rules: [
{
...(tslintRule.ruleArguments.length !== 0 && {
ruleArguments: [{ allow: tslintRule.ruleArguments }],
notices: ["Custom console methods, if they exist, will no longer be allowed."],
ruleArguments: [
{
allow: Object.keys(console).filter(
method => !tslintRule.ruleArguments.includes(method),
),
},
],
}),
ruleName: "no-console",
},
Expand Down
13 changes: 12 additions & 1 deletion src/rules/converters/tests/no-console.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { convertNoConsole } from "../no-console";

const consoleKeysExcluding = (...keys: string[]) => {
const knownConsoleKeys = new Set(Object.keys(console));

for (const key of keys) {
knownConsoleKeys.delete(key);
}

return Array.from(knownConsoleKeys);
};

describe(convertNoConsole, () => {
test("conversion without arguments", () => {
const result = convertNoConsole({
Expand All @@ -23,7 +33,8 @@ describe(convertNoConsole, () => {
expect(result).toEqual({
rules: [
{
ruleArguments: [{ allow: ["info", "log"] }],
notices: ["Custom console methods, if they exist, will no longer be allowed."],
ruleArguments: [{ allow: consoleKeysExcluding("info", "log") }],
ruleName: "no-console",
},
],
Expand Down

0 comments on commit 319e0b1

Please sign in to comment.