eslint-plugin-function-rule 0.0.16 → 0.0.17
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 +21 -24
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
ESLint plugin to write custom rules with JavaScript functions.
|
|
2
2
|
|
|
3
|
-
> [!WARNING]
|
|
4
|
-
> This package is a work in progress and is not yet ready for production use.
|
|
5
|
-
|
|
6
3
|
## Index
|
|
7
4
|
|
|
8
5
|
- [Index](#index)
|
|
@@ -57,28 +54,28 @@ export default defineConfig(
|
|
|
57
54
|
## Or import function rules from modules
|
|
58
55
|
|
|
59
56
|
```js
|
|
60
|
-
//
|
|
57
|
+
// no-null.ts
|
|
61
58
|
|
|
62
59
|
import type { Rule } from "eslint";
|
|
63
|
-
import { functionRuleListener } from "eslint-plugin-function-rule";
|
|
64
|
-
|
|
65
|
-
// Define and document function rule options
|
|
66
|
-
export interface noDebuggerOptions {}
|
|
67
60
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
61
|
+
export function noNull(options?: { enableAutoFix?: boolean; enableSuggest?: boolean }) {
|
|
62
|
+
const { enableAutoFix = false, enableSuggest = false } = options ?? {};
|
|
63
|
+
return (context: Rule.RuleContext): Rule.RuleListener => {
|
|
64
|
+
return {
|
|
65
|
+
Literal(node) {
|
|
66
|
+
if (node.raw !== "null") return;
|
|
67
|
+
function fix(fixer: Rule.RuleFixer) {
|
|
68
|
+
return fixer.replaceText(node, "undefined");
|
|
69
|
+
}
|
|
70
|
+
context.report({
|
|
71
|
+
node: node.parent,
|
|
72
|
+
message: "Avoid using 'null'; Use 'undefined' instead.",
|
|
73
|
+
...enableAutoFix ? { fix } : {},
|
|
74
|
+
...enableSuggest ? { suggest: [{ fix, desc: "Replace with 'undefined'." }] } : {},
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
};
|
|
82
79
|
}
|
|
83
80
|
```
|
|
84
81
|
|
|
@@ -87,7 +84,7 @@ export function noDebugger(options?: noDebuggerOptions) {
|
|
|
87
84
|
|
|
88
85
|
import { functionRule } from "eslint-plugin-function-rule";
|
|
89
86
|
import { defineConfig } from "eslint/config";
|
|
90
|
-
import {
|
|
87
|
+
import { noNull } from "./no-null.ts";
|
|
91
88
|
|
|
92
89
|
export default defineConfig(
|
|
93
90
|
{
|
|
@@ -96,7 +93,7 @@ export default defineConfig(
|
|
|
96
93
|
"function-rule/function-rule": "error",
|
|
97
94
|
},
|
|
98
95
|
plugins: {
|
|
99
|
-
"function-rule": functionRule(
|
|
96
|
+
"function-rule": functionRule(noNull({ enableAutoFix: true })),
|
|
100
97
|
},
|
|
101
98
|
},
|
|
102
99
|
);
|
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.17",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
"dist",
|
|
20
20
|
"package.json"
|
|
21
21
|
],
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@eslint/core": "^1.0.0"
|
|
24
|
-
},
|
|
25
22
|
"devDependencies": {
|
|
23
|
+
"@eslint/core": "^1.0.0",
|
|
26
24
|
"dprint": "^0.50.2",
|
|
27
|
-
"
|
|
25
|
+
"eslint": "^9.39.1",
|
|
26
|
+
"tsdown": "^0.16.4",
|
|
27
|
+
"typescript": "^5.9.3"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"eslint": "^
|
|
31
|
-
"
|
|
30
|
+
"@eslint/core": "^1.0.0",
|
|
31
|
+
"eslint": "^9.39.1"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "tsdown",
|