Skip to content

Commit cbb4e09

Browse files
committed
convert to ts
1 parent 234ec8c commit cbb4e09

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

.eslintrc.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@ module.exports = {
44
es2021: true,
55
node: true,
66
},
7-
extends: ["eslint:recommended", "airbnb-base", "prettier"],
7+
extends: [
8+
"eslint:recommended",
9+
"airbnb-base",
10+
"plugin:@typescript-eslint/recommended",
11+
"prettier",
12+
],
813
parserOptions: {
914
ecmaVersion: "latest",
1015
},
1116
rules: {
12-
strict: "off",
17+
"import/extensions": "off",
18+
"import/prefer-default-export": "off",
19+
},
20+
settings: {
21+
"import/resolver": {
22+
node: {
23+
extensions: [".js", ".ts"],
24+
},
25+
},
1326
},
1427
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"scripts": {
1111
"prepare": "husky install",
12-
"format": "prettier --check ./**/*.js",
12+
"format": "prettier --check ./**/*.ts",
1313
"lint": "eslint .",
1414
"test": "mocha tests/**/*.js",
1515
"test:watch": "mocha --watch --reporter min tests/**/*.js"
+5-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
// @ts-check
1+
import type { ESLint } from "eslint";
22

3-
"use strict";
3+
import { sortComponentsRule } from "./rules/vue-sort-components";
44

5-
const sortComponentsRule = require("./rules/vue-sort-components");
6-
7-
/** @type {import('eslint').ESLint.Plugin} */
8-
module.exports = {
5+
const plugin: ESLint.Plugin = {
96
rules: {
107
"vue-sort-components": sortComponentsRule,
118
},
@@ -18,3 +15,5 @@ module.exports = {
1815
},
1916
},
2017
};
18+
19+
export default plugin;

lib/rules/vue-sort-components.js renamed to src/rules/vue-sort-components.ts

+11-23
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
1-
// @ts-check
1+
import type { Rule } from "eslint";
2+
import type { Expression, Property, SpreadElement } from "estree";
3+
import naturalCompare from "natural-compare";
24

3-
"use strict";
4-
5-
const naturalCompare = require("natural-compare");
6-
7-
/**
8-
* @param {import('estree').Property} node
9-
* @returns {string}
10-
*/
11-
const getKeyName = (node) =>
5+
const getKeyName = (node: Property): string =>
126
node.key.type === "Identifier" ? node.key.name : "";
137

14-
/**
15-
* @param {import('estree').Expression} arg
16-
* @returns {string}
17-
*/
18-
const getArgName = (arg) => (arg.type === "Identifier" ? arg.name : "");
8+
const getArgName = (arg: Expression): string =>
9+
arg.type === "Identifier" ? arg.name : "";
1910

20-
/**
21-
* @param {import('estree').Property | import('estree').SpreadElement} a
22-
* @param {import('estree').Property | import('estree').SpreadElement} b
23-
* @returns {-1 | 0 | 1}
24-
*/
25-
const compareNodes = (a, b) => {
11+
const compareNodes = (
12+
a: Property | SpreadElement,
13+
b: Property | SpreadElement
14+
): -1 | 0 | 1 => {
2615
if (a.type === "Property" && b.type === "Property") {
2716
return naturalCompare(getKeyName(a), getKeyName(b));
2817
}
@@ -34,8 +23,7 @@ const compareNodes = (a, b) => {
3423
return a.type === "SpreadElement" ? -1 : 1;
3524
};
3625

37-
/** @type {import('eslint').Rule.RuleModule} */
38-
module.exports = {
26+
export const sortComponentsRule: Rule.RuleModule = {
3927
meta: {
4028
type: "layout",
4129
fixable: "code",

0 commit comments

Comments
 (0)