This plugin aims to enforce the usage of smart tabs, as defined in the emacs wiki:
- Tabs are only used at the beginning of lines. Everything else, like ASCII art and tables, should be formatted with spaces.
- 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:
- The line contains an inline tabulation:
β Valid | β Invalid |
---|---|
const foo = true;
const foobar = false; |
const fooβββπ·= true;
const foobar = false; |
- 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';
} |
- 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,
ββββπ·};
} |
npm i -D eslint-plugin-smarter-tabs
Make sure you've also installed ESLint.
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"
}
}
See the full changelog here.
Contributions are welcomed! Please open an issue before submitting substantial changes.
indent
,no-multi-spaces
,no-mixed-spaces-and-tabs
β Useful core ESLint rules to manage white space in codeunicorn/template-indent
β Rule from the unicorn plugin to fix whitespace-insensitive template indentation
ISC