@pobammer-ts/eslint-cease-nonsense-rules 1.10.0 → 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.
- package/README.md +91 -0
- package/dist/build-metadata.json +3 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +461 -55
- package/dist/index.js.map +11 -5
- package/dist/rules/prefer-pattern-replacements.d.ts +13 -0
- package/dist/rules/prefer-pattern-replacements.d.ts.map +1 -0
- package/dist/utilities/configure-utilities.d.ts +7 -0
- package/dist/utilities/configure-utilities.d.ts.map +1 -1
- package/dist/utilities/pattern-replacement/constant-folder.d.ts +24 -0
- package/dist/utilities/pattern-replacement/constant-folder.d.ts.map +1 -0
- package/dist/utilities/pattern-replacement/index.d.ts +7 -0
- package/dist/utilities/pattern-replacement/index.d.ts.map +1 -0
- package/dist/utilities/pattern-replacement/pattern-matcher.d.ts +62 -0
- package/dist/utilities/pattern-replacement/pattern-matcher.d.ts.map +1 -0
- package/dist/utilities/pattern-replacement/pattern-parser.d.ts +22 -0
- package/dist/utilities/pattern-replacement/pattern-parser.d.ts.map +1 -0
- package/dist/utilities/pattern-replacement/pattern-types.d.ts +69 -0
- package/dist/utilities/pattern-replacement/pattern-types.d.ts.map +1 -0
- package/dist/utilities/pattern-replacement/replacement-generator.d.ts +16 -0
- package/dist/utilities/pattern-replacement/replacement-generator.d.ts.map +1 -0
- 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",
|
|
@@ -923,6 +924,96 @@ const deltaTime = 0.016;
|
|
|
923
924
|
const model = entity.char; // Property access is allowed
|
|
924
925
|
```
|
|
925
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
|
+
|
|
926
1017
|
#### `prefer-class-properties`
|
|
927
1018
|
|
|
928
1019
|
Prefer class properties over assignment of literals in constructors.
|
package/dist/build-metadata.json
CHANGED
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
|
*
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM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