Repository: prettier/prettier-eslint
Pull request #52 (2017-03-14 16:00:12)

fix: Allow for no presence of .eslintrc
This fixes #51 because after it we try to read eslint config even if eslintConfig is provided.
Unfortunately it also means eslint will crash if .eslintrc is not present. This change makes
.eslintrc presence optional.

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


```diff
@@          Coverage Diff          @@
##           master    #52   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines         120    120           
=====================================
  Hits          120    120
```


| [Impacted Files](https://codecov.io/gh/prettier/prettier-eslint/pull/52?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/index.js](https://codecov.io/gh/prettier/prettier-eslint/compare/da46ba78c8c16d1056d00605814e7cf5c9117bf0...bfbac73acafa5d51732fe886a3da1177965ccf7e?src=pr&el=tree#diff-c3JjL2luZGV4Lmpz) | `100% <100%> (ø)` | :white_check_mark: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/prettier/prettier-eslint/pull/52?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/52?src=pr&el=footer). Last update [da46ba7...bfbac73](https://codecov.io/gh/prettier/prettier-eslint/compare/da46ba78c8c16d1056d00605814e7cf5c9117bf0...bfbac73acafa5d51732fe886a3da1177965ccf7e?src=pr&el=footer&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Patch:
diff --git a/src/index.js b/src/index.js
index e14b1e4..9123bf1 100644
--- a/src/index.js
+++ b/src/index.js
@@ -188,8 +188,8 @@ function getConfig(filePath, eslintPath) {
     return config
   } catch (error) {
     // is this noisy? Try setting options.disableLog to false
-    logger.error('Unable to find config')
-    throw error
+    logger.warn('Unable to find config')
+    return { rules: {} }
   }
 }
 


Test patch:
diff --git a/src/index.test.js b/src/index.test.js
index 74c8c71..7f32206 100644
--- a/src/index.test.js
+++ b/src/index.test.js
@@ -124,15 +124,6 @@ tests.forEach(({title, modifier, input, output}) => {
   })
 })
 
-test('failure to get the config throws and logs an error', () => {
-  const {getConfigForFile} = eslintMock.mock
-  const error = 'Something happened'
-  getConfigForFile.throwError = new Error(error)
-  expect(() => format({text: ''})).toThrowError(error)
-  expect(logger.error).toHaveBeenCalledTimes(1)
-  getConfigForFile.throwError = null
-})
-
 test('failure to fix with eslint throws and logs an error', () => {
   const {executeOnText} = eslintMock.mock
   const error = 'Something happened'
@@ -240,7 +231,8 @@ test('reads text from fs if filePath is provided but not text', () => {
   } catch (e) {
     // ignore
   }
-  expect(fsMock.readFileSync).toHaveBeenCalledTimes(1)
+  // Two hits to .eslintignore
+  expect(fsMock.readFileSync).toHaveBeenCalledTimes(3)
   expect(fsMock.readFileSync).toHaveBeenCalledWith(filePath, 'utf8')
 })
 
diff --git a/src/utils.test.js b/src/utils.test.js
index 2254f96..c246b0e 100644
--- a/src/utils.test.js
+++ b/src/utils.test.js
@@ -62,6 +62,11 @@ const defaultEslintConfigTests = [
       },
     },
   },
+  {
+    config: undefined,
+    defaults: undefined,
+    result: {},
+  },
   {
     config: {},
     defaults: {},