Skip to content

prefer-enum-item

Replaces string and number literals with Roblox Enum items when the expected type already points to one.

This 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
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);
OptionDefaultWhat it does
fixNumericToValuefalseFixes numeric literals to Enum.Type.Member.Value instead of Enum.Type.Member.
performanceModetrueUses cached enum lookups to skip work. It does not change what gets reported.
eslint.config.js
import ceaseNonsense from "eslint-plugin-cease-nonsense";
export default [
{
plugins: {
"cease-nonsense": ceaseNonsense,
},
rules: {
"cease-nonsense/prefer-enum-item": ["error", { fixNumericToValue: true }],
},
},
];