Skip to content
Open
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
14 changes: 5 additions & 9 deletions docs/rules/template-no-negated-comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

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

> **Note**: This rule is NOT a port of upstream `ember-template-lint`'s `no-negated-condition`.
> Upstream's rule prefers `not-eq` over `if/else`; this rule bans `not-eq` (and similar) entirely.
> These are opposite goals.

Disallows negated comparison operators in templates.

## Rule Details

Use positive comparison operators with `{{unless}}` instead of negated comparison operators like `not-eq` or `ne`.
Use positive comparison operators with `{{unless}}` instead of negated comparison operators like `not-eq`.

## Examples

Expand All @@ -20,14 +24,6 @@ Examples of **incorrect** code for this rule:
</template>
```

```gjs
<template>
{{#if (ne this.a this.b)}}
Not equal
{{/if}}
</template>
```

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

```gjs
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/template-no-negated-comparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
if (
node.path &&
node.path.type === 'GlimmerPathExpression' &&
(node.path.original === 'not-eq' || node.path.original === 'ne')
node.path.original === 'not-eq'
) {
context.report({
node,
Expand Down
20 changes: 6 additions & 14 deletions tests/lib/rules/template-no-negated-comparison.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ ruleTester.run('template-no-negated-comparison', rule, {
`<template>
<div></div>
</template>`,
// `ne` is not a standard Ember/ember-truth-helpers helper; the rule must not flag it.
`<template>
{{#if (ne this.a this.b)}}
Not equal
{{/if}}
</template>`,
],

invalid: [
Expand All @@ -46,20 +52,6 @@ ruleTester.run('template-no-negated-comparison', rule, {
},
],
},
{
code: `<template>
{{#if (ne this.a this.b)}}
Not equal
{{/if}}
</template>`,
output: null,
errors: [
{
message: 'Use positive comparison operators instead of negated ones.',
type: 'GlimmerSubExpression',
},
],
},
{
code: `<template>
<div class={{if (not-eq this.state "active") "inactive"}}></div>
Expand Down
Loading