-
Notifications
You must be signed in to change notification settings - Fork 5
/
no-debug.ts
62 lines (56 loc) · 1.63 KB
/
no-debug.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { type Rule, createRule } from '../utils'
import { isPandaProp, isPandaAttribute, isRecipeVariant } from '../utils/helpers'
import { TSESTree } from '@typescript-eslint/utils'
export const RULE_NAME = 'no-debug'
const rule: Rule = createRule({
name: RULE_NAME,
meta: {
docs: {
description: 'Disallow the inclusion of the debug attribute when shipping code to the production environment.',
},
messages: {
debug: 'Unnecessary debug utility.',
prop: 'Remove the debug prop.',
property: 'Remove the debug property.',
},
type: 'problem',
hasSuggestions: true,
schema: [],
},
defaultOptions: [],
create(context) {
return {
'JSXAttribute[name.name="debug"]'(node: TSESTree.JSXAttribute) {
// Ensure the attribute is a Panda prop
if (!isPandaProp(node, context)) return
context.report({
node,
messageId: 'debug',
suggest: [
{
messageId: 'prop',
fix: (fixer) => fixer.remove(node),
},
],
})
},
'Property[key.name="debug"]'(node: TSESTree.Property) {
// Ensure the property is a Panda attribute
if (!isPandaAttribute(node, context)) return
// Exclude recipe variants
if (isRecipeVariant(node, context)) return
context.report({
node: node.key,
messageId: 'debug',
suggest: [
{
messageId: 'property',
fix: (fixer) => fixer.removeRange([node.range[0], node.range[1] + 1]),
},
],
})
},
}
},
})
export default rule