Skip to content

Commit

Permalink
feat!: remove read-tsconfig option in sort-imports rule
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Jul 15, 2023
1 parent 3f8fffa commit bce9c64
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 113 deletions.
16 changes: 3 additions & 13 deletions docs/rules/sort-imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ If you use the [`sort-imports`](https://eslint.org/docs/latest/rules/sort-import
Rule `perfectionist/sort-imports` works in a similar way to rule `import/order`, but with some differences:

1. Supporting for new import types: `'side-effect'`, `'style'`, `'builtin-type'`, `'internal-type'`, `'parent-type'`, `'sibling-type'`, `'index-type'`
2. Parsing `tsconfig.json` with the `read-tsconfig` option enabled to recognize internal imports
3. Supporting for adding custom import groups
4. Sorting not only alphabetically, but also naturally and by line length
2. Supporting for adding custom import groups
3. Sorting not only alphabetically, but also naturally and by line length

## 💡 Examples

Expand Down Expand Up @@ -126,7 +125,6 @@ interface Options {
}
'internal-pattern'?: string[]
'newlines-between'?: 'always' | 'ignore' | 'never'
'read-tsconfig'?: boolean
```
### type
Expand Down Expand Up @@ -244,12 +242,6 @@ The [minimatch](https://github.com/isaacs/minimatch) library is used for pattern
- `always` - one new line between each group will be enforced, and new lines inside a group will be forbidden.
- `never` - no new lines are allowed in the entire import section.
### read-tsconfig
<sub>(default: `false`)</sub>
If your project is written in TypeScript, you can read `tsconfig.json` and use `paths` as internal imports.
## ⚙️ Usage
::: code-group
Expand Down Expand Up @@ -293,8 +285,7 @@ If your project is written in TypeScript, you can read `tsconfig.json` and use `
"@/stores/**",
"@/pages/**",
"@/lib/**"
],
"read-tsconfig": false
]
}
]
}
Expand Down Expand Up @@ -346,7 +337,6 @@ export default [
'@/pages/**',
'@/lib/**',
],
'read-tsconfig': false,
},
],
},
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"@typescript-eslint/types": "^5.62.0",
"@typescript-eslint/utils": "^5.62.0",
"is-core-module": "^2.12.1",
"json5": "^2.2.3",
"minimatch": "^9.0.3",
"natural-compare-lite": "^1.4.0"
},
Expand Down
4 changes: 1 addition & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions rules/sort-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { getCommentBefore } from '../utils/get-comment-before'
import { createEslintRule } from '../utils/create-eslint-rule'
import { getNodeRange } from '../utils/get-node-range'
import { rangeToDiff } from '../utils/range-to-diff'
import { TSConfig } from '../utils/read-ts-config'
import { SortOrder, SortType } from '../typings'
import { sortNodes } from '../utils/sort-nodes'
import { complete } from '../utils/complete'
Expand Down Expand Up @@ -58,7 +57,6 @@ type Options<T extends string[]> = [
'newlines-between': NewlinesBetweenValue
groups: (Group<T>[] | Group<T>)[]
'internal-pattern': string[]
'read-tsconfig': boolean
'ignore-case': boolean
order: SortOrder
type: SortType
Expand Down Expand Up @@ -132,10 +130,6 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
],
default: NewlinesBetweenValue.always,
},
'read-tsconfig': {
type: 'boolean',
default: false,
},
},
additionalProperties: false,
},
Expand All @@ -160,24 +154,13 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
'custom-groups': { type: {}, value: {} },
'internal-pattern': ['~/**'],
type: SortType.alphabetical,
'read-tsconfig': false,
order: SortOrder.asc,
'ignore-case': false,
groups: [],
})

let tsPaths: string[] = []

if (options['read-tsconfig']) {
let tsConfig = TSConfig.get()

if (tsConfig.compilerOptions?.paths) {
for (let path of Object.keys(tsConfig.compilerOptions.paths)) {
tsPaths.push(path)
}
}
}

let source = context.getSourceCode()

let nodes: SortingNodeWithGroup<string[]>[] = []
Expand Down
54 changes: 0 additions & 54 deletions test/sort-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3273,59 +3273,5 @@ describe(RULE_NAME, () => {
}),
},
}))

ruleTester.run(RULE_NAME, rule, {
valid: [],
invalid: [
{
code: dedent`
import { MikuruAsahina } from '@/components/mikuru'
import { HaruhiSuzumiya } from '@melancholy/haruhi-suzumiya'
import { YukiNagato } from '~/data/yuki'
`,
output: dedent`
import { HaruhiSuzumiya } from '@melancholy/haruhi-suzumiya'
import { MikuruAsahina } from '@/components/mikuru'
import { YukiNagato } from '~/data/yuki'
`,
options: [
{
type: SortType['line-length'],
order: SortOrder.desc,
'newlines-between': NewlinesBetweenValue.always,
'internal-pattern': ['~/**'],
groups: [
'type',
['builtin', 'external'],
'internal-type',
'internal',
['parent-type', 'sibling-type', 'index-type'],
['parent', 'sibling', 'index'],
'object',
'unknown',
],
'read-tsconfig': true,
},
],
errors: [
{
messageId: 'unexpectedImportsOrder',
data: {
left: '@/components/mikuru',
right: '@melancholy/haruhi-suzumiya',
},
},
{
messageId: 'missedSpacingBetweenImports',
data: {
left: '@melancholy/haruhi-suzumiya',
right: '~/data/yuki',
},
},
],
},
],
})
})
})
25 changes: 0 additions & 25 deletions utils/read-ts-config.ts

This file was deleted.

0 comments on commit bce9c64

Please sign in to comment.