diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 987166b3ae..76ba9052c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: os: [ ubuntu, windows ] - node-version: [16.x, 18.x] + node-version: [14.x, 16.x, 18.x] steps: - uses: actions/checkout@v3 diff --git a/lib/parsers/gjs-parser.js b/lib/parsers/gjs-parser.js index f0f275984a..67152116b8 100644 --- a/lib/parsers/gjs-parser.js +++ b/lib/parsers/gjs-parser.js @@ -9,7 +9,6 @@ const glimmerVisitorKeys = require(path.join( )).default; const babelParser = require('@babel/eslint-parser'); const typescriptParser = require('@typescript-eslint/parser'); -// eslint-disable-next-line node/no-missing-require const TypescriptScope = require('@typescript-eslint/scope-manager'); const { Reference, Scope, Variable, Definition } = require('eslint-scope'); @@ -162,31 +161,33 @@ function tokenize(template, doc, startOffset) { } current += c; } else { + let range = [startOffset + start, startOffset + i]; if (current.length > 0) { const t = { type: 'word', value: current, - range: [startOffset + start, startOffset + i], - start: startOffset + start, - end: startOffset + i, + range: range, + start: range[0], + end: range[1], loc: { - start: { ...doc.offsetToPosition(startOffset + start), index: startOffset + start }, - end: { ...doc.offsetToPosition(startOffset + i), index: startOffset + i }, + start: { ...doc.offsetToPosition(range[0]), index: range[0] }, + end: { ...doc.offsetToPosition(range[1]), index: range[1] }, }, }; tokens.push(t); current = ''; } + range = [startOffset + i, startOffset + i + 1]; if (!isWhiteSpace(c)) { tokens.push({ type: 'punctuator', value: c, - range: [startOffset + i, startOffset + i + 1], - start: startOffset + i, - end: startOffset + i + 1, + range: range, + start: range[0], + end: range[1], loc: { - start: { ...doc.offsetToPosition(startOffset + i), index: startOffset + i }, - end: { ...doc.offsetToPosition(startOffset + i + 1), index: startOffset + i + 1 }, + start: { ...doc.offsetToPosition(range[0]), index: range[0] }, + end: { ...doc.offsetToPosition(range[1]), index: range[1] }, }, }); } @@ -233,6 +234,17 @@ function preprocessGlimmerTemplates(info, code) { ast.content = template; const allNodeTypes = new Set(); for (const n of allNodes) { + // remove empty text nodes + if (n.type === 'TextNode' && n.chars.trim().length === 0) { + if (n.parent.children) { + const idx = n.parent.children.indexOf(n); + n.parent.children.splice(idx, 1); + } + if (n.parent.body) { + const idx = n.parent.body.indexOf(n); + n.parent.body.splice(idx, 1); + } + } if (n.type === 'PathExpression') { n.head.range = [ range[0] + docLines.positionToOffset(n.head.loc.start), diff --git a/package.json b/package.json index 83905f582d..7ca65f818f 100644 --- a/package.json +++ b/package.json @@ -68,8 +68,8 @@ "@babel/eslint-parser": "^7.15.8", "@ember-data/rfc395-data": "^0.0.4", "@glimmer/syntax": "^0.84.2", - "@typescript-eslint/parser": "^5.31.0", - "@typescript-eslint/scope-manager": "^6.2.0", + "@typescript-eslint/parser": "^5.62.0", + "@typescript-eslint/scope-manager": "^5.62.0", "css-tree": "^2.0.4", "ember-rfc176-data": "^0.3.15", "ember-template-tag": "^2.3.1", @@ -84,7 +84,7 @@ "devDependencies": { "@babel/plugin-proposal-class-properties": "^7.13.0", "@babel/plugin-proposal-decorators": "^7.15.8", - "@typescript-eslint/eslint-plugin": "^6.3.0", + "@typescript-eslint/eslint-plugin": "^5.62.0", "eslint": "^8.46.0", "eslint-config-prettier": "^8.5.0", "eslint-doc-generator": "^1.0.0", diff --git a/tests/lib/rules-preprocessor/gjs-gts-processor-test.js b/tests/lib/rules-preprocessor/gjs-gts-processor-test.js index 7c4bc9aaf7..4e8a526c5b 100644 --- a/tests/lib/rules-preprocessor/gjs-gts-processor-test.js +++ b/tests/lib/rules-preprocessor/gjs-gts-processor-test.js @@ -44,9 +44,12 @@ function initESLint(parser = gjsParser) { { files: ['**/*.gts'], extends: [ - 'plugin:@typescript-eslint/recommended-type-checked', + 'plugin:@typescript-eslint/recommended-requiring-type-checking', 'plugin:ember/recommended', ], + rules: { + 'no-trailing-spaces': 'error', + }, }, ], rules: { @@ -75,7 +78,7 @@ const valid = [ super(...arguments); } } - `, + `, }, { filename: 'my-component.gjs', @@ -128,7 +131,9 @@ const valid = [ } export default class List extends Component> { - + }`, parser: gtsParser, }, @@ -312,6 +317,29 @@ const invalid = [ }, ], }, + { + filename: 'my-component.gts', + parser: gtsParser, + code: ` + import Component from '@glimmer/component'; + + export default class MyComponent extends Component { + foo = 'bar'; + + + }`, + errors: [ + { + message: 'Trailing spaces not allowed.', + line: 8, + endLine: 8, + column: 22, + endColumn: 24, + }, + ], + }, { filename: 'my-component.gjs', code: ` @@ -403,7 +431,9 @@ describe('template-vars', () => { // eslint-disable-next-line jest/valid-title it(code, async () => { const eslint = initESLint(parser); - const results = await eslint.lintText(code, { filePath: filename }); + const results = await eslint.lintText(code, { + filePath: `./tests/lib/rules-preprocessor/${filename}`, + }); const resultErrors = results.flatMap((result) => result.messages); expect(resultErrors).toHaveLength(errors.length); diff --git a/tests/lib/rules-preprocessor/my-component.gts b/tests/lib/rules-preprocessor/my-component.gts index e69de29bb2..c0fdc022b3 100644 --- a/tests/lib/rules-preprocessor/my-component.gts +++ b/tests/lib/rules-preprocessor/my-component.gts @@ -0,0 +1 @@ +// needed for typed linting diff --git a/yarn.lock b/yarn.lock index 545cb69d1f..a462f60aa1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -398,14 +398,14 @@ resolved "https://registry.yarnpkg.com/@ember-data/rfc395-data/-/rfc395-data-0.0.4.tgz#ecb86efdf5d7733a76ff14ea651a1b0ed1f8a843" integrity sha512-tGRdvgC9/QMQSuSuJV45xoyhI0Pzjm7A9o/MVVA3HakXIImJbbzx/k/6dO9CUEQXIyS2y0fW6C1XaYOG7rY0FQ== -"@eslint-community/eslint-utils@^4.1.2", "@eslint-community/eslint-utils@^4.2.0", "@eslint-community/eslint-utils@^4.4.0": +"@eslint-community/eslint-utils@^4.1.2", "@eslint-community/eslint-utils@^4.2.0": version "4.4.0" resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz#a23514e8fb9af1269d5f7788aa556798d61c6b59" integrity sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA== dependencies: eslint-visitor-keys "^3.3.0" -"@eslint-community/regexpp@^4.5.1", "@eslint-community/regexpp@^4.6.1": +"@eslint-community/regexpp@^4.4.0", "@eslint-community/regexpp@^4.6.1": version "4.6.2" resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.6.2.tgz#1816b5f6948029c5eaacb0703b850ee0cb37d8f8" integrity sha512-pPTNuaAG3QMH+buKyBIGJs3g/S5y0caxw0ygM3YyE6yJFySwiGGSzA+mM3KJ8QQvzeLh3blwgSonkFjgQdxzMw== @@ -1062,7 +1062,7 @@ dependencies: "@types/istanbul-lib-report" "*" -"@types/json-schema@^7.0.12", "@types/json-schema@^7.0.9": +"@types/json-schema@^7.0.9": version "7.0.12" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.12.tgz#d70faba7039d5fca54c83c7dbab41051d2b6f6cb" integrity sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA== @@ -1104,7 +1104,7 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.3.tgz#3e51a17e291d01d17d3fc61422015a933af7a08f" integrity sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA== -"@types/semver@^7.3.12", "@types/semver@^7.5.0": +"@types/semver@^7.3.12": version "7.5.0" resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.0.tgz#591c1ce3a702c45ee15f47a42ade72c2fd78978a" integrity sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw== @@ -1136,25 +1136,23 @@ resolved "https://registry.yarnpkg.com/@types/yoga-layout/-/yoga-layout-1.9.2.tgz#efaf9e991a7390dc081a0b679185979a83a9639a" integrity sha512-S9q47ByT2pPvD65IvrWp7qppVMpk9WGMbVq9wbWZOHg6tnXSD4vyhao6nOSBwwfDdV2p3Kx9evA9vI+XWTfDvw== -"@typescript-eslint/eslint-plugin@^6.3.0": - version "6.3.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.3.0.tgz#e751e148aab7ccaf8a7bfd370f7ce9e6bdd1f3f4" - integrity sha512-IZYjYZ0ifGSLZbwMqIip/nOamFiWJ9AH+T/GYNZBWkVcyNQOFGtSMoWV7RvY4poYCMZ/4lHzNl796WOSNxmk8A== - dependencies: - "@eslint-community/regexpp" "^4.5.1" - "@typescript-eslint/scope-manager" "6.3.0" - "@typescript-eslint/type-utils" "6.3.0" - "@typescript-eslint/utils" "6.3.0" - "@typescript-eslint/visitor-keys" "6.3.0" +"@typescript-eslint/eslint-plugin@^5.62.0": + version "5.62.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.62.0.tgz#aeef0328d172b9e37d9bab6dbc13b87ed88977db" + integrity sha512-TiZzBSJja/LbhNPvk6yc0JrX9XqhQ0hdh6M2svYfsHGejaKFIAGd9MQ+ERIMzLGlN/kZoYIgdxFV0PuljTKXag== + dependencies: + "@eslint-community/regexpp" "^4.4.0" + "@typescript-eslint/scope-manager" "5.62.0" + "@typescript-eslint/type-utils" "5.62.0" + "@typescript-eslint/utils" "5.62.0" debug "^4.3.4" graphemer "^1.4.0" - ignore "^5.2.4" - natural-compare "^1.4.0" + ignore "^5.2.0" natural-compare-lite "^1.4.0" - semver "^7.5.4" - ts-api-utils "^1.0.1" + semver "^7.3.7" + tsutils "^3.21.0" -"@typescript-eslint/parser@^5.31.0": +"@typescript-eslint/parser@^5.62.0": version "5.62.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.62.0.tgz#1b63d082d849a2fcae8a569248fbe2ee1b8a56c7" integrity sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA== @@ -1164,7 +1162,7 @@ "@typescript-eslint/typescript-estree" "5.62.0" debug "^4.3.4" -"@typescript-eslint/scope-manager@5.62.0": +"@typescript-eslint/scope-manager@5.62.0", "@typescript-eslint/scope-manager@^5.62.0": version "5.62.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.62.0.tgz#d9457ccc6a0b8d6b37d0eb252a23022478c5460c" integrity sha512-VXuvVvZeQCQb5Zgf4HAxc04q5j+WrNAtNh9OwCsCgpKqESMTu3tF/jhZ3xG6T4NZwWl65Bg8KuS2uEvhSfLl0w== @@ -1172,47 +1170,21 @@ "@typescript-eslint/types" "5.62.0" "@typescript-eslint/visitor-keys" "5.62.0" -"@typescript-eslint/scope-manager@6.3.0": - version "6.3.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.3.0.tgz#6b74e338c4b88d5e1dfc1a28c570dd5cf8c86b09" - integrity sha512-WlNFgBEuGu74ahrXzgefiz/QlVb+qg8KDTpknKwR7hMH+lQygWyx0CQFoUmMn1zDkQjTBBIn75IxtWss77iBIQ== - dependencies: - "@typescript-eslint/types" "6.3.0" - "@typescript-eslint/visitor-keys" "6.3.0" - -"@typescript-eslint/scope-manager@^6.2.0": - version "6.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.2.0.tgz#412a710d8fa20bc045533b3b19f423810b24f87a" - integrity sha512-1ZMNVgm5nnHURU8ZSJ3snsHzpFeNK84rdZjluEVBGNu7jDymfqceB3kdIZ6A4xCfEFFhRIB6rF8q/JIqJd2R0Q== - dependencies: - "@typescript-eslint/types" "6.2.0" - "@typescript-eslint/visitor-keys" "6.2.0" - -"@typescript-eslint/type-utils@6.3.0": - version "6.3.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-6.3.0.tgz#3bf89ccd36621ddec1b7f8246afe467c67adc247" - integrity sha512-7Oj+1ox1T2Yc8PKpBvOKWhoI/4rWFd1j7FA/rPE0lbBPXTKjdbtC+7Ev0SeBjEKkIhKWVeZSP+mR7y1Db1CdfQ== +"@typescript-eslint/type-utils@5.62.0": + version "5.62.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.62.0.tgz#286f0389c41681376cdad96b309cedd17d70346a" + integrity sha512-xsSQreu+VnfbqQpW5vnCJdq1Z3Q0U31qiWmRhr98ONQmcp/yhiPJFPq8MXiJVLiksmOKSjIldZzkebzHuCGzew== dependencies: - "@typescript-eslint/typescript-estree" "6.3.0" - "@typescript-eslint/utils" "6.3.0" + "@typescript-eslint/typescript-estree" "5.62.0" + "@typescript-eslint/utils" "5.62.0" debug "^4.3.4" - ts-api-utils "^1.0.1" + tsutils "^3.21.0" "@typescript-eslint/types@5.62.0": version "5.62.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.62.0.tgz#258607e60effa309f067608931c3df6fed41fd2f" integrity sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ== -"@typescript-eslint/types@6.2.0": - version "6.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.2.0.tgz#b341a4e6d5f609267306b07afc6f62bcf92b1495" - integrity sha512-1nRRaDlp/XYJQLvkQJG5F3uBTno5SHPT7XVcJ5n1/k2WfNI28nJsvLakxwZRNY5spuatEKO7d5nZWsQpkqXwBA== - -"@typescript-eslint/types@6.3.0": - version "6.3.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.3.0.tgz#84517f1427923e714b8418981e493b6635ab4c9d" - integrity sha512-K6TZOvfVyc7MO9j60MkRNWyFSf86IbOatTKGrpTQnzarDZPYPVy0oe3myTMq7VjhfsUAbNUW8I5s+2lZvtx1gg== - "@typescript-eslint/typescript-estree@5.62.0": version "5.62.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz#7d17794b77fabcac615d6a48fb143330d962eb9b" @@ -1226,33 +1198,7 @@ semver "^7.3.7" tsutils "^3.21.0" -"@typescript-eslint/typescript-estree@6.3.0": - version "6.3.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.3.0.tgz#20e1e10e2f51cdb9e19a2751215cac92c003643c" - integrity sha512-Xh4NVDaC4eYKY4O3QGPuQNp5NxBAlEvNQYOqJquR2MePNxO11E5K3t5x4M4Mx53IZvtpW+mBxIT0s274fLUocg== - dependencies: - "@typescript-eslint/types" "6.3.0" - "@typescript-eslint/visitor-keys" "6.3.0" - debug "^4.3.4" - globby "^11.1.0" - is-glob "^4.0.3" - semver "^7.5.4" - ts-api-utils "^1.0.1" - -"@typescript-eslint/utils@6.3.0": - version "6.3.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-6.3.0.tgz#0898c5e374372c2092ca1b979ea7ee9cc020ce84" - integrity sha512-hLLg3BZE07XHnpzglNBG8P/IXq/ZVXraEbgY7FM0Cnc1ehM8RMdn9mat3LubJ3KBeYXXPxV1nugWbQPjGeJk6Q== - dependencies: - "@eslint-community/eslint-utils" "^4.4.0" - "@types/json-schema" "^7.0.12" - "@types/semver" "^7.5.0" - "@typescript-eslint/scope-manager" "6.3.0" - "@typescript-eslint/types" "6.3.0" - "@typescript-eslint/typescript-estree" "6.3.0" - semver "^7.5.4" - -"@typescript-eslint/utils@^5.10.0", "@typescript-eslint/utils@^5.38.1": +"@typescript-eslint/utils@5.62.0", "@typescript-eslint/utils@^5.10.0", "@typescript-eslint/utils@^5.38.1": version "5.62.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.62.0.tgz#141e809c71636e4a75daa39faed2fb5f4b10df86" integrity sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ== @@ -1274,22 +1220,6 @@ "@typescript-eslint/types" "5.62.0" eslint-visitor-keys "^3.3.0" -"@typescript-eslint/visitor-keys@6.2.0": - version "6.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.2.0.tgz#71943f42fdaa2ec86dc3222091f41761a49ae71a" - integrity sha512-QbaYUQVKKo9bgCzpjz45llCfwakyoxHetIy8CAvYCtd16Zu1KrpzNHofwF8kGkpPOxZB2o6kz+0nqH8ZkIzuoQ== - dependencies: - "@typescript-eslint/types" "6.2.0" - eslint-visitor-keys "^3.4.1" - -"@typescript-eslint/visitor-keys@6.3.0": - version "6.3.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.3.0.tgz#8d09aa3e389ae0971426124c155ac289afbe450a" - integrity sha512-kEhRRj7HnvaSjux1J9+7dBen15CdWmDnwrpyiHsFX6Qx2iW5LOBUgNefOFeh2PjWPlNwN8TOn6+4eBU3J/gupw== - dependencies: - "@typescript-eslint/types" "6.3.0" - eslint-visitor-keys "^3.4.1" - JSONStream@^1.3.5: version "1.3.5" resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0" @@ -6497,7 +6427,7 @@ semver@^6.1.0, semver@^6.3.0, semver@^6.3.1: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== -semver@^7.0.0, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semver@^7.3.8, semver@^7.5.3, semver@^7.5.4: +semver@^7.0.0, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semver@^7.3.8, semver@^7.5.3: version "7.5.4" resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e" integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA== @@ -6992,11 +6922,6 @@ trim-newlines@^3.0.0: resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-3.0.1.tgz#260a5d962d8b752425b32f3a7db0dcacd176c144" integrity sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw== -ts-api-utils@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.0.1.tgz#8144e811d44c749cd65b2da305a032510774452d" - integrity sha512-lC/RGlPmwdrIBFTX59wwNzqh7aR2otPNPR/5brHZm/XKFYKsfqxihXUe9pU3JI+3vGkl+vyCoNNnPhJn3aLK1A== - tsconfig-paths@^3.14.1: version "3.14.2" resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz#6e32f1f79412decd261f92d633a9dc1cfa99f088"