Skip to content

Commit

Permalink
feat!: move the optional sort-keys plugin to perfectionist, close #…
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Nov 2, 2023
1 parent 7ea4636 commit 9fa7426
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 50 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -299,22 +299,22 @@ export default antfu({

This config also provides some optional plugins/rules for extended usages.

#### `sort-keys`
#### `perfectionist` (sorting)

This plugin [`eslint-plugin-sort-keys`](https://github.com/namnm/eslint-plugin-sort-keys) allows you to keep object keys sorted with auto-fix.
This plugin [`eslint-plugin-perfectionist`](https://github.com/azat-io/eslint-plugin-perfectionist) allows you to sorted object keys, imports, etc, with auto-fix.

It's installed but no rules are enabled by default.
The plugin is installed but no rules are enabled by default.

It's recommended to opt-in on each file individually using [configuration comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1).

```js
/* eslint sort-keys/sort-keys-fix: "error" */
/* eslint perfectionist/sort-objects: "error" */
const objectWantedToSort = {
a: 2,
b: 1,
c: 3,
}
/* eslint sort-keys/sort-keys-fix: "off" */
/* eslint perfectionist/sort-objects: "off" */
```

### Type Aware Rules
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.js
Expand Up @@ -14,7 +14,7 @@ export default antfu(
{
files: ['src/**/*.ts'],
rules: {
'sort-keys/sort-keys-fix': 'error',
'perfectionist/sort-objects': 'error',
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -50,7 +50,7 @@
"eslint-plugin-markdown": "^3.0.1",
"eslint-plugin-n": "^16.2.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-sort-keys": "^2.3.5",
"eslint-plugin-perfectionist": "^2.2.0",
"eslint-plugin-unicorn": "^49.0.0",
"eslint-plugin-unused-imports": "^3.0.0",
"eslint-plugin-vitest": "^0.3.8",
Expand Down
40 changes: 32 additions & 8 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/configs/index.ts
Expand Up @@ -13,4 +13,4 @@ export * from './unicorn'
export * from './vue'
export * from './yaml'
export * from './test'
export * from './sort-keys'
export * from './perfectionist'
2 changes: 1 addition & 1 deletion src/configs/jsonc.ts
Expand Up @@ -4,8 +4,8 @@ import { parserJsonc, pluginJsonc } from '../plugins'

export function jsonc(options: OptionsStylistic & OptionsOverrides = {}): ConfigItem[] {
const {
stylistic = true,
overrides = {},
stylistic = true,
} = options

const {
Expand Down
18 changes: 18 additions & 0 deletions src/configs/perfectionist.ts
@@ -0,0 +1,18 @@
import type { ConfigItem } from '../types'
import { pluginPerfectionist } from '../plugins'

/**
* Optional perfectionist plugin for props and items sorting.
*
* @see https://github.com/azat-io/eslint-plugin-perfectionist
*/
export function perfectionist(): ConfigItem[] {
return [
{
name: 'antfu:perfectionist',
plugins: {
perfectionist: pluginPerfectionist,
},
},
]
}
18 changes: 0 additions & 18 deletions src/configs/sort-keys.ts

This file was deleted.

14 changes: 7 additions & 7 deletions src/configs/stylistic.ts
Expand Up @@ -4,8 +4,8 @@ import { pluginAntfu, pluginStylistic } from '../plugins'
export function stylistic(options: StylisticConfig = {}): ConfigItem[] {
const {
indent = 2,
quotes = 'single',
jsx = true,
quotes = 'single',
} = options

return [
Expand Down Expand Up @@ -36,14 +36,9 @@ export function stylistic(options: StylisticConfig = {}): ConfigItem[] {
'style/indent': ['error', indent, {
ArrayExpression: 1,
CallExpression: { arguments: 1 },
flatTernaryExpressions: false,
FunctionDeclaration: { body: 1, parameters: 1 },
FunctionExpression: { body: 1, parameters: 1 },
ImportDeclaration: 1,
MemberExpression: 1,
ObjectExpression: 1,
SwitchCase: 1,
VariableDeclarator: 1,
flatTernaryExpressions: false,
ignoreComments: false,
ignoredNodes: [
'TemplateLiteral *',
Expand All @@ -68,8 +63,13 @@ export function stylistic(options: StylisticConfig = {}): ConfigItem[] {
'FunctionExpression > .params > :matches(Decorator, :not(:first-child))',
'ClassBody.body > PropertyDefinition[decorators.length > 0] > .key',
],
ImportDeclaration: 1,
MemberExpression: 1,
ObjectExpression: 1,
offsetTernaryExpressions: true,
outerIIFEBody: 1,
SwitchCase: 1,
VariableDeclarator: 1,
}],
'style/key-spacing': ['error', { afterColon: true, beforeColon: false }],
'style/keyword-spacing': ['error', { after: true, before: true }],
Expand Down
14 changes: 7 additions & 7 deletions src/factory.ts
Expand Up @@ -12,7 +12,7 @@ import {
jsonc,
markdown,
node,
sortKeys,
perfectionist,
sortPackageJson,
sortTsconfig,
stylistic,
Expand Down Expand Up @@ -47,12 +47,12 @@ const VuePackages = [
*/
export function antfu(options: OptionsConfig & ConfigItem = {}, ...userConfigs: (ConfigItem | ConfigItem[])[]) {
const {
isInEditor = !!((process.env.VSCODE_PID || process.env.JETBRAINS_IDE) && !process.env.CI),
vue: enableVue = VuePackages.some(i => isPackageExists(i)),
typescript: enableTypeScript = isPackageExists('typescript'),
componentExts = [],
gitignore: enableGitignore = true,
isInEditor = !!((process.env.VSCODE_PID || process.env.JETBRAINS_IDE) && !process.env.CI),
overrides = {},
componentExts = [],
typescript: enableTypeScript = isPackageExists('typescript'),
vue: enableVue = VuePackages.some(i => isPackageExists(i)),
} = options

const stylisticOptions = options.stylistic === false
Expand Down Expand Up @@ -92,8 +92,8 @@ export function antfu(options: OptionsConfig & ConfigItem = {}, ...userConfigs:
}),
unicorn(),

// Optional plugins (not enabled by default)
sortKeys(),
// Optional plugins (installed but not enabled by default)
perfectionist(),
)

if (enableVue)
Expand Down
2 changes: 1 addition & 1 deletion src/plugins.ts
Expand Up @@ -16,7 +16,7 @@ export { default as pluginVue } from 'eslint-plugin-vue'
export * as pluginYaml from 'eslint-plugin-yml'
export { default as pluginNoOnlyTests } from 'eslint-plugin-no-only-tests'
export { default as pluginVitest } from 'eslint-plugin-vitest'
export { default as pluginSortKeys } from 'eslint-plugin-sort-keys'
export { default as pluginPerfectionist } from 'eslint-plugin-perfectionist'

export * as parserTs from '@typescript-eslint/parser'
export { default as parserVue } from 'vue-eslint-parser'
Expand Down

0 comments on commit 9fa7426

Please sign in to comment.