eslint-plugin-function-rule 0.0.2 → 0.0.5

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 REL1CX
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,15 +1,121 @@
1
1
  # eslint-plugin-function-rule
2
2
 
3
- To install dependencies:
3
+ ESLint plugin to write custom rules with JavaScript functions.
4
4
 
5
- ```bash
6
- bun install
5
+ > [!WARNING]
6
+ > This package is a work in progress and is not yet ready for production use.
7
+
8
+ ## Installation
9
+
10
+ ```sh
11
+ # npm
12
+ npm install --save-dev eslint-plugin-function-rule
13
+ ```
14
+
15
+ ## Configure ESLint
16
+
17
+ ### Write function rules inline
18
+
19
+ ```js
20
+ // eslint.config.js
21
+
22
+ // @ts-check
23
+ import eslintJs from "@eslint/js";
24
+ import type { RuleListener } from "@typescript-eslint/utils/ts-eslint";
25
+ import functionRule from "eslint-plugin-function-rule";
26
+ import { defineConfig } from "eslint/config";
27
+ import tseslint from "typescript-eslint";
28
+
29
+ export default defineConfig(
30
+ {
31
+ files: ["**/*.ts", "**/*.tsx"],
32
+ extends: [
33
+ eslintJs.configs.recommended,
34
+ tseslint.configs.recommended,
35
+ ],
36
+ languageOptions: {
37
+ parser: tseslint.parser,
38
+ parserOptions: {
39
+ projectService: true,
40
+ tsconfigRootDir: import.meta.dirname,
41
+ },
42
+ },
43
+ },
44
+ {
45
+ files: ["**/*.ts"],
46
+ rules: {
47
+ "function-rule/function-rule": "error",
48
+ },
49
+ plugins: {
50
+ "function-rule": functionRule((context) => {
51
+ return {
52
+ DebuggerStatement(node) {
53
+ context.report({
54
+ node,
55
+ message: "Remove 'debugger' from code.",
56
+
57
+ fix(fixer) {
58
+ return fixer.remove(node);
59
+ },
60
+ });
61
+ },
62
+ } satisfies RuleListener;
63
+ }),
64
+ },
65
+ },
66
+ );
7
67
  ```
8
68
 
9
- To run:
69
+ ### Import function rules from packages
70
+
71
+ ```js
72
+ // noDebugger.ts
73
+
74
+ /**
75
+ * Remove console methods from code
76
+ * @param options The rule options
77
+ * @returns RuleFunction
78
+ */
79
+ export function noDebugger(options?: unknown): RuleDefinition["create"] {
80
+ return (context) => {
81
+ return {
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
+ },
92
+ } satisfies RuleListener;
93
+ };
94
+ }
10
95
 
11
- ```bash
12
- bun run index.ts
13
96
  ```
14
97
 
15
- This project was created using `bun init` in bun v1.3.2. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
98
+ ```js
99
+ // eslint.config.js
100
+
101
+ // @ts-check
102
+ // ...
103
+ import { noDebugger } from "./noDebugger.ts";
104
+
105
+ const noDebuggerRule = noDebugger({/* rule options */});
106
+
107
+ export default defineConfig(
108
+ // ...
109
+ {
110
+ files: ["**/*.ts"],
111
+ rules: {
112
+ "function-rule/function-rule": "error",
113
+ },
114
+ plugins: {
115
+ "function-rule": functionRule((context) => {
116
+ noDebuggerRule(context);
117
+ }),
118
+ },
119
+ },
120
+ );
121
+ ```
package/dist/index.d.ts CHANGED
@@ -3,13 +3,13 @@ import { RuleDefinition } from "@eslint/core";
3
3
 
4
4
  //#region index.d.ts
5
5
  declare function functionRule(create: RuleDefinition["create"]): {
6
- rules: {
7
- "function-rule": {
8
- meta: {
9
- fixable: string;
10
- hasSuggestions: boolean;
6
+ readonly rules: {
7
+ readonly "function-rule": {
8
+ readonly meta: {
9
+ readonly fixable: "code";
10
+ readonly hasSuggestions: true;
11
11
  };
12
- create: (context: _eslint_core0.RuleContext<{
12
+ readonly create: (context: _eslint_core0.RuleContext<{
13
13
  LangOptions: _eslint_core0.LanguageOptions;
14
14
  Code: _eslint_core0.SourceCode<{
15
15
  LangOptions: _eslint_core0.LanguageOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-function-rule",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "type": "module",