eslint-plugin-function-rule 0.0.5 → 0.0.7
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 +26 -12
- package/dist/index.d.ts +5 -16
- package/dist/index.js +7 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -17,9 +17,8 @@ npm install --save-dev eslint-plugin-function-rule
|
|
|
17
17
|
### Write function rules inline
|
|
18
18
|
|
|
19
19
|
```js
|
|
20
|
-
// eslint.config.
|
|
20
|
+
// eslint.config.ts
|
|
21
21
|
|
|
22
|
-
// @ts-check
|
|
23
22
|
import eslintJs from "@eslint/js";
|
|
24
23
|
import type { RuleListener } from "@typescript-eslint/utils/ts-eslint";
|
|
25
24
|
import functionRule from "eslint-plugin-function-rule";
|
|
@@ -66,19 +65,34 @@ export default defineConfig(
|
|
|
66
65
|
);
|
|
67
66
|
```
|
|
68
67
|
|
|
69
|
-
### Import function rules from
|
|
68
|
+
### Import function rules from modules
|
|
70
69
|
|
|
71
70
|
```js
|
|
72
71
|
// noDebugger.ts
|
|
73
72
|
|
|
73
|
+
import type { RuleDefinition } from "@eslint/core";
|
|
74
|
+
import type { RuleListener } from "@typescript-eslint/utils/ts-eslint";
|
|
75
|
+
import { defineRuleVisitor } from "eslint-plugin-function-rule";
|
|
76
|
+
|
|
77
|
+
// Define and document function rule options
|
|
78
|
+
export interface noDebuggerOptions {
|
|
79
|
+
/**
|
|
80
|
+
* @deprecated Use bar instead
|
|
81
|
+
*/
|
|
82
|
+
foo: string
|
|
83
|
+
bar: string
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Define and document function rule
|
|
74
87
|
/**
|
|
75
|
-
* Remove
|
|
88
|
+
* Remove debugger from code
|
|
89
|
+
*
|
|
76
90
|
* @param options The rule options
|
|
77
91
|
* @returns RuleFunction
|
|
78
92
|
*/
|
|
79
|
-
export function noDebugger(options?:
|
|
93
|
+
export function noDebugger(options?: noDebuggerOptions): RuleDefinition["create"] {
|
|
80
94
|
return (context) => {
|
|
81
|
-
return {
|
|
95
|
+
return defineRuleVisitor({
|
|
82
96
|
DebuggerStatement(node) {
|
|
83
97
|
context.report({
|
|
84
98
|
node,
|
|
@@ -89,20 +103,18 @@ export function noDebugger(options?: unknown): RuleDefinition["create"] {
|
|
|
89
103
|
},
|
|
90
104
|
});
|
|
91
105
|
},
|
|
92
|
-
}
|
|
106
|
+
});
|
|
93
107
|
};
|
|
94
108
|
}
|
|
95
|
-
|
|
96
109
|
```
|
|
97
110
|
|
|
98
111
|
```js
|
|
99
|
-
//
|
|
112
|
+
// Import and use function rule
|
|
100
113
|
|
|
101
|
-
// @ts-check
|
|
102
114
|
// ...
|
|
103
115
|
import { noDebugger } from "./noDebugger.ts";
|
|
104
116
|
|
|
105
|
-
const noDebuggerRule = noDebugger({
|
|
117
|
+
const noDebuggerRule = noDebugger({ bar: "pass rule options" });
|
|
106
118
|
|
|
107
119
|
export default defineConfig(
|
|
108
120
|
// ...
|
|
@@ -113,7 +125,9 @@ export default defineConfig(
|
|
|
113
125
|
},
|
|
114
126
|
plugins: {
|
|
115
127
|
"function-rule": functionRule((context) => {
|
|
116
|
-
|
|
128
|
+
return {
|
|
129
|
+
...noDebuggerRule(context)
|
|
130
|
+
}
|
|
117
131
|
}),
|
|
118
132
|
},
|
|
119
133
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { RuleDefinition } from "@eslint/core";
|
|
1
|
+
import { Rule } from "eslint";
|
|
3
2
|
|
|
4
3
|
//#region index.d.ts
|
|
5
|
-
declare function
|
|
4
|
+
declare function defineRuleListener(ruleListener: Rule.RuleListener): Rule.RuleListener;
|
|
5
|
+
declare function functionRule(create: Rule.RuleModule["create"]): {
|
|
6
6
|
readonly rules: {
|
|
7
7
|
readonly "function-rule": {
|
|
8
8
|
readonly meta: {
|
|
9
9
|
readonly fixable: "code";
|
|
10
10
|
readonly hasSuggestions: true;
|
|
11
11
|
};
|
|
12
|
-
readonly create: (context:
|
|
13
|
-
LangOptions: _eslint_core0.LanguageOptions;
|
|
14
|
-
Code: _eslint_core0.SourceCode<{
|
|
15
|
-
LangOptions: _eslint_core0.LanguageOptions;
|
|
16
|
-
RootNode: unknown;
|
|
17
|
-
SyntaxElementWithLoc: unknown;
|
|
18
|
-
ConfigNode: unknown;
|
|
19
|
-
}>;
|
|
20
|
-
RuleOptions: unknown[];
|
|
21
|
-
Node: unknown;
|
|
22
|
-
MessageIds: string;
|
|
23
|
-
}>) => _eslint_core0.RuleVisitor;
|
|
12
|
+
readonly create: (context: Rule.RuleContext) => Rule.RuleListener;
|
|
24
13
|
};
|
|
25
14
|
};
|
|
26
15
|
};
|
|
27
16
|
//#endregion
|
|
28
|
-
export { functionRule as default };
|
|
17
|
+
export { functionRule as default, defineRuleListener };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
//#region index.ts
|
|
2
|
+
const id = 0;
|
|
3
|
+
function defineRuleListener(ruleListener) {
|
|
4
|
+
const listener = {};
|
|
5
|
+
for (const key of Object.keys(ruleListener)) listener[key + `[type!=${id}]`] = ruleListener[key];
|
|
6
|
+
return listener;
|
|
7
|
+
}
|
|
2
8
|
function functionRule(create) {
|
|
3
9
|
return { rules: { "function-rule": {
|
|
4
10
|
meta: {
|
|
@@ -10,4 +16,4 @@ function functionRule(create) {
|
|
|
10
16
|
}
|
|
11
17
|
|
|
12
18
|
//#endregion
|
|
13
|
-
export { functionRule as default };
|
|
19
|
+
export { functionRule as default, defineRuleListener };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-function-rule",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"tsdown": "^0.16.1"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
+
"eslint": "^9.39.1",
|
|
24
25
|
"typescript": "^5"
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|