Skip to content

Commit

Permalink
use custom parser for gts/gjs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
patricklx committed Aug 22, 2023
1 parent 1b172a6 commit a96dc3b
Show file tree
Hide file tree
Showing 14 changed files with 1,005 additions and 1,068 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@ module.exports = {
};
```

To correctly parse gjs/gts:
Do not set an override for the parser in the global config.
To use e.g. the typescript parser, the following should be used

```js
// .eslintrc.js
module.exports = {
plugins: ['ember'],
// parser: '@typescript-eslint/parser', <-- needs to be removed, or set the gts/gjs one
// so we could also have:
// parser: "eslint-plugin-ember/gts-parser",
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/base', // or typescript-eslint/recommended, must come before plugin:ember/recommended
'plugin:ember/recommended', // or other configuration
],
rules: {
// override / enable optional rules
'ember/no-replace-test-comments': 'error'
}
};
```

## 🧰 Configurations

| | Name | Description |
Expand Down
12 changes: 6 additions & 6 deletions lib/config/recommended.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const rules = require('../recommended-rules');
const util = require('ember-template-imports/src/util');

module.exports = {
root: true,
Expand Down Expand Up @@ -29,11 +28,12 @@ module.exports = {
* on -- and isn't relevant to user-land code.
*/
{
files: ['**/*.gjs', '**/*.gts'],
processor: 'ember/<template>',
globals: {
[util.TEMPLATE_TAG_PLACEHOLDER]: 'readonly',
},
files: ['**/*.gts'],
parser: require.resolve('../parsers/gts-parser'),
},
{
files: ['**/*.gjs'],
parser: require.resolve('../parsers/gjs-parser'),
},
],
};
8 changes: 0 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@

const requireIndex = require('requireindex');

const gjs = require('./preprocessors/glimmer');

module.exports = {
rules: requireIndex(`${__dirname}/rules`),
configs: requireIndex(`${__dirname}/config`),
utils: {
ember: require('./utils/ember'),
},
processors: {
// https://eslint.org/docs/developer-guide/working-with-plugins#file-extension-named-processor
'.gjs': gjs,
'.gts': gjs,
'<template>': gjs,
},
};
Loading

0 comments on commit a96dc3b

Please sign in to comment.