Skip to content

Commit 1a261e2

Browse files
committed
add block comment eslint directives
1 parent e42d472 commit 1a261e2

File tree

5 files changed

+51
-31
lines changed

5 files changed

+51
-31
lines changed

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = {
5757
plugins: ['ember'],
5858
extends: [
5959
'eslint:recommended',
60-
'plugin:ember/gts-recommended', // or other configuration
60+
'plugin:ember/recommended', // or other configuration
6161
],
6262
rules: {
6363
// override / enable optional rules
@@ -97,12 +97,9 @@ module.exports = {
9797

9898
- semi rule, same as [prettier plugin](https://github.com/gitKrystan/prettier-plugin-ember-template-tag/issues/1)
9999
- no-undef rule will take effect for template vars (includes js scope)
100-
- no-unsed rule will take effect for template block params
101-
102-
rules in tempates can be disabled with eslint directives with mustache or html comments:
100+
- no-unused rule will take effect for template block params
103101

104-
[!NOTE]
105-
html does not have the distinction of line or block comments, which is why block comments should start with `<!--- ... -->` (3 dashes and a space, end with 2 dashes)
102+
rules in templates can be disabled with eslint directives with mustache or html comments:
106103

107104
```hbs
108105
<template>
@@ -127,11 +124,11 @@ html does not have the distinction of line or block comments, which is why block
127124
{{test}}
128125
</div>
129126
<div>
130-
<!--- eslint-disable -->
127+
<!-- eslint-disable -->
131128
{{test}}
132129
{{test}}
133130
{{test}}
134-
<!--- eslint-enable -->
131+
<!-- eslint-enable -->
135132
</div>
136133
</template>
137134
```

lib/parsers/gjs-gts-parser.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ function preprocessGlimmerTemplates(info, code) {
291291
n.type = `Glimmer${n.type}`;
292292
allNodeTypes.add(n.type);
293293
}
294+
// ast should not contain comment nodes
295+
for (const comment of comments) {
296+
const parentBody = comment.parent.body || comment.parent.children;
297+
const idx = parentBody.indexOf(comment);
298+
parentBody.splice(idx, 1);
299+
// comment type can be a block comment or a line comment
300+
// mark comments as always block comment, this works for eslint in all cases
301+
comment.type = 'Block';
302+
}
294303
// tokens should not contain tokens of comments
295304
ast.tokens = ast.tokens.filter(
296305
(t) => !comments.some((c) => c.range[0] <= t.range[0] && c.range[1] >= t.range[1])

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"dependencies": {
7171
"@babel/eslint-parser": "^7.15.8",
7272
"@ember-data/rfc395-data": "^0.0.4",
73-
"@glimmer/syntax": "^0.85.8",
73+
"@glimmer/syntax": "^0.85.11",
7474
"@typescript-eslint/parser": "^5.62.0",
7575
"@typescript-eslint/scope-manager": "^5.62.0",
7676
"content-tag": "^1.1.2",

tests/lib/rules-preprocessor/gjs-gts-parser-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,13 @@ describe('supports eslint directives inside templates', () => {
573573
{{!eslint-disable-next-line}}
574574
{{test}}
575575
</div>
576+
<div>
577+
{{!--eslint-disable--}}
578+
{{test}}
579+
{{test}}
580+
{{test}}
581+
{{!--eslint-enable--}}
582+
</div>
576583
</template>
577584
`;
578585
const results = await eslint.lintText(code, { filePath: 'my-component.gjs' });
@@ -588,6 +595,13 @@ describe('supports eslint directives inside templates', () => {
588595
<!--eslint-disable-next-line-->
589596
{{test}}
590597
</div>
598+
<div>
599+
<!-- eslint-disable -->
600+
{{test}}
601+
{{test}}
602+
{{test}}
603+
<!-- eslint-enable -->
604+
</div>
591605
</template>
592606
`;
593607
const results = await eslint.lintText(code, { filePath: 'my-component.gjs' });

yarn.lock

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -570,39 +570,39 @@
570570
resolved "https://registry.yarnpkg.com/@glimmer/env/-/env-0.1.7.tgz#fd2d2b55a9029c6b37a6c935e8c8871ae70dfa07"
571571
integrity sha512-JKF/a9I9jw6fGoz8kA7LEQslrwJ5jms5CXhu/aqkBWk+PmZ6pTl8mlb/eJ/5ujBGTiQzBhy5AIWF712iA+4/mw==
572572

573-
"@glimmer/interfaces@^0.85.8":
574-
version "0.85.8"
575-
resolved "https://registry.yarnpkg.com/@glimmer/interfaces/-/interfaces-0.85.8.tgz#2f2ebf131f4f1afa66c2dd6ed5a1514f5e12d369"
576-
integrity sha512-Pzz05027itnvPTfjFQbXE7710bfOcPQIV8QLqvHk4+3iZZ+9C50xbv3NzbkUVkUKTkm+Acijc768bz4aVQkd9Q==
573+
"@glimmer/interfaces@^0.85.11":
574+
version "0.85.11"
575+
resolved "https://registry.yarnpkg.com/@glimmer/interfaces/-/interfaces-0.85.11.tgz#b213645db2ed6ea6ec3b2c37968c719919868cdb"
576+
integrity sha512-MgILQDes+Deey//aqdYTfseW7Sks29DkDqr0uWMBmuD3x8lRvSPd+K6RwsC8mHmKWGAwnZ5pisnC7hwr0FykCg==
577577
dependencies:
578578
"@simple-dom/interface" "^1.4.0"
579579

580-
"@glimmer/syntax@^0.85.8":
581-
version "0.85.8"
582-
resolved "https://registry.yarnpkg.com/@glimmer/syntax/-/syntax-0.85.8.tgz#891ac6ab8581c013d372b592f304385fde734107"
583-
integrity sha512-OjiMHZ+TuSqSbymTOSbNfOgf2lVD/9X1MVcPxzVcRLQa45Y2WH7tkwvN/GLvLb/5GeMtsLhU7eZann8IV3MJSA==
580+
"@glimmer/syntax@^0.85.11":
581+
version "0.85.11"
582+
resolved "https://registry.yarnpkg.com/@glimmer/syntax/-/syntax-0.85.11.tgz#fa9daf96a09248c025ea3ed22e39bb3357617ab2"
583+
integrity sha512-XF6hXP2MmomJ25ShRCh5r43LXdegVvTe4GcYfok2z3ALb+3mBXAOoZgyOY1ntmlQt4a8hFM7RHW3C4++UM/bLQ==
584584
dependencies:
585-
"@glimmer/interfaces" "^0.85.8"
586-
"@glimmer/util" "^0.85.8"
587-
"@glimmer/wire-format" "^0.85.8"
585+
"@glimmer/interfaces" "^0.85.11"
586+
"@glimmer/util" "^0.85.11"
587+
"@glimmer/wire-format" "^0.85.11"
588588
"@handlebars/parser" "~2.0.0"
589589
simple-html-tokenizer "^0.5.11"
590590

591-
"@glimmer/util@^0.85.8":
592-
version "0.85.8"
593-
resolved "https://registry.yarnpkg.com/@glimmer/util/-/util-0.85.8.tgz#479fe1455b2e28f745d5950c10df68ba0051f774"
594-
integrity sha512-DUSJwb+2BeAXPtQFM4/mQ+gCZCHu1TDKvYcR2cIip0fNdPTaaPuYnCU4nqazXVvqGDHAC1m/Mjv0xzGL4vsB+w==
591+
"@glimmer/util@^0.85.11":
592+
version "0.85.11"
593+
resolved "https://registry.yarnpkg.com/@glimmer/util/-/util-0.85.11.tgz#59b58988c0cb9e252e80391dba02c375b71571f1"
594+
integrity sha512-GE1zYMpF1SHCTMcun6ozrDd/cPQz+HTFNP4S5pLmazKz3A0koTg8Dqg6hfiJeBsq/8WYRXgFPLAGumIomsubxA==
595595
dependencies:
596596
"@glimmer/env" "0.1.7"
597-
"@glimmer/interfaces" "^0.85.8"
597+
"@glimmer/interfaces" "^0.85.11"
598598

599-
"@glimmer/wire-format@^0.85.8":
600-
version "0.85.8"
601-
resolved "https://registry.yarnpkg.com/@glimmer/wire-format/-/wire-format-0.85.8.tgz#3f9da5735ea504dc4c3fa4bf5489e70c5b03b2cd"
602-
integrity sha512-HYWjS/IhHP49mXPFBtBDjL4FiCyaTzcHiQIiOPe7Kvi26k4A7i0yX8I3U4fA+WIrKf0cLDd7Duyd3vz8X058Cw==
599+
"@glimmer/wire-format@^0.85.11":
600+
version "0.85.11"
601+
resolved "https://registry.yarnpkg.com/@glimmer/wire-format/-/wire-format-0.85.11.tgz#3726eac0039bf0021f2f76262e4309b373b78e9f"
602+
integrity sha512-FTC74lbM0XFgNhp14y+lw6uqQR4eoZ+1Gy9omVHB8D+aFPX+WRfnKz2RTU7W19A9/1RsNqsgalr360NXCokcJA==
603603
dependencies:
604-
"@glimmer/interfaces" "^0.85.8"
605-
"@glimmer/util" "^0.85.8"
604+
"@glimmer/interfaces" "^0.85.11"
605+
"@glimmer/util" "^0.85.11"
606606

607607
"@handlebars/parser@~2.0.0":
608608
version "2.0.0"

0 commit comments

Comments
 (0)