eslint-plugin-decimal-system 1.0.0

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 ADDED
@@ -0,0 +1,92 @@
1
+ ## @fenazemax/eslint-plugin-decimal-system
2
+
3
+ ESLint plugin that enforces usage of decimal numeric literals only.
4
+
5
+ ## Disallows:
6
+
7
+ - Hexadecimal (`0xFF`)
8
+ - Binary (`0b1010`)
9
+ - Octal (`0o755`)
10
+ - BigInt in non-decimal form (`0xFFn`)
11
+
12
+ Allows:
13
+
14
+ - Decimal numbers (`10`, `12345`, `0`, `42n`)
15
+
16
+ ## Installation
17
+ ```bash
18
+ npm install --save-dev @fenazemax/eslint-plugin-decimal-system
19
+ ```
20
+
21
+ Peer dependency:
22
+ ```bash
23
+ npm install --save-dev eslint
24
+ ```
25
+
26
+ ### Usage
27
+ ESLint 9 (Flat Config)
28
+ ```js
29
+ import decimal from "@fenazemax/eslint-plugin-decimal-system";
30
+
31
+ export default [
32
+ {
33
+ plugins: {
34
+ decimal,
35
+ },
36
+ },
37
+ ...decimal.configs.recommended,
38
+ ];
39
+ ```
40
+
41
+ Or enable manually:
42
+ ```js
43
+
44
+ export default [
45
+ {
46
+ plugins: { decimal },
47
+ rules: {
48
+ "decimal/decimal-system-only": "error",
49
+ },
50
+ },
51
+ ];
52
+ ```
53
+ ### Legacy Config (.eslintrc)
54
+ ```js
55
+ {
56
+ "extends": ["plugin:decimal/recommended"]
57
+ }
58
+ ```
59
+
60
+ Or:
61
+ ```js
62
+ {
63
+ "plugins": ["decimal"],
64
+ "rules": {
65
+ "decimal/decimal-system-only": "error"
66
+ }
67
+ }
68
+ ```
69
+
70
+ ### Rule Details
71
+
72
+ - The rule checks all Literal AST nodes and reports when:
73
+
74
+ - The literal is number or bigint
75
+
76
+ - The raw source starts with 0x, 0b, or 0o
77
+
78
+ ### When to Use
79
+
80
+ - This rule is useful when:
81
+
82
+ - Enforcing numeric consistency in codebases
83
+
84
+ - Avoiding mixed numeral systems
85
+
86
+ - Improving readability
87
+
88
+ - Preventing accidental octal usage
89
+
90
+ ### License
91
+
92
+ ISC
@@ -0,0 +1,23 @@
1
+ export declare const rules: {
2
+ "decimal-system-only": import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"unexpected", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
3
+ };
4
+ export declare const configs: {
5
+ recommended: {
6
+ rules: {
7
+ "decimal/decimal-system-only": string;
8
+ };
9
+ };
10
+ };
11
+ declare const _default: {
12
+ rules: {
13
+ "decimal-system-only": import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"unexpected", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
14
+ };
15
+ configs: {
16
+ recommended: {
17
+ rules: {
18
+ "decimal/decimal-system-only": string;
19
+ };
20
+ };
21
+ };
22
+ };
23
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import decimalSystemOnly from "./rules/decimal-system-only";
2
+ export const rules = {
3
+ "decimal-system-only": decimalSystemOnly,
4
+ };
5
+ export const configs = {
6
+ recommended: {
7
+ rules: {
8
+ "decimal/decimal-system-only": "error",
9
+ },
10
+ },
11
+ };
12
+ export default {
13
+ rules,
14
+ configs,
15
+ };
@@ -0,0 +1 @@
1
+ export declare const NON_DECIMAL_REGEX: RegExp;
package/dist/regex.js ADDED
@@ -0,0 +1 @@
1
+ export const NON_DECIMAL_REGEX = /^0[xob]/i;
@@ -0,0 +1,3 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ declare const rule: ESLintUtils.RuleModule<"unexpected", [], unknown, ESLintUtils.RuleListener>;
3
+ export default rule;
@@ -0,0 +1,27 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ import { NON_DECIMAL_REGEX } from '../regex';
3
+ const rule = ESLintUtils.RuleCreator.withoutDocs({
4
+ create(context) {
5
+ return {
6
+ Literal(node) {
7
+ if ((typeof node.value === "number" || typeof node.value === "bigint") &&
8
+ typeof node.raw === 'string' &&
9
+ NON_DECIMAL_REGEX.test(node.raw)) {
10
+ context.report({
11
+ messageId: 'unexpected',
12
+ node
13
+ });
14
+ }
15
+ }
16
+ };
17
+ },
18
+ meta: {
19
+ type: "problem",
20
+ schema: [],
21
+ messages: {
22
+ unexpected: "Only decimal literals are allowed",
23
+ },
24
+ },
25
+ defaultOptions: [],
26
+ });
27
+ export default rule;
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "eslint-plugin-decimal-system",
3
+ "version": "1.0.0",
4
+ "description": "ESLint plugin that allows only decimal numeric literals",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "types": "./dist/index.d.ts"
10
+ }
11
+ },
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "files": ["dist"],
15
+ "keywords": ["eslint", "eslintplugin"],
16
+ "license": "ISC",
17
+ "peerDependencies": {
18
+ "eslint": "^9.0.0"
19
+ },
20
+ "devDependencies": {
21
+ "typescript": "^5.9.3",
22
+ "@typescript-eslint/utils": "^8.56.1",
23
+ "@types/eslint": "^9.0.0"
24
+ },
25
+ "scripts": {
26
+ "build": "tsc",
27
+ "prepare": "npm run build"
28
+ }
29
+ }