"The end may justify the means as long as there is something that justifies the end." β Leon Trotsky
Enforce comments explaining code (justify
) β
πΌ This rule is enabled in the following configs: π all
, β
recommended
.
π§ This rule is automatically fixable by the --fix
CLI option.
π Rule details β
Every line of code should be accompanied by a comment. Not all readers possess the same experience or context as you. Well-placed comments can save hours for both future you and others, aiding in faster comprehension.
π‘ Examples β
js
// β Incorrect
if (a) {
b = c
function foo(d) {
e = f
}
}
// β
Correct
// if a
if (a) {
// then assign c to b
b = c
// define foo
function foo(d) {
// assign f to e
e = f
}
}
π§ Config β
js
{ rules: { 'ninja/justify': 2 } }