Skip to content

Commit

Permalink
feat(eslint): use simple-import-sort to relace import/order (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored Oct 9, 2021
1 parent 86e3ccc commit f90c027
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/khaki-lions-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@1stg/eslint-config": minor
"@1stg/tslint-config": major
---

feat(eslint): use simple-import-sort to relace import/order
31 changes: 25 additions & 6 deletions packages/eslint-config/base.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { builtinModules } = require('module')

const { isTsAvailable } = require('@pkgr/utils')
const { getGlobals } = require('eslint-plugin-mdx')

Expand All @@ -16,6 +18,7 @@ module.exports = {
'standard',
'plugin:prettier/recommended',
].filter(Boolean),
plugins: ['simple-import-sort'],
globals: isWebpackAvailable ? getGlobals(webpackSpecVars) : undefined,
rules: {
'arrow-body-style': 2,
Expand All @@ -34,13 +37,9 @@ module.exports = {
},
],
'eslint-comments/no-unused-disable': 2,
'import/first': 2,
'import/newline-after-import': 2,
'import/order': [
2,
{
'newlines-between': 'always',
},
],
'import/no-duplicates': 2,
'no-else-return': [
2,
{
Expand Down Expand Up @@ -78,6 +77,26 @@ module.exports = {
'node/no-unpublished-require': 0,
'prefer-const': 2,
'prefer-object-spread': 2,
'simple-import-sort/exports': 2,
'simple-import-sort/imports': [
2,
{
groups: [
// side effect imports
['^\\u0000'],
// common node built-in packages
[`^(${builtinModules.join('|')})$`],
// packages
['^(?!app[\\w-]*/)(@[^/]|[^@.])'],
// app paths
['^(@|app[\\w-]*)/'],
// parent imports
['^(../)+'],
// relative imports
['^(?!\\./.*\\.(p?css|less|s[ac]ss|styl(us)?))'],
],
},
],
'unicorn/catch-error-name': [
2,
{
Expand Down
2 changes: 0 additions & 2 deletions packages/eslint-config/overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,6 @@ exports.tslint = {
excludedFiles: '*.d.ts',
plugins: TSLINT_CONFIG ? ['@typescript-eslint/tslint'] : undefined,
rules: {
// `ordered-imports` of tslint is better for now
'import/order': 0,
...(TSLINT_CONFIG
? undefined
: {
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-react": "^7.26.1",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-sonar": "^0.6.1",
"eslint-plugin-sonarjs": "^0.10.0",
"eslint-plugin-svelte": "^1.1.2",
Expand Down
1 change: 1 addition & 0 deletions packages/tslint-config/eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"tslint-config-eslint/sonar"
],
"rules": {
"ordered-imports": false,
"validate-decorators": false
}
}
10 changes: 8 additions & 2 deletions packages/tslint-config/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
"import-sources-order": "lowercase-first",
"named-imports-order": "lowercase-last",
"groups": [
// common node builtin modules
"^(async_hooks|child_process|http[2s]?|fs|module|path|url|util|vm|worker_threads)$",
// side effect imports
"^\\u0000",
// common node built-in packages, generated by `^(${require('module').builtinModules.join('|')})$`
"^(_http_agent|_http_client|_http_common|_http_incoming|_http_outgoing|_http_server|_stream_duplex|_stream_passthrough|_stream_readable|_stream_transform|_stream_wrap|_stream_writable|_tls_common|_tls_wrap|assert|async_hooks|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|http2|https|inspector|module|net|os|path|perf_hooks|process|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|trace_events|tty|url|util|v8|vm|wasi|worker_threads|zlib)$",
// packages
"^(?!app[\\w-]*/)(@[^/]|[^@.])",
// app paths
"^(@|app[\\w-]*)/",
// parent imports
"^(../)+",
// relative imports
"^(?!\\./.*\\.(p?css|less|s[ac]ss|styl(us)?))"
]
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { promisify } from 'util'
import { interval } from 'rxjs'
import { Position } from 'unist'

import { TestCase, content } from './_test'
import { content, TestCase } from './_test'

promisify(fs.readFile)

Expand Down
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": ["@1stg/tslint-config/react", "tslint-config-eslint/prettier"],
"extends": ["@1stg/tslint-config/eslint"],
"linterOptions": {
"exclude": ["**/node_modules/**"]
}
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5093,6 +5093,11 @@ eslint-plugin-react@^7.26.1:
semver "^6.3.0"
string.prototype.matchall "^4.0.5"

eslint-plugin-simple-import-sort@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-7.0.0.tgz#a1dad262f46d2184a90095a60c66fef74727f0f8"
integrity sha512-U3vEDB5zhYPNfxT5TYR7u01dboFZp+HNpnGhkDB2g/2E4wZ/g1Q9Ton8UwCLfRV9yAKyYqDh62oHOamvkFxsvw==

eslint-plugin-sonar@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-sonar/-/eslint-plugin-sonar-0.6.1.tgz#65a25e834577ad0027624b198bbb570e242560ba"
Expand Down

0 comments on commit f90c027

Please sign in to comment.