File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -176,9 +176,10 @@ rules in templates can be disabled with eslint directives with mustache or html
176176
177177### Best Practices
178178
179- | Name | Description | 💼 | 🔧 | 💡 |
180- | :----------------------------------------------- | :---------------------------- | :- | :- | :- |
181- | [ template-no-log] ( docs/rules/template-no-log.md ) | disallow {{log}} in templates | | | |
179+ | Name | Description | 💼 | 🔧 | 💡 |
180+ | :--------------------------------------------------------- | :--------------------------------- | :- | :- | :- |
181+ | [ template-no-debugger] ( docs/rules/template-no-debugger.md ) | disallow {{debugger}} in templates | | | |
182+ | [ template-no-log] ( docs/rules/template-no-log.md ) | disallow {{log}} in templates | | | |
182183
183184### Components
184185
Original file line number Diff line number Diff line change 1+ # ember/template-no-debugger
2+
3+ <!-- end auto-generated rule header -->
4+
5+ Disallows usage of ` {{debugger}} ` in templates.
6+
7+ The ` {{debugger}} ` helper is useful for debugging but should not be present in production code.
8+
9+ ## Rule Details
10+
11+ This rule disallows the use of ` {{debugger}} ` statements in templates.
12+
13+ ## Examples
14+
15+ Examples of ** incorrect** code for this rule:
16+
17+ ``` gjs
18+ <template>
19+ {{debugger}}
20+ <div>Content</div>
21+ </template>
22+ ```
23+
24+ ``` gjs
25+ <template>
26+ {{#if condition}}
27+ {{debugger}}
28+ {{/if}}
29+ </template>
30+ ```
31+
32+ Examples of ** correct** code for this rule:
33+
34+ ``` gjs
35+ <template>
36+ <div>Content</div>
37+ </template>
38+ ```
39+
40+ ``` gjs
41+ <template>
42+ {{this.debug}}
43+ </template>
44+ ```
45+
46+ ## Related Rules
47+
48+ - [ no-debugger] ( https://eslint.org/docs/rules/no-debugger ) from ESLint
49+
50+ ## References
51+
52+ - [ ember-template-lint no-debugger] ( https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-debugger.md )
Original file line number Diff line number Diff line change 1+ /** @type {import('eslint').Rule.RuleModule } */
2+ module . exports = {
3+ meta : {
4+ type : 'problem' ,
5+ docs : {
6+ description : 'disallow {{debugger}} in templates' ,
7+ category : 'Best Practices' ,
8+ url : 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-debugger.md' ,
9+ } ,
10+ fixable : null ,
11+ schema : [ ] ,
12+ messages : {
13+ unexpected : 'Unexpected debugger statement in template.' ,
14+ } ,
15+ } ,
16+
17+ create ( context ) {
18+ function checkForDebugger ( node ) {
19+ if (
20+ node . path &&
21+ node . path . type === 'GlimmerPathExpression' &&
22+ node . path . original === 'debugger'
23+ ) {
24+ context . report ( {
25+ node,
26+ messageId : 'unexpected' ,
27+ } ) ;
28+ }
29+ }
30+
31+ return {
32+ GlimmerMustacheStatement ( node ) {
33+ checkForDebugger ( node ) ;
34+ } ,
35+
36+ GlimmerBlockStatement ( node ) {
37+ checkForDebugger ( node ) ;
38+ } ,
39+ } ;
40+ } ,
41+ } ;
Original file line number Diff line number Diff line change 1+ //------------------------------------------------------------------------------
2+ // Requirements
3+ //------------------------------------------------------------------------------
4+
5+ const rule = require ( '../../../lib/rules/template-no-debugger' ) ;
6+ const RuleTester = require ( 'eslint' ) . RuleTester ;
7+
8+ //------------------------------------------------------------------------------
9+ // Tests
10+ //------------------------------------------------------------------------------
11+
12+ const ruleTester = new RuleTester ( {
13+ parser : require . resolve ( 'ember-eslint-parser' ) ,
14+ parserOptions : { ecmaVersion : 2022 , sourceType : 'module' } ,
15+ } ) ;
16+
17+ ruleTester . run ( 'template-no-debugger' , rule , {
18+ valid : [
19+ `<template>
20+ <div>Hello World</div>
21+ </template>` ,
22+ `<template>
23+ {{this.debug}}
24+ </template>` ,
25+ `<template>
26+ {{debugMode}}
27+ </template>` ,
28+ `<template>
29+ <div data-test-debugger={{true}}></div>
30+ </template>` ,
31+ ] ,
32+
33+ invalid : [
34+ {
35+ code : `<template>
36+ {{debugger}}
37+ </template>` ,
38+ output : null ,
39+ errors : [
40+ {
41+ message : 'Unexpected debugger statement in template.' ,
42+ type : 'GlimmerMustacheStatement' ,
43+ } ,
44+ ] ,
45+ } ,
46+ {
47+ code : `<template>
48+ {{#if condition}}
49+ {{debugger}}
50+ {{/if}}
51+ </template>` ,
52+ output : null ,
53+ errors : [
54+ {
55+ message : 'Unexpected debugger statement in template.' ,
56+ type : 'GlimmerMustacheStatement' ,
57+ } ,
58+ ] ,
59+ } ,
60+ {
61+ code : `<template>
62+ {{#debugger}}
63+ content
64+ {{/debugger}}
65+ </template>` ,
66+ output : null ,
67+ errors : [
68+ {
69+ message : 'Unexpected debugger statement in template.' ,
70+ type : 'GlimmerBlockStatement' ,
71+ } ,
72+ ] ,
73+ } ,
74+ ] ,
75+ } ) ;
You can’t perform that action at this time.
0 commit comments