@pobammer-ts/eslint-cease-nonsense-rules 0.7.0 → 0.8.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 CHANGED
@@ -29,6 +29,7 @@ export default [
29
29
  "cease-nonsense/no-print": "error",
30
30
  "cease-nonsense/no-shorthand-names": "error",
31
31
  "cease-nonsense/no-warn": "error",
32
+ "cease-nonsense/prefer-sequence-overloads": "error",
32
33
  "cease-nonsense/prefer-udim2-shorthand": "error",
33
34
  "cease-nonsense/require-named-effect-functions": "error",
34
35
  "cease-nonsense/require-react-component-keys": "error",
@@ -348,6 +349,38 @@ UDim2.fromOffset(100, 50);
348
349
  new UDim2(0, 0, 0, 0); // Allowed
349
350
  ```
350
351
 
352
+ #### `prefer-sequence-overloads`
353
+
354
+ Prefer the optimized `ColorSequence` and `NumberSequence` constructor overloads instead of building an array of `*SequenceKeypoint`s for the 0/1 endpoints. Includes auto-fix.
355
+
356
+ **❌ Bad:**
357
+
358
+ ```typescript
359
+ new ColorSequence([
360
+ new ColorSequenceKeypoint(0, Color3.fromRGB(100, 200, 255)),
361
+ new ColorSequenceKeypoint(1, Color3.fromRGB(255, 100, 200)),
362
+ ]);
363
+
364
+ new NumberSequence([
365
+ new NumberSequenceKeypoint(0, 0),
366
+ new NumberSequenceKeypoint(1, 100),
367
+ ]);
368
+ ```
369
+
370
+ **✅ Good:**
371
+
372
+ ```typescript
373
+ new ColorSequence(Color3.fromRGB(100, 200, 255), Color3.fromRGB(255, 100, 200));
374
+
375
+ new ColorSequence(Color3.fromRGB(255, 255, 255));
376
+
377
+ new NumberSequence(0, 100);
378
+
379
+ new NumberSequence(42);
380
+ ```
381
+
382
+ Automatically collapses identical 0/1 endpoints to the single-argument overload.
383
+
351
384
  #### `no-shorthand-names`
352
385
 
353
386
  Bans shorthand variable names in favor of descriptive full names.
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-sequence-overloads": "error";
32
33
  readonly "cease-nonsense/prefer-udim2-shorthand": "error";
33
34
  readonly "cease-nonsense/require-named-effect-functions": "error";
34
35
  readonly "cease-nonsense/require-react-component-keys": "error";
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import noPrint from "./rules/no-print";
4
4
  import noShorthandNames from "./rules/no-shorthand-names";
5
5
  import noWarn from "./rules/no-warn";
6
6
  import preferUDim2Shorthand from "./rules/prefer-udim2-shorthand";
7
+ import preferSequenceOverloads from "./rules/prefer-sequence-overloads";
7
8
  import requireNamedEffectFunctions from "./rules/require-named-effect-functions";
8
9
  import requireReactComponentKeys from "./rules/require-react-component-keys";
9
10
  import useExhaustiveDependencies from "./rules/use-exhaustive-dependencies";
@@ -19,6 +20,7 @@ const rules = {
19
20
  "no-print": noPrint,
20
21
  "no-shorthand-names": noShorthandNames,
21
22
  "no-warn": noWarn,
23
+ "prefer-sequence-overloads": preferSequenceOverloads,
22
24
  "prefer-udim2-shorthand": preferUDim2Shorthand,
23
25
  "require-named-effect-functions": requireNamedEffectFunctions,
24
26
  "require-react-component-keys": requireReactComponentKeys,
@@ -53,6 +55,7 @@ const recommended = {
53
55
  "cease-nonsense/no-print": "error",
54
56
  "cease-nonsense/no-shorthand-names": "error",
55
57
  "cease-nonsense/no-warn": "error",
58
+ "cease-nonsense/prefer-sequence-overloads": "error",
56
59
  "cease-nonsense/prefer-udim2-shorthand": "error",
57
60
  "cease-nonsense/require-named-effect-functions": "error",
58
61
  "cease-nonsense/require-react-component-keys": "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,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E,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,7 @@
1
+ import type { TSESLint } from "@typescript-eslint/utils";
2
+ interface RuleDocsWithRecommended extends TSESLint.RuleMetaDataDocs {
3
+ recommended?: boolean;
4
+ }
5
+ declare const preferSequenceOverloads: TSESLint.RuleModuleWithMetaDocs<"preferSingleOverload" | "preferTwoPointOverload", [
6
+ ], RuleDocsWithRecommended>;
7
+ export default preferSequenceOverloads;
@@ -0,0 +1,106 @@
1
+ import { AST_NODE_TYPES } from "@typescript-eslint/types";
2
+ const sequenceDescriptors = [
3
+ { keypointName: "ColorSequenceKeypoint", sequenceName: "ColorSequence" },
4
+ { keypointName: "NumberSequenceKeypoint", sequenceName: "NumberSequence" },
5
+ ];
6
+ function isSequenceIdentifier(node) {
7
+ return (node.type === AST_NODE_TYPES.Identifier &&
8
+ sequenceDescriptors.some((descriptor) => descriptor.sequenceName === node.name));
9
+ }
10
+ function findDescriptor(sequenceName) {
11
+ return sequenceDescriptors.find((descriptor) => descriptor.sequenceName === sequenceName);
12
+ }
13
+ function isNumericLiteral(argument) {
14
+ return argument !== undefined && argument.type === AST_NODE_TYPES.Literal && typeof argument.value === "number";
15
+ }
16
+ function isExpressionArgument(argument) {
17
+ return argument !== undefined && argument.type !== AST_NODE_TYPES.SpreadElement;
18
+ }
19
+ function extractKeypoint(element, descriptor) {
20
+ if (element === null || element.type !== AST_NODE_TYPES.NewExpression)
21
+ return undefined;
22
+ if (element.callee.type !== AST_NODE_TYPES.Identifier || element.callee.name !== descriptor.keypointName) {
23
+ return undefined;
24
+ }
25
+ if (element.arguments.length !== 2)
26
+ return undefined;
27
+ const [timeArgument, valueArgument] = element.arguments;
28
+ if (!isNumericLiteral(timeArgument))
29
+ return undefined;
30
+ if (!isExpressionArgument(valueArgument))
31
+ return undefined;
32
+ return {
33
+ time: timeArgument.value,
34
+ value: valueArgument,
35
+ };
36
+ }
37
+ const docs = {
38
+ description: "Prefer the optimized ColorSequence and NumberSequence constructor overloads over passing ColorSequenceKeypoint or NumberSequenceKeypoint arrays when only using endpoints 0 and 1.",
39
+ recommended: true,
40
+ };
41
+ const preferSequenceOverloads = {
42
+ create(context) {
43
+ const sourceCode = context.getSourceCode();
44
+ return {
45
+ NewExpression(node) {
46
+ const callee = node.callee;
47
+ if (!isSequenceIdentifier(callee))
48
+ return;
49
+ const descriptor = findDescriptor(callee.name);
50
+ if (descriptor === undefined)
51
+ return;
52
+ if (node.arguments.length !== 1)
53
+ return;
54
+ const [argument] = node.arguments;
55
+ if (argument === undefined || argument.type !== AST_NODE_TYPES.ArrayExpression)
56
+ return;
57
+ if (argument.elements.length !== 2)
58
+ return;
59
+ const firstElement = argument.elements[0] ?? null;
60
+ const secondElement = argument.elements[1] ?? null;
61
+ const firstKeypoint = extractKeypoint(firstElement, descriptor);
62
+ const secondKeypoint = extractKeypoint(secondElement, descriptor);
63
+ if (firstKeypoint === undefined || secondKeypoint === undefined)
64
+ return;
65
+ if (firstKeypoint.time !== 0 || secondKeypoint.time !== 1)
66
+ return;
67
+ const firstValueText = sourceCode.getText(firstKeypoint.value);
68
+ const secondValueText = sourceCode.getText(secondKeypoint.value);
69
+ const normalizedFirstValue = firstValueText.trim();
70
+ const normalizedSecondValue = secondValueText.trim();
71
+ if (normalizedFirstValue === normalizedSecondValue) {
72
+ context.report({
73
+ fix: (fixer) => fixer.replaceText(node, `new ${descriptor.sequenceName}(${firstValueText})`),
74
+ messageId: "preferSingleOverload",
75
+ node,
76
+ data: {
77
+ sequenceName: descriptor.sequenceName,
78
+ },
79
+ });
80
+ return;
81
+ }
82
+ context.report({
83
+ fix: (fixer) => fixer.replaceText(node, `new ${descriptor.sequenceName}(${firstValueText}, ${secondValueText})`),
84
+ messageId: "preferTwoPointOverload",
85
+ node,
86
+ data: {
87
+ sequenceName: descriptor.sequenceName,
88
+ },
89
+ });
90
+ },
91
+ };
92
+ },
93
+ defaultOptions: [],
94
+ meta: {
95
+ docs,
96
+ fixable: "code",
97
+ messages: {
98
+ preferSingleOverload: "Use the single-argument {{sequenceName}} constructor overload instead of redundant keypoints when both endpoints share the same value.",
99
+ preferTwoPointOverload: "Use the two-argument {{sequenceName}} constructor overload instead of allocating an array of keypoints for endpoints 0 and 1.",
100
+ },
101
+ schema: [],
102
+ type: "problem",
103
+ },
104
+ };
105
+ export default preferSequenceOverloads;
106
+ //# sourceMappingURL=prefer-sequence-overloads.js.map
@@ -0,0 +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;AAiB1D,MAAM,mBAAmB,GAAsC;IAC9D,EAAE,YAAY,EAAE,uBAAuB,EAAE,YAAY,EAAE,eAAe,EAAE;IACxE,EAAE,YAAY,EAAE,wBAAwB,EAAE,YAAY,EAAE,gBAAgB,EAAE;CAC1E,CAAC;AAEF,SAAS,oBAAoB,CAC5B,IAA0C;IAE1C,OAAO,CACN,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,UAAU;QACvC,mBAAmB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,CAC/E,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,YAAgD;IACvE,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,YAAY,KAAK,YAAY,CAAC,CAAC;AAC3F,CAAC;AAED,SAAS,gBAAgB,CAAC,QAAqD;IAG9E,OAAO,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,IAAI,KAAK,cAAc,CAAC,OAAO,IAAI,OAAO,QAAQ,CAAC,KAAK,KAAK,QAAQ,CAAC;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,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,UAAU,CAAC,YAAY,IAAI,cAAc,GAAG,CAAC;wBAC5F,SAAS,EAAE,sBAAsB;wBACjC,IAAI;wBACJ,IAAI,EAAE;4BACL,YAAY,EAAE,UAAU,CAAC,YAAY;yBACrC;qBACD,CAAC,CAAC;oBACH,OAAO;gBACR,CAAC;gBAED,OAAO,CAAC,MAAM,CAAC;oBACd,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,CACd,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,UAAU,CAAC,YAAY,IAAI,cAAc,KAAK,eAAe,GAAG,CAAC;oBACjG,SAAS,EAAE,wBAAwB;oBACnC,IAAI;oBACJ,IAAI,EAAE;wBACL,YAAY,EAAE,UAAU,CAAC,YAAY;qBACrC;iBACD,CAAC,CAAC;YACJ,CAAC;SACD,CAAC;IACH,CAAC;IACD,cAAc,EAAE,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"}
package/package.json CHANGED
@@ -65,5 +65,5 @@
65
65
  "sideEffects": false,
66
66
  "type": "module",
67
67
  "types": "./dist/index.d.ts",
68
- "version": "0.7.0"
68
+ "version": "0.8.0"
69
69
  }