Skip to content

Commit

Permalink
Merge pull request #1971 from patricklx/add-block-comment
Browse files Browse the repository at this point in the history
add template block comment eslint directives
  • Loading branch information
NullVoxPopuli authored Nov 2, 2023
2 parents e42d472 + 1a261e2 commit 8543535
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 31 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = {
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/gts-recommended', // or other configuration
'plugin:ember/recommended', // or other configuration
],
rules: {
// override / enable optional rules
Expand Down Expand Up @@ -97,12 +97,9 @@ module.exports = {

- semi rule, same as [prettier plugin](https://github.com/gitKrystan/prettier-plugin-ember-template-tag/issues/1)
- no-undef rule will take effect for template vars (includes js scope)
- no-unsed rule will take effect for template block params

rules in tempates can be disabled with eslint directives with mustache or html comments:
- no-unused rule will take effect for template block params

[!NOTE]
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)
rules in templates can be disabled with eslint directives with mustache or html comments:

```hbs
<template>
Expand All @@ -127,11 +124,11 @@ html does not have the distinction of line or block comments, which is why block
{{test}}
</div>
<div>
<!--- eslint-disable -->
<!-- eslint-disable -->
{{test}}
{{test}}
{{test}}
<!--- eslint-enable -->
<!-- eslint-enable -->
</div>
</template>
```
Expand Down
9 changes: 9 additions & 0 deletions lib/parsers/gjs-gts-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,15 @@ function preprocessGlimmerTemplates(info, code) {
n.type = `Glimmer${n.type}`;
allNodeTypes.add(n.type);
}
// ast should not contain comment nodes
for (const comment of comments) {
const parentBody = comment.parent.body || comment.parent.children;
const idx = parentBody.indexOf(comment);
parentBody.splice(idx, 1);
// comment type can be a block comment or a line comment
// mark comments as always block comment, this works for eslint in all cases
comment.type = 'Block';
}
// tokens should not contain tokens of comments
ast.tokens = ast.tokens.filter(
(t) => !comments.some((c) => c.range[0] <= t.range[0] && c.range[1] >= t.range[1])
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"dependencies": {
"@babel/eslint-parser": "^7.15.8",
"@ember-data/rfc395-data": "^0.0.4",
"@glimmer/syntax": "^0.85.8",
"@glimmer/syntax": "^0.85.11",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/scope-manager": "^5.62.0",
"content-tag": "^1.1.2",
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules-preprocessor/gjs-gts-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,13 @@ describe('supports eslint directives inside templates', () => {
{{!eslint-disable-next-line}}
{{test}}
</div>
<div>
{{!--eslint-disable--}}
{{test}}
{{test}}
{{test}}
{{!--eslint-enable--}}
</div>
</template>
`;
const results = await eslint.lintText(code, { filePath: 'my-component.gjs' });
Expand All @@ -588,6 +595,13 @@ describe('supports eslint directives inside templates', () => {
<!--eslint-disable-next-line-->
{{test}}
</div>
<div>
<!-- eslint-disable -->
{{test}}
{{test}}
{{test}}
<!-- eslint-enable -->
</div>
</template>
`;
const results = await eslint.lintText(code, { filePath: 'my-component.gjs' });
Expand Down
44 changes: 22 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -570,39 +570,39 @@
resolved "https://registry.yarnpkg.com/@glimmer/env/-/env-0.1.7.tgz#fd2d2b55a9029c6b37a6c935e8c8871ae70dfa07"
integrity sha512-JKF/a9I9jw6fGoz8kA7LEQslrwJ5jms5CXhu/aqkBWk+PmZ6pTl8mlb/eJ/5ujBGTiQzBhy5AIWF712iA+4/mw==

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

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

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

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

"@handlebars/parser@~2.0.0":
version "2.0.0"
Expand Down

0 comments on commit 8543535

Please sign in to comment.