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

require-tagless-components rule fails for Service.extend #601

Closed
mehulkar opened this issue Nov 20, 2019 · 15 comments · Fixed by #1211
Closed

require-tagless-components rule fails for Service.extend #601

mehulkar opened this issue Nov 20, 2019 · 15 comments · Fixed by #1211
Labels

Comments

@mehulkar
Copy link

In tests/integration/components/foo-test.js, if I have:

import Service from '@ember/service';
Service.extend({});

the lint rule fails

@bmish bmish added the Bug label Nov 20, 2019
@bmish
Copy link
Member

bmish commented Nov 20, 2019

Can you include the error it fails with?

CC: @alexlafroscia

@bmish bmish changed the title require-tagless-components fails for Service.extend require-tagless-components rule fails for Service.extend Nov 20, 2019
@mehulkar
Copy link
Author

Seems similar to #235, and based on an initial look, looks like the problem is here: https://github.com/ember-cli/eslint-plugin-ember/blob/master/lib/utils/ember.js#L171-L192

@mehulkar
Copy link
Author

@bmish do you mean the lint failure error message? (I'm not getting an exception thrown, just a false positive on the lint rule)

113:21  error  Please switch to a tagless component by setting `tagName: ''` or converting to a Glimmer component  ember/require-tagless-components

@alexlafroscia
Copy link
Contributor

alexlafroscia commented Nov 20, 2019

Ah, I suppose we missed test cases for Ember objects that are not components! I can take a look at fixing this tonight. Feel free to assign this bug to me!

alexlafroscia added a commit to alexlafroscia/eslint-plugin-ember that referenced this issue Nov 21, 2019
@alexlafroscia
Copy link
Contributor

I added a couple of test cases that look like your example @mehulkar -- however, the tests don't actually report the false positive that you're seeing.

Are you running the latest version of eslint-plugin-ember?

@bmish
Copy link
Member

bmish commented Nov 21, 2019

Try specifying a component filename in the unit test.

@alexlafroscia
Copy link
Contributor

alexlafroscia commented Nov 21, 2019

Oooh yup, that's what it was! Configuring that causes a failure.

It really feels like getting away from file names as part of the lint rules would be good, and instead just looking at the actual source of the import 😅

I'll keep following the thread here and figure out what's up!

@bmish
Copy link
Member

bmish commented Nov 21, 2019

Yeah, definitely agree that we should be checking imports instead of file paths, tracking that improvement with #590.

@alexlafroscia
Copy link
Contributor

Would you be OK with a PR that fixed that? It would be pretty extensive, but I think that's really the right fix in this case.

@bmish
Copy link
Member

bmish commented Nov 21, 2019

Yeah, since this lint rule just relies on emberUtils.isEmberComponent(), I agree that the right fix would be to check imports instead of filepaths inside that util function. That would affect a lot of rules, but I would support pursuing that fix.

@alexlafroscia
Copy link
Contributor

Sweet! I'm going to take a stab at this, I have some time I can invest in it over the next few days

alexlafroscia added a commit to alexlafroscia/eslint-plugin-ember that referenced this issue Nov 21, 2019
The original logic for determining if a Identifier was of a specific Ember class used the file name to make this decision, rather than resolving the import of the Identifier back to the Ember module it was imported from.

This ended up causing a number of issues in lint rule in cases where people places a class in a location that was unexpected based on Ember’s convention. Such issues include ember-cli#601 and ember-cli#430.

Making this change avoids the need for something like ember-cli#213, which adds additional logic based on file names to prevent some of these issues.

Closes ember-cli#590
alexlafroscia added a commit to alexlafroscia/eslint-plugin-ember that referenced this issue Nov 21, 2019
alexlafroscia added a commit to alexlafroscia/eslint-plugin-ember that referenced this issue Nov 21, 2019
The original logic for determining if a Identifier was of a specific Ember class used the file name to make this decision, rather than resolving the import of the Identifier back to the Ember module it was imported from.

This ended up causing a number of issues in lint rule in cases where people places a class in a location that was unexpected based on Ember’s convention. Such issues include ember-cli#601 and ember-cli#430.

Making this change avoids the need for something like ember-cli#213, which adds additional logic based on file names to prevent some of these issues.

Closes ember-cli#590
alexlafroscia added a commit to alexlafroscia/eslint-plugin-ember that referenced this issue Nov 21, 2019
@Turbo87
Copy link
Member

Turbo87 commented Dec 22, 2020

@mehulkar @alexlafroscia is this still an issue or has it been fixed by #603?

@alexlafroscia
Copy link
Contributor

That PR was never merged, and at this point I can't see myself coming back to it unfortunately. I just don't have much OSS time these days.

@Turbo87
Copy link
Member

Turbo87 commented Dec 22, 2020

oh, lol, I totally missed that the PR was still open 😅

@ballPointPenguin
Copy link

I see false positives as well when lodash extend is in use within a component, eg

_.extend(notAComponentOrClass(), { foo: 'bar' })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants