1- const { defineConfig } = require ( "eslint/config" ) ;
2- const jsdoc = require ( "eslint-plugin-jsdoc" ) ;
3- const sortKeys = require ( "eslint-plugin-sort-keys" ) ;
4- const unicorn = require ( "eslint-plugin-unicorn" ) ;
5- const tseslint = require ( "typescript-eslint" ) ;
1+ import { defineConfig } from "eslint/config" ;
2+ import jsdoc from "eslint-plugin-jsdoc" ;
3+ import perfectionist from "eslint-plugin-perfectionist" ;
4+ import unicorn from "eslint-plugin-unicorn" ;
5+ import tseslint from "typescript-eslint" ;
66
77const config = {
88 files : [ "**/*.{js,jsx,ts,tsx}" ] ,
@@ -19,7 +19,7 @@ const config = {
1919 plugins : {
2020 "@typescript-eslint" : tseslint . plugin ,
2121 jsdoc,
22- "sort-keys" : sortKeys ,
22+ perfectionist ,
2323 unicorn,
2424 } ,
2525 //
@@ -80,17 +80,7 @@ const config = {
8080 // "prefer-object-has-own": "error",
8181 // "prefer-object-spread": "error",
8282 "prefer-template" : "error" ,
83- // This only sorts members within an individual import statement, not import
84- // statements ("declarations") themselves. We disable that because this
85- // rule sorts in a weird way: by first member rather than by module name.
86- // The `import/order` rule provided by eslint-plugin-import does sort
87- // declarations by module name, but we forgo that too because it groups
88- // declarations based on environmental factors (e.g. node_modules, Node
89- // version) that we can't easily determine or reproduce here in a
90- // repo-agnostic way. One compromise might be to use `import/order` and
91- // simply disable its regrouping feature in favor of whatever groups are
92- // found in the source code to be formatted, but no such option exists :/
93- "sort-imports" : [ "error" , { ignoreDeclarationSort : true } ] ,
83+ // "sort-imports": "error", // Replaced by perfectionist/sort-imports and perfectionist/sort-named-imports
9484 "sort-vars" : "error" ,
9585 // "strict": "error",
9686 // "unicode-bom": "error",
@@ -132,8 +122,54 @@ const config = {
132122 // "jsdoc/tag-lines": "error",
133123 // "jsdoc/text-escaping": "error",
134124
135- // sort-keys rules. https://github.com/namnm/eslint-plugin-sort-keys
136- "sort-keys/sort-keys-fix" : [ "error" , "asc" , { natural : true } ] ,
125+ // perfectionist rules. https://perfectionist.dev/rules
126+ "perfectionist/sort-enums" : [
127+ "error" ,
128+ { order : "asc" , partitionByNewLine : true , type : "natural" } ,
129+ ] ,
130+ "perfectionist/sort-heritage-clauses" : [
131+ "error" ,
132+ { order : "asc" , partitionByNewLine : true , type : "natural" } ,
133+ ] ,
134+ "perfectionist/sort-imports" : [
135+ "error" ,
136+ {
137+ newlinesBetween : "ignore" ,
138+ newlinesInside : "ignore" ,
139+ order : "asc" ,
140+ partitionByNewLine : true ,
141+ type : "natural" ,
142+ } ,
143+ ] ,
144+ "perfectionist/sort-interfaces" : [
145+ "error" ,
146+ { order : "asc" , partitionByNewLine : true , type : "natural" } ,
147+ ] ,
148+ "perfectionist/sort-intersection-types" : [
149+ "error" ,
150+ { order : "asc" , partitionByNewLine : true , type : "natural" } ,
151+ ] ,
152+ "perfectionist/sort-named-exports" : [
153+ "error" ,
154+ { order : "asc" , partitionByNewLine : true , type : "natural" } ,
155+ ] ,
156+ "perfectionist/sort-named-imports" : [
157+ "error" ,
158+ { order : "asc" , type : "natural" } ,
159+ ] ,
160+ "perfectionist/sort-object-types" : [
161+ "error" ,
162+ { order : "asc" , partitionByNewLine : true , type : "natural" } ,
163+ ] ,
164+ "perfectionist/sort-objects" : [
165+ "error" ,
166+ { order : "asc" , partitionByNewLine : true , type : "natural" } ,
167+ ] ,
168+ // "perfectionist/sort-switch-case" // TODO: Enable once it supports partitionByNewLine
169+ "perfectionist/sort-union-types" : [
170+ "error" ,
171+ { order : "asc" , partitionByNewLine : true , type : "natural" } ,
172+ ] ,
137173
138174 // typescript-eslint rules. We exclude rules that require type info because
139175 // they're prohibitively slow. Get the list of autofixable rules by running
@@ -189,10 +225,9 @@ const config = {
189225 // "unicorn/new-for-builtins": "error",
190226 // "unicorn/no-array-for-each": "error", // Bug: fixer deletes comments
191227 // "unicorn/no-array-method-this-argument": "error",
192- // "unicorn/no-array-push-push": "error", // Bug: fixer deletes comments
193228 // "unicorn/no-await-expression-member": "error",
194229 "unicorn/no-console-spaces" : "error" ,
195- // "unicorn/no-for-loop": "error", // Bug: https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1802
230+ "unicorn/no-for-loop" : "error" ,
196231 // "unicorn/no-hex-escape": "error",
197232 // "unicorn/no-lonely-if": "error", // Bug: Moves comments around
198233 "unicorn/no-negated-condition" : "error" ,
@@ -249,6 +284,7 @@ const config = {
249284 "unicorn/prefer-regexp-test" : "error" ,
250285 // "unicorn/prefer-set-has": "error",
251286 "unicorn/prefer-set-size" : "error" ,
287+ // "unicorn/prefer-single-call": "error", // Bug: fixer deletes comments
252288 // "unicorn/prefer-spread": "error", // Bug: https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2041
253289 // "unicorn/prefer-string-raw": "error",
254290 // "unicorn/prefer-string-replace-all": "error",
@@ -272,4 +308,4 @@ const config = {
272308 } ,
273309} ;
274310
275- module . exports = defineConfig ( [ config ] ) ;
311+ export default defineConfig ( [ config ] ) ;
0 commit comments