Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Add eslint rules for imports and eslint comments #999

Merged
merged 7 commits into from
Mar 1, 2022

Conversation

sarayourfriend
Copy link
Contributor

Fixes

Fixes #901 by @krysal
Fixes #855 by @sarayourfriend

Description

Adds two new ESLint plugins, eslint-comments and import 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

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • [N/A] I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@sarayourfriend sarayourfriend added 🟩 priority: low Low priority and doesn't need to be rushed 🤖 aspect: dx Concerns developers' experience with the codebase 🧰 goal: internal improvement Improvement that benefits maintainers, not users labels Feb 23, 2022
@sarayourfriend sarayourfriend requested a review from a team as a code owner February 23, 2022 21:40
Copy link
Member

@krysal krysal left a 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'],
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

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'
Copy link
Contributor

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.

Copy link
Contributor Author

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'
Copy link
Contributor

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 ~/

Copy link
Contributor Author

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'

Copy link
Contributor

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... 🤔

Copy link
Contributor

@obulat obulat left a 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!

@sarayourfriend sarayourfriend force-pushed the add/more-eslint-rules branch from 0fcaa0c to 2f0adce Compare March 1, 2022 15:54
@sarayourfriend sarayourfriend requested a review from krysal March 1, 2022 15:55
@sarayourfriend sarayourfriend force-pushed the add/more-eslint-rules branch from 2f0adce to db7d179 Compare March 1, 2022 20:34
Copy link
Member

@zackkrida zackkrida left a 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!

@sarayourfriend sarayourfriend merged commit e8cab9f into main Mar 1, 2022
@sarayourfriend sarayourfriend deleted the add/more-eslint-rules branch March 1, 2022 21:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🤖 aspect: dx Concerns developers' experience with the codebase 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🟩 priority: low Low priority and doesn't need to be rushed
Projects
None yet
4 participants