Skip to content

"Typography is two-dimensional architecture, based on experience and imagination, and guided by rules and readability." β€” Hermann Zapf

Enforce elegant text alignment (align) ​

πŸ’Ό This rule is enabled in the following configs: 🌐 all, βœ… recommended.

πŸ”§ This rule is automatically fixable by the --fix CLI option.

πŸ“– Rule details ​

While traditionalists might find the idea of center or right-aligned code unconventional, many innovations in software development were once deemed unorthodox. It's important to keep an open mind, recognizing that seemingly aesthetic choices can have deeper implications for cognition, creativity, and code readability. For developers accustomed to right-aligned languages like Arabic or Hebrew, this alignment might feel more intuitive, bridging the gap between natural linguistic processing and coding.

πŸ’‘ Examples ​

js
   // βœ… Correct
     if (a) {
      b = c;
function foo(d) {
      e = f;
        }
        }
js
     // βœ… Correct
         if (a) {
           b = c;
function foo(d) {
           e = f;
                }
                }
js
// βœ… Correct
if (a) {
b = c;
function foo(d) {
e = f;
}
}
js
       // βœ… Correct
           if (a) {
           b = c;
function foo(d) {
         e = f;
                }
                  }
js
// βœ… Correct
if (a) {
  b = c;
  function foo(d) {
    e = f;
  }
}

βš™οΈ Options ​

side ​

(default: 'center')

  • left
  • center
  • rigth
  • rtlIndent
  • ltrIndent

πŸ”§ Config ​

js
{ rules: { 'ninja/align': [2, { side: 'center' }] } }

πŸ”— See also ​

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

Released under the MIT License