@pobammer-ts/eslint-cease-nonsense-rules 1.9.2 → 1.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.
Files changed (30) hide show
  1. package/README.md +139 -6
  2. package/dist/build-metadata.json +3 -3
  3. package/dist/index.d.ts +3 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +678 -142
  6. package/dist/index.js.map +16 -10
  7. package/dist/rules/no-shorthand-names.d.ts +1 -0
  8. package/dist/rules/no-shorthand-names.d.ts.map +1 -1
  9. package/dist/rules/prefer-pattern-replacements.d.ts +13 -0
  10. package/dist/rules/prefer-pattern-replacements.d.ts.map +1 -0
  11. package/dist/rules/require-paired-calls.d.ts +18 -2
  12. package/dist/rules/require-paired-calls.d.ts.map +1 -1
  13. package/dist/rules/strict-component-boundaries.d.ts.map +1 -1
  14. package/dist/rules/use-exhaustive-dependencies.d.ts.map +1 -1
  15. package/dist/rules/use-hook-at-top-level.d.ts.map +1 -1
  16. package/dist/utilities/configure-utilities.d.ts +7 -0
  17. package/dist/utilities/configure-utilities.d.ts.map +1 -1
  18. package/dist/utilities/pattern-replacement/constant-folder.d.ts +24 -0
  19. package/dist/utilities/pattern-replacement/constant-folder.d.ts.map +1 -0
  20. package/dist/utilities/pattern-replacement/index.d.ts +7 -0
  21. package/dist/utilities/pattern-replacement/index.d.ts.map +1 -0
  22. package/dist/utilities/pattern-replacement/pattern-matcher.d.ts +62 -0
  23. package/dist/utilities/pattern-replacement/pattern-matcher.d.ts.map +1 -0
  24. package/dist/utilities/pattern-replacement/pattern-parser.d.ts +22 -0
  25. package/dist/utilities/pattern-replacement/pattern-parser.d.ts.map +1 -0
  26. package/dist/utilities/pattern-replacement/pattern-types.d.ts +69 -0
  27. package/dist/utilities/pattern-replacement/pattern-types.d.ts.map +1 -0
  28. package/dist/utilities/pattern-replacement/replacement-generator.d.ts +16 -0
  29. package/dist/utilities/pattern-replacement/replacement-generator.d.ts.map +1 -0
  30. package/package.json +1 -1
package/README.md CHANGED
@@ -57,6 +57,7 @@ export default [
57
57
  "cease-nonsense/prefer-early-return": "error",
58
58
  "cease-nonsense/prefer-module-scope-constants": "error",
59
59
  "cease-nonsense/prefer-pascal-case-enums": "error",
60
+ "cease-nonsense/prefer-pattern-replacements": "error",
60
61
  "cease-nonsense/prefer-sequence-overloads": "error",
61
62
  "cease-nonsense/prefer-singular-enums": "error",
62
63
  "cease-nonsense/prefer-udim2-shorthand": "error",
@@ -838,13 +839,19 @@ const doubled = items.map((x) => x * 2);
838
839
 
839
840
  Bans shorthand variable names in favor of descriptive full names.
840
841
 
842
+ **Features**
843
+
844
+ - Matches shorthands within compound identifiers (e.g., `plrData` → `playerData`)
845
+ - Supports glob patterns (`*`, `?`) for flexible matching
846
+ - Supports regex patterns (`/pattern/flags`) for advanced matching
847
+ - Automatically ignores import specifiers (external packages control their naming)
848
+
841
849
  **Default mappings**
842
850
 
843
851
  - `plr` → `player` (or `localPlayer` for `Players.LocalPlayer`)
844
852
  - `args` → `parameters`
845
853
  - `dt` → `deltaTime`
846
854
  - `char` → `character`
847
- - `btn` → `button`
848
855
 
849
856
  **Configuration**
850
857
 
@@ -853,16 +860,52 @@ Bans shorthand variable names in favor of descriptive full names.
853
860
  "cease-nonsense/no-shorthand-names": ["error", {
854
861
  "shorthands": {
855
862
  "plr": "player",
856
- "args": "parameters",
857
- "dt": "deltaTime",
858
- "char": "character",
859
- "btn": "button"
863
+ "*Props": "*Properties"
860
864
  },
861
- "allowPropertyAccess": ["char"] // Allow as property
865
+ "allowPropertyAccess": ["char", "Props"], // Allow as property/qualified name
866
+ "ignoreShorthands": ["PropsWithoutRef"] // Ignore completely
862
867
  }]
863
868
  }
864
869
  ```
865
870
 
871
+ **Options**
872
+
873
+ - `shorthands`: Map of shorthand patterns to replacements (exact, glob `*`/`?`, or regex `/pattern/flags`)
874
+ - `allowPropertyAccess`: Words allowed in property access (`obj.prop`) or type qualified names (`React.Props`)
875
+ - `ignoreShorthands`: Words to ignore completely, regardless of context (supports same pattern syntax)
876
+
877
+ **Pattern syntax**
878
+
879
+ Glob patterns use `*` (any characters) and `?` (single character):
880
+
881
+ ```typescript
882
+ {
883
+ "shorthands": {
884
+ "str*": "string*", // strValue → stringValue
885
+ "*Props": "*Properties", // DataProps → DataProperties
886
+ "*Btn*": "*Button*" // myBtnClick → myButtonClick
887
+ }
888
+ }
889
+ ```
890
+
891
+ Regex patterns use `/pattern/flags` syntax:
892
+
893
+ ```typescript
894
+ {
895
+ "shorthands": {
896
+ "/^str(.*)$/": "string$1", // strName → stringName
897
+ "/^props$/i": "properties" // Props or props → properties
898
+ }
899
+ }
900
+ ```
901
+
902
+ **Compound identifier matching**
903
+
904
+ Identifiers are split at camelCase/PascalCase boundaries, and each word is checked independently:
905
+
906
+ - `propsData` with `{ "props": "properties" }` → `propertiesData`
907
+ - `UnitBoxBadgeInfoProps` with `{ "Props": "Properties" }` → `UnitBoxBadgeInfoProperties`
908
+
866
909
  **❌ Bad**
867
910
 
868
911
  ```typescript
@@ -881,6 +924,96 @@ const deltaTime = 0.016;
881
924
  const model = entity.char; // Property access is allowed
882
925
  ```
883
926
 
927
+ #### `prefer-pattern-replacements`
928
+
929
+ Enforces replacement of verbose constructor/method patterns with simpler alternatives.
930
+
931
+ **Features**
932
+
933
+ - ✨ Has auto-fix
934
+ - Type-safe `pattern()` API with compile-time capture validation
935
+ - Supports captures (`$x`), optional args (`0?`), wildcards (`_`)
936
+ - Constant expression evaluation (`1 - 1` matches `0`)
937
+ - Same-variable matching (`$x, $x` requires identical arguments)
938
+ - Scope-aware: skips fix if replacement would shadow local variable
939
+
940
+ **Configuration**
941
+
942
+ ```typescript
943
+ import { pattern } from "@pobammer-ts/eslint-cease-nonsense-rules";
944
+
945
+ {
946
+ "cease-nonsense/prefer-pattern-replacements": ["error", {
947
+ "patterns": [
948
+ // Simple patterns
949
+ pattern({
950
+ match: "UDim2.fromScale(1, 1)",
951
+ replacement: "oneScale"
952
+ }),
953
+
954
+ // Captures and conditions
955
+ pattern({
956
+ match: "new Vector2($x, $x)",
957
+ replacement: "fromUniform($x)",
958
+ when: { x: "!= 0" }
959
+ }),
960
+
961
+ // Optional args (0? matches 0 or missing)
962
+ pattern({
963
+ match: "new Vector2($x, 0?)",
964
+ replacement: "fromX($x)"
965
+ }),
966
+
967
+ // Wildcards (match any value, don't capture)
968
+ pattern({
969
+ match: "new UDim2(_, 0, _, 0)",
970
+ replacement: "UDim2.fromScale"
971
+ })
972
+ ]
973
+ }]
974
+ }
975
+ ```
976
+
977
+ **Pattern syntax**
978
+
979
+ - `$name` - Capture variable, stores value for replacement
980
+ - `0?` - Optional: matches literal `0` or missing argument
981
+ - `_` - Wildcard: matches any value, not captured
982
+ - `when` clause - Conditions on captures (`== 0`, `!= 0`, `> 5`, etc.)
983
+
984
+ **Replacement types**
985
+
986
+ - Identifier: `oneScale`
987
+ - Static access: `Vector2.one`
988
+ - Call: `fromUniform($x)` or `Vector2.fromUniform($x, $y)`
989
+
990
+ **❌ Bad**
991
+
992
+ ```typescript
993
+ const scale = UDim2.fromScale(1, 1);
994
+ const vec = new Vector2(5, 5);
995
+ const offset = new Vector2(10, 0);
996
+ ```
997
+
998
+ **✅ Good**
999
+
1000
+ ```typescript
1001
+ const scale = oneScale;
1002
+ const vec = fromUniform(5);
1003
+ const offset = fromX(10);
1004
+ ```
1005
+
1006
+ **Scope awareness**
1007
+
1008
+ The rule automatically skips fixes when the replacement would conflict with a local variable:
1009
+
1010
+ ```typescript
1011
+ function example() {
1012
+ const oneScale = 5; // Local variable shadows replacement
1013
+ const scale = UDim2.fromScale(1, 1); // No fix applied (would shadow)
1014
+ }
1015
+ ```
1016
+
884
1017
  #### `prefer-class-properties`
885
1018
 
886
1019
  Prefer class properties over assignment of literals in constructors.
@@ -1,5 +1,5 @@
1
1
  {
2
- "commit": "d84eba40b7747b35f7141d5e4f2ef9ce11db5e57",
3
- "time": "2025-12-22T21:43:58.605Z",
4
- "version": "1.9.2"
2
+ "commit": "33b03ad58201aa1a174c1516a9b52a659f746afc",
3
+ "time": "2025-12-28T16:15:11.008Z",
4
+ "version": "1.11.0"
5
5
  }
package/dist/index.d.ts CHANGED
@@ -12,7 +12,9 @@ export type { EffectFunctionOptions, EnvironmentMode, HookConfiguration } from "
12
12
  export type { PairConfiguration, RequirePairedCallsOptions } from "./rules/require-paired-calls";
13
13
  export type { ReactKeysOptions } from "./rules/require-react-component-keys";
14
14
  export type { HookEntry, UseExhaustiveDependenciesOptions } from "./rules/use-exhaustive-dependencies";
15
- export { createBanInstancesOptions, createComplexityConfiguration, createEffectFunctionOptions, createHookConfiguration, createNoGodComponentsOptions, createNoInstanceMethodsOptions, createNoShorthandOptions, createNoUselessUseSpringOptions, createPairConfiguration, createReactKeysOptions, createRequirePairedCallsOptions, createUseExhaustiveDependenciesOptions, createUseHookAtTopLevelOptions, defaultRobloxProfilePair, } from "./utilities/configure-utilities";
15
+ export { createBanInstancesOptions, createComplexityConfiguration, createEffectFunctionOptions, createHookConfiguration, createNoGodComponentsOptions, createNoInstanceMethodsOptions, createNoShorthandOptions, createNoUselessUseSpringOptions, createPairConfiguration, createPreferPatternReplacementsOptions, createReactKeysOptions, createRequirePairedCallsOptions, createUseExhaustiveDependenciesOptions, createUseHookAtTopLevelOptions, defaultRobloxProfilePair, } from "./utilities/configure-utilities";
16
+ export type { Pattern, PreferPatternReplacementsOptions } from "./utilities/pattern-replacement";
17
+ export { pattern } from "./utilities/pattern-replacement";
16
18
  /**
17
19
  * Recommended configuration for ESLint flat config.
18
20
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AA8BnC,KAAK,aAAa,GAAG,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,yBAAyB,CAAC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