Skip to content

Commit 03564b5

Browse files
committed
fix(no-debug): only accept known debug utils
1 parent 2c473ab commit 03564b5

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

lib/rules/no-debug.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ASTUtils, TSESTree } from '@typescript-eslint/experimental-utils';
1313

1414
export const RULE_NAME = 'no-debug';
1515
export type MessageIds = 'noDebug';
16-
type Options = [{ utilNames: string[] }];
16+
type Options = [{ utilNames: Array<'debug' | 'logTestingPlaygroundURL'> }];
1717

1818
export default createTestingLibraryRule<Options, MessageIds>({
1919
name: RULE_NAME,
@@ -38,14 +38,17 @@ export default createTestingLibraryRule<Options, MessageIds>({
3838
properties: {
3939
utilNames: {
4040
type: 'array',
41-
items: { type: 'string' },
41+
items: {
42+
type: 'string',
43+
enum: ['debug', 'logTestingPlaygroundURL'],
44+
},
4245
},
4346
},
4447
additionalProperties: false,
4548
},
4649
],
4750
},
48-
defaultOptions: [{ utilNames: ['debug'] }],
51+
defaultOptions: [{ utilNames: ['debug', 'logTestingPlaygroundURL'] }],
4952

5053
create(context, [{ utilNames }], helpers) {
5154
const suspiciousDebugVariableNames: string[] = [];
@@ -95,7 +98,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
9598
if (
9699
isProperty(property) &&
97100
ASTUtils.isIdentifier(property.key) &&
98-
utilNames.includes(property.key.name)
101+
(utilNames as string[]).includes(property.key.name)
99102
) {
100103
const identifierNode = getDeepestIdentifierNode(property.value);
101104

@@ -140,7 +143,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
140143
const isChainedReferenceDebug = suspiciousReferenceNodes.some(
141144
(suspiciousReferenceIdentifier) => {
142145
return (
143-
utilNames.includes(callExpressionIdentifier.name) &&
146+
(utilNames as string[]).includes(callExpressionIdentifier.name) &&
144147
suspiciousReferenceIdentifier.name === referenceIdentifier.name
145148
);
146149
}

tests/lib/rules/no-debug.test.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,7 @@ ruleTester.run(RULE_NAME, rule, {
9292
import { screen } from '@testing-library/dom'
9393
screen.logTestingPlaygroundURL()
9494
`,
95-
},
96-
{
97-
code: `
98-
import { screen } from '@testing-library/dom'
99-
screen.debug()
100-
`,
101-
options: [{ utilNames: ['anotherUtil'] }],
95+
options: [{ utilNames: ['debug'] }],
10296
},
10397
{
10498
code: `const { queries } = require('@testing-library/dom')`,

0 commit comments

Comments
 (0)