@kazupon/eslint-plugin 0.1.0 → 0.1.2
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/lib/index.d.ts +14 -6
- package/lib/index.js +16 -45
- package/package.json +5 -6
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { ESLint } from "eslint";
|
|
1
|
+
import { ESLint, Linter } from "eslint";
|
|
2
2
|
|
|
3
|
-
//#region
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
type PluginConfigs = {
|
|
5
|
+
recommended: Linter.Config<Linter.RulesRecord>[]
|
|
6
|
+
comment: Linter.Config<Linter.RulesRecord>[]
|
|
7
|
+
};
|
|
8
|
+
declare const plugin: Omit<ESLint.Plugin, "configs"> & {
|
|
9
|
+
configs: PluginConfigs
|
|
10
|
+
};
|
|
11
|
+
declare const commentConfig: Linter.Config[];
|
|
12
|
+
declare const configs: {
|
|
13
|
+
recommended: typeof commentConfig
|
|
14
|
+
comment: typeof commentConfig
|
|
15
|
+
};
|
|
8
16
|
|
|
9
17
|
//#endregion
|
|
10
18
|
export { configs, plugin as default, plugin };
|
package/lib/index.js
CHANGED
|
@@ -1,68 +1,39 @@
|
|
|
1
1
|
import { parseComment } from "@es-joy/jsdoccomment";
|
|
2
|
-
import fs from "node:fs";
|
|
3
2
|
|
|
4
|
-
//#region src/utils/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/utils/meta.ts
|
|
11
|
-
const pkg = readPackageJson(new URL("../../package.json", import.meta.url));
|
|
12
|
-
const name = pkg.name;
|
|
13
|
-
const version = pkg.version;
|
|
14
|
-
const namespace = pkg.name.split("/")[0];
|
|
3
|
+
//#region src/utils/constants.ts
|
|
4
|
+
const name = "@kazupon/eslint-plugin";
|
|
5
|
+
const version = "0.1.2";
|
|
6
|
+
const namespace = "@kazupon";
|
|
15
7
|
|
|
16
8
|
//#endregion
|
|
17
9
|
//#region src/utils/rule.ts
|
|
18
|
-
const
|
|
19
|
-
/**
|
|
20
|
-
* Creates reusable function to create rules with default options and docs URLs.
|
|
21
|
-
*
|
|
22
|
-
* @param urlCreator Creates a documentation URL for a given rule name.
|
|
23
|
-
* @returns Function to create a rule with the docs URL format.
|
|
24
|
-
*/
|
|
10
|
+
const BLOB_URL = "https://github.com/kazupon/eslint-plugin/tree/main/src/rules";
|
|
25
11
|
function RuleCreator(urlCreator, namespace$1 = "") {
|
|
26
12
|
return function createNamedRule({ meta, name: name$1,...rule$1 }) {
|
|
27
13
|
const ruleId = namespace$1 ? `${namespace$1}/${name$1}` : name$1;
|
|
28
|
-
return
|
|
14
|
+
return {
|
|
29
15
|
meta: {
|
|
30
16
|
...meta,
|
|
31
17
|
docs: {
|
|
32
|
-
...meta
|
|
18
|
+
...meta?.docs,
|
|
33
19
|
url: urlCreator(name$1),
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
ruleName: name$1,
|
|
21
|
+
ruleId
|
|
36
22
|
}
|
|
37
23
|
},
|
|
38
24
|
...rule$1
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function _createRule({ create, defaultOptions, meta }) {
|
|
43
|
-
return {
|
|
44
|
-
create: (context) => {
|
|
45
|
-
const optionsWithDefault = context.options.map((options, index) => {
|
|
46
|
-
return {
|
|
47
|
-
...defaultOptions[index],
|
|
48
|
-
...options
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
return create(context, optionsWithDefault);
|
|
52
|
-
},
|
|
53
|
-
defaultOptions,
|
|
54
|
-
meta
|
|
25
|
+
};
|
|
55
26
|
};
|
|
56
27
|
}
|
|
57
28
|
const createRule = RuleCreator((ruleName) => {
|
|
58
|
-
return `${
|
|
29
|
+
return `${BLOB_URL}/${ruleName}.ts`;
|
|
59
30
|
}, namespace);
|
|
60
31
|
|
|
61
32
|
//#endregion
|
|
62
33
|
//#region src/rules/enforce-header-comment.ts
|
|
63
34
|
const ENFORCED_TAGS = ["author", "license"];
|
|
64
35
|
function initializeTagDiagnosis(tags) {
|
|
65
|
-
const tagDiagnosis =
|
|
36
|
+
const tagDiagnosis = Object.create(null);
|
|
66
37
|
for (const tag of tags) tagDiagnosis[tag] = "require";
|
|
67
38
|
return tagDiagnosis;
|
|
68
39
|
}
|
|
@@ -87,7 +58,6 @@ const rule = createRule({
|
|
|
87
58
|
},
|
|
88
59
|
schema: []
|
|
89
60
|
},
|
|
90
|
-
defaultOptions: [{}],
|
|
91
61
|
create(ctx) {
|
|
92
62
|
/**
|
|
93
63
|
* Report the tag diagnosis
|
|
@@ -191,7 +161,8 @@ const plugin = {
|
|
|
191
161
|
name,
|
|
192
162
|
version
|
|
193
163
|
},
|
|
194
|
-
rules
|
|
164
|
+
rules,
|
|
165
|
+
configs: {}
|
|
195
166
|
};
|
|
196
167
|
const commentConfig = [{
|
|
197
168
|
name: "@kazupon/eslint-plugin/comment",
|
|
@@ -199,8 +170,8 @@ const commentConfig = [{
|
|
|
199
170
|
ignores: ["**/*.md", "**/*.md/**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
|
|
200
171
|
plugins: { [namespace]: plugin },
|
|
201
172
|
rules: Object.entries(rules).reduce((rules$1, [ruleName, rule$1]) => {
|
|
202
|
-
const ruleId = rule$1.meta
|
|
203
|
-
rules$1[ruleId] = rule$1.meta
|
|
173
|
+
const ruleId = rule$1.meta?.docs?.ruleId || (namespace ? `${namespace}/${ruleName}` : ruleName);
|
|
174
|
+
rules$1[ruleId] = rule$1.meta?.docs?.defaultSeverity || "warn";
|
|
204
175
|
return rules$1;
|
|
205
176
|
}, Object.create(null))
|
|
206
177
|
}];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kazupon/eslint-plugin",
|
|
3
3
|
"description": "ESLint plugin for @kazupon",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"funding": "https://github.com/sponsors/kazupon",
|
|
7
7
|
"bugs": {
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@es-joy/jsdoccomment": "^0.50.0"
|
|
50
|
+
"@es-joy/jsdoccomment": "^0.50.0",
|
|
51
|
+
"@eslint/core": "^0.13.0"
|
|
51
52
|
},
|
|
52
53
|
"peerDependencies": {
|
|
53
|
-
"eslint": "^9.0.0"
|
|
54
|
-
"typescript-eslint": "^8.29.1"
|
|
54
|
+
"eslint": "^9.0.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@eslint/markdown": "^6.3.0",
|
|
@@ -59,7 +59,6 @@
|
|
|
59
59
|
"@kazupon/prettier-config": "^0.1.1",
|
|
60
60
|
"@shikijs/vitepress-twoslash": "^3.2.2",
|
|
61
61
|
"@types/node": "^22.14.1",
|
|
62
|
-
"@typescript-eslint/utils": "^8.29.1",
|
|
63
62
|
"@vitest/eslint-plugin": "^1.1.42",
|
|
64
63
|
"bumpp": "^10.1.0",
|
|
65
64
|
"eslint": "^9.24.0",
|
|
@@ -79,7 +78,7 @@
|
|
|
79
78
|
"pkg-pr-new": "^0.0.42",
|
|
80
79
|
"prettier": "^3.5.3",
|
|
81
80
|
"publint": "^0.3.11",
|
|
82
|
-
"tsdown": "^0.
|
|
81
|
+
"tsdown": "^0.8.0-beta.2",
|
|
83
82
|
"tsx": "^4.19.3",
|
|
84
83
|
"twoslash-eslint": "^0.3.1",
|
|
85
84
|
"typescript": "^5.8.3",
|