Skip to content

Commit 101ed8d

Browse files
committed
feat(rule): implement no-debugger
1 parent 82ed353 commit 101ed8d

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

internal/config/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ import (
3333
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_empty_interface"
3434
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_explicit_any"
3535
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_extraneous_class"
36-
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_invalid_void_type"
3736
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_floating_promises"
3837
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_for_in_array"
3938
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_implied_eval"
39+
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_invalid_void_type"
4040
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_meaningless_void_operator"
4141
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_misused_promises"
4242
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_misused_spread"
4343
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_mixed_enums"
4444
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_namespace"
4545
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_redundant_type_constituents"
46-
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_this_alias"
4746
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_require_imports"
47+
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_this_alias"
4848
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_unnecessary_boolean_literal_compare"
4949
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_unnecessary_template_expression"
5050
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/no_unnecessary_type_arguments"
@@ -94,6 +94,7 @@ import (
9494
"github.com/web-infra-dev/rslint/internal/rules/no_constant_binary_expression"
9595
"github.com/web-infra-dev/rslint/internal/rules/no_constant_condition"
9696
"github.com/web-infra-dev/rslint/internal/rules/no_constructor_return"
97+
"github.com/web-infra-dev/rslint/internal/rules/no_debugger"
9798
)
9899

99100
// RslintConfig represents the top-level configuration array
@@ -457,6 +458,7 @@ func registerAllCoreEslintRules() {
457458
GlobalRuleRegistry.Register("no-constant-binary-expression", no_constant_binary_expression.NoConstantBinaryExpressionRule)
458459
GlobalRuleRegistry.Register("no-constant-condition", no_constant_condition.NoConstantConditionRule)
459460
GlobalRuleRegistry.Register("no-constructor-return", no_constructor_return.NoConstructorReturnRule)
461+
GlobalRuleRegistry.Register("no-debugger", no_debugger.NoDebuggerRule)
460462
}
461463

462464
// getAllTypeScriptEslintPluginRules returns all registered rules (for backward compatibility when no config is provided)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package no_debugger
2+
3+
import (
4+
"github.com/microsoft/typescript-go/shim/ast"
5+
"github.com/web-infra-dev/rslint/internal/rule"
6+
)
7+
8+
// https://eslint.org/docs/latest/rules/no-debugger
9+
var NoDebuggerRule = rule.Rule{
10+
Name: "no-debugger",
11+
Run: func(ctx rule.RuleContext, options any) rule.RuleListeners {
12+
return rule.RuleListeners{
13+
ast.KindDebuggerStatement: func(node *ast.Node) {
14+
ctx.ReportNode(node, rule.RuleMessage{
15+
Id: "no-debugger",
16+
Description: "Unexpected 'debugger' statement.",
17+
})
18+
},
19+
}
20+
},
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package no_debugger
2+
3+
import (
4+
"testing"
5+
6+
"github.com/web-infra-dev/rslint/internal/plugins/typescript/rules/fixtures"
7+
"github.com/web-infra-dev/rslint/internal/rule_tester"
8+
)
9+
10+
func TestNoDebuggerRule(t *testing.T) {
11+
rule_tester.RunRuleTester(
12+
fixtures.GetRootDir(),
13+
"tsconfig.json",
14+
t,
15+
&NoDebuggerRule,
16+
// Valid cases - ported from ESLint
17+
[]rule_tester.ValidTestCase{
18+
{Code: `var test = { debugger: 1 }; test.debugger;`},
19+
},
20+
// Invalid cases - ported from ESLint
21+
[]rule_tester.InvalidTestCase{
22+
{
23+
Code: `if (foo) debugger`,
24+
Errors: []rule_tester.InvalidTestCaseError{
25+
{MessageId: "no-debugger", Line: 1, Column: 10},
26+
},
27+
},
28+
},
29+
)
30+
}

0 commit comments

Comments
 (0)