Repository: prettier/prettier-eslint
Pull request #143 (2017-11-15 18:10:26)

Fix tab width
Let's redo the merge so semantic-release can find the fix.

codecov-io: # [Codecov](https://codecov.io/gh/prettier/prettier-eslint/pull/143?src=pr&el=h1) Report
> Merging [#143](https://codecov.io/gh/prettier/prettier-eslint/pull/143?src=pr&el=desc) into [master](https://codecov.io/gh/prettier/prettier-eslint/commit/d2c74d205e5c679004826b984cd0dee6ce395bf3?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/prettier/prettier-eslint/pull/143/graphs/tree.svg?height=150&width=650&token=SKAX5tKPfD&src=pr)](https://codecov.io/gh/prettier/prettier-eslint/pull/143?src=pr&el=tree)

```diff
@@          Coverage Diff          @@
##           master   #143   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines         200    202    +2     
  Branches       36     36           
=====================================
+ Hits          200    202    +2
```


| [Impacted Files](https://codecov.io/gh/prettier/prettier-eslint/pull/143?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/utils.js](https://codecov.io/gh/prettier/prettier-eslint/pull/143?src=pr&el=tree#diff-c3JjL3V0aWxzLmpz) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/prettier/prettier-eslint/pull/143?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/prettier/prettier-eslint/pull/143?src=pr&el=footer). Last update [d2c74d2...6d0dfba](https://codecov.io/gh/prettier/prettier-eslint/pull/143?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/utils.js b/src/utils.js
index b1465c0..3d61cef 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -11,7 +11,13 @@ const OPTION_GETTERS = {
     ruleValueToPrettierOption: getPrintWidth,
   },
   tabWidth: {
-    ruleValue: rules => getRuleValue(rules, 'indent'),
+    ruleValue: rules => {
+      let value = getRuleValue(rules, 'indent')
+      if (value === 'tab') {
+        value = getRuleValue(rules, 'max-len', 'tabWidth')
+      }
+      return value
+    },
     ruleValueToPrettierOption: getTabWidth,
   },
   parser: {
@@ -158,10 +164,7 @@ function getPrintWidth(eslintValue, fallbacks) {
 }
 
 function getTabWidth(eslintValue, fallbacks) {
-  // if it's set to tabs, then the tabWidth value doesn't matter
-  const prettierValue = eslintValue === 'tab' ? RULE_DISABLED : eslintValue
-
-  return makePrettierOption('tabWidth', prettierValue, fallbacks, 2)
+  return makePrettierOption('tabWidth', eslintValue, fallbacks, 2)
 }
 
 function getParser(eslintValue, fallbacks) {


Test patch:
diff --git a/src/__tests__/utils.js b/src/__tests__/utils.js
index 14a3e2a..57a386f 100644
--- a/src/__tests__/utils.js
+++ b/src/__tests__/utils.js
@@ -173,6 +173,26 @@ test('if fallbacks are provided, those are used if not found in eslint', () => {
   expect(prettier).toMatchObject({singleQuote: false})
 })
 
+test('eslint max-len.tabWidth value should be used for tabWidth when tabs are used', () => {
+  const {prettier} = getOptionsForFormatting({rules: {
+    indent: ['error', 'tab'],
+    'max-len': [2, {
+      tabWidth: 4,
+    }],
+  }})
+
+  expect(prettier).toMatchObject({
+    printWidth: 80,
+    tabWidth: 4,
+    parser: 'babylon',
+    singleQuote: false,
+    trailingComma: 'none',
+    bracketSpacing: true,
+    semi: true,
+    useTabs: true,
+  })
+})
+
 test('eslint config has only necessary properties', () => {
   const {eslint} = getOptionsForFormatting({
     globals: {window: false},