eslint-plugin-ember icon indicating copy to clipboard operation
eslint-plugin-ember copied to clipboard

Support `<template>` (no-undef, etc)

Open NullVoxPopuli opened this issue 4 years ago • 8 comments

Per RFC: https://github.com/emberjs/rfcs/pull/779

Overall plan, and maybe this is silly, but:

  • for *gjs and *gts files, use a parser plugin, similar to eslint-plugin-markdown

Supports parsing <template> and discovering if tokens are violating no-undef, etc

Something to keep an eye on in the future:

  • https://github.com/eslint/eslint/issues/13481

NullVoxPopuli avatar Dec 18 '21 23:12 NullVoxPopuli

Jest: "global" coverage threshold for branches (96%) not met: 95.98%

so close. lol

NullVoxPopuli avatar Feb 05 '22 17:02 NullVoxPopuli

Green!

NullVoxPopuli avatar Feb 05 '22 17:02 NullVoxPopuli

And can you talk about the timeline given that the RFC hasn't been approved yet? We don't want to merge support for a feature that hasn't been approved yet, correct?

It's now in final comment period! 🎉

Can you explain the semver implications of this PR (aside from dropping support for old Node/ESLint versions which we will do separately/regardless)?

The capabilities (I think) are only additive, and no one expecting semver guarantees is currently using gjs/gts, so once people start to author gjs/gts, they'll have ESLint run on those files (currently ESLint skips those files).

NullVoxPopuli avatar Feb 19 '22 16:02 NullVoxPopuli

Just tried this in a real project over here:

  • https://github.com/NullVoxPopuli/limber/pull/392
  • with: https://github.com/NullVoxPopuli/eslint-configs/pull/166

And there are errors -- so it's possible I've misconfigured the tests, or have missed something in my eslint configs, so.. fyi, I guess.

I'll report back when I can successfully run eslint with gjs/gts in a real project

NullVoxPopuli avatar Feb 25 '22 02:02 NullVoxPopuli

Will unused variable detection come into play at all here (this PR or future PR)? There's an ESLint API for helping the no-unused-vars rule detect if variables are used, e.g. in the react/jsx-uses-var rule (implementation).

bmish avatar Sep 13 '22 15:09 bmish

@bmish we don't need to worry about unused vars in JS because eslint takes care of it (eslint sees the raw format, rather than the <template> stuff) :tada:

NullVoxPopuli avatar Sep 14 '22 01:09 NullVoxPopuli

Good news! tested this on a project with gjs -- things work, which is nice.

const one = 1;
const two = 2;

<template>
  {{one}}
</template>
❯ yarn/pnpm/npm lint:js --fix
$ eslint . --cache --fix

<repo>/app/components/test.gjs
  2:7  error  'two' is assigned a value but never used  no-unused-vars

✖ 1 problem (1 error, 0 warnings)}

Bad news is that prettier doesn't know how to parse gjs, so to lint gjs, I had to remove:

    'plugin:prettier/recommended',

from my config.

So, I think that means we need to PR parser support to prettier

NullVoxPopuli avatar Sep 20 '22 02:09 NullVoxPopuli

Here is a more robust solution:

adding this entry to the app + addon blueprint's .eslintrc.js config:

    {
      files: ['**/*.gjs', '**/*.gts'],
      rules: {
        'prettier/prettier': 'off',
      }
    },

NullVoxPopuli avatar Sep 20 '22 02:09 NullVoxPopuli

Can you merge/rebase the latest master?

bmish avatar Oct 12 '22 17:10 bmish

Rebased

NullVoxPopuli avatar Oct 25 '22 13:10 NullVoxPopuli