-
Notifications
You must be signed in to change notification settings - Fork 398
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 eslint to catch import mistakes and style nits #945
Conversation
I'm on PTO without my laptop so I'll have to pass this review to someone else. It has conflicts though. |
This is awesome. Let me know when the conflicts are resolved and I'll take a closer look. |
@@ -10,7 +10,7 @@ import AddonDetail, { allowedDescriptionTags } | |||
import I18nProvider from 'core/i18n/Provider'; | |||
import InstallButton from 'core/components/InstallButton'; | |||
|
|||
import { getFakeI18nInst } from 'tests/client/helpers'; | |||
import { getFakeI18nInst } from '../../helpers'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to not need non-relative imports here - I see we wouldn't want cwd configured in the linter though. We could explicity add the project root couldn't we?
Using relative imports gets really messy fast with all the ../../../../
. Also it makes test code less easily portable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we directly add the project root can we do that just for tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add the project root but it feels a bit risky to me. If you look at our project root we have a lot of directories. For example, ./config
is a directory but we also use the config
from node_module as well. This actually confuses the linter in some places (which may be a bug). It doesn't cause errors though so we could do it.
The other alternative is to push tests into another subdirectory like tests/testlib
and import everything from testlib
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah node-config is a bit magical in the way it works.
I'm not sure I understand the need to suffix components with Historically our usage was like this: import WhateverComponent from 'disco/components/whatever'; and that's going to get the default exported component. But if you want the un-wrapped component we do: import { WhateverComponent } from 'disco/components/whatever'; So am I right in thinking that adding |
It really comes down to this rule: https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-named-as-default-member.md Do we want to keep it? If we do, we can't name components the same as the default variable we use to import them with. We can do this just fine:
but we can't name the undecorated class
I can see how this kind of mistake might happen so the rule seems useful. To use the rule, we have to rename all the base components to something like
This is actually kind of nice because it makes it unambiguous that you meant to import a base component for a test, one that is not decorated. |
Ok that works for me - keep it in. |
ooh, I can maybe solve the test import path issue by adding the project root path only to |
It's worth bearing in mind that the server code gets the root in the NODE_PATH. Maybe we can get rid of that? See package.json. |
d'oh! NODE_PATH is not recognized. Once that's fixed we could switch to that. However, adding the entire project root to |
To clarify: I thought that maybe we could use |
@muffinresearch thanks for the review. If anything breaks while I'm on PTO next week, you know what to do :) (and sorry). I think it should be fine. |
Fixes mozilla/addons#9804
If
thing.Foo
actually exists then this could have been a typo. The developer probably meant:I feel like we were abusing this to get at raw components without their redux decorators. Thus, I needed to rename all non-decorated components from
TheComponent
toTheComponentBase
. If this makes things awkward, just let me know and we can change it back.karma runs from the rootwe setNODE_PATH
and technically we could allow it in the linter by addingcwd
to the import resolver. However, I think this is bad practice because it makes other imports confusing. For example, isimport config
getting the one fromnode_modules
or the one at./config
? I don't think it's too gnarly to use relative imports in the test suite (like../../helpers
). UPDATE we decided to allow relative imports in the test code.