Skip to content

Commit

Permalink
Turn no-tabs into a validatable rule
Browse files Browse the repository at this point in the history
Closes #55.
  • Loading branch information
lydell committed Nov 29, 2020
1 parent 4ab6937 commit 7867a9c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
28 changes: 4 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,31 +401,13 @@ Example ESLint configuration:

### [no-tabs]

**This rule requires certain Prettier options.**

This rule disallows the use of tab characters at all. It can be used just fine with Prettier as long as you don’t configure Prettier to indent using tabs.

Example ESLint configuration:

<!-- prettier-ignore -->
```json
{
"rules": {
"no-tabs": "error"
}
}
```
**This rule requires certain options.**

Example Prettier configuration (this is the default, so adding this is not required):
This rule disallows the use of tab characters. By default the rule forbids _all_ tab characters. That can be used just fine with Prettier as long as you don’t configure Prettier to indent using tabs.

<!-- prettier-ignore -->
```json
{
"useTabs": false
}
```
Luckily, it’s possible to configure the rule so that it works regardless of whether Prettier uses spaces or tabs: Set `allowIndentationTabs` to `true`. This way Prettier takes care of your indentation, while the `no-tabs` takes care of potential tab characters anywhere else in your code.

**Note:** Since [ESlint 5.7.0] this rule can be configured to work regardless of your Prettier configuration:
Example ESLint configuration:

<!-- prettier-ignore -->
```json
Expand All @@ -436,8 +418,6 @@ Example Prettier configuration (this is the default, so adding this is not requi
}
```

A future version of eslint-config-prettier might check for that automatically.

### [no-unexpected-multiline]

**This rule requires special attention when writing code.**
Expand Down
9 changes: 9 additions & 0 deletions bin/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ module.exports = {
return firstOption ? firstOption.allowParens === false : false;
},

"no-tabs"(options) {
if (options.length === 0) {
return false;
}

const firstOption = options[0];
return Boolean(firstOption && firstOption.allowIndentationTabs);
},

"vue/html-self-closing"(options) {
if (options.length === 0) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ https://github.com/prettier/eslint-config-prettier#special-rules
- curly
- lines-around-comment
- no-confusing-arrow
- no-tabs
- vue/html-self-closing
The following rules are enabled but cannot be automatically checked. See:
Expand All @@ -154,7 +155,6 @@ https://github.com/prettier/eslint-config-prettier#special-rules
- arrow-body-style
- max-len
- no-mixed-operators
- no-tabs
- no-unexpected-multiline
- prefer-arrow-callback
- quotes",
Expand Down
5 changes: 5 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ rule("no-confusing-arrow", {
invalid: [[], [null], [{ allowParens: true }], [{ other: true }]],
});

rule("no-tabs", {
valid: [[{ allowIndentationTabs: true }]],
invalid: [[], [null], [{ allowIndentationTabs: false }], [{ other: true }]],
});

rule("vue/html-self-closing", {
valid: [
[{ html: { void: "any" } }],
Expand Down

0 comments on commit 7867a9c

Please sign in to comment.