Skip to content

Commit 7a715a0

Browse files
committed
Fix (not (not c1 c2)) to produce (or c1 c2) instead of just c1
1 parent cef5767 commit 7a715a0

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

lib/rules/template-no-negated-condition.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ module.exports = {
9696
const inverted = HELPER_INVERSIONS[helperName];
9797
if (inverted !== undefined) {
9898
if (inverted === null) {
99+
if (inner.params.length > 1) {
100+
// (not (not c1 c2)) -> (or c1 c2)
101+
const paramsText = inner.params.map((p) => sourceCode.getText(p)).join(' ');
102+
return `(or ${paramsText})`;
103+
}
99104
// (not (not x)) -> just x
100105
return sourceCode.getText(inner.params[0]);
101106
}

tests/lib/rules/template-no-negated-condition.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ruleTester.run('template-no-negated-condition', rule, {
7474
},
7575
{
7676
code: '<template>{{#if (not (not c1 c2))}}<img>{{/if}}</template>',
77-
output: '<template>{{#if c1}}<img>{{/if}}</template>',
77+
output: '<template>{{#if (or c1 c2)}}<img>{{/if}}</template>',
7878
errors: [{ messageId: 'negatedHelper' }],
7979
},
8080
{
@@ -263,7 +263,7 @@ hbsRuleTester.run('template-no-negated-condition', rule, {
263263
},
264264
{
265265
code: '{{#if (not (not c1 c2))}}<img>{{/if}}',
266-
output: '{{#if c1}}<img>{{/if}}',
266+
output: '{{#if (or c1 c2)}}<img>{{/if}}',
267267
errors: [{ message: 'Simplify unnecessary negation of helper.' }],
268268
},
269269
{

0 commit comments

Comments
 (0)