Why add empty line bettween two react imports
tjx666 opened this issue · comments
settings:
{
'simple-import-sort/imports': [
'error',
{
groups: [
// Side effect imports.
['^\\u0000'],
// Node.js builtins prefixed with `node:`.
['^node:'],
// framework
['^react$', '^next(/.*)?$', '^jotai$', '^@mui/'],
// Packages.
// Things that start with a letter (or digit or underscore), or `@` followed by a letter.
['^@?\\w'],
['^@?(minimals|lib|components|hooks|utils|types|constants)(/.*|$)'],
// Absolute imports and other imports such as Vue-style `@/foo`.
// Anything not matched in another group.
['^'],
// Relative imports.
// Anything that starts with a dot.
['^\\.'],
],
},
],
}
input:
import { useState } from 'react';
import type { FC } from 'react';
output:
import { useState } from 'react';
import type { FC } from 'react';
![image](https://private-user-images.githubusercontent.com/41773861/328797719-0fd43405-a709-4a59-be68-055d976c1290.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTY1NTc0OTgsIm5iZiI6MTcxNjU1NzE5OCwicGF0aCI6Ii80MTc3Mzg2MS8zMjg3OTc3MTktMGZkNDM0MDUtYTcwOS00YTU5LWJlNjgtMDU1ZDk3NmMxMjkwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA1MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNTI0VDEzMjYzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJmNzhjMTFlMGYzMzcwZGE2MDViMTE5NWMxODAxZTA5N2NkNjc0NTkwZjhiYTNiZTA0ZWUwNTJmOWQ3OGYwODAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.fUANVvKbXX5gKFpJUdbRfZnDEZhp5pVej2_GDku6kW4)
versions:
"eslint": "^8.57.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-simple-import-sort": "^12.1.0",
Hi! From https://github.com/lydell/eslint-plugin-simple-import-sort?tab=readme-ov-file#custom-grouping:
Type imports have \u0000 appended to their from string (ends with \u0000). You can match them with "\u0000$".
This means that your '^react$'
regex doesn’t match in the type import, because it is matched against 'react\u0000'
.
(Yes, this \u0000 stuff is pretty weird, but it is what it is.)
Ok, I rewrite to:
'simple-import-sort/imports': [
error,
{
groups: [
// Side effect imports.
['^\\u0000'],
// Node.js builtins
[
'^node:',
`^(${require('node:module')
.builtinModules.filter((mod) => mod !== 'constants')
.join('|')})(/.*|$)`,
],
// Framework
['^react\u0000?$', '^next(/.*)?\u0000?$', '^jotai\u0000?$', '^@mui/'],
// Packages
['^@?\\w'],
// Internal modules
['^(@/)?(minimals|lib|components|hooks|utils|types|constants)(/.*|$)'],
// Absolute imports and other imports such as Vue-style `@/foo`.
// Anything not matched in another group.
['^'],
// Relative imports.
// Anything that starts with a dot.
['^\\.'],
],
},
],
Nice! 👍