eslint-plugin-function-rule 0.0.9 → 0.0.11
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/README.md +37 -5
- package/dist/index.d.ts +4 -4
- package/dist/index.js +9 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ npm install --save-dev eslint-plugin-function-rule
|
|
|
21
21
|
|
|
22
22
|
import eslintJs from "@eslint/js";
|
|
23
23
|
import type { Rule } from "eslint";
|
|
24
|
-
import
|
|
24
|
+
import { defineRule } from "eslint-plugin-function-rule";
|
|
25
25
|
import { defineConfig } from "eslint/config";
|
|
26
26
|
import tseslint from "typescript-eslint";
|
|
27
27
|
|
|
@@ -43,10 +43,10 @@ export default defineConfig(
|
|
|
43
43
|
{
|
|
44
44
|
files: ["**/*.ts"],
|
|
45
45
|
rules: {
|
|
46
|
-
"function-rule/
|
|
46
|
+
"function-rule/function-rule": "error",
|
|
47
47
|
},
|
|
48
48
|
plugins: {
|
|
49
|
-
"function-rule":
|
|
49
|
+
"function-rule": defineRule((context) => {
|
|
50
50
|
return {
|
|
51
51
|
DebuggerStatement(node) {
|
|
52
52
|
context.report({
|
|
@@ -93,10 +93,13 @@ export function noDebugger(options?: noDebuggerOptions) {
|
|
|
93
93
|
}
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
+
### Define function rule with default prefix
|
|
97
|
+
|
|
96
98
|
```js
|
|
97
99
|
// eslint.config.ts
|
|
98
100
|
|
|
99
101
|
// ...
|
|
102
|
+
import { defineRule } from "eslint-plugin-function-rule";
|
|
100
103
|
import { noDebugger } from "./noDebugger.ts";
|
|
101
104
|
|
|
102
105
|
export default defineConfig(
|
|
@@ -104,10 +107,39 @@ export default defineConfig(
|
|
|
104
107
|
{
|
|
105
108
|
files: ["**/*.ts"],
|
|
106
109
|
rules: {
|
|
107
|
-
"
|
|
110
|
+
"function-rule/function-rule": "error",
|
|
108
111
|
},
|
|
109
112
|
plugins: {
|
|
110
|
-
"
|
|
113
|
+
"function-rule": defineRule(noDebugger({ /* pass rule options */ })),
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Define function rule with custom prefix
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
// eslint.config.ts
|
|
123
|
+
|
|
124
|
+
// ...
|
|
125
|
+
import { defineRule } from "eslint-plugin-function-rule";
|
|
126
|
+
import { noDebugger } from "./noDebugger.ts";
|
|
127
|
+
|
|
128
|
+
export default defineConfig(
|
|
129
|
+
// ...
|
|
130
|
+
{
|
|
131
|
+
files: ["**/*.ts"],
|
|
132
|
+
rules: {
|
|
133
|
+
"no-debugger/function-rule": "error",
|
|
134
|
+
|
|
135
|
+
"custom/function-rule": "error",
|
|
136
|
+
},
|
|
137
|
+
plugins: {
|
|
138
|
+
"no-debugger": defineRule(noDebugger({ /* pass rule options */ })),
|
|
139
|
+
|
|
140
|
+
custom: defineRule((context) => {
|
|
141
|
+
return { /* your won rule logic */ }
|
|
142
|
+
}),
|
|
111
143
|
},
|
|
112
144
|
},
|
|
113
145
|
);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Rule } from "eslint";
|
|
2
2
|
|
|
3
3
|
//#region index.d.ts
|
|
4
|
-
declare function
|
|
5
|
-
declare function functionRule(name: string, create: Rule.RuleModule["create"]): {
|
|
4
|
+
declare function defineRule(create: Rule.RuleModule["create"]): {
|
|
6
5
|
readonly rules: {
|
|
7
|
-
readonly
|
|
6
|
+
readonly "function-rule": {
|
|
8
7
|
readonly meta: {
|
|
9
8
|
readonly fixable: "code";
|
|
10
9
|
readonly hasSuggestions: true;
|
|
@@ -13,5 +12,6 @@ declare function functionRule(name: string, create: Rule.RuleModule["create"]):
|
|
|
13
12
|
};
|
|
14
13
|
};
|
|
15
14
|
};
|
|
15
|
+
declare function defineRuleListener(ruleListener: Rule.RuleListener): Rule.RuleListener;
|
|
16
16
|
//#endregion
|
|
17
|
-
export {
|
|
17
|
+
export { defineRule, defineRuleListener };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
//#region index.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const listener = {};
|
|
5
|
-
for (const key of Object.keys(ruleListener)) listener[key + `[type!=${id}]`] = ruleListener[key];
|
|
6
|
-
return listener;
|
|
7
|
-
}
|
|
8
|
-
function functionRule(name, create) {
|
|
9
|
-
return { rules: { [name]: {
|
|
2
|
+
function defineRule(create) {
|
|
3
|
+
return { rules: { "function-rule": {
|
|
10
4
|
meta: {
|
|
11
5
|
fixable: "code",
|
|
12
6
|
hasSuggestions: true
|
|
@@ -14,6 +8,12 @@ function functionRule(name, create) {
|
|
|
14
8
|
create
|
|
15
9
|
} } };
|
|
16
10
|
}
|
|
11
|
+
const id = 0;
|
|
12
|
+
function defineRuleListener(ruleListener) {
|
|
13
|
+
const listener = {};
|
|
14
|
+
for (const key of Object.keys(ruleListener)) listener[key + `[type!=${id}]`] = ruleListener[key];
|
|
15
|
+
return listener;
|
|
16
|
+
}
|
|
17
17
|
|
|
18
18
|
//#endregion
|
|
19
|
-
export {
|
|
19
|
+
export { defineRule, defineRuleListener };
|