Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change rule for comparisons against -0 #424

Merged
merged 2 commits into from
Mar 23, 2022
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ecmarkup",
"version": "10.0.2",
"version": "11.0.0",
"description": "Custom element definitions and core utilities for markup that specifies ECMAScript and related technologies.",
"main": "lib/ecmarkup.js",
"typings": "lib/ecmarkup.d.ts",
Expand Down
13 changes: 11 additions & 2 deletions src/lint/collect-spelling-diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,17 @@ const matchers = [
message: 'tags should not contain trailing whitespace',
},
{
pattern: /(?<=&[lg][et]; ?\*)-0\*/gu,
message: 'comparisons against floating-point zero should use positive zero',
pattern: /(?<=&lt; ?\*)\+0\*/gu,
message: '"less than" comparisons against floating-point zero should use negative zero',
},
{
pattern: /(?<=&gt; ?\*)-0\*/gu,
message: '"greater than" comparisons against floating-point zero should use positive zero',
},
{
pattern: /(?<=&[lg]e; ?\*)[+-]0\*/gu,
message:
'comparisons against floating-point zero should use strict comparisons (< or >); guard the equals case with "is"',
},
{
pattern: /(÷|&divide;)/gu,
Expand Down
22 changes: 12 additions & 10 deletions test/lint-spelling.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,48 +465,50 @@ windows:${M}\r
);
});

it('comparison with *-0*', async () => {
it('comparison with *+/-0*', async () => {
await assertLint(
positioned`
<p>If _x_ &lt; *${M}-0*<sub>𝔽</sub></p>
<p>If _x_ &lt; *${M}+0*<sub>𝔽</sub></p>
`,
{
ruleId: 'spelling',
nodeType: 'html',
message: 'comparisons against floating-point zero should use positive zero',
message: '"less than" comparisons against floating-point zero should use negative zero',
}
);

await assertLint(
positioned`
<p>If _x_ &le; *${M}-0*<sub>𝔽</sub></p>
<p>If _x_ &gt; *${M}-0*<sub>𝔽</sub></p>
`,
{
ruleId: 'spelling',
nodeType: 'html',
message: 'comparisons against floating-point zero should use positive zero',
message: '"greater than" comparisons against floating-point zero should use positive zero',
}
);

await assertLint(
positioned`
<p>If _x_ &gt; *${M}-0*<sub>𝔽</sub></p>
<p>If _x_ &le; *${M}-0*<sub>𝔽</sub></p>
`,
{
ruleId: 'spelling',
nodeType: 'html',
message: 'comparisons against floating-point zero should use positive zero',
message:
'comparisons against floating-point zero should use strict comparisons (< or >); guard the equals case with "is"',
}
);

await assertLint(
positioned`
<p>If _x_ &ge; *${M}-0*<sub>𝔽</sub></p>
<p>If _x_ &ge; *${M}+0*<sub>𝔽</sub></p>
`,
{
ruleId: 'spelling',
nodeType: 'html',
message: 'comparisons against floating-point zero should use positive zero',
message:
'comparisons against floating-point zero should use strict comparisons (< or >); guard the equals case with "is"',
}
);
});
Expand Down Expand Up @@ -586,7 +588,7 @@ windows:${M}\r
Paragraphs with the open/close tags on their own line are OK.
</p>

<p>Comparisons with positive zero are OK: _x_ &lt; *+0*<sub>𝔽</sub>, _x_ &le; *+0*<sub>𝔽</sub>, _x_ &gt; *+0*<sub>𝔽</sub>, _x_ &ge; *+0*<sub>𝔽</sub></p>
<p>Comparisons with appropriately-signed zero are OK: _x_ &lt; *-0*<sub>𝔽</sub>, _x_ &gt; *+0*<sub>𝔽</sub>.</p>

`);
});
Expand Down