Skip to content

πŸŽ“ A tiny ESLint plugin to enforce the usage of smart tabs.

License

Notifications You must be signed in to change notification settings

cheap-glitch/eslint-plugin-smarter-tabs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

61 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŽ“ eslint-plugin-smarter-tabs

License Latest release Coverage status

This plugin aims to enforce the usage of smart tabs, as defined in the emacs wiki:

  1. Tabs are only used at the beginning of lines. Everything else, like ASCII art and tables, should be formatted with spaces.
  2. Tabs are only used for expressing the indentation level. One tab per β€œblock” β€” any remaining whitespace is spaces only.

To accomplish this, the plugin exports a single rule which issues a report in three cases:

  1. The line contains an inline tabulation:
βœ… Valid ❌ Invalid
const foo    = true;
const foobar = false;
const fooβ€”β€”β€”πˆ·= true;
const foobar = false;
  1. The line use spaces for indentation. This happens when a line is indented with spaces or starts with tabs followed by spaces, and its indentation level is different than the one of its block:
βœ… Valid ❌ Invalid
function foo(bar) {
β€”β€”β€”β€”πˆ·return (bar === undefined)
β€”β€”β€”β€”πˆ·       ? 'foo';
β€”β€”β€”β€”πˆ·       : 'bar';
}
function foo(bar) {
β€”β€”β€”β€”πˆ·return (bar === undefined)
β€”β€”β€”β€”πˆ·β€”β€”β€”β€”πˆ·  ? 'foo';
β€”β€”β€”β€”πˆ·β€”β€”β€”β€”πˆ·  : 'bar';
}
  1. The line has a mismatched indentation level. This happens when the indentation level of the line is greater than the one of the line before it by two or more:
βœ… Valid ❌ Invalid
if (baz) {
β€”β€”β€”β€”πˆ·let p = { x: 1,
β€”β€”β€”β€”πˆ·          y: 2,
β€”β€”β€”β€”πˆ·          z: 3,
β€”β€”β€”β€”πˆ·};
}
if (baz) {
β€”β€”β€”β€”πˆ·let p = { x: 1,
β€”β€”β€”β€”πˆ·β€”β€”β€”β€”πˆ·β€”β€”β€”β€”πˆ·y: 2,
β€”β€”β€”β€”πˆ·β€”β€”β€”β€”πˆ·β€”β€”β€”β€”πˆ·z: 3,
β€”β€”β€”β€”πˆ·};
}

Installation

npm i -D eslint-plugin-smarter-tabs

Make sure you've also installed ESLint.

Usage

This plugin exports a single rule, called smarter-tabs:

{
  "plugins": [
    "smarter-tabs"
  ],
  "rules": {
    "smarter-tabs/smarter-tabs": "warn"
  }
}

If you use the eslint:recommended preset, you may also want to disable the no-mixed-spaces-and-tabs rule as it might clash with this plugin:

{
  "rules": {
    "no-mixed-spaces-and-tabs": "off",
    "smarter-tabs/smarter-tabs": "warn"
  }
}

Or you could pass it the smart-tabs options:

{
  "rules": {
    "no-mixed-spaces-and-tabs": ["warn", "smart-tabs"],
    "smarter-tabs/smarter-tabs": "warn"
  }
}

Changelog

See the full changelog here.

Contributing

Contributions are welcomed! Please open an issue before submitting substantial changes.

Related

License

ISC