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

chore(imports): enforce a convention in module import order #602

Merged
merged 3 commits into from
Jul 18, 2021
Merged

chore(imports): enforce a convention in module import order #602

merged 3 commits into from
Jul 18, 2021

Conversation

liby
Copy link
Contributor

@liby liby commented Jul 18, 2021

Specific changes and motives:

  1. Add rules for js,jsx,ts,tsx files in overrides
    1.1 alphabetize: Sort the order within each group in alphabetical manner based on import path.(autofixable)
    1.2 groups: Details(autofixable)
    1.3 newlines-between: Enforces or forbids new lines between import groups.(autofixable)
    1.4 pathGroups: Force sort order of certain packages within group.(autofixable)
    1.5 pathGroupsExcludedImportTypes : Configure the pathGroups option to use the.(autofixable)
    1.6 sort-imports: Order members of import with multiple members.(autofixable)
  2. Move "react/jsx-uses-react": "off", and "react/react-in-jsx-scope": "off", into the overrides

@vercel
Copy link

vercel bot commented Jul 18, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pmndrs/jotai/DT4WJ98C5CGvFMbhpmdcLafBk7W5
✅ Preview: https://jotai-git-fork-liby-master-pmndrs.vercel.app

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 18, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d040535:

Sandbox Source
React Configuration
React Typescript Configuration

"object",
"type"
],
"newlines-between": "never",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would it be like if we make this "always"? Something too weird?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, will it require newlines between import { foo } from './foo' and import { bar } from './bar'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would it be like if we make this "always"? Something too weird?

If set to always, at least one new line between each group will be enforced, and new lines inside a group will be forbidden.

/* eslint import/order: ["error", {"newlines-between": "always"}] */
import fs from 'fs';
import path from 'path';

import index from './';

import sibling from './foo';

ah, will it require newlines between import { foo } from './foo' and import { bar } from './bar'?

The following is only a personal opinion:

  1. Now everyone is using auto import
  2. Configuring eslint rules will help us sort imports

In summary, there are now very few cases where the imports section needs to be managed manually, then it is not so necessary to add blank lines just for the sake of readability.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, it's just unfortunate for me that the rule doesn't allow adding one line only between absolute path imports and relative path imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will study this again, and if it can be realized, I’ll launch a PR.

Comment on lines 7 to 8
import { atom } from 'jotai'
import type { Getter } from 'jotai'
import { clientAtom } from './clientAtom'
import type { Getter } from 'jotai'
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 looks a little unfortunate...

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work!
We would be removing FC, so I'd just leave it for now.

@@ -1,9 +1,9 @@
import { createElement, useRef, useDebugValue, FC } from 'react'
import { FC, createElement, useDebugValue, useRef } from 'react'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be out of the scope of this PR, but as we strictly use import type for types, this would be:

Suggested change
import { FC, createElement, useDebugValue, useRef } from 'react'
import { createElement, useDebugValue, useRef } from 'react'
import type { FC } from 'react'

@@ -1,6 +1,6 @@
import { StrictMode, Suspense, useRef, useEffect, FC } from 'react'
import { FC, StrictMode, Suspense, useEffect, useRef } from 'react'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { FC, StrictMode, Suspense, useEffect, useRef } from 'react'
import { StrictMode, Suspense, useEffect, useRef } from 'react'
import type { FC } from 'react'

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

Successfully merging this pull request may close these issues.

2 participants