@pobammer-ts/eslint-cease-nonsense-rules 0.10.0 → 0.11.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/rules/ban-react-fc.js +2 -30
- package/dist/rules/ban-react-fc.js.map +1 -1
- package/dist/rules/enforce-ianitor-check-type.js +69 -157
- package/dist/rules/enforce-ianitor-check-type.js.map +1 -1
- package/dist/rules/no-color3-constructor.d.ts +0 -17
- package/dist/rules/no-color3-constructor.js +9 -31
- package/dist/rules/no-color3-constructor.js.map +1 -1
- package/dist/rules/no-instance-methods-without-this.js +2 -3
- package/dist/rules/no-instance-methods-without-this.js.map +1 -1
- package/dist/rules/no-print.d.ts +0 -15
- package/dist/rules/no-print.js +0 -21
- package/dist/rules/no-print.js.map +1 -1
- package/dist/rules/no-shorthand-names.d.ts +0 -24
- package/dist/rules/no-shorthand-names.js +18 -72
- package/dist/rules/no-shorthand-names.js.map +1 -1
- package/dist/rules/no-warn.d.ts +0 -15
- package/dist/rules/no-warn.js +0 -21
- package/dist/rules/no-warn.js.map +1 -1
- package/dist/rules/prefer-sequence-overloads.js +9 -16
- package/dist/rules/prefer-sequence-overloads.js.map +1 -1
- package/dist/rules/prefer-udim2-shorthand.d.ts +0 -14
- package/dist/rules/prefer-udim2-shorthand.js +17 -46
- package/dist/rules/prefer-udim2-shorthand.js.map +1 -1
- package/dist/rules/require-named-effect-functions.js +197 -59
- package/dist/rules/require-named-effect-functions.js.map +1 -1
- package/dist/rules/require-react-component-keys.d.ts +5 -6
- package/dist/rules/require-react-component-keys.js +119 -129
- package/dist/rules/require-react-component-keys.js.map +1 -1
- package/dist/rules/use-exhaustive-dependencies.d.ts +0 -42
- package/dist/rules/use-exhaustive-dependencies.js +100 -227
- package/dist/rules/use-exhaustive-dependencies.js.map +1 -1
- package/package.json +9 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-instance-methods-without-this.js","sourceRoot":"","sources":["../../src/r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,MAAM,IAAI,KAAK,CAAC;AACvE,CAAC;AAED,6EAA6E;AAC7E,SAAS,
|
|
1
|
+
{"version":3,"file":"no-instance-methods-without-this.js","sourceRoot":"","sources":["../../src/rules/no-instance-methods-without-this.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAqB1D,MAAM,eAAe,GAA0B;IAC9C,YAAY,EAAE,IAAI;IAClB,cAAc,EAAE,IAAI;IACpB,WAAW,EAAE,IAAI;CACjB,CAAC;AAEF,SAAS,gBAAgB,CAAC,UAAmC;IAC5D,MAAM,aAAa,GAA0B,EAAE,GAAG,eAAe,EAAE,CAAC;IACpE,IAAI,UAAU,EAAE,YAAY,KAAK,SAAS;QAAE,aAAa,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;IACjG,IAAI,UAAU,EAAE,cAAc,KAAK,SAAS;QAAE,aAAa,CAAC,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;IACvG,IAAI,UAAU,EAAE,WAAW,KAAK,SAAS;QAAE,aAAa,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;IAE9F,OAAO,aAAa,CAAC;AACtB,CAAC;AAED,SAAS,iBAAiB,CAAC,IAA+B,EAAE,OAA0B;IACrF,IAAI,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC9B,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAEzC,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,QAAQ,CAAC;IACrD,IAAI,aAAa,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,YAAY;QAAE,OAAO,KAAK,CAAC;IACvE,IAAI,aAAa,KAAK,WAAW,IAAI,CAAC,OAAO,CAAC,cAAc;QAAE,OAAO,KAAK,CAAC;IAC3E,IAAI,aAAa,KAAK,QAAQ,IAAI,CAAC,OAAO,CAAC,WAAW;QAAE,OAAO,KAAK,CAAC;IAEr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ACb,WAAW,EAAE,yCAAyC;wBACtD,IAAI,EAAE,SAAS;qBACf;oBACD,WAAW,EAAE;wBACZ,OAAO,EAAE,IAAI;wBACb,WAAW,EAAE,sCAAsC;wBACnD,IAAI,EAAE,SAAS;qBACf;iBACD;gBACD,IAAI,EAAE,QAAQ;aACd;SACD;QACD,IAAI,EAAE,SAAS;KACf;CACD,CAAC;AAEF,eAAe,4BAA4B,CAAC"}
|
package/dist/rules/no-print.d.ts
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
1
|
import type { Rule } from "eslint";
|
|
2
|
-
/**
|
|
3
|
-
* Bans use of `print()` function calls. Use `Log` instead.
|
|
4
|
-
*
|
|
5
|
-
* The `print()` function is not wanted in this codebase and discouraged in favor of a proper
|
|
6
|
-
* logging system like `Log`.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* // ❌ Reports
|
|
10
|
-
* print("Hello");
|
|
11
|
-
* print(value);
|
|
12
|
-
*
|
|
13
|
-
* // ✅ OK
|
|
14
|
-
* Log.info("Hello");
|
|
15
|
-
* Log.debug(value);
|
|
16
|
-
*/
|
|
17
2
|
declare const noPrint: Rule.RuleModule;
|
|
18
3
|
export default noPrint;
|
package/dist/rules/no-print.js
CHANGED
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bans use of `print()` function calls. Use `Log` instead.
|
|
3
|
-
*
|
|
4
|
-
* The `print()` function is not wanted in this codebase and discouraged in favor of a proper
|
|
5
|
-
* logging system like `Log`.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* // ❌ Reports
|
|
9
|
-
* print("Hello");
|
|
10
|
-
* print(value);
|
|
11
|
-
*
|
|
12
|
-
* // ✅ OK
|
|
13
|
-
* Log.info("Hello");
|
|
14
|
-
* Log.debug(value);
|
|
15
|
-
*/
|
|
16
1
|
const noPrint = {
|
|
17
|
-
/**
|
|
18
|
-
* Creates the ESLint rule visitor.
|
|
19
|
-
*
|
|
20
|
-
* @param context - The ESLint rule context.
|
|
21
|
-
* @returns The visitor object with AST node handlers.
|
|
22
|
-
*/
|
|
23
2
|
create(context) {
|
|
24
3
|
return {
|
|
25
4
|
'CallExpression[callee.type="Identifier"][callee.name="print"]'(node) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-print.js","sourceRoot":"","sources":["../../src/rules/no-print.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"no-print.js","sourceRoot":"","sources":["../../src/rules/no-print.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,GAAoB;IAChC,MAAM,CAAC,OAAO;QACb,OAAO;YACN,+DAA+D,CAAC,IAAe;gBAC9E,OAAO,CAAC,MAAM,CAAC;oBACd,SAAS,EAAE,QAAQ;oBACnB,IAAI;iBACJ,CAAC,CAAC;YACJ,CAAC;SACD,CAAC;IACH,CAAC;IACD,IAAI,EAAE;QACL,IAAI,EAAE;YACL,WAAW,EAAE,8CAA8C;YAC3D,WAAW,EAAE,KAAK;SAClB;QACD,QAAQ,EAAE;YACT,MAAM,EAAE,4BAA4B;SACpC;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,SAAS;KACf;CACD,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -1,27 +1,3 @@
|
|
|
1
1
|
import type { Rule } from "eslint";
|
|
2
|
-
/**
|
|
3
|
-
* Bans shorthand variable names in favor of descriptive full names.
|
|
4
|
-
*
|
|
5
|
-
* Enforces:
|
|
6
|
-
* - `plr` → `player` (or `localPlayer` for Players.LocalPlayer assignments)
|
|
7
|
-
* - `args` → `parameters`
|
|
8
|
-
* - `dt` → `deltaTime`
|
|
9
|
-
* - `char` → `character` (except when used as property access)
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* // ❌ Reports
|
|
13
|
-
* const plr = getPlayer();
|
|
14
|
-
* const args = [1, 2, 3];
|
|
15
|
-
* const dt = 0.016;
|
|
16
|
-
* const char = getCharacter();
|
|
17
|
-
*
|
|
18
|
-
* // ✅ OK
|
|
19
|
-
* const player = getPlayer();
|
|
20
|
-
* const localPlayer = Players.LocalPlayer;
|
|
21
|
-
* const parameters = [1, 2, 3];
|
|
22
|
-
* const deltaTime = 0.016;
|
|
23
|
-
* const character = getCharacter();
|
|
24
|
-
* const model = entity.char; // property access is allowed
|
|
25
|
-
*/
|
|
26
2
|
declare const noShorthandNames: Rule.RuleModule;
|
|
27
3
|
export default noShorthandNames;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import Type from "typebox";
|
|
2
|
+
import { Compile } from "typebox/compile";
|
|
3
|
+
const isRuleOptions = Compile(Type.Object({
|
|
4
|
+
allowPropertyAccess: Type.Optional(Type.Array(Type.String())),
|
|
5
|
+
shorthands: Type.Optional(Type.Record(Type.String(), Type.String())),
|
|
6
|
+
}));
|
|
4
7
|
const DEFAULT_OPTIONS = {
|
|
5
8
|
allowPropertyAccess: ["char"],
|
|
6
9
|
shorthands: {
|
|
@@ -13,32 +16,9 @@ const DEFAULT_OPTIONS = {
|
|
|
13
16
|
function isUnknownRecord(value) {
|
|
14
17
|
return typeof value === "object" && value !== null;
|
|
15
18
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function isStringArray(value) {
|
|
20
|
-
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Escapes special regex characters in a string.
|
|
24
|
-
*
|
|
25
|
-
* @param str - The string to escape.
|
|
26
|
-
* @returns The escaped string safe for use in regex.
|
|
27
|
-
*/
|
|
28
|
-
function escapeRegex(str) {
|
|
29
|
-
return str.replaceAll(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Type guard to check if an unknown value is valid RuleOptions.
|
|
33
|
-
*
|
|
34
|
-
* @param value - The value to check.
|
|
35
|
-
* @returns True if the value is valid RuleOptions.
|
|
36
|
-
*/
|
|
37
|
-
function isRuleOptions(value) {
|
|
38
|
-
if (!isUnknownRecord(value))
|
|
39
|
-
return false;
|
|
40
|
-
return ((!("shorthands" in value) || isStringRecord(value.shorthands)) &&
|
|
41
|
-
(!("allowPropertyAccess" in value) || isStringArray(value.allowPropertyAccess)));
|
|
19
|
+
const ESCAPE_REGEXP = /[.*+?^${}()|[\]\\]/g;
|
|
20
|
+
function escapeRegex(value) {
|
|
21
|
+
return value.replaceAll(ESCAPE_REGEXP, "\\$&");
|
|
42
22
|
}
|
|
43
23
|
function normalizeOptions(rawOptions) {
|
|
44
24
|
const mergedShorthands = { ...DEFAULT_OPTIONS.shorthands };
|
|
@@ -47,8 +27,8 @@ function normalizeOptions(rawOptions) {
|
|
|
47
27
|
mergedShorthands[key] = value;
|
|
48
28
|
const shorthandsMap = new Map(Object.entries(mergedShorthands));
|
|
49
29
|
const allowPropertyAccessSource = rawOptions?.allowPropertyAccess ?? DEFAULT_OPTIONS.allowPropertyAccess;
|
|
50
|
-
//
|
|
51
|
-
const escapedKeys = Array.from(shorthandsMap.keys()).map(
|
|
30
|
+
// oxlint-disable-next-line no-array-callback-reference
|
|
31
|
+
const escapedKeys = Array.from(shorthandsMap.keys()).map(escapeRegex);
|
|
52
32
|
const selector = `Identifier[name=/^(${escapedKeys.join("|")})$/]`;
|
|
53
33
|
return {
|
|
54
34
|
allowPropertyAccess: new Set(allowPropertyAccessSource),
|
|
@@ -56,67 +36,33 @@ function normalizeOptions(rawOptions) {
|
|
|
56
36
|
shorthands: shorthandsMap,
|
|
57
37
|
};
|
|
58
38
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Bans shorthand variable names in favor of descriptive full names.
|
|
61
|
-
*
|
|
62
|
-
* Enforces:
|
|
63
|
-
* - `plr` → `player` (or `localPlayer` for Players.LocalPlayer assignments)
|
|
64
|
-
* - `args` → `parameters`
|
|
65
|
-
* - `dt` → `deltaTime`
|
|
66
|
-
* - `char` → `character` (except when used as property access)
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* // ❌ Reports
|
|
70
|
-
* const plr = getPlayer();
|
|
71
|
-
* const args = [1, 2, 3];
|
|
72
|
-
* const dt = 0.016;
|
|
73
|
-
* const char = getCharacter();
|
|
74
|
-
*
|
|
75
|
-
* // ✅ OK
|
|
76
|
-
* const player = getPlayer();
|
|
77
|
-
* const localPlayer = Players.LocalPlayer;
|
|
78
|
-
* const parameters = [1, 2, 3];
|
|
79
|
-
* const deltaTime = 0.016;
|
|
80
|
-
* const character = getCharacter();
|
|
81
|
-
* const model = entity.char; // property access is allowed
|
|
82
|
-
*/
|
|
83
39
|
const noShorthandNames = {
|
|
84
|
-
/**
|
|
85
|
-
* Creates the ESLint rule visitor.
|
|
86
|
-
*
|
|
87
|
-
* @param context - The ESLint rule context.
|
|
88
|
-
* @returns The visitor object with AST node handlers.
|
|
89
|
-
*/
|
|
90
40
|
create(context) {
|
|
91
|
-
const validatedOptions = isRuleOptions(context.options[0]) ? context.options[0] : undefined;
|
|
92
|
-
const
|
|
93
|
-
const { shorthands, allowPropertyAccess, selector } = normalized;
|
|
41
|
+
const validatedOptions = isRuleOptions.Check(context.options[0]) ? context.options[0] : undefined;
|
|
42
|
+
const { shorthands, allowPropertyAccess, selector } = normalizeOptions(validatedOptions);
|
|
94
43
|
return {
|
|
95
44
|
[selector](node) {
|
|
96
45
|
const shorthandName = node.name;
|
|
97
46
|
const replacement = shorthands.get(shorthandName);
|
|
98
|
-
if (
|
|
47
|
+
if (replacement === undefined || replacement === "")
|
|
99
48
|
return;
|
|
100
|
-
// Cache parent lookup
|
|
101
49
|
const parent = node.parent;
|
|
102
|
-
// Inline property access check
|
|
103
50
|
if (allowPropertyAccess.has(shorthandName) &&
|
|
104
|
-
parent &&
|
|
51
|
+
parent !== undefined &&
|
|
105
52
|
isUnknownRecord(parent) &&
|
|
106
53
|
parent.type === "MemberExpression" &&
|
|
107
54
|
parent.property === node)
|
|
108
55
|
return;
|
|
109
|
-
// Special case: plr → localPlayer for Players.LocalPlayer
|
|
110
56
|
if (shorthandName === "plr" && parent?.type === "VariableDeclarator" && parent.id === node) {
|
|
111
|
-
const init = parent
|
|
57
|
+
const { init } = parent;
|
|
112
58
|
if (init &&
|
|
113
59
|
isUnknownRecord(init) &&
|
|
114
60
|
init.type === "MemberExpression" &&
|
|
115
|
-
init.object &&
|
|
61
|
+
init.object !== undefined &&
|
|
116
62
|
isUnknownRecord(init.object) &&
|
|
117
63
|
init.object.type === "Identifier" &&
|
|
118
64
|
init.object.name === "Players" &&
|
|
119
|
-
init.property &&
|
|
65
|
+
init.property !== undefined &&
|
|
120
66
|
isUnknownRecord(init.property) &&
|
|
121
67
|
init.property.type === "Identifier" &&
|
|
122
68
|
init.property.name === "LocalPlayer") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-shorthand-names.js","sourceRoot":"","sources":["../../src/rules/no-shorthand-names.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"no-shorthand-names.js","sourceRoot":"","sources":["../../src/rules/no-shorthand-names.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAO1C,MAAM,aAAa,GAAG,OAAO,CAC5B,IAAI,CAAC,MAAM,CAAC;IACX,mBAAmB,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7D,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;CACpE,CAAC,CACF,CAAC;AAQF,MAAM,eAAe,GAA0B;IAC9C,mBAAmB,EAAE,CAAC,MAAM,CAAC;IAC7B,UAAU,EAAE;QACX,IAAI,EAAE,YAAY;QAClB,IAA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wBAC9B,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY;wBACnC,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,aAAa,EACnC,CAAC;wBACF,OAAO,CAAC,MAAM,CAAC;4BACd,IAAI,EAAE,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE;4BAC9D,SAAS,EAAE,gBAAgB;4BAC3B,IAAI;yBACJ,CAAC,CAAC;wBACH,OAAO;oBACR,CAAC;gBACF,CAAC;gBAED,OAAO,CAAC,MAAM,CAAC;oBACd,IAAI,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE;oBAC/C,SAAS,EAAE,gBAAgB;oBAC3B,IAAI;iBACJ,CAAC,CAAC;YACJ,CAAC;SACD,CAAC;IACH,CAAC;IACD,IAAI,EAAE;QACL,IAAI,EAAE;YACL,WAAW,EAAE,mEAAmE;YAChF,WAAW,EAAE,IAAI;SACjB;QACD,QAAQ,EAAE;YACT,cAAc,EAAE,4DAA4D;SAC5E;QACD,MAAM,EAAE;YACP;gBACC,oBAAoB,EAAE,KAAK;gBAC3B,UAAU,EAAE;oBACX,mBAAmB,EAAE;wBACpB,WAAW,EAAE,qDAAqD;wBAClE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;wBACzB,IAAI,EAAE,OAAO;qBACb;oBACD,UAAU,EAAE;wBACX,oBAAoB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;wBACxC,WAAW,EAAE,mDAAmD;wBAChE,IAAI,EAAE,QAAQ;qBACd;iBACD;gBACD,IAAI,EAAE,QAAQ;aACd;SACD;QACD,IAAI,EAAE,YAAY;KAClB;CACD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
package/dist/rules/no-warn.d.ts
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
1
|
import type { Rule } from "eslint";
|
|
2
|
-
/**
|
|
3
|
-
* Bans use of `warn()` function calls. Use `Log` instead.
|
|
4
|
-
*
|
|
5
|
-
* The `warn()` function is not wanted in this codebase and discouraged in favor of a proper
|
|
6
|
-
* logging system like `Log`.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* // ❌ Reports
|
|
10
|
-
* warn("Warning");
|
|
11
|
-
* warn(error);
|
|
12
|
-
*
|
|
13
|
-
* // ✅ OK
|
|
14
|
-
* Log.warn("Warning");
|
|
15
|
-
* Log.error(error);
|
|
16
|
-
*/
|
|
17
2
|
declare const noWarn: Rule.RuleModule;
|
|
18
3
|
export default noWarn;
|
package/dist/rules/no-warn.js
CHANGED
|
@@ -1,25 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bans use of `warn()` function calls. Use `Log` instead.
|
|
3
|
-
*
|
|
4
|
-
* The `warn()` function is not wanted in this codebase and discouraged in favor of a proper
|
|
5
|
-
* logging system like `Log`.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* // ❌ Reports
|
|
9
|
-
* warn("Warning");
|
|
10
|
-
* warn(error);
|
|
11
|
-
*
|
|
12
|
-
* // ✅ OK
|
|
13
|
-
* Log.warn("Warning");
|
|
14
|
-
* Log.error(error);
|
|
15
|
-
*/
|
|
16
1
|
const noWarn = {
|
|
17
|
-
/**
|
|
18
|
-
* Creates the ESLint rule visitor.
|
|
19
|
-
*
|
|
20
|
-
* @param context - The ESLint rule context.
|
|
21
|
-
* @returns The visitor object with AST node handlers.
|
|
22
|
-
*/
|
|
23
2
|
create(context) {
|
|
24
3
|
return {
|
|
25
4
|
'CallExpression[callee.type="Identifier"][callee.name="warn"]'(node) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-warn.js","sourceRoot":"","sources":["../../src/rules/no-warn.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"no-warn.js","sourceRoot":"","sources":["../../src/rules/no-warn.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,GAAoB;IAC/B,MAAM,CAAC,OAAO;QACb,OAAO;YACN,8DAA8D,CAAC,IAAe;gBAC7E,OAAO,CAAC,MAAM,CAAC;oBACd,SAAS,EAAE,QAAQ;oBACnB,IAAI;iBACJ,CAAC,CAAC;YACJ,CAAC;SACD,CAAC;IACH,CAAC;IACD,IAAI,EAAE;QACL,IAAI,EAAE;YACL,WAAW,EAAE,6CAA6C;YAC1D,WAAW,EAAE,KAAK;SAClB;QACD,QAAQ,EAAE;YACT,MAAM,EAAE,2BAA2B;SACnC;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,SAAS;KACf;CACD,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -19,9 +19,8 @@ function isExpressionArgument(argument) {
|
|
|
19
19
|
function extractKeypoint(element, descriptor) {
|
|
20
20
|
if (element === null || element.type !== AST_NODE_TYPES.NewExpression)
|
|
21
21
|
return undefined;
|
|
22
|
-
if (element.callee.type !== AST_NODE_TYPES.Identifier || element.callee.name !== descriptor.keypointName)
|
|
22
|
+
if (element.callee.type !== AST_NODE_TYPES.Identifier || element.callee.name !== descriptor.keypointName)
|
|
23
23
|
return undefined;
|
|
24
|
-
}
|
|
25
24
|
if (element.arguments.length !== 2)
|
|
26
25
|
return undefined;
|
|
27
26
|
const [timeArgument, valueArgument] = element.arguments;
|
|
@@ -40,21 +39,19 @@ const docs = {
|
|
|
40
39
|
};
|
|
41
40
|
const preferSequenceOverloads = {
|
|
42
41
|
create(context) {
|
|
43
|
-
const sourceCode = context
|
|
42
|
+
const { sourceCode } = context;
|
|
44
43
|
return {
|
|
45
44
|
NewExpression(node) {
|
|
46
|
-
const callee = node
|
|
45
|
+
const { callee } = node;
|
|
47
46
|
if (!isSequenceIdentifier(callee))
|
|
48
47
|
return;
|
|
49
48
|
const descriptor = findDescriptor(callee.name);
|
|
50
|
-
if (descriptor === undefined)
|
|
51
|
-
return;
|
|
52
|
-
if (node.arguments.length !== 1)
|
|
49
|
+
if (descriptor === undefined || node.arguments.length !== 1)
|
|
53
50
|
return;
|
|
54
51
|
const [argument] = node.arguments;
|
|
55
|
-
if (argument === undefined ||
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
if (argument === undefined ||
|
|
53
|
+
argument.type !== AST_NODE_TYPES.ArrayExpression ||
|
|
54
|
+
argument.elements.length !== 2)
|
|
58
55
|
return;
|
|
59
56
|
const firstElement = argument.elements[0] ?? null;
|
|
60
57
|
const secondElement = argument.elements[1] ?? null;
|
|
@@ -70,9 +67,7 @@ const preferSequenceOverloads = {
|
|
|
70
67
|
const normalizedSecondValue = secondValueText.trim();
|
|
71
68
|
if (normalizedFirstValue === normalizedSecondValue) {
|
|
72
69
|
context.report({
|
|
73
|
-
data: {
|
|
74
|
-
sequenceName: descriptor.sequenceName,
|
|
75
|
-
},
|
|
70
|
+
data: { sequenceName: descriptor.sequenceName },
|
|
76
71
|
fix: (fixer) => fixer.replaceText(node, `new ${descriptor.sequenceName}(${firstValueText})`),
|
|
77
72
|
messageId: "preferSingleOverload",
|
|
78
73
|
node,
|
|
@@ -80,9 +75,7 @@ const preferSequenceOverloads = {
|
|
|
80
75
|
return;
|
|
81
76
|
}
|
|
82
77
|
context.report({
|
|
83
|
-
data: {
|
|
84
|
-
sequenceName: descriptor.sequenceName,
|
|
85
|
-
},
|
|
78
|
+
data: { sequenceName: descriptor.sequenceName },
|
|
86
79
|
fix: (fixer) => fixer.replaceText(node, `new ${descriptor.sequenceName}(${firstValueText}, ${secondValueText})`),
|
|
87
80
|
messageId: "preferTwoPointOverload",
|
|
88
81
|
node,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-sequence-overloads.js","sourceRoot":"","sources":["../../src/rules/prefer-sequence-overloads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"prefer-sequence-overloads.js","sourceRoot":"","sources":["../../src/rules/prefer-sequence-overloads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,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AAE,EAAE;IAClB,IAAI,EAAE;QACL,IAAI;QACJ,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE;YACT,oBAAoB,EACnB,wIAAwI;YACzI,sBAAsB,EACrB,+HAA+H;SAChI;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,SAAS;KACf;CACD,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
|
|
@@ -1,17 +1,3 @@
|
|
|
1
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
2
|
declare const preferUDim2Shorthand: Rule.RuleModule;
|
|
17
3
|
export default preferUDim2Shorthand;
|
|
@@ -1,61 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { TSESTree } from "@typescript-eslint/types";
|
|
2
|
+
import Type from "typebox";
|
|
3
|
+
import { Compile } from "typebox/compile";
|
|
4
|
+
const isNumericLiteralNode = Compile(Type.Object({
|
|
5
|
+
type: Type.Literal(TSESTree.AST_NODE_TYPES.Literal),
|
|
6
|
+
value: Type.Number(),
|
|
7
|
+
}));
|
|
8
|
+
const isCorrectParameters = Compile(Type.Tuple([isNumericLiteralNode, isNumericLiteralNode, isNumericLiteralNode, isNumericLiteralNode], {}));
|
|
7
9
|
function collectNumericArguments(parameters) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
};
|
|
10
|
+
return isCorrectParameters.Check(parameters)
|
|
11
|
+
? {
|
|
12
|
+
offsetX: parameters[1].value,
|
|
13
|
+
offsetY: parameters[3].value,
|
|
14
|
+
scaleX: parameters[0].value,
|
|
15
|
+
scaleY: parameters[2].value,
|
|
16
|
+
}
|
|
17
|
+
: undefined;
|
|
24
18
|
}
|
|
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
19
|
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
20
|
create(context) {
|
|
47
21
|
return {
|
|
48
22
|
NewExpression(node) {
|
|
49
|
-
if (node.callee.type !==
|
|
23
|
+
if (node.callee.type !== TSESTree.AST_NODE_TYPES.Identifier || node.callee.name !== "UDim2")
|
|
50
24
|
return;
|
|
51
25
|
const collected = collectNumericArguments(node.arguments);
|
|
52
26
|
if (!collected)
|
|
53
27
|
return;
|
|
54
28
|
const { scaleX, offsetX, scaleY, offsetY } = collected;
|
|
55
|
-
// Allow all zeros
|
|
56
29
|
if (scaleX === 0 && offsetX === 0 && scaleY === 0 && offsetY === 0)
|
|
57
30
|
return;
|
|
58
|
-
// Check for fromScale pattern (offsets are zero)
|
|
59
31
|
if (offsetX === 0 && offsetY === 0) {
|
|
60
32
|
context.report({
|
|
61
33
|
fix: (fixer) => fixer.replaceText(node, `UDim2.fromScale(${scaleX}, ${scaleY})`),
|
|
@@ -64,7 +36,6 @@ const preferUDim2Shorthand = {
|
|
|
64
36
|
});
|
|
65
37
|
return;
|
|
66
38
|
}
|
|
67
|
-
// Check for fromOffset pattern (scales are zero)
|
|
68
39
|
if (scaleX === 0 && scaleY === 0) {
|
|
69
40
|
context.report({
|
|
70
41
|
fix: (fixer) => fixer.replaceText(node, `UDim2.fromOffset(${offsetX}, ${offsetY})`),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-udim2-shorthand.js","sourceRoot":"","sources":["../../src/rules/prefer-udim2-shorthand.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prefer-udim2-shorthand.js","sourceRoot":"","sources":["../../src/rules/prefer-udim2-shorthand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,oBAAoB,GAAG,OAAO,CACnC,IAAI,CAAC,MAAM,CAAC;IACX,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;IACnD,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;CACpB,CAAC,CACF,CAAC;AAEF,MAAM,mBAAmB,GAAG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