eslint-plugin-vue-perfectionist 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +94 -0
- package/dist/index.d.mts +94 -0
- package/dist/index.mjs +1133 -0
- package/package.json +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-PRESENT ntnyq <https://github.com/ntnyq>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# eslint-plugin-vue-perfectionist
|
|
2
|
+
|
|
3
|
+
[](https://github.com/ntnyq/eslint-plugin-vue-perfectionist/actions)
|
|
4
|
+
[](https://www.npmjs.com/package/eslint-plugin-vue-perfectionist)
|
|
5
|
+
[](https://www.npmjs.com/package/eslint-plugin-vue-perfectionist)
|
|
6
|
+
[](https://github.com/ntnyq/eslint-plugin-vue-perfectionist/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
ESLint rules for consistent, readable, and maintainable Vue 3 code.
|
|
9
|
+
|
|
10
|
+
Starting with configurable ordering for `<script setup>`, this plugin aims to provide a growing collection of Vue-specific rules for code organization, consistency, and maintainability. Sorting is the first area of focus, with more rules planned beyond ordering.
|
|
11
|
+
|
|
12
|
+
**Supports Vue 3 only. Vue 2 is not supported.**
|
|
13
|
+
|
|
14
|
+
## Status
|
|
15
|
+
|
|
16
|
+
This project is in early development. The first rule and flat ESLint configuration presets are implemented. The API may change before the first stable release.
|
|
17
|
+
|
|
18
|
+
## Scope
|
|
19
|
+
|
|
20
|
+
The first rule targets top-level statements inside Vue 3 `<script setup>` blocks, including JavaScript and TypeScript. It is intended to help organize compiler macros, type declarations, reactive state, computed values, functions, watchers, and lifecycle hooks.
|
|
21
|
+
|
|
22
|
+
Ordinary `<script>` blocks, Options API component options, and function bodies are outside the first rule's scope. Future rules may cover other aspects of Vue 3 code.
|
|
23
|
+
|
|
24
|
+
The plugin is intended to complement `eslint-plugin-vue` and `eslint-plugin-perfectionist`. Existing rules can continue to handle Vue correctness checks, import sorting, and ordering within objects or types.
|
|
25
|
+
|
|
26
|
+
## Rules
|
|
27
|
+
|
|
28
|
+
| Rule | Description | Status |
|
|
29
|
+
| -------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | --------- |
|
|
30
|
+
| [`vue-perfectionist/sort-script-setup`](./docs/rules/sort-script-setup.md) | Enforce configurable grouping and ordering of top-level statements in `<script setup>`. | Available |
|
|
31
|
+
|
|
32
|
+
### sort-script-setup
|
|
33
|
+
|
|
34
|
+
The sorting API is inspired by `eslint-plugin-perfectionist`, with Vue-specific statement groups:
|
|
35
|
+
|
|
36
|
+
- `groups` defines the order of statement categories.
|
|
37
|
+
- `customGroups` allows project-specific classification, such as custom composables.
|
|
38
|
+
- `type` and `order` control sorting within a group. The default, `type: 'unsorted'`, preserves the original order within groups while still enforcing group order.
|
|
39
|
+
- `newlinesBetween` and `newlinesInside` control spacing between groups and statements.
|
|
40
|
+
- `partitionByComment` and `partitionByNewLine` define separate sorting regions.
|
|
41
|
+
|
|
42
|
+
Execution dependencies take priority over the configured order. Automatic fixes apply only to changes that can be verified to preserve behavior; recognizing a Vue API call does not make it safe to move. Fixes cover independent type declarations, primitive constant declarations, ordinary function declarations, and spacing. Reordering runtime calls, watchers, or lifecycle registrations is reported without an automatic fix.
|
|
43
|
+
|
|
44
|
+
The rule keeps imports in place and leaves import sorting to `perfectionist/sort-imports`. Disable `perfectionist/sort-modules` and `vue/define-macros-order` for the same `.vue` files when this rule manages their declarations and macros.
|
|
45
|
+
|
|
46
|
+
See the [rule documentation](./docs/rules/sort-script-setup.md) for all options, matching semantics, and safety limits. Full compatibility with Perfectionist's options is not promised.
|
|
47
|
+
|
|
48
|
+
## Install
|
|
49
|
+
|
|
50
|
+
Requires ESLint 9.10+ or 10 and `vue-eslint-parser` 10. TypeScript SFCs also require `@typescript-eslint/parser`.
|
|
51
|
+
|
|
52
|
+
```shell
|
|
53
|
+
npm install -D eslint-plugin-vue-perfectionist
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```shell
|
|
57
|
+
yarn add -D eslint-plugin-vue-perfectionist
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```shell
|
|
61
|
+
pnpm add -D eslint-plugin-vue-perfectionist
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
import tsParser from '@typescript-eslint/parser'
|
|
68
|
+
import vueParser from 'vue-eslint-parser'
|
|
69
|
+
import vuePerfectionist from 'eslint-plugin-vue-perfectionist'
|
|
70
|
+
|
|
71
|
+
export default [
|
|
72
|
+
{
|
|
73
|
+
files: ['**/*.vue'],
|
|
74
|
+
languageOptions: {
|
|
75
|
+
parser: vueParser,
|
|
76
|
+
parserOptions: { parser: tsParser },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
vuePerfectionist.configs.recommended,
|
|
80
|
+
]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
For JavaScript-only SFCs, omit `parserOptions.parser`. Existing Vue configurations can supply the parsers instead. The plugin also exports `recommended-natural` and `recommended-alphabetical` presets through `configs`.
|
|
84
|
+
|
|
85
|
+
## Credits
|
|
86
|
+
|
|
87
|
+
- [eslint-plugin-perfectionist](https://github.com/azat-io/eslint-plugin-perfectionist) for inspiring the sorting rule names, grouping model, and configuration API.
|
|
88
|
+
- [eslint-plugin-vue](https://github.com/vuejs/eslint-plugin-vue) and [vue-eslint-parser](https://github.com/vuejs/vue-eslint-parser) for their work on Vue linting and single-file component parsing.
|
|
89
|
+
|
|
90
|
+
This is an independent project and is not an official extension of `eslint-plugin-perfectionist` or `eslint-plugin-vue`.
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
[MIT](./LICENSE) License © 2026-PRESENT [ntnyq](https://github.com/ntnyq)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import "@typescript-eslint/utils";
|
|
2
|
+
import { ESLint, Linter } from "eslint";
|
|
3
|
+
//#region src/types/plugins.d.ts
|
|
4
|
+
type PresetName = 'recommended-alphabetical' | 'recommended-natural' | 'recommended';
|
|
5
|
+
type PluginConfigs = Record<PresetName, Linter.Config>;
|
|
6
|
+
/**
|
|
7
|
+
* Public plugin contract keeps ESLint's host types portable in declarations.
|
|
8
|
+
*/
|
|
9
|
+
interface VuePerfectionistPlugin extends ESLint.Plugin {
|
|
10
|
+
configs: PluginConfigs;
|
|
11
|
+
meta: {
|
|
12
|
+
name: string;
|
|
13
|
+
version: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/types/rules/sort-script-setup.d.ts
|
|
18
|
+
type SortType = 'alphabetical' | 'custom' | 'line-length' | 'natural' | 'unsorted';
|
|
19
|
+
type SortOrder = 'asc' | 'desc';
|
|
20
|
+
type Newlines = 'ignore' | number;
|
|
21
|
+
type RegexPattern = string | {
|
|
22
|
+
pattern: string;
|
|
23
|
+
flags?: string;
|
|
24
|
+
};
|
|
25
|
+
type RegexOption = RegexPattern | RegexPattern[];
|
|
26
|
+
type CommentPartition = boolean | RegexOption | {
|
|
27
|
+
block?: boolean | RegexOption;
|
|
28
|
+
line?: boolean | RegexOption;
|
|
29
|
+
};
|
|
30
|
+
interface FallbackSort {
|
|
31
|
+
type: 'subgroup-order' | SortType;
|
|
32
|
+
order?: SortOrder;
|
|
33
|
+
}
|
|
34
|
+
interface GroupOverrides {
|
|
35
|
+
fallbackSort?: FallbackSort;
|
|
36
|
+
newlinesInside?: Newlines;
|
|
37
|
+
order?: SortOrder;
|
|
38
|
+
type?: SortType;
|
|
39
|
+
}
|
|
40
|
+
type GroupEntry = string | string[] | (GroupOverrides & {
|
|
41
|
+
group: string | string[];
|
|
42
|
+
}) | {
|
|
43
|
+
newlinesBetween: Newlines;
|
|
44
|
+
};
|
|
45
|
+
type Selector = 'call' | 'class' | 'composable' | 'computed' | 'constant' | 'define-emits' | 'define-expose' | 'define-model' | 'define-options' | 'define-props' | 'define-slots' | 'enum' | 'function' | 'inject' | 'interface' | 'lifecycle-hook' | 'provide' | 'reactive' | 'ref' | 'template-ref' | 'type' | 'variable' | 'watch';
|
|
46
|
+
type Modifier = 'async' | 'const' | 'declare' | 'destructured' | 'let' | 'var';
|
|
47
|
+
interface MatchCondition {
|
|
48
|
+
callNamePattern?: RegexOption;
|
|
49
|
+
elementNamePattern?: RegexOption;
|
|
50
|
+
importSourcePattern?: RegexOption;
|
|
51
|
+
modifiers?: Modifier[];
|
|
52
|
+
selector?: Selector;
|
|
53
|
+
}
|
|
54
|
+
type CustomGroup = GroupOverrides & {
|
|
55
|
+
groupName: string;
|
|
56
|
+
} & ((MatchCondition & {
|
|
57
|
+
anyOf?: never;
|
|
58
|
+
}) | {
|
|
59
|
+
anyOf: MatchCondition[];
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* Sorting preferences shared by the rule and plugin settings.
|
|
63
|
+
*/
|
|
64
|
+
interface CommonSortOptions {
|
|
65
|
+
alphabet?: string;
|
|
66
|
+
fallbackSort?: FallbackSort;
|
|
67
|
+
ignoreCase?: boolean;
|
|
68
|
+
locales?: string | string[];
|
|
69
|
+
newlinesBetween?: Newlines;
|
|
70
|
+
newlinesInside?: 'newlinesBetween' | Newlines;
|
|
71
|
+
order?: SortOrder;
|
|
72
|
+
partitionByComment?: CommentPartition;
|
|
73
|
+
partitionByNewLine?: boolean;
|
|
74
|
+
specialCharacters?: 'keep' | 'remove' | 'trim';
|
|
75
|
+
type?: SortType;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Options for ordering top-level Vue 3 script setup statements.
|
|
79
|
+
*/
|
|
80
|
+
interface SortScriptSetupOptions extends CommonSortOptions {
|
|
81
|
+
customGroups?: CustomGroup[];
|
|
82
|
+
fix?: 'none' | 'safe';
|
|
83
|
+
groups?: GroupEntry[];
|
|
84
|
+
vueGlobals?: string[];
|
|
85
|
+
vueImportSources?: string[];
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/configs.d.ts
|
|
89
|
+
export declare const configs: PluginConfigs;
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/index.d.ts
|
|
92
|
+
export declare const plugin: VuePerfectionistPlugin;
|
|
93
|
+
//#endregion
|
|
94
|
+
export { type CommonSortOptions, type CustomGroup, type GroupEntry, type PluginConfigs, type PresetName, type SortScriptSetupOptions, type VuePerfectionistPlugin, plugin as default };
|