From e8c8be61d3703642840cf2d764f8586cc3cdbd00 Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 27 Jul 2023 13:21:47 +0200 Subject: [PATCH] use custom parser for gts/gjs bonus: * enables type aware lints * prettier eslint plugin (with template tag prettier plugin) will just work for gts/gjs * can detect unused block params in templates * can detect undef vars in PathExpression * can add eslint directive comments in mustache or html disadvantage: * prettier will not work without template tag prettier plugin for gts/gjs files --- README.md | 27 + lib/config/recommended.js | 14 +- lib/index.js | 7 +- lib/parsers/gjs-parser.js | 446 +++++++++ lib/parsers/gts-parser.js | 7 + lib/preprocessors/glimmer.js | 313 ------ lib/preprocessors/noop.js | 25 + .../no-empty-glimmer-component-classes.js | 5 +- lib/rules/no-unused-services.js | 26 +- lib/utils/document.js | 10 +- package.json | 20 +- ...ocessor-test.js => gjs-gts-parser-test.js} | 210 +++- tests/lib/rules-preprocessor/my-component.gts | 1 + .../rules-preprocessor/tsconfig.eslint.json | 10 + .../no-empty-glimmer-component-classes.js | 10 + yarn.lock | 916 +++++------------- 16 files changed, 975 insertions(+), 1072 deletions(-) create mode 100644 lib/parsers/gjs-parser.js create mode 100644 lib/parsers/gts-parser.js delete mode 100644 lib/preprocessors/glimmer.js create mode 100644 lib/preprocessors/noop.js rename tests/lib/rules-preprocessor/{gjs-gts-processor-test.js => gjs-gts-parser-test.js} (74%) create mode 100644 tests/lib/rules-preprocessor/my-component.gts create mode 100644 tests/lib/rules-preprocessor/tsconfig.eslint.json diff --git a/README.md b/README.md index b73f8f9a16..1b3aca9038 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,33 @@ module.exports = { }; ``` +## Gts/Gjs eslint setup + +```js +// .eslintrc.js +module.exports = { + plugins: ['ember'], + extends: [ + 'eslint:recommended', + 'plugin:ember/recommended', // or other configuration + ], + overrides: [ + { + files: ['**/*.gts'], + parser: 'eslint-plugin-ember/gts-parser', + }, + { + files: ['**/*.gjs'], + parser: 'eslint-plugin-ember/gjs-parser', + } + ], + rules: { + // override / enable optional rules + 'ember/no-replace-test-comments': 'error' + } +}; +``` + ## 🧰 Configurations | | Name | Description | diff --git a/lib/config/recommended.js b/lib/config/recommended.js index e45976c2ef..f2ae501c96 100644 --- a/lib/config/recommended.js +++ b/lib/config/recommended.js @@ -1,5 +1,4 @@ const rules = require('../recommended-rules'); -const util = require('ember-template-imports/src/util'); module.exports = { root: true, @@ -29,11 +28,14 @@ module.exports = { * on -- and isn't relevant to user-land code. */ { - files: ['**/*.gjs', '**/*.gts'], - processor: 'ember/