Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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