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

[Feature]: Add import/order rule to ESLint config #110

Open
g-elwell opened this issue Apr 8, 2024 · 2 comments
Open

[Feature]: Add import/order rule to ESLint config #110

g-elwell opened this issue Apr 8, 2024 · 2 comments
Assignees
Labels
discussion Points that need discussing before implementation. enhancement New feature or request

Comments

@g-elwell
Copy link
Member

g-elwell commented Apr 8, 2024

The feature

We should consider adding the import/order eslint rule, which enforces alphabetical module imports, use of 'import groups' and single line spacing between import groups.

Import groups include namespaced modules such as @wordpress packages, external/vs internal dependencies, components vs non-components, eg:

Before:
image

After:
image

This enhances readability of code and separating imports into groups is a practice most of the lead engineering team loosely follow by default already.

The alphabetical aspect is likely not currently implemented by most people, but in practice isn't as annoying as one might think. Although, applying the rule to existing code-bases is likely to flag up a lot of warnings/errors.

@g-elwell g-elwell added enhancement New feature or request discussion Points that need discussing before implementation. labels Apr 8, 2024
@ampersarnie
Copy link
Member

Merging #111


The feature

To further bolster our working standards and to set some common styling across JS, it has been agreed that it would be worth adding the import/order rule to our ES Lint configuration.

There are additional configurations that need to be considered, however I believe (and this is personal preference) that we should follow this:

"import/order": [
  "error",
  {
    "alphabetize": "asc",
    "warnOnUnassignedImports": true,
    "newlines-between": "always",
    "pathGroups": [
      {
        "pattern": "@wordpress/**",
        "group": "builtin",
        "position": "before"
      }
    ],
  }
]

With this setup it do the following:

Documentation: https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md

@g-elwell
Copy link
Member Author

g-elwell commented Apr 9, 2024

Having reviewed the docs, that config looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Points that need discussing before implementation. enhancement New feature or request
Projects
Status: To do
Development

No branches or pull requests

2 participants