Ensures that Component lifecycle methods are ordered consistently
A consistent ordering for Component lifecycle methods can make Components easier to read, navigate, and edit.
Ordering lifecycle methods by their natural call order (call-order
) makes the functionality of each self-documenting.
This rule optionally accepts a single argument, which is a string. It should be one of the following values:
call-order
alphabetical
If no argument is provided, this rule will enforce the default functionality (which matches that of call-order
.)
{ "lifecycle-sort": [true, "call-order"] }
{ "lifecycle-sort": [true, "alphabetical"] }
{
"type": "array",
"items": {
"type": "string",
"enum": [
"alphabetical",
"call-order"
]
},
"minLength": 0,
"maxLength": 2
}
-
Order lifecycle methods by their natural call order (
call-order
ordefault
)⚙️ Config
"rules": { "lifecycle-sort": [true, "call-order"] }
✅ Pass
componentWillLoad() { } componentDidLoad() { } componentWillUpdate() { } componentDidUpdate() { } componentDidUnload() { }
-
Order lifecycle methods alphabetically (
alphabetical
) ⚙️ Config"rules": { "lifecycle-sort": [true, "alphabetical"] }
✅ Pass
componentDidLoad() { } componentDidUnload() { } componentDidUpdate() { } componentWillLoad() { } componentWillUpdate() { }