eslint-plugin-function-rule 0.0.7 → 0.0.9
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 +22 -43
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npm install --save-dev eslint-plugin-function-rule
|
|
|
20
20
|
// eslint.config.ts
|
|
21
21
|
|
|
22
22
|
import eslintJs from "@eslint/js";
|
|
23
|
-
import type {
|
|
23
|
+
import type { Rule } from "eslint";
|
|
24
24
|
import functionRule from "eslint-plugin-function-rule";
|
|
25
25
|
import { defineConfig } from "eslint/config";
|
|
26
26
|
import tseslint from "typescript-eslint";
|
|
@@ -43,10 +43,10 @@ export default defineConfig(
|
|
|
43
43
|
{
|
|
44
44
|
files: ["**/*.ts"],
|
|
45
45
|
rules: {
|
|
46
|
-
"function-rule/
|
|
46
|
+
"function-rule/v1": "error",
|
|
47
47
|
},
|
|
48
48
|
plugins: {
|
|
49
|
-
"function-rule": functionRule((context) => {
|
|
49
|
+
"function-rule": functionRule("v1", (context) => {
|
|
50
50
|
return {
|
|
51
51
|
DebuggerStatement(node) {
|
|
52
52
|
context.report({
|
|
@@ -58,7 +58,7 @@ export default defineConfig(
|
|
|
58
58
|
},
|
|
59
59
|
});
|
|
60
60
|
},
|
|
61
|
-
} satisfies RuleListener;
|
|
61
|
+
} satisfies Rule.RuleListener;
|
|
62
62
|
}),
|
|
63
63
|
},
|
|
64
64
|
},
|
|
@@ -70,65 +70,44 @@ export default defineConfig(
|
|
|
70
70
|
```js
|
|
71
71
|
// noDebugger.ts
|
|
72
72
|
|
|
73
|
-
import type {
|
|
74
|
-
import
|
|
75
|
-
import { defineRuleVisitor } from "eslint-plugin-function-rule";
|
|
73
|
+
import type { Rule } from "eslint";
|
|
74
|
+
import { defineRuleListener } from "eslint-plugin-function-rule";
|
|
76
75
|
|
|
77
76
|
// Define and document function rule options
|
|
78
|
-
export interface noDebuggerOptions {
|
|
79
|
-
/**
|
|
80
|
-
* @deprecated Use bar instead
|
|
81
|
-
*/
|
|
82
|
-
foo: string
|
|
83
|
-
bar: string
|
|
84
|
-
}
|
|
77
|
+
export interface noDebuggerOptions {}
|
|
85
78
|
|
|
86
79
|
// Define and document function rule
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
message: "Remove 'debugger' from code.",
|
|
100
|
-
|
|
101
|
-
fix(fixer) {
|
|
102
|
-
return fixer.remove(node);
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
},
|
|
80
|
+
export function noDebugger(options?: noDebuggerOptions) {
|
|
81
|
+
return (context: Rule.RuleContext) => defineRuleListener({
|
|
82
|
+
DebuggerStatement(node) {
|
|
83
|
+
context.report({
|
|
84
|
+
node,
|
|
85
|
+
message: "Remove 'debugger' from code.",
|
|
86
|
+
|
|
87
|
+
fix(fixer) {
|
|
88
|
+
return fixer.remove(node);
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
},
|
|
106
92
|
});
|
|
107
|
-
};
|
|
108
93
|
}
|
|
109
94
|
```
|
|
110
95
|
|
|
111
96
|
```js
|
|
112
|
-
//
|
|
97
|
+
// eslint.config.ts
|
|
113
98
|
|
|
114
99
|
// ...
|
|
115
100
|
import { noDebugger } from "./noDebugger.ts";
|
|
116
101
|
|
|
117
|
-
const noDebuggerRule = noDebugger({ bar: "pass rule options" });
|
|
118
|
-
|
|
119
102
|
export default defineConfig(
|
|
120
103
|
// ...
|
|
121
104
|
{
|
|
122
105
|
files: ["**/*.ts"],
|
|
123
106
|
rules: {
|
|
124
|
-
"
|
|
107
|
+
"no-debugger/v1": "error",
|
|
125
108
|
},
|
|
126
109
|
plugins: {
|
|
127
|
-
"
|
|
128
|
-
return {
|
|
129
|
-
...noDebuggerRule(context)
|
|
130
|
-
}
|
|
131
|
-
}),
|
|
110
|
+
"no-debugger": functionRule("v1", noDebugger({ /* pass rule options */ })),
|
|
132
111
|
},
|
|
133
112
|
},
|
|
134
113
|
);
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { Rule } from "eslint";
|
|
|
2
2
|
|
|
3
3
|
//#region index.d.ts
|
|
4
4
|
declare function defineRuleListener(ruleListener: Rule.RuleListener): Rule.RuleListener;
|
|
5
|
-
declare function functionRule(create: Rule.RuleModule["create"]): {
|
|
5
|
+
declare function functionRule(name: string, create: Rule.RuleModule["create"]): {
|
|
6
6
|
readonly rules: {
|
|
7
|
-
readonly
|
|
7
|
+
readonly [name]: {
|
|
8
8
|
readonly meta: {
|
|
9
9
|
readonly fixable: "code";
|
|
10
10
|
readonly hasSuggestions: true;
|
|
@@ -14,4 +14,4 @@ declare function functionRule(create: Rule.RuleModule["create"]): {
|
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
//#endregion
|
|
17
|
-
export {
|
|
17
|
+
export { defineRuleListener, functionRule };
|
package/dist/index.js
CHANGED
|
@@ -5,8 +5,8 @@ function defineRuleListener(ruleListener) {
|
|
|
5
5
|
for (const key of Object.keys(ruleListener)) listener[key + `[type!=${id}]`] = ruleListener[key];
|
|
6
6
|
return listener;
|
|
7
7
|
}
|
|
8
|
-
function functionRule(create) {
|
|
9
|
-
return { rules: {
|
|
8
|
+
function functionRule(name, create) {
|
|
9
|
+
return { rules: { [name]: {
|
|
10
10
|
meta: {
|
|
11
11
|
fixable: "code",
|
|
12
12
|
hasSuggestions: true
|
|
@@ -16,4 +16,4 @@ function functionRule(create) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
//#endregion
|
|
19
|
-
export {
|
|
19
|
+
export { defineRuleListener, functionRule };
|