Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use custom parser for gts/gjs #1942

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ module.exports = {
};
```

## gts/gjs

lint files having `First-Class Component Templates`

learn more [here](https://github.com/ember-template-imports/ember-template-imports)

```js
// .eslintrc.js
module.exports = {
overrides: [
{
files: ['**/*.gts', '**/*.gjs'],
parser: 'eslint-plugin-ember/gjs-gts-parser',
}
],
};
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer we specify:

overrides: [
{
  files: ["**/*.{gjs,gts}"],
  parser: 'ember',
}
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this also be okay?

{
      files: ['**/*.gts'],
      parser: 'eslint-plugin-ember/gts-parser',
    },
    {
      files: ['**/*.gjs'],
      parser: 'eslint-plugin-ember/gjs-parser',
    },

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine, but just wondering, is there a need or benefit to separating the parsers, or can they be specified as one?

overrides: [
  {
    files: ["**/*.{gjs,gts}"],
    parser: 'eslint-plugin-ember/gjs-gts-parser',
  }
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could.
we would need to detect if the extension is gts or gjs and choose by that, which internal parser should be chosen

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that be simple? Is there any reason why we shouldn't just auto-detect the extension for the user? If the user doesn't care about distinguishing between these file types, then we can avoid exposing that complexity to the user, and just handle it internally, right?

```

## 🧰 Configurations

<!-- begin auto-generated configs list -->
Expand Down
9 changes: 3 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,9 @@ 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', '**/*.gjs'],
parser: 'eslint-plugin-ember/gjs-gts-parser',
processor: 'ember/<noop>',
},
],
};
7 changes: 2 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

const requireIndex = require('requireindex');

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

module.exports = {
rules: requireIndex(`${__dirname}/rules`),
Expand All @@ -12,8 +11,6 @@ module.exports = {
},
processors: {
// https://eslint.org/docs/developer-guide/working-with-plugins#file-extension-named-processor
'.gjs': gjs,
'.gts': gjs,
'<template>': gjs,
'<noop>': noop,
},
};
Loading