@oxlint/plugins 1.43.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 +22 -0
- package/README.md +95 -0
- package/index.cjs +110 -0
- package/index.d.ts +3954 -0
- package/index.js +110 -0
- package/package.json +43 -0
package/index.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
function definePlugin(plugin) {
|
|
2
|
+
return plugin;
|
|
3
|
+
}
|
|
4
|
+
function defineRule(rule) {
|
|
5
|
+
return rule;
|
|
6
|
+
}
|
|
7
|
+
const EMPTY_VISITOR = {};
|
|
8
|
+
function eslintCompatPlugin(plugin) {
|
|
9
|
+
if (typeof plugin != "object" || !plugin) throw Error("Plugin must be an object");
|
|
10
|
+
let { rules } = plugin;
|
|
11
|
+
if (typeof rules != "object" || !rules) throw Error("Plugin must have an object as `rules` property");
|
|
12
|
+
for (let ruleName in rules) Object.hasOwn(rules, ruleName) && convertRule(rules[ruleName]);
|
|
13
|
+
return plugin;
|
|
14
|
+
}
|
|
15
|
+
function convertRule(rule) {
|
|
16
|
+
if (typeof rule != "object" || !rule) throw Error("Rule must be an object");
|
|
17
|
+
if ("create" in rule) return;
|
|
18
|
+
let context = null, visitor, beforeHook;
|
|
19
|
+
rule.create = (eslintContext) => (context === null && ({context, visitor, beforeHook} = createContextAndVisitor(rule)), Object.defineProperties(context, {
|
|
20
|
+
id: { value: eslintContext.id },
|
|
21
|
+
options: { value: eslintContext.options },
|
|
22
|
+
report: { value: eslintContext.report }
|
|
23
|
+
}), Object.setPrototypeOf(context, Object.getPrototypeOf(eslintContext)), beforeHook !== null && beforeHook() === !1 ? EMPTY_VISITOR : visitor);
|
|
24
|
+
}
|
|
25
|
+
const FILE_CONTEXT = Object.freeze({
|
|
26
|
+
get filename() {
|
|
27
|
+
throw Error("Cannot access `context.filename` in `createOnce`");
|
|
28
|
+
},
|
|
29
|
+
getFilename() {
|
|
30
|
+
throw Error("Cannot call `context.getFilename` in `createOnce`");
|
|
31
|
+
},
|
|
32
|
+
get physicalFilename() {
|
|
33
|
+
throw Error("Cannot access `context.physicalFilename` in `createOnce`");
|
|
34
|
+
},
|
|
35
|
+
getPhysicalFilename() {
|
|
36
|
+
throw Error("Cannot call `context.getPhysicalFilename` in `createOnce`");
|
|
37
|
+
},
|
|
38
|
+
get cwd() {
|
|
39
|
+
throw Error("Cannot access `context.cwd` in `createOnce`");
|
|
40
|
+
},
|
|
41
|
+
getCwd() {
|
|
42
|
+
throw Error("Cannot call `context.getCwd` in `createOnce`");
|
|
43
|
+
},
|
|
44
|
+
get sourceCode() {
|
|
45
|
+
throw Error("Cannot access `context.sourceCode` in `createOnce`");
|
|
46
|
+
},
|
|
47
|
+
getSourceCode() {
|
|
48
|
+
throw Error("Cannot call `context.getSourceCode` in `createOnce`");
|
|
49
|
+
},
|
|
50
|
+
get languageOptions() {
|
|
51
|
+
throw Error("Cannot access `context.languageOptions` in `createOnce`");
|
|
52
|
+
},
|
|
53
|
+
get settings() {
|
|
54
|
+
throw Error("Cannot access `context.settings` in `createOnce`");
|
|
55
|
+
},
|
|
56
|
+
extend(extension) {
|
|
57
|
+
return Object.freeze(Object.assign(Object.create(this), extension));
|
|
58
|
+
},
|
|
59
|
+
get parserOptions() {
|
|
60
|
+
throw Error("Cannot access `context.parserOptions` in `createOnce`");
|
|
61
|
+
},
|
|
62
|
+
get parserPath() {
|
|
63
|
+
throw Error("Cannot access `context.parserPath` in `createOnce`");
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
function createContextAndVisitor(rule) {
|
|
67
|
+
let { createOnce } = rule;
|
|
68
|
+
if (createOnce == null) throw Error("Rules must define either a `create` or `createOnce` method");
|
|
69
|
+
if (typeof createOnce != "function") throw Error("Rule `createOnce` property must be a function");
|
|
70
|
+
let context = Object.create(FILE_CONTEXT, {
|
|
71
|
+
id: {
|
|
72
|
+
value: "",
|
|
73
|
+
enumerable: !0,
|
|
74
|
+
configurable: !0
|
|
75
|
+
},
|
|
76
|
+
options: {
|
|
77
|
+
value: null,
|
|
78
|
+
enumerable: !0,
|
|
79
|
+
configurable: !0
|
|
80
|
+
},
|
|
81
|
+
report: {
|
|
82
|
+
value: null,
|
|
83
|
+
enumerable: !0,
|
|
84
|
+
configurable: !0
|
|
85
|
+
}
|
|
86
|
+
}), { before: beforeHook, after: afterHook, ...visitor } = createOnce.call(rule, context);
|
|
87
|
+
if (beforeHook === void 0) beforeHook = null;
|
|
88
|
+
else if (beforeHook !== null && typeof beforeHook != "function") throw Error("`before` property of visitor must be a function if defined");
|
|
89
|
+
if (afterHook != null) {
|
|
90
|
+
if (typeof afterHook != "function") throw Error("`after` property of visitor must be a function if defined");
|
|
91
|
+
let maxAttrs = -1;
|
|
92
|
+
for (let key in visitor) {
|
|
93
|
+
if (!Object.hasOwn(visitor, key) || !key.endsWith(":exit")) continue;
|
|
94
|
+
let end = key.length - 5, count = 0;
|
|
95
|
+
for (let i = 0; i < end; i++) {
|
|
96
|
+
let c = key.charCodeAt(i);
|
|
97
|
+
(c === 91 || c === 46 || c === 58) && count++;
|
|
98
|
+
}
|
|
99
|
+
count > maxAttrs && (maxAttrs = count);
|
|
100
|
+
}
|
|
101
|
+
let key = `Program${"[type]".repeat(maxAttrs + 1)}:exit`;
|
|
102
|
+
visitor[key] = (_node) => afterHook();
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
context,
|
|
106
|
+
visitor,
|
|
107
|
+
beforeHook
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
export { definePlugin, defineRule, eslintCompatPlugin };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oxlint/plugins",
|
|
3
|
+
"version": "1.43.0",
|
|
4
|
+
"description": "Plugin utilities for Oxlint",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"eslint",
|
|
7
|
+
"linter",
|
|
8
|
+
"oxlint",
|
|
9
|
+
"plugin"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://oxc.rs/docs/guide/usage/linter/js-plugins",
|
|
12
|
+
"bugs": "https://github.com/oxc-project/oxc/issues",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Boshen and oxc contributors",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/oxc-project/oxc.git",
|
|
18
|
+
"directory": "npm/oxlint-plugins"
|
|
19
|
+
},
|
|
20
|
+
"funding": {
|
|
21
|
+
"url": "https://github.com/sponsors/Boshen"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"index.js",
|
|
25
|
+
"index.cjs",
|
|
26
|
+
"index.d.ts",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"type": "module",
|
|
30
|
+
"main": "index.js",
|
|
31
|
+
"types": "index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./index.d.ts",
|
|
35
|
+
"import": "./index.js",
|
|
36
|
+
"require": "./index.cjs",
|
|
37
|
+
"default": "./index.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
|
42
|
+
}
|
|
43
|
+
}
|