From 1a261e2a00f7ed2bafe10e2322a46f96c9313ba6 Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 2 Nov 2023 11:18:15 +0100 Subject: [PATCH] add block comment eslint directives --- README.md | 13 +++--- lib/parsers/gjs-gts-parser.js | 9 ++++ package.json | 2 +- .../rules-preprocessor/gjs-gts-parser-test.js | 14 ++++++ yarn.lock | 44 +++++++++---------- 5 files changed, 51 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 68e1078b68..89313f5df0 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` diff --git a/lib/parsers/gjs-gts-parser.js b/lib/parsers/gjs-gts-parser.js index 38cf081088..ab449c5cb1 100644 --- a/lib/parsers/gjs-gts-parser.js +++ b/lib/parsers/gjs-gts-parser.js @@ -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]) diff --git a/package.json b/package.json index e2aa2a9a95..8f37e30be8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/lib/rules-preprocessor/gjs-gts-parser-test.js b/tests/lib/rules-preprocessor/gjs-gts-parser-test.js index 2c4926aa4d..9fab97661e 100644 --- a/tests/lib/rules-preprocessor/gjs-gts-parser-test.js +++ b/tests/lib/rules-preprocessor/gjs-gts-parser-test.js @@ -573,6 +573,13 @@ describe('supports eslint directives inside templates', () => { {{!eslint-disable-next-line}} {{test}} +
+ {{!--eslint-disable--}} + {{test}} + {{test}} + {{test}} + {{!--eslint-enable--}} +
`; const results = await eslint.lintText(code, { filePath: 'my-component.gjs' }); @@ -588,6 +595,13 @@ describe('supports eslint directives inside templates', () => { {{test}} +
+ + {{test}} + {{test}} + {{test}} + +
`; const results = await eslint.lintText(code, { filePath: 'my-component.gjs' }); diff --git a/yarn.lock b/yarn.lock index fa314ab3aa..231a8e3410 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"