Skip to content

"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 } }

πŸ”— See also ​

πŸ§‘β€πŸ’» Demo ​

Released under the MIT License