Skip to content

Commit

Permalink
feat: add locales option for all rules
Browse files Browse the repository at this point in the history
  • Loading branch information
fkworld authored and azat-io committed Nov 19, 2024
1 parent e240971 commit f84cb5f
Show file tree
Hide file tree
Showing 63 changed files with 681 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/content/guide/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ In settings you can set the following options:
- `ignoreCase` — Ignore case when sorting.
- `ignorePattern` — Ignore sorting for elements that match the pattern.
- `specialCharacters` — Control whether special characters should be kept, trimmed or removed before sorting. Values can be `'keep'`, `'trim'` or `'remove'`.
- `locales` - The locales of sorting. Values can be a string with a BCP 47 language tag, or an array of such strings. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).
- `partitionByComment` — Partition the sorted elements by comments. Values can be `true`, `false` or regexp pattern.
- `partitionByNewLine` — Partition the sorted elements by new lines. Values can be `true` or `false`.

Expand Down
10 changes: 10 additions & 0 deletions docs/content/rules/sort-array-includes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### groupKind

Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-classes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### partitionByComment

<sub>default: `false`</sub>
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-decorators.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### partitionByComment

<sub>default: `false`</sub>
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-enums.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### sortByValue

<sub>default: `false`</sub>
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-exports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### partitionByComment

<sub>default: `false`</sub>
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-heritage-clauses.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### groups

<sub>
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-imports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### internalPattern

<sub>default: `['^~/.*']`</sub>
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-interfaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### ignorePattern

<sub>default: `[]`</sub>
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-intersection-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### partitionByComment

<sub>default: `false`</sub>
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-jsx-props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### ignorePattern

<sub>default: `[]`</sub>
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-maps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### partitionByComment

<sub>default: `false`</sub>
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-named-exports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### groupKind

<sub>default: `'mixed'`</sub>
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-named-imports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### ignoreAlias

<sub>default: `false`</sub>
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-object-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### partitionByComment

<sub>default: `false`</sub>
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-objects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### partitionByComment

<sub>default: `false`</sub>
Expand Down
10 changes: 10 additions & 0 deletions docs/content/rules/sort-sets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### groupKind

Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-switch-case.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

## Usage

<CodeTabs
Expand Down
11 changes: 11 additions & 0 deletions docs/content/rules/sort-union-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### partitionByComment

<sub>default: `false`</sub>
Expand Down
10 changes: 10 additions & 0 deletions docs/content/rules/sort-variable-declarations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ Controls whether special characters should be trimmed, removed or kept before so
- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same).
- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same).

### locales

<sub>default: `'en-US'`</sub>

Specifies the sorting locales. See [String.prototype.localeCompare() - locales](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#locales).

- `string` — A BCP 47 language tag (e.g. `'en'`, `'en-US'`, `'zh-CN'`).
- `string[]` — An array of BCP 47 language tags.

**Note:** Only effective when `type` is `alphabetical`.

### partitionByComment

Expand Down
4 changes: 4 additions & 0 deletions rules/sort-array-includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
partitionByCommentJsonSchema,
specialCharactersJsonSchema,
ignoreCaseJsonSchema,
localesJsonSchema,
orderJsonSchema,
typeJsonSchema,
} from '../utils/common-json-schemas'
Expand Down Expand Up @@ -35,6 +36,7 @@ export type Options = [
type: 'alphabetical' | 'line-length' | 'natural'
partitionByComment: string[] | boolean | string
specialCharacters: 'remove' | 'trim' | 'keep'
locales: NonNullable<Intl.LocalesArgument>
partitionByNewLine: boolean
order: 'desc' | 'asc'
ignoreCase: boolean
Expand All @@ -49,13 +51,15 @@ export const defaultOptions: Required<Options[0]> = {
order: 'asc',
partitionByComment: false,
partitionByNewLine: false,
locales: 'en-US',
}

export let jsonSchema: JSONSchema4 = {
type: 'object',
properties: {
type: typeJsonSchema,
order: orderJsonSchema,
locales: localesJsonSchema,
ignoreCase: ignoreCaseJsonSchema,
specialCharacters: specialCharactersJsonSchema,
groupKind: {
Expand Down
1 change: 1 addition & 0 deletions rules/sort-classes-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export const getCompareOptions = (
: options.order,
specialCharacters: options.specialCharacters,
ignoreCase: options.ignoreCase,
locales: options.locales,
}
}

Expand Down
Loading

0 comments on commit f84cb5f

Please sign in to comment.