@pobammer-ts/eslint-cease-nonsense-rules 0.4.3 → 0.5.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/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ declare const recommended: {
|
|
|
29
29
|
readonly "cease-nonsense/no-print": "error";
|
|
30
30
|
readonly "cease-nonsense/no-shorthand-names": "error";
|
|
31
31
|
readonly "cease-nonsense/no-warn": "error";
|
|
32
|
+
readonly "cease-nonsense/prefer-udim2-shorthand": "error";
|
|
32
33
|
readonly "cease-nonsense/require-react-component-keys": "error";
|
|
33
34
|
readonly "cease-nonsense/use-exhaustive-dependencies": "error";
|
|
34
35
|
readonly "cease-nonsense/use-hook-at-top-level": "error";
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import noColor3Constructor from "./rules/no-color3-constructor";
|
|
|
3
3
|
import noPrint from "./rules/no-print";
|
|
4
4
|
import noShorthandNames from "./rules/no-shorthand-names";
|
|
5
5
|
import noWarn from "./rules/no-warn";
|
|
6
|
+
import preferUDim2Shorthand from "./rules/prefer-udim2-shorthand";
|
|
6
7
|
import requireReactComponentKeys from "./rules/require-react-component-keys";
|
|
7
8
|
import useExhaustiveDependencies from "./rules/use-exhaustive-dependencies";
|
|
8
9
|
import useHookAtTopLevel from "./rules/use-hook-at-top-level";
|
|
@@ -17,6 +18,7 @@ const rules = {
|
|
|
17
18
|
"no-print": noPrint,
|
|
18
19
|
"no-shorthand-names": noShorthandNames,
|
|
19
20
|
"no-warn": noWarn,
|
|
21
|
+
"prefer-udim2-shorthand": preferUDim2Shorthand,
|
|
20
22
|
"require-react-component-keys": requireReactComponentKeys,
|
|
21
23
|
"use-exhaustive-dependencies": useExhaustiveDependencies,
|
|
22
24
|
"use-hook-at-top-level": useHookAtTopLevel,
|
|
@@ -49,6 +51,7 @@ const recommended = {
|
|
|
49
51
|
"cease-nonsense/no-print": "error",
|
|
50
52
|
"cease-nonsense/no-shorthand-names": "error",
|
|
51
53
|
"cease-nonsense/no-warn": "error",
|
|
54
|
+
"cease-nonsense/prefer-udim2-shorthand": "error",
|
|
52
55
|
"cease-nonsense/require-react-component-keys": "error",
|
|
53
56
|
"cease-nonsense/use-exhaustive-dependencies": "error",
|
|
54
57
|
"cease-nonsense/use-hook-at-top-level": "error",
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,uBAAuB,MAAM,oCAAoC,CAAC;AACzE,OAAO,mBAAmB,MAAM,+BAA+B,CAAC;AAChE,OAAO,OAAO,MAAM,kBAAkB,CAAC;AACvC,OAAO,gBAAgB,MAAM,4BAA4B,CAAC;AAC1D,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,yBAAyB,MAAM,sCAAsC,CAAC;AAC7E,OAAO,yBAAyB,MAAM,qCAAqC,CAAC;AAC5E,OAAO,iBAAiB,MAAM,+BAA+B,CAAC;AAI9D;;;;GAIG;AACH,MAAM,KAAK,GAA4C;IACtD,4BAA4B,EAAE,uBAAuB;IACrD,uBAAuB,EAAE,mBAAmB;IAC5C,UAAU,EAAE,OAAO;IACnB,oBAAoB,EAAE,gBAAgB;IACtC,SAAS,EAAE,MAAM;IACjB,8BAA8B,EAAE,yBAAyB;IACzD,6BAA6B,EAAE,yBAAyB;IACxD,uBAAuB,EAAE,iBAAiB;CACjC,CAAC;AAEX;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,GAAG;IACnB,OAAO,EAAE;QACR,gBAAgB,EAAE;YACjB,KAAK;SACL;KACD;IACD,KAAK,EAAE;QACN,2CAA2C,EAAE,OAAO;QACpD,sCAAsC,EAAE,OAAO;QAC/C,yBAAyB,EAAE,OAAO;QAClC,mCAAmC,EAAE,OAAO;QAC5C,wBAAwB,EAAE,OAAO;QACjC,6CAA6C,EAAE,OAAO;QACtD,4CAA4C,EA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C,EAAE,OAAO;QACrD,sCAAsC,EAAE,OAAO;KAC/C;CACQ,CAAC;AAWX,MAAM,MAAM,GAAW;IACtB,OAAO,EAAE,EAAE,WAAW,EAAE;IACxB,KAAK;CACI,CAAC;AAEX,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Rule } from "eslint";
|
|
2
|
+
/**
|
|
3
|
+
* Detects `new UDim2(...)` calls that can be simplified to `UDim2.fromScale()` or `UDim2.fromOffset()`.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // ❌ Reports
|
|
7
|
+
* new UDim2(1, 0, 1, 0);
|
|
8
|
+
* new UDim2(0, 100, 0, 50);
|
|
9
|
+
*
|
|
10
|
+
* // ✅ OK
|
|
11
|
+
* new UDim2(0, 0, 0, 0);
|
|
12
|
+
* new UDim2(1, 2, 3, 4);
|
|
13
|
+
* UDim2.fromScale(1, 1);
|
|
14
|
+
* UDim2.fromOffset(100, 50);
|
|
15
|
+
*/
|
|
16
|
+
declare const preferUDim2Shorthand: Rule.RuleModule;
|
|
17
|
+
export default preferUDim2Shorthand;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
function isUnknownRecord(value) {
|
|
2
|
+
return typeof value === "object" && value !== null;
|
|
3
|
+
}
|
|
4
|
+
function isNumericLiteralNode(value) {
|
|
5
|
+
return isUnknownRecord(value) && value.type === "Literal" && "value" in value && typeof value.value === "number";
|
|
6
|
+
}
|
|
7
|
+
function collectNumericArguments(parameters) {
|
|
8
|
+
if (parameters.length !== 4)
|
|
9
|
+
return undefined;
|
|
10
|
+
if (!isNumericLiteralNode(parameters[0]))
|
|
11
|
+
return undefined;
|
|
12
|
+
if (!isNumericLiteralNode(parameters[1]))
|
|
13
|
+
return undefined;
|
|
14
|
+
if (!isNumericLiteralNode(parameters[2]))
|
|
15
|
+
return undefined;
|
|
16
|
+
if (!isNumericLiteralNode(parameters[3]))
|
|
17
|
+
return undefined;
|
|
18
|
+
return {
|
|
19
|
+
offsetX: parameters[1].value,
|
|
20
|
+
offsetY: parameters[3].value,
|
|
21
|
+
scaleX: parameters[0].value,
|
|
22
|
+
scaleY: parameters[2].value,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Detects `new UDim2(...)` calls that can be simplified to `UDim2.fromScale()` or `UDim2.fromOffset()`.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // ❌ Reports
|
|
30
|
+
* new UDim2(1, 0, 1, 0);
|
|
31
|
+
* new UDim2(0, 100, 0, 50);
|
|
32
|
+
*
|
|
33
|
+
* // ✅ OK
|
|
34
|
+
* new UDim2(0, 0, 0, 0);
|
|
35
|
+
* new UDim2(1, 2, 3, 4);
|
|
36
|
+
* UDim2.fromScale(1, 1);
|
|
37
|
+
* UDim2.fromOffset(100, 50);
|
|
38
|
+
*/
|
|
39
|
+
const preferUDim2Shorthand = {
|
|
40
|
+
/**
|
|
41
|
+
* Creates the ESLint rule visitor.
|
|
42
|
+
*
|
|
43
|
+
* @param context - The ESLint rule context.
|
|
44
|
+
* @returns The visitor object with AST node handlers.
|
|
45
|
+
*/
|
|
46
|
+
create(context) {
|
|
47
|
+
return {
|
|
48
|
+
NewExpression(node) {
|
|
49
|
+
if (node.callee.type !== "Identifier" || node.callee.name !== "UDim2")
|
|
50
|
+
return;
|
|
51
|
+
const collected = collectNumericArguments(node.arguments);
|
|
52
|
+
if (!collected)
|
|
53
|
+
return;
|
|
54
|
+
const { scaleX, offsetX, scaleY, offsetY } = collected;
|
|
55
|
+
// Allow all zeros
|
|
56
|
+
if (scaleX === 0 && offsetX === 0 && scaleY === 0 && offsetY === 0)
|
|
57
|
+
return;
|
|
58
|
+
// Check for fromScale pattern (offsets are zero)
|
|
59
|
+
if (offsetX === 0 && offsetY === 0) {
|
|
60
|
+
context.report({
|
|
61
|
+
fix: (fixer) => fixer.replaceText(node, `UDim2.fromScale(${scaleX}, ${scaleY})`),
|
|
62
|
+
messageId: "preferFromScale",
|
|
63
|
+
node,
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
// Check for fromOffset pattern (scales are zero)
|
|
68
|
+
if (scaleX === 0 && scaleY === 0) {
|
|
69
|
+
context.report({
|
|
70
|
+
fix: (fixer) => fixer.replaceText(node, `UDim2.fromOffset(${offsetX}, ${offsetY})`),
|
|
71
|
+
messageId: "preferFromOffset",
|
|
72
|
+
node,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
meta: {
|
|
79
|
+
docs: {
|
|
80
|
+
description: "Prefer UDim2.fromScale() or UDim2.fromOffset() over new UDim2() when all offsets or all scales are zero.",
|
|
81
|
+
recommended: true,
|
|
82
|
+
},
|
|
83
|
+
fixable: "code",
|
|
84
|
+
messages: {
|
|
85
|
+
preferFromOffset: "Use UDim2.fromOffset() instead of new UDim2(). When all scales are zero, use UDim2.fromOffset() for clarity.",
|
|
86
|
+
preferFromScale: "Use UDim2.fromScale() instead of new UDim2(). When all offsets are zero, use UDim2.fromScale() for clarity.",
|
|
87
|
+
},
|
|
88
|
+
schema: [],
|
|
89
|
+
type: "suggestion",
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
export default preferUDim2Shorthand;
|
|
93
|
+
//# sourceMappingURL=prefer-udim2-shorthand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-udim2-shorthand.js","sourceRoot":"","sources":["../../src/rules/prefer-udim2-shorthand.ts"],"names":[],"mappings":"AAOA,SAAS,eAAe,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACpD,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAc;IAC3C,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,KAAK,IAAI,O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ent idiot mistakes I encounter with frequency.",
|
|
4
7
|
"devDependencies": {
|
|
5
8
|
"@biomejs/biome": "^2.2.6",
|
|
@@ -15,7 +18,6 @@
|
|
|
15
18
|
"mitata": "^1.0.34",
|
|
16
19
|
"oxlint": "^1.23.0",
|
|
17
20
|
"oxlint-tsgolint": "^0.2.0",
|
|
18
|
-
"sury": "^11.0.0-alpha.4",
|
|
19
21
|
"typescript": "^5.6.3"
|
|
20
22
|
},
|
|
21
23
|
"engines": {
|
|
@@ -61,5 +63,5 @@
|
|
|
61
63
|
"sideEffects": false,
|
|
62
64
|
"type": "module",
|
|
63
65
|
"types": "./dist/index.d.ts",
|
|
64
|
-
"version": "0.
|
|
66
|
+
"version": "0.5.0"
|
|
65
67
|
}
|