-
-
Notifications
You must be signed in to change notification settings - Fork 649
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
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pmndrs/jotai/DT4WJ98C5CGvFMbhpmdcLafBk7W5 |
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:
|
"object", | ||
"type" | ||
], | ||
"newlines-between": "never", |
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 would it be like if we make this "always"? Something too weird?
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.
ah, will it require newlines between import { foo } from './foo'
and import { bar } from './bar'
?
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 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:
- Now everyone is using auto import
- 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.
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.
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.
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 will study this again, and if it can be realized, I’ll launch a PR.
src/urql/atomWithMutation.ts
Outdated
import { atom } from 'jotai' | ||
import type { Getter } from 'jotai' | ||
import { clientAtom } from './clientAtom' | ||
import type { Getter } from 'jotai' |
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 looks a little unfortunate...
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.
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' |
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 might be out of the scope of this PR, but as we strictly use import type
for types, this would be:
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' |
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.
import { FC, StrictMode, Suspense, useEffect, useRef } from 'react' | |
import { StrictMode, Suspense, useEffect, useRef } from 'react' | |
import type { FC } from 'react' |
Specific changes and motives:
js,jsx,ts,tsx
files inoverrides
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 thepathGroups
option to use the.(autofixable)1.6
sort-imports
: Order members of import with multiple members.(autofixable)"react/jsx-uses-react": "off",
and"react/react-in-jsx-scope": "off",
into theoverrides