prefer-enum-item
Replaces string and number literals with Roblox Enum items when the expected type already points to one.
Rule details Suggestion
Section titled “Rule details ”SuggestionThis rule uses type information. It reports a literal only when TypeScript can tell that the surrounding position
expects one or more Roblox Enum items and the literal matches one of them.
That means the rule can catch cases like:
- function and constructor arguments
- object property values
- JSX attribute values
- variable initializers with an explicit type annotation
Examples
Section titled “Examples” Incorrect
<uiflexitem FlexMode="Fill" />
const props: { ScaleType: Enum.ScaleType } = { ScaleType: 1,};
setFlexMode("Fill"); Correct
<uiflexitem FlexMode={Enum.UIFlexMode.Fill} />
const props: { ScaleType: Enum.ScaleType } = { ScaleType: Enum.ScaleType.Slice,};
setFlexMode(Enum.UIFlexMode.Fill);Options
Section titled “Options”| Option | Default | What it does |
|---|---|---|
fixNumericToValue | false | Fixes numeric literals to Enum.Type.Member.Value instead of Enum.Type.Member. |
performanceMode | true | Uses cached enum lookups to skip work. It does not change what gets reported. |
import ceaseNonsense from "eslint-plugin-cease-nonsense";
export default [ { plugins: { "cease-nonsense": ceaseNonsense, }, rules: { "cease-nonsense/prefer-enum-item": ["error", { fixNumericToValue: true }], }, },];Related rules
Section titled “Related rules” prefer-enum-member Does the same kind of check for TypeScript enums
prefer-pascal-case-enums Keeps enum names in a consistent style