semi
JavaScript doesn’t require semicolons at the end of statements. Automatic Semicolon Insertion (ASI) adds them. This rule enforces consistent semicolon usage.Rule Type: Layout
Fixable: Yes (automatically fixable)
Deprecated: Consider using Prettier
Fixable: Yes (automatically fixable)
Deprecated: Consider using Prettier
Why This Rule Exists
There are two schools of thought:- Always use semicolons - More explicit, no ASI surprises
- Never use semicolons - Cleaner, ASI handles it
ASI Gotchas
Rule Details
This rule enforces consistent semicolon usage.Options
"always" (default)
Require semicolons at the end of statements.
Incorrect:
omitLastInOneLineBlock
Omit the last semicolon in single-line blocks:
omitLastInOneLineClassBody
Omit the last semicolon in single-line class bodies:
"never"
Disallow semicolons (except to disambiguate).
Incorrect:
beforeStatementContinuationChars
Control semicolons before continuation characters [, (, /, +, -:
"any"(default) - Ignore"always"- Require semicolons before these"never"- Disallow semicolons before these
Configuration Examples
Common Patterns
Return Statements
IIFE
Array Access
When to Use Each Style
Always (Recommended for Beginners)
Pros:- More explicit
- Fewer ASI surprises
- Easier to understand
- More verbose
- Extra characters
Never (For Experienced Developers)
Pros:- Cleaner look
- Less typing
- Must understand ASI rules
- Need to handle edge cases
- Can be tricky for beginners
When Not to Use It
Disable if:- You use Prettier or another formatter
- Your team hasn’t agreed on semicolon usage
- You don’t want to enforce a particular style