Repository: prettier/prettier-eslint
Pull request #141 (2017-11-13 20:25:58)

Add test for #138

zimme: What's the difference between this solution and the previous one you closed?
Robert-Frampton: @zimme the previous solution didn't actually resolve the issue. It wasn't taking eslint's `max-len.tabWidth` into account.
Robert-Frampton: Also, I'll add another test to address the drop in code coverage.
codecov-io: # [Codecov](https://codecov.io/gh/prettier/prettier-eslint/pull/141?src=pr&el=h1) Report
> Merging [#141](https://codecov.io/gh/prettier/prettier-eslint/pull/141?src=pr&el=desc) into [master](https://codecov.io/gh/prettier/prettier-eslint/commit/9e08f4c79a6c746b41b32123e4bae3b88f8f7729?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/141/graphs/tree.svg?height=150&token=SKAX5tKPfD&width=650&src=pr)](https://codecov.io/gh/prettier/prettier-eslint/pull/141?src=pr&el=tree)

```diff
@@          Coverage Diff          @@
##           master   #141   +/-   ##
=====================================
  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/141?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/utils.js](https://codecov.io/gh/prettier/prettier-eslint/pull/141?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/141?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/141?src=pr&el=footer). Last update [9e08f4c...6d0dfba](https://codecov.io/gh/prettier/prettier-eslint/pull/141?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Robert-Frampton: Hey @zimme 

Any chance you can merge this? It's a blocker for my team. 

I know that few people are maintaining this package at the moment, I'm open to lending a hand if you're open.

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},