-
Notifications
You must be signed in to change notification settings - Fork 63
Add eslint rules for imports and eslint comments #999
Conversation
195a096
to
58a4ef6
Compare
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.
The codebase will look much more organized! I'll look into it further, but I did notice a small detail that maybe belongs in a separate issue/PR.
@@ -73,12 +75,89 @@ module.exports = { | |||
], | |||
'unicorn/filename-case': ['error', { case: 'kebabCase' }], | |||
'@typescript-eslint/ban-ts-comment': ['warn'], | |||
'@typescript-eslint/no-var-requires': ['warn'], | |||
'@typescript-eslint/no-var-requires': ['off'], |
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.
This change seems unrelated, I'd think we have to discuss whether disabling this rule or not.
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.
Sure thing. I don't really know why those files are being imported using requires.
FWIW, I turned it off because we didn't previously have this rule until the introduction of the TypeScript eslint package, so it seemed safe to turn off and add back if we found it was causing issues with TypeScript stuff in particular. There's apparently no issue with it for other things?
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.
Also, based on the description that the ESLint plugin gives, I think we can safely disable it anyway: https://typescript-eslint.io/rules/no-var-requires/#when-not-to-use-it
66f9cd3
to
0fcaa0c
Compare
import useSearchType from '~/composables/use-search-type' | ||
import { isMinScreen } from '~/composables/use-media-query' | ||
|
||
import caretDownIcon from '~/assets/icons/caret-down.svg' | ||
import VIcon from '~/components/VIcon/VIcon.vue' |
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.
It only reorders the imports, and does not add empty lines between groups, right? The blank line between two components # 37 could be removed, too.
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.
It does add empty lines between groups and allows optional empty lines within groups.
import audioIcon from 'assets/icons/audio-wave.svg' | ||
import imageIcon from 'assets/icons/image.svg' | ||
import allIcon from 'assets/icons/all-content.svg' | ||
import audioIcon from '~/assets/icons/audio-wave.svg' |
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.
How did this get in 🤦 . I think it raises an error in tests when there is no leading ~/
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.
Interesting! Well our linter will prevent it from now 🙂
import useSearchType from '~/composables/use-search-type' | ||
|
||
import VItemGroup from '~/components/VItemGroup/VItemGroup.vue' | ||
|
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.
Oh, it even adds blank lines between components... 🤔
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.
Thank you so much for adding this! It would make reviewing so much easier on the eyes!
0fcaa0c
to
2f0adce
Compare
2f0adce
to
db7d179
Compare
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.
I apologize for the delay—I had actually reviewed this previously, last week, and I guess I never submit my review for some reason.
I had no idea import order rules existed, and I'm so excited that we're able to enforce standards we've been conventionally following but sometimes miss. The app is working as expected, the comments on the import order rules are great, and lgtm!
Fixes
Fixes #901 by @krysal
Fixes #855 by @sarayourfriend
Description
Adds two new ESLint plugins,
eslint-comments
andimport
and configures them and fixes any errors they surfaced.The biggest change here is of course the import order linting. I tried to create an ordering scheme that more or less matched what we'd been doing on our own. I'm not sure it's perfect and we can bikeshed a little bit about it in this PR (in particular whether treating assets and components as separate groups makes sense).
Overall just hoping to get some consistency 🙂
Testing Instructions
Checkout the branch and try some of the new rules out. Almost all the import ones are auto-fixable which is really nice. The eslint-comments ones take a little more manual work.
Also review each of the plugins and see if there's any rules in their recommended sets that we want to disable. Likewise, see if there are any excluded from the recommended set that we'd like to use.
Please also let me know if there're any additional comments that would be helpful to add to the rule configurations.
Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin