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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ rules in templates can be disabled with eslint directives with mustache or html

### Best Practices

| Name | Description | 💼 | 🔧 | 💡 |
| :----------------------------------------------- | :---------------------------- | :- | :- | :- |
| [template-no-log](docs/rules/template-no-log.md) | disallow {{log}} in templates | | | |
| Name | Description | 💼 | 🔧 | 💡 |
| :--------------------------------------------------------- | :--------------------------------- | :- | :- | :- |
| [template-no-debugger](docs/rules/template-no-debugger.md) | disallow {{debugger}} in templates | | | |
| [template-no-log](docs/rules/template-no-log.md) | disallow {{log}} in templates | | | |

### Components

Expand Down
52 changes: 52 additions & 0 deletions docs/rules/template-no-debugger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# ember/template-no-debugger

<!-- end auto-generated rule header -->

Disallows usage of `{{debugger}}` in templates.

The `{{debugger}}` helper is useful for debugging but should not be present in production code.

## Rule Details

This rule disallows the use of `{{debugger}}` statements in templates.

## Examples

Examples of **incorrect** code for this rule:

```gjs
<template>
{{debugger}}
<div>Content</div>
</template>
```

```gjs
<template>
{{#if condition}}
{{debugger}}
{{/if}}
</template>
```

Examples of **correct** code for this rule:

```gjs
<template>
<div>Content</div>
</template>
```

```gjs
<template>
{{this.debug}}
</template>
```

## Related Rules

- [no-debugger](https://eslint.org/docs/rules/no-debugger) from ESLint

## References

- [ember-template-lint no-debugger](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-debugger.md)
41 changes: 41 additions & 0 deletions lib/rules/template-no-debugger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow {{debugger}} in templates',
category: 'Best Practices',
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-debugger.md',
},
fixable: null,
schema: [],
messages: {
unexpected: 'Unexpected debugger statement in template.',
},
},

create(context) {
function checkForDebugger(node) {
if (
node.path &&
node.path.type === 'GlimmerPathExpression' &&
node.path.original === 'debugger'
) {
context.report({
node,
messageId: 'unexpected',
});
}
}

return {
GlimmerMustacheStatement(node) {
checkForDebugger(node);
},

GlimmerBlockStatement(node) {
checkForDebugger(node);
},
};
},
};
75 changes: 75 additions & 0 deletions tests/lib/rules/template-no-debugger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const rule = require('../../../lib/rules/template-no-debugger');
const RuleTester = require('eslint').RuleTester;

//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser'),
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
});

ruleTester.run('template-no-debugger', rule, {
valid: [
`<template>
<div>Hello World</div>
</template>`,
`<template>
{{this.debug}}
</template>`,
`<template>
{{debugMode}}
</template>`,
`<template>
<div data-test-debugger={{true}}></div>
</template>`,
],

invalid: [
{
code: `<template>
{{debugger}}
</template>`,
output: null,
errors: [
{
message: 'Unexpected debugger statement in template.',
type: 'GlimmerMustacheStatement',
},
],
},
{
code: `<template>
{{#if condition}}
{{debugger}}
{{/if}}
</template>`,
output: null,
errors: [
{
message: 'Unexpected debugger statement in template.',
type: 'GlimmerMustacheStatement',
},
],
},
{
code: `<template>
{{#debugger}}
content
{{/debugger}}
</template>`,
output: null,
errors: [
{
message: 'Unexpected debugger statement in template.',
type: 'GlimmerBlockStatement',
},
],
},
],
});
Loading