Skip to content

Commit 90f1ef0

Browse files
committed
chore: wip
1 parent 68edaf7 commit 90f1ef0

20 files changed

+2439
-18
lines changed

docs/advanced/plugin-system.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default config
2929

3030
Built-in plugins and rules (see the Rules section for details):
3131

32-
- `pickier`: [`sort-objects`](/rules/pickier-sort-objects), [`sort-imports`](/rules/pickier-sort-imports), [`sort-named-imports`](/rules/pickier-sort-named-imports), [`sort-heritage-clauses`](/rules/pickier-sort-heritage-clauses), [`sort-keys`](/rules/sort-keys), [`sort-exports`](/rules/sort-exports), [`no-unused-vars`](/rules/no-unused-vars), [`prefer-const`](/rules/prefer-const)
32+
- `pickier`: [`no-unused-vars`](/rules/no-unused-vars), [`prefer-const`](/rules/prefer-const), [`sort-array-includes`](/rules/sort-array-includes), [`sort-classes`](/rules/sort-classes), [`sort-enums`](/rules/sort-enums), [`sort-exports`](/rules/sort-exports), [`sort-heritage-clauses`](/rules/pickier-sort-heritage-clauses), [`sort-imports`](/rules/pickier-sort-imports), [`sort-interfaces`](/rules/sort-interfaces), [`sort-keys`](/rules/sort-keys), [`sort-maps`](/rules/sort-maps), [`sort-named-imports`](/rules/pickier-sort-named-imports), [`sort-object-types`](/rules/sort-object-types), [`sort-objects`](/rules/pickier-sort-objects)
3333
- `style`: [`max-statements-per-line`](/rules/style-max-statements-per-line)
3434
- `regexp`: [`no-super-linear-backtracking`](/rules/regexp-no-super-linear-backtracking)
3535

docs/rules/overview.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,22 @@ Core:
1616

1717
Plugin:
1818

19-
- [`sort-objects`](/rules/pickier-sort-objects)
20-
- [`sort-imports`](/rules/pickier-sort-imports)
21-
- [`sort-named-imports`](/rules/pickier-sort-named-imports)
22-
- [`sort-heritage-clauses`](/rules/pickier-sort-heritage-clauses)
23-
- [`sort-keys`](/rules/sort-keys)
24-
- [`sort-exports`](/rules/sort-exports)
2519
- [`max-statements-per-line`](/rules/style-max-statements-per-line)
26-
- [`pickier/no-unused-vars`](/rules/no-unused-vars)
2720
- [`no-super-linear-backtracking`](/rules/regexp-no-super-linear-backtracking)
21+
- [`no-unused-vars`](/rules/no-unused-vars)
2822
- [`prefer-const`](/rules/prefer-const)
23+
- [`sort-array-includes`](/rules/sort-array-includes)
24+
- [`sort-classes`](/rules/sort-classes)
25+
- [`sort-enums`](/rules/sort-enums)
26+
- [`sort-exports`](/rules/sort-exports)
27+
- [`sort-heritage-clauses`](/rules/pickier-sort-heritage-clauses)
28+
- [`sort-imports`](/rules/pickier-sort-imports)
29+
- [`sort-interfaces`](/rules/sort-interfaces)
30+
- [`sort-keys`](/rules/sort-keys)
31+
- [`sort-maps`](/rules/sort-maps)
32+
- [`sort-named-imports`](/rules/pickier-sort-named-imports)
33+
- [`sort-object-types`](/rules/sort-object-types)
34+
- [`sort-objects`](/rules/pickier-sort-objects)
2935

3036
Groups:
3137

docs/rules/pickier.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
Rules provided by the built-in `pickier` plugin. These focus on layout, sorting, and practical hygiene checks.
44

5-
- [`sort-objects`](/rules/pickier-sort-objects): require object literal keys to be sorted
6-
- [`sort-imports`](/rules/pickier-sort-imports): enforce canonical ordering/grouping of the import block
7-
- [`sort-named-imports`](/rules/pickier-sort-named-imports): sort named specifiers within a single import statement
8-
- [`sort-heritage-clauses`](/rules/pickier-sort-heritage-clauses): sort TypeScript `extends`/`implements` lists
9-
- [`sort-keys`](/rules/sort-keys): ESLint-like object key sort check
10-
- [`sort-exports`](/rules/sort-exports): sort contiguous export statements
115
- [`no-unused-vars`](/rules/no-unused-vars): report variables/parameters that are declared but never used
126
- [`prefer-const`](/rules/prefer-const): suggest `const` for variables that are never reassigned
7+
- [`sort-array-includes`](/rules/sort-array-includes): enforce sorted array literals immediately used with `.includes(...)`
8+
- [`sort-classes`](/rules/sort-classes): enforce sorted class members
9+
- [`sort-enums`](/rules/sort-enums): enforce sorted enum members
10+
- [`sort-exports`](/rules/sort-exports): sort contiguous export statements
11+
- [`sort-heritage-clauses`](/rules/pickier-sort-heritage-clauses): sort TypeScript `extends`/`implements` lists
12+
- [`sort-imports`](/rules/pickier-sort-imports): enforce canonical ordering/grouping of the import block
13+
- [`sort-interfaces`](/rules/sort-interfaces): enforce sorted TypeScript interface members
14+
- [`sort-keys`](/rules/sort-keys): ESLint-like object key sort check
15+
- [`sort-maps`](/rules/sort-maps): enforce sorted entries inside `new Map([...])`
16+
- [`sort-named-imports`](/rules/pickier-sort-named-imports): sort named specifiers within a single import statement
17+
- [`sort-object-types`](/rules/sort-object-types): enforce sorted TypeScript object type members
18+
- [`sort-objects`](/rules/pickier-sort-objects): require object literal keys to be sorted
1319

1420
See the [Plugin System](/advanced/plugin-system) for configuration examples.

docs/rules/sort-array-includes.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# sort-array-includes
2+
3+
Enforce sorted array values when immediately used with `.includes(...)`.
4+
5+
Keeping arrays sorted improves scanability and reduces mistakes in membership checks.
6+
7+
## Config
8+
9+
```ts
10+
pluginRules: {
11+
sort-array-includes: [warn, { type: alphabetical, order: asc, ignoreCase: true }],
12+
}
13+
```
14+
15+
Options:
16+
17+
- `type`: alphabetical | natural | line-length | custom | unsorted (default: alphabetical)
18+
- `order`: asc | desc (default: asc)
19+
- `ignoreCase`: boolean (default: true)
20+
- `specialCharacters`: keep | trim | remove (default: keep)
21+
- `alphabet`: string (default: ) — only when type=custom
22+
- `partitionByNewLine`: boolean (default: false)
23+
24+
Note: Heuristic detection; focuses on literal arrays directly followed by `.includes(...)`.
25+
26+
## Example
27+
28+
Before:
29+
30+
```ts
31+
function getProductCategories(product) {
32+
if ([
33+
Mouse,
34+
Drone,
35+
Smartphone,
36+
Keyboard,
37+
Tablet,
38+
Monitor,
39+
Laptop,
40+
Smartwatch,
41+
Router,
42+
Headphones,
43+
].includes(product.name)) {
44+
return Electronics
45+
}
46+
return Unknown
47+
}
48+
```
49+
50+
After (alphabetical asc):
51+
52+
```ts
53+
if ([
54+
Drone,
55+
Headphones,
56+
Keyboard,
57+
Laptop,
58+
Monitor,
59+
Mouse,
60+
Router,
61+
Smartphone,
62+
Smartwatch,
63+
Tablet,
64+
].includes(product.name)) { /* ... */ }
65+
```
66+
67+
## Best practices
68+
69+
- Use `natural` when values include numeric suffixes (e.g., `item2`, `item10`)
70+
- Consider `partitionByNewLine: true` to preserve logical grouping inside long arrays
71+
- Keep at `warn` to surface unsorted lists without blocking

docs/rules/sort-classes.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# sort-classes
2+
3+
Enforce sorted class members.
4+
5+
Organizing class members in a consistent order improves readability and maintainability. This rule helps developers quickly locate class members and understand the overall structure of the class.
6+
7+
## Config
8+
9+
```ts
10+
pluginRules: {
11+
sort-classes: [warn, { type: alphabetical, order: asc, ignoreCase: true }],
12+
}
13+
```
14+
15+
Options:
16+
17+
- `type`: alphabetical | natural | line-length | custom | unsorted (default: alphabetical)
18+
- `order`: asc | desc (default: asc)
19+
- `ignoreCase`: boolean (default: true)
20+
- `specialCharacters`: keep | trim | remove (default: keep)
21+
- `alphabet`: string (default: ) — only when type=custom
22+
- `partitionByNewLine`: boolean (default: false) — respect blank-line groups and do not sort across them
23+
24+
Note: This is a heuristic rule; it does not parse full TypeScript syntax trees.
25+
26+
## Example
27+
28+
Before:
29+
30+
```ts
31+
class User {
32+
constructor(username: string, email: string, isActive: boolean) {
33+
this.username = username
34+
this.email = email
35+
this.isActive = isActive
36+
this.roles = []
37+
}
38+
39+
addRole(role: string) {
40+
this.roles.push(role)
41+
}
42+
43+
deactivate() {
44+
this.isActive = false
45+
}
46+
47+
setEmail(newEmail: string) {
48+
this.email = newEmail
49+
}
50+
51+
activate() {
52+
this.isActive = true
53+
}
54+
55+
removeRole(role: string) {
56+
this.roles = this.roles.filter(r => r !== role)
57+
}
58+
59+
getProfile() {
60+
return {
61+
username: this.username,
62+
email: this.email,
63+
isActive: this.isActive,
64+
roles: this.roles,
65+
}
66+
}
67+
}
68+
```
69+
70+
After (alphabetical asc):
71+
72+
```ts
73+
class User {
74+
activate() { this.isActive = true }
75+
addRole(role: string) { this.roles.push(role) }
76+
constructor(username: string, email: string, isActive: boolean) { /* ... */ }
77+
deactivate() { this.isActive = false }
78+
getProfile() { /* ... */ }
79+
removeRole(role: string) { /* ... */ }
80+
setEmail(newEmail: string) { /* ... */ }
81+
}
82+
```
83+
84+
## Best practices
85+
86+
- Choose `natural` when member names include numeric suffixes (e.g., `step2`, `step10`)
87+
- Use `partitionByNewLine: true` to preserve intentional manual grouping
88+
- Keep the rule at `warn` initially to catch problematic cases without blocking
89+
- Combine with code review guidelines for constructor-first or accessors-first conventions as needed

docs/rules/sort-enums.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# sort-enums
2+
3+
Enforce sorted TypeScript enum members.
4+
5+
Keeping enum members in a consistent and predictable order improves readability and maintainability.
6+
7+
## Config
8+
9+
```ts
10+
pluginRules: {
11+
sort-enums: [warn, { type: alphabetical, order: asc, ignoreCase: true }],
12+
}
13+
```
14+
15+
Options:
16+
17+
- `type`: alphabetical | natural | line-length | custom | unsorted (default: alphabetical)
18+
- `order`: asc | desc (default: asc)
19+
- `ignoreCase`: boolean (default: true)
20+
- `specialCharacters`: keep | trim | remove (default: keep)
21+
- `alphabet`: string (default: ) — only when type=custom
22+
- `partitionByNewLine`: boolean (default: false)
23+
- `sortByValue`: boolean (default: false) — sort by enum values (names by default)
24+
- `forceNumericSort`: boolean (default: false) — numeric enums sorted numerically regardless of type/order
25+
26+
Note: This is a heuristic rule; it does not parse full TypeScript syntax trees.
27+
28+
## Example
29+
30+
Before:
31+
32+
```ts
33+
enum Priority {
34+
Critical = Critical,
35+
None = None,
36+
Low = Low,
37+
High = High,
38+
Medium = Medium,
39+
}
40+
```
41+
42+
After (alphabetical asc by name):
43+
44+
```ts
45+
enum Priority {
46+
Critical = Critical,
47+
High = High,
48+
Low = Low,
49+
Medium = Medium,
50+
None = None,
51+
}
52+
```
53+
54+
## Best practices
55+
56+
- Use `natural` when enum member names include numeric suffixes
57+
- Enable `sortByValue` when values matter more than names (e.g., localized strings)
58+
- Use `partitionByNewLine: true` to keep logical groups intact
59+
- Pair with code review expectations for enum organization (e.g., status enums grouped by lifecycle)

docs/rules/sort-interfaces.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# sort-interfaces
2+
3+
Enforce sorted TypeScript interface properties.
4+
5+
Sorting interface properties provides a clear and predictable structure, improving readability and maintenance. Property comments and documentation remain adjacent to their properties when sorted by this rule.
6+
7+
## Config
8+
9+
```ts
10+
pluginRules: {
11+
sort-interfaces: [warn, { type: alphabetical, order: asc, ignoreCase: true }],
12+
}
13+
```
14+
15+
Options:
16+
17+
- `type`: alphabetical | natural | line-length | custom | unsorted (default: alphabetical)
18+
- `order`: asc | desc (default: asc)
19+
- `ignoreCase`: boolean (default: true)
20+
- `specialCharacters`: keep | trim | remove (default: keep)
21+
- `alphabet`: string (default: ) — only when type=custom
22+
- `partitionByNewLine`: boolean (default: false)
23+
- `sortBy`: name | value (default: name) — sort by property names or by their value types
24+
25+
Note: Heuristic detection focusing on single-line property and method signatures.
26+
27+
## Example
28+
29+
Before:
30+
31+
```ts
32+
interface User {
33+
firstName: string
34+
email: string
35+
roles: string[]
36+
login: string
37+
phoneNumber?: string
38+
address: Address
39+
id: string
40+
}
41+
```
42+
43+
After (alphabetical asc):
44+
45+
```ts
46+
interface User {
47+
address: Address
48+
email: string
49+
firstName: string
50+
id: string
51+
login: string
52+
phoneNumber?: string
53+
roles: string[]
54+
}
55+
```
56+
57+
## Best practices
58+
59+
- Prefer `natural` when keys include numbers (e.g., `field2`, `field10`)
60+
- Use `partitionByNewLine: true` to preserve logical grouping (e.g., identification vs. metadata)
61+
- Consider `sortBy: value` to group by type when helpful (e.g., all `string` fields together)
62+
- Avoid combining with adjacent-overload-signatures rules to prevent conflicts

0 commit comments

Comments
 (0)