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

`no-empty-glimmer-component-classes` reports violation for glimmer component when `this` reference in template

Open Mifrill opened this issue 3 years ago • 2 comments

Glimmer component required js file when template contains this reference usage. In this case, we need to create a js file with empty-glimmer-component-class and it is not an error, right?

But we have eslint offense:

yarn lint:js
yarn run v1.21.1
$ eslint . --cache

/demo-ember-no-empty-glimmer-component-classes-bug-when-this-in-template/app/components/checkbox.js
  4:16  error  Do not create empty backing classes for Glimmer components  ember/no-empty-glimmer-component-classes

✖ 1 problem (1 error, 0 warnings)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

it force to skip this rule, which looks incorrect:

// eslint-disable-next-line ember/no-empty-glimmer-component-classes

Details: https://github.com/Mifrill/demo-ember-no-empty-glimmer-component-classes-bug-when-this-in-template/blob/main/app/components/checkbox.hbs

https://github.com/Mifrill/demo-ember-no-empty-glimmer-component-classes-bug-when-this-in-template/blob/main/app/components/checkbox.js

"ember-source": "~3.24.0",
"eslint": "^7.17.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-ember": "^10.1.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",

Related to:

  • https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/no-empty-glimmer-component-classes.md
  • https://discuss.emberjs.com/t/can-addons-use-template-only-components/17399/6

Repo with bug reproduce: https://github.com/Mifrill/demo-ember-no-empty-glimmer-component-classes-bug-when-this-in-template

Mifrill avatar Jul 29 '21 06:07 Mifrill

Looking at your example given, I would question if the backing JavaScript class should be empty. I think it should explicitly declare the isChecked property, which is used in the template. It should also be decorated with @tracked. Current code relies on {{toogle}} helper using Ember.set(). Otherwise the property wouldn't be tracked.

jelhan avatar Oct 06 '21 06:10 jelhan

:thinking: interesting point, my thought was about: declare the tracked property only if going to use it in js file itself, because it's working fine in a template without tracked decorator in js

Mifrill avatar Oct 06 '21 07:10 Mifrill