eslint-plugin-function-rule 0.0.17 → 0.1.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 REL1CX
3
+ Copyright (c) 2025 Rel1cx
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ESLint plugin to write custom rules with JavaScript functions.
1
+ An ESLint plugin to write custom rules with JavaScript functions.
2
2
 
3
3
  ## Index
4
4
 
@@ -18,12 +18,12 @@ npm install --save-dev eslint-plugin-function-rule
18
18
 
19
19
  ## Write function rules inline
20
20
 
21
- ```js
21
+ ```ts
22
22
  // eslint.config.ts
23
23
 
24
24
  import type { Rule } from "eslint";
25
- import { defineConfig } from "eslint/config";
26
25
  import { functionRule } from "eslint-plugin-function-rule";
26
+ import { defineConfig } from "eslint/config";
27
27
 
28
28
  export default defineConfig(
29
29
  {
@@ -53,7 +53,7 @@ export default defineConfig(
53
53
 
54
54
  ## Or import function rules from modules
55
55
 
56
- ```js
56
+ ```ts
57
57
  // no-null.ts
58
58
 
59
59
  import type { Rule } from "eslint";
@@ -63,7 +63,7 @@ export function noNull(options?: { enableAutoFix?: boolean; enableSuggest?: bool
63
63
  return (context: Rule.RuleContext): Rule.RuleListener => {
64
64
  return {
65
65
  Literal(node) {
66
- if (node.raw !== "null") return;
66
+ if (node.raw !== "null" || node.parent.type !== "BinaryExpression") return;
67
67
  function fix(fixer: Rule.RuleFixer) {
68
68
  return fixer.replaceText(node, "undefined");
69
69
  }
@@ -79,7 +79,7 @@ export function noNull(options?: { enableAutoFix?: boolean; enableSuggest?: bool
79
79
  }
80
80
  ```
81
81
 
82
- ```js
82
+ ```ts
83
83
  // eslint.config.ts
84
84
 
85
85
  import { functionRule } from "eslint-plugin-function-rule";
@@ -101,7 +101,7 @@ export default defineConfig(
101
101
 
102
102
  ## Define multiple function rules with custom prefix
103
103
 
104
- ```js
104
+ ```ts
105
105
  // eslint.config.ts
106
106
 
107
107
  import { functionRule } from "eslint-plugin-function-rule";
@@ -116,10 +116,28 @@ export default defineConfig(
116
116
  },
117
117
  plugins: {
118
118
  "custom-1": functionRule((context) => {
119
- return {/* your won rule logic */};
119
+ return {
120
+ CallExpression(node) {
121
+ if (context.sourceCode.getText(node.callee) === "Date.now") {
122
+ context.report({
123
+ node,
124
+ message: "Don't use 'Date.now'.",
125
+ });
126
+ }
127
+ },
128
+ };
120
129
  }),
121
130
  "custom-2": functionRule((context) => {
122
- return {/* your won rule logic */};
131
+ return {
132
+ CallExpression(node) {
133
+ if (context.sourceCode.getText(node.callee) === "Math.random") {
134
+ context.report({
135
+ node,
136
+ message: "Don't use 'Math.random()'.",
137
+ });
138
+ }
139
+ },
140
+ };
123
141
  }),
124
142
  },
125
143
  },
package/dist/index.d.ts CHANGED
@@ -2,7 +2,20 @@ import { Plugin } from "@eslint/core";
2
2
  import { Rule } from "eslint";
3
3
 
4
4
  //#region src/index.d.ts
5
+
6
+ /**
7
+ * Wraps an ESLint rule's create function as an ESLint Plugin with a single rule named "function-rule".
8
+ * The rule is fixable and supports suggestions.
9
+ * @param create The rule's listener create function.
10
+ * @returns ESLint Plugin object with "function-rule".
11
+ */
5
12
  declare function functionRule(create: Rule.RuleModule["create"]): Plugin;
13
+ /**
14
+ * Returns a copy of the given rule listener,
15
+ * but prepends an increasing number of spaces to each event key name for uniqueness.
16
+ * @param ruleListener ESLint rule listener object (mapping event name to handler).
17
+ * @returns New rule listener object with modified keys for uniqueness.
18
+ */
6
19
  declare function defineRuleListener(ruleListener: Rule.RuleListener): Rule.RuleListener;
7
20
  //#endregion
8
21
  export { defineRuleListener, functionRule };
package/dist/index.js CHANGED
@@ -1,4 +1,10 @@
1
1
  //#region src/index.ts
2
+ /**
3
+ * Wraps an ESLint rule's create function as an ESLint Plugin with a single rule named "function-rule".
4
+ * The rule is fixable and supports suggestions.
5
+ * @param create The rule's listener create function.
6
+ * @returns ESLint Plugin object with "function-rule".
7
+ */
2
8
  function functionRule(create) {
3
9
  return { rules: { "function-rule": {
4
10
  meta: {
@@ -9,6 +15,12 @@ function functionRule(create) {
9
15
  } } };
10
16
  }
11
17
  let id = 1;
18
+ /**
19
+ * Returns a copy of the given rule listener,
20
+ * but prepends an increasing number of spaces to each event key name for uniqueness.
21
+ * @param ruleListener ESLint rule listener object (mapping event name to handler).
22
+ * @returns New rule listener object with modified keys for uniqueness.
23
+ */
12
24
  function defineRuleListener(ruleListener) {
13
25
  const listener = {};
14
26
  for (const key of Object.keys(ruleListener)) listener[" ".repeat(id++) + key] = ruleListener[key];
package/package.json CHANGED
@@ -1,39 +1,44 @@
1
1
  {
2
2
  "name": "eslint-plugin-function-rule",
3
- "version": "0.0.17",
3
+ "version": "0.1.1",
4
+ "description": "An ESLint plugin to write custom rules with JavaScript functions.",
5
+ "homepage": "https://github.com/Rel1cx/dx",
6
+ "bugs": {
7
+ "url": "https://github.com/Rel1cx/dx/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Rel1cx/dx.git"
12
+ },
4
13
  "license": "MIT",
14
+ "author": "Rel1cx<rel1cx@proton.me>",
5
15
  "sideEffects": false,
6
16
  "type": "module",
7
17
  "exports": {
8
18
  ".": {
9
- "import": {
10
- "types": "./dist/index.d.ts",
11
- "default": "./dist/index.js"
12
- }
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
13
21
  },
14
22
  "./package.json": "./package.json"
15
23
  },
24
+ "main": "./dist/index.js",
16
25
  "module": "./dist/index.js",
17
26
  "types": "./dist/index.d.ts",
18
27
  "files": [
19
28
  "dist",
20
- "package.json"
29
+ "./package.json"
21
30
  ],
22
- "devDependencies": {
23
- "@eslint/core": "^1.0.0",
24
- "dprint": "^0.50.2",
25
- "eslint": "^9.39.1",
26
- "tsdown": "^0.16.4",
27
- "typescript": "^5.9.3"
28
- },
29
31
  "peerDependencies": {
30
32
  "@eslint/core": "^1.0.0",
31
33
  "eslint": "^9.39.1"
32
34
  },
35
+ "engines": {
36
+ "node": ">=20.0.0"
37
+ },
33
38
  "scripts": {
34
- "build": "tsdown",
35
- "format:check": "dprint check",
36
- "format:write": "dprint fmt",
37
- "type-check": "tsc --noEmit"
39
+ "build": "tsdown --dts-resolve",
40
+ "build:docs": "typedoc",
41
+ "lint:publish": "publint",
42
+ "lint:ts": "tsc --noEmit"
38
43
  }
39
44
  }