What is an ESLint rule?
An ESLint rule is a separate, checkable condition that the code must satisfy. Each rule is responsible for a specific aspect of quality, style, or safety, and when it is violated, ESLint reports an error or a warning.
What a rule does
A rule can:
- forbid a dangerous or unwanted construct
(for example,
no-eval,no-unused-vars) - enforce a consistent style
(for example,
quotes- single or double quotes) - warn about potential bugs
(for example,
eqeqeq- use===instead of==)
What a rule looks like in the config
In .eslintrc, each rule has a level:
{
"rules": {
"no-unused-vars": "warn",
"eqeqeq": "error",
"quotes": ["error", "single"]
}
}Where "off" | "warn" | "error" means:
| Level | What it means |
|---|---|
"off" | the rule is disabled |
"warn" | a warning, but the build does not fail |
"error" | an error - it affects the build/commit |
An important point
ESLint is a set of rules, not one general requirement. Each rule is responsible for its own area of the code, and together they form the project's code style and quality rules.
Summary
An ESLint rule is a specific check that controls a certain behavior or style in the code and signals its violation.
Through a set of such rules, ESLint ensures cleanliness, predictability, and consistency of code in a project.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.