eslint-plugin-function-rule 0.0.10 → 0.0.12
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 +48 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
# eslint-plugin-function-rule
|
|
2
|
-
|
|
3
1
|
ESLint plugin to write custom rules with JavaScript functions.
|
|
4
2
|
|
|
5
3
|
> [!WARNING]
|
|
6
4
|
> This package is a work in progress and is not yet ready for production use.
|
|
7
5
|
|
|
6
|
+
## Index
|
|
7
|
+
|
|
8
|
+
- [Index](#index)
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [Write function rules inline](#write-function-rules-inline)
|
|
11
|
+
- [Or import function rules from modules](#or-import-function-rules-from-modules)
|
|
12
|
+
- [Define multiple function rules with custom prefix](#define-multiple-function-rules-with-custom-prefix)
|
|
13
|
+
- [License](#license)
|
|
14
|
+
|
|
8
15
|
## Installation
|
|
9
16
|
|
|
10
17
|
```sh
|
|
@@ -12,9 +19,7 @@ ESLint plugin to write custom rules with JavaScript functions.
|
|
|
12
19
|
npm install --save-dev eslint-plugin-function-rule
|
|
13
20
|
```
|
|
14
21
|
|
|
15
|
-
##
|
|
16
|
-
|
|
17
|
-
### Write function rules inline
|
|
22
|
+
## Write function rules inline
|
|
18
23
|
|
|
19
24
|
```js
|
|
20
25
|
// eslint.config.ts
|
|
@@ -43,10 +48,10 @@ export default defineConfig(
|
|
|
43
48
|
{
|
|
44
49
|
files: ["**/*.ts"],
|
|
45
50
|
rules: {
|
|
46
|
-
"function-rule/
|
|
51
|
+
"function-rule/function-rule": "error",
|
|
47
52
|
},
|
|
48
53
|
plugins: {
|
|
49
|
-
"function-rule": defineRule(
|
|
54
|
+
"function-rule": defineRule((context) => {
|
|
50
55
|
return {
|
|
51
56
|
DebuggerStatement(node) {
|
|
52
57
|
context.report({
|
|
@@ -65,7 +70,7 @@ export default defineConfig(
|
|
|
65
70
|
);
|
|
66
71
|
```
|
|
67
72
|
|
|
68
|
-
|
|
73
|
+
## Or import function rules from modules
|
|
69
74
|
|
|
70
75
|
```js
|
|
71
76
|
// noDebugger.ts
|
|
@@ -97,6 +102,7 @@ export function noDebugger(options?: noDebuggerOptions) {
|
|
|
97
102
|
// eslint.config.ts
|
|
98
103
|
|
|
99
104
|
// ...
|
|
105
|
+
import { defineRule } from "eslint-plugin-function-rule";
|
|
100
106
|
import { noDebugger } from "./noDebugger.ts";
|
|
101
107
|
|
|
102
108
|
export default defineConfig(
|
|
@@ -104,11 +110,43 @@ export default defineConfig(
|
|
|
104
110
|
{
|
|
105
111
|
files: ["**/*.ts"],
|
|
106
112
|
rules: {
|
|
107
|
-
"
|
|
113
|
+
"function-rule/function-rule": "error",
|
|
114
|
+
},
|
|
115
|
+
plugins: {
|
|
116
|
+
"function-rule": defineRule(noDebugger({ /* pass rule options */ })),
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Define multiple function rules with custom prefix
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
// eslint.config.ts
|
|
126
|
+
|
|
127
|
+
// ...
|
|
128
|
+
import { defineRule } from "eslint-plugin-function-rule";
|
|
129
|
+
|
|
130
|
+
export default defineConfig(
|
|
131
|
+
// ...
|
|
132
|
+
{
|
|
133
|
+
files: ["**/*.ts"],
|
|
134
|
+
rules: {
|
|
135
|
+
"custom-1/function-rule": 1,
|
|
136
|
+
"custom-2/function-rule": 2,
|
|
108
137
|
},
|
|
109
138
|
plugins: {
|
|
110
|
-
"
|
|
139
|
+
"custom-1": defineRule((context) => {
|
|
140
|
+
return { /* your won rule logic */ }
|
|
141
|
+
}),
|
|
142
|
+
"custom-2": defineRule((context) => {
|
|
143
|
+
return { /* your won rule logic */ }
|
|
144
|
+
}),
|
|
111
145
|
},
|
|
112
146
|
},
|
|
113
147
|
);
|
|
114
148
|
```
|
|
149
|
+
|
|
150
|
+
## License
|
|
151
|
+
|
|
152
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Rule } from "eslint";
|
|
2
2
|
|
|
3
3
|
//#region index.d.ts
|
|
4
|
-
declare function defineRule(
|
|
4
|
+
declare function defineRule(create: Rule.RuleModule["create"]): {
|
|
5
5
|
readonly rules: {
|
|
6
|
-
readonly
|
|
6
|
+
readonly "function-rule": {
|
|
7
7
|
readonly meta: {
|
|
8
8
|
readonly fixable: "code";
|
|
9
9
|
readonly hasSuggestions: true;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region index.ts
|
|
2
|
-
function defineRule(
|
|
3
|
-
return { rules: {
|
|
2
|
+
function defineRule(create) {
|
|
3
|
+
return { rules: { "function-rule": {
|
|
4
4
|
meta: {
|
|
5
5
|
fixable: "code",
|
|
6
6
|
hasSuggestions: true
|
|
@@ -8,10 +8,10 @@ function defineRule(name, create) {
|
|
|
8
8
|
create
|
|
9
9
|
} } };
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
let id = 0;
|
|
12
12
|
function defineRuleListener(ruleListener) {
|
|
13
13
|
const listener = {};
|
|
14
|
-
for (const key of Object.keys(ruleListener)) listener[key + `[type!=${id}]`] = ruleListener[key];
|
|
14
|
+
for (const key of Object.keys(ruleListener)) listener[key + `[type!=${id++}]`] = ruleListener[key];
|
|
15
15
|
return listener;
|
|
16
16
|
}
|
|
17
17
|
|