Repository: prettier/prettier-eslint (ts)

Issue:
Eslint config based prettying
Hey,
based on:
https://github.com/jlongster/prettier-atom/issues/85#issuecomment-286129306

there is something wrong with reading eslint configuration.

```
prettier-atom: TypeError: Cannot read property 'indexOf' of undefined
```

```
TypeError: Cannot read property 'indexOf' of undefined
    at isAlways (/Users/patrykpeas/.atom/packages/prettier-atom/node_modules/prettier-eslint/dist/utils.js:187:13)
    at Array.some (native)
    at getValFromObjectConfig (/Users/patrykpeas/.atom/packages/prettier-atom/node_modules/prettier-eslint/dist/utils.js:131:33)
    at getTrailingComma (/Users/patrykpeas/.atom/packages/prettier-atom/node_modules/prettier-eslint/dist/utils.js:118:14)
    at /Users/patrykpeas/.atom/packages/prettier-atom/node_modules/prettier-eslint/dist/utils.js:91:50
    at Array.reduce (native)
    at getPrettierOptionsFromESLintRules (/Users/patrykpeas/.atom/packages/prettier-atom/node_modules/prettier-eslint/dist/utils.js:87:37)
    at getOptionsForFormatting (/Users/patrykpeas/.atom/packages/prettier-atom/node_modules/prettier-eslint/dist/utils.js:34:18)
    at format (/Users/patrykpeas/.atom/packages/prettier-atom/node_modules/prettier-eslint/dist/index.js:79:62)
    at /Users/patrykpeas/.atom/packages/prettier-atom/dist/executePrettier.js:33:16
    at exports.allowUnsafeNewFunction (/Users/patrykpeas/.atom/packages/prettier-atom/node_modules/loophole/lib/loophole.js:25:14)
    at executePrettier (/Users/patrykpeas/.atom/packages/prettier-atom/dist/executePrettier.js:32:14)
    at executePrettierOnBufferRange (/Users/patrykpeas/.atom/packages/prettier-atom/dist/executePrettier.js:45:21)
    at formatOnSaveIfAppropriate (/Users/patrykpeas/.atom/packages/prettier-atom/dist/formatOnSave.js:36:5)
    at lazyFormatOnSave (/Users/patrykpeas/.atom/packages/prettier-atom/dist/main.js:31:15)
    at /Users/patrykpeas/.atom/packages/prettier-atom/dist/main.js:45:12
    at Function.module.exports.Emitter.simpleDispatch (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/event-kit/lib/emitter.js:25:14)
    at Emitter.module.exports.Emitter.emit (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/event-kit/lib/emitter.js:129:28)
    at TextBuffer.module.exports.TextBuffer.saveAs (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:1059:20)
    at TextBuffer.module.exports.TextBuffer.save (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:1048:19)
    at TextEditor.module.exports.TextEditor.save (/Applications/Atom.app/Contents/Resources/app.asar/src/text-editor.js:915:26)
    at Pane.module.exports.Pane.saveItem (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:753:18)
    at Pane.saveItem (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:3:59)
    at Pane.module.exports.Pane.saveActiveItem (/Applications/Atom.app/Contents/Resources/app.asar/src/pane.js:736:19)
    at Workspace.module.exports.Workspace.saveActivePaneItem (/Applications/Atom.app/Contents/Resources/app.asar/src/workspace.js:693:35)
    at atom-workspace.core:save (/Applications/Atom.app/Contents/Resources/app.asar/src/register-default-commands.js:225:32)
    at CommandRegistry.module.exports.CommandRegistry.handleCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:259:29)
    at /Applications/Atom.app/Contents/Resources/app.asar/src/command-registry.js:3:59
    at KeymapManager.module.exports.KeymapManager.dispatchCommandEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:599:16)
    at KeymapManager.module.exports.KeymapManager.handleKeyboardEvent (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/atom-keymap/lib/keymap-manager.js:390:22)
    at WindowEventHandler.module.exports.WindowEventHandler.handleDocumentKeyEvent (/Applications/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:106:36)
    at HTMLDocument.<anonymous> (/Applications/Atom.app/Contents/Resources/app.asar/src/window-event-handler.js:3:59)
```

Used configuration
```
{
  "parserOptions": {
    "ecmaVersion": 7,
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true,
      "jsx": true
    },
    "sourceType": "module"
  },

  "settings": {
    "import/resolver": {
      "webpack": {
        "config": "config/webpack/config.js"
      }
    }
  },

  "env": {
    "es6": true,
    "browser": true
  },

  "plugins": [
  ],

  "globals": {
    "document": false,
    "window": false
  },

  "rules": {
    "no-cond-assign": "error",
    "no-console": ["error", {
      "allow": ["warn", "error", "info"]
    }],
    "no-constant-condition": "error",
    "no-debugger": "error",
    "no-alert": "error",
    "no-dupe-args": "error",
    "no-dupe-keys": "error",
    "no-duplicate-case": "error",
    "no-empty": "error",
    "no-empty-character-class": "error",
    "no-ex-assign": "error",
    "no-extra-boolean-cast": "error",
    "no-extra-parens": "error",
    "no-extra-semi": "error",
    "no-func-assign": "error",
    "no-invalid-regexp": "error",
    "no-irregular-whitespace": ["error", {
      "skipComments": true,
      "skipStrings": true,
      "skipTemplates": true
    }],
    "no-obj-calls": "error",
    "no-regex-spaces": "error",
    "no-sparse-arrays": "error",
    "no-template-curly-in-string": "error",
    "no-unreachable": "error",
    "no-unsafe-finally": "error",
    "array-callback-return": "error",
    "curly": "error",
    "default-case": "error",
    "dot-location": ["error", "property"],
    "no-caller": "error",
    "no-empty-function": "error",
    "no-empty-pattern": "error",
    "no-fallthrough": "error",
    "no-global-assign": "error",
    "no-implied-eval": "error",
    "no-invalid-this": "error",
    "no-labels": "error",
    "no-lone-blocks": "error",
    "no-multi-spaces": "error",
    "no-multi-str": "error",
    "no-octal": "error",
    "no-redeclare": "error",
    "no-return-assign": "error",
    "no-self-assign": "error",
    "no-self-compare": "error",
    "no-sequences": "error",
    "no-useless-call": "error",
    "no-useless-concat": "error",
    "no-useless-return": "error",
    "yoda": "error",
    "no-undef": "error",
    "no-undef-init": "error",
    "no-unused-vars": "error",
    "no-use-before-define": "error",
    "array-bracket-spacing": ["error", "never"],
    "block-spacing": "error",
    "brace-style": ["error", "1tbs", {
      "allowSingleLine": true
    }],
    "comma-spacing": "error",
    "comma-style": ["error", "last"],
    "computed-property-spacing": "error",
    "eol-last": "error",
    "func-call-spacing": "error",
    "indent": ["error", 2],
    "jsx-quotes": ["error", "prefer-double"],
    "key-spacing": "error",
    "keyword-spacing": "error",
    "new-parens": "error",
    "no-multiple-empty-lines": ["error", {
      "max": 1,
      "maxEOF": 1,
      "maxBOF": 0
    }],
    "no-trailing-spaces": "error",
    "no-unneeded-ternary": "error",
    "no-whitespace-before-property": "error",
    "object-curly-newline": "error",
    "object-curly-spacing": "error",
    "object-property-newline": ["error", {
      "allowMultiplePropertiesPerLine": true
    }],
    "one-var": ["error", "never"],
    "quotes": "error",
    "semi": "error",
    "semi-spacing": "error",
    "space-before-function-paren": ["error", "never"],
    "space-in-parens": "error",
    "space-infix-ops": "error",
    "template-tag-spacing": "error",
    "arrow-body-style": ["error", "as-needed"],
    "arrow-parens": ["error", "as-needed"],
    "arrow-spacing": "error",
    "no-const-assign": "error",
    "no-dupe-class-members": "error",
    "no-duplicate-imports": "error",
    "no-this-before-super": "error",
    "no-useless-constructor": "error",
    "no-useless-rename": "error",
    "prefer-const": "error",
    "prefer-template": "error",
    "require-yield": "error",
    "rest-spread-spacing": "error",
    "yield-star-spacing": "error",
    "generator-star-spacing": ["error", {
      "before": false,
      "after": true
    }],
    "no-unsafe-negation": "error",
    "use-isnan": "error",
    "consistent-return": "error",
    "no-case-declarations": "error",
    "no-implicit-globals": "error",
    "no-undefined": "error",
    "camelcase": "error",
    "comma-dangle": ["error", {
      "imports": "never",
      "exports": "never"
    }],
    "indent": ["error", 2],
    "quotes": ["error", "double"]
  }
}
```

and output from `prettier-eslint-cli`:
```
prettier-eslint-cli [ERROR]: There was an error formatting "./app/frontend/rails_ujs.js":
    TypeError: Cannot read property 'indexOf' of undefined
        at isAlways (/Users/patrykpeas/code/***/node_modules/prettier-eslint/dist/utils.js:187:13)
        at Array.some (native)
        at getValFromObjectConfig (/Users/patrykpeas/code/***/node_modules/prettier-eslint/dist/utils.js:131:33)
        at getTrailingComma (/Users/patrykpeas/code/***/node_modules/prettier-eslint/dist/utils.js:118:14)
        at /Users/patrykpeas/code/***/node_modules/prettier-eslint/dist/utils.js:91:50
        at Array.reduce (native)
        at getPrettierOptionsFromESLintRules (/Users/patrykpeas/code/***/node_modules/prettier-eslint/dist/utils.js:87:37)
        at getOptionsForFormatting (/Users/patrykpeas/code/***/node_modules/prettier-eslint/dist/utils.js:34:18)
        at format (/Users/patrykpeas/code/***/node_modules/prettier-eslint/dist/index.js:79:62)
        at MapSubscriber.project (/Users/patrykpeas/code/***/node_modules/prettier-eslint-cli/dist/format-files.js:276:55)
failure formatting 1 file with prettier-eslint
```

Pull request description:
fix(scripts): Set defaults for getValFromTrailingCommaConfig missings…
… keys in objectConfig

Closes #48

Patch:
diff --git a/.all-contributorsrc b/.all-contributorsrc
index a1de10a..300d130 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -160,6 +160,17 @@
         "doc",
         "code"
       ]
+    },
+    {
+      "login": "Belir",
+      "name": "Patryk Peas",
+      "avatar_url": "https://avatars0.githubusercontent.com/u/4818642?v=3",
+      "profile": "https://github.com/Belir",
+      "contributions": [
+        "bug",
+        "code",
+        "test"
+      ]
     }
   ]
 }
diff --git a/README.md b/README.md
index cdeaf2b..c32afe7 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ Formats your JavaScript using [`prettier`][prettier] followed by [`eslint --fix`
 [![downloads][downloads-badge]][npm-stat]
 [![MIT License][license-badge]][LICENSE]
 
-[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors)
+[![All Contributors](https://img.shields.io/badge/all_contributors-17-orange.svg?style=flat-square)](#contributors)
 [![PRs Welcome][prs-badge]][prs]
 [![Donate][donate-badge]][donate]
 [![Code of Conduct][coc-badge]][coc]
@@ -223,7 +223,7 @@ Thanks goes to these people ([emoji key][emojis]):
 | [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[💻](https://github.com/prettier/prettier-eslint/commits?author=kentcdodds) [📖](https://github.com/prettier/prettier-eslint/commits?author=kentcdodds) 🚇 [⚠️](https://github.com/prettier/prettier-eslint/commits?author=kentcdodds) | [<img src="https://avatars.githubusercontent.com/u/5554486?v=3" width="100px;"/><br /><sub>Gyandeep Singh</sub>](http://gyandeeps.com)<br />👀 | [<img src="https://avatars.githubusercontent.com/u/682584?v=3" width="100px;"/><br /><sub>Igor Pnev</sub>](https://github.com/exdeniz)<br />[🐛](https://github.com/prettier/prettier-eslint/issues?q=author%3Aexdeniz) | [<img src="https://avatars.githubusercontent.com/u/813865?v=3" width="100px;"/><br /><sub>Benjamin Tan</sub>](https://demoneaux.github.io/)<br />💬 👀 | [<img src="https://avatars.githubusercontent.com/u/622118?v=3" width="100px;"/><br /><sub>Eric McCormick</sub>](https://ericmccormick.io)<br />[💻](https://github.com/prettier/prettier-eslint/commits?author=edm00se) [📖](https://github.com/prettier/prettier-eslint/commits?author=edm00se) [⚠️](https://github.com/prettier/prettier-eslint/commits?author=edm00se) | [<img src="https://avatars.githubusercontent.com/u/2142817?v=3" width="100px;"/><br /><sub>Simon Lydell</sub>](https://github.com/lydell)<br />[📖](https://github.com/prettier/prettier-eslint/commits?author=lydell) | [<img src="https://avatars0.githubusercontent.com/u/981957?v=3" width="100px;"/><br /><sub>Tom McKearney</sub>](https://github.com/tommck)<br />[📖](https://github.com/prettier/prettier-eslint/commits?author=tommck) 💡 |
 | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
 | [<img src="https://avatars.githubusercontent.com/u/463105?v=3" width="100px;"/><br /><sub>Patrik Åkerstrand</sub>](https://github.com/PAkerstrand)<br />[💻](https://github.com/prettier/prettier-eslint/commits?author=PAkerstrand) | [<img src="https://avatars.githubusercontent.com/u/1560301?v=3" width="100px;"/><br /><sub>Lochlan Bunn</sub>](https://twitter.com/loklaan)<br />[💻](https://github.com/prettier/prettier-eslint/commits?author=loklaan) | [<img src="https://avatars.githubusercontent.com/u/25886902?v=3" width="100px;"/><br /><sub>Daniël Terwiel</sub>](https://github.com/danielterwiel)<br />🔌 🔧 | [<img src="https://avatars1.githubusercontent.com/u/1834413?v=3" width="100px;"/><br /><sub>Robin Malfait</sub>](https://robinmalfait.com)<br />🔧 | [<img src="https://avatars0.githubusercontent.com/u/8161781?v=3" width="100px;"/><br /><sub>Michael McDermott</sub>](http://mgmcdermott.com)<br />[💻](https://github.com/prettier/prettier-eslint/commits?author=mgmcdermott) | [<img src="https://avatars3.githubusercontent.com/u/292365?v=3" width="100px;"/><br /><sub>Adam Stankiewicz</sub>](http://sheerun.net)<br />[💻](https://github.com/prettier/prettier-eslint/commits?author=sheerun) | [<img src="https://avatars3.githubusercontent.com/u/487068?v=3" width="100px;"/><br /><sub>Stephen John Sorensen</sub>](http://www.stephenjohnsorensen.com/)<br />[💻](https://github.com/prettier/prettier-eslint/commits?author=spudly) |
-| [<img src="https://avatars2.githubusercontent.com/u/1597820?v=3" width="100px;"/><br /><sub>Brian Di Palma</sub>](https://github.com/briandipalma)<br />[🐛](https://github.com/prettier/prettier-eslint/issues?q=author%3Abriandipalma) [💻](https://github.com/prettier/prettier-eslint/commits?author=briandipalma) | [<img src="https://avatars0.githubusercontent.com/u/6173488?v=3" width="100px;"/><br /><sub>Rob Wise</sub>](https://robwise.github.io)<br />[📖](https://github.com/prettier/prettier-eslint/commits?author=robwise) [💻](https://github.com/prettier/prettier-eslint/commits?author=robwise) |
+| [<img src="https://avatars2.githubusercontent.com/u/1597820?v=3" width="100px;"/><br /><sub>Brian Di Palma</sub>](https://github.com/briandipalma)<br />[🐛](https://github.com/prettier/prettier-eslint/issues?q=author%3Abriandipalma) [💻](https://github.com/prettier/prettier-eslint/commits?author=briandipalma) | [<img src="https://avatars0.githubusercontent.com/u/6173488?v=3" width="100px;"/><br /><sub>Rob Wise</sub>](https://robwise.github.io)<br />[📖](https://github.com/prettier/prettier-eslint/commits?author=robwise) [💻](https://github.com/prettier/prettier-eslint/commits?author=robwise) | [<img src="https://avatars0.githubusercontent.com/u/4818642?v=3" width="100px;"/><br /><sub>Patryk Peas</sub>](https://github.com/Belir)<br />[🐛](https://github.com/prettier/prettier-eslint/issues?q=author%3ABelir) [💻](https://github.com/prettier/prettier-eslint/commits?author=Belir) [⚠️](https://github.com/prettier/prettier-eslint/commits?author=Belir) |
 <!-- ALL-CONTRIBUTORS-LIST:END -->
 
 This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome!
diff --git a/src/utils.js b/src/utils.js
index 2ede922..83f563a 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -214,7 +214,7 @@ function getTrailingComma(value, fallbacks, rules) {
 }
 
 function getValFromTrailingCommaConfig(objectConfig) {
-  const [, {arrays, objects, functions}] = objectConfig
+  const [, {arrays = '', objects = '', functions = ''}] = objectConfig
   const fns = isAlways(functions)
   const es5 = [arrays, objects].some(isAlways)
 


Test patch:
diff --git a/src/utils.test.js b/src/utils.test.js
index c576a20..1ac66ac 100644
--- a/src/utils.test.js
+++ b/src/utils.test.js
@@ -168,6 +168,18 @@ const getPrettierOptionsFromESLintRulesTests = [
   },
   {rules: {'max-len': ['error', {code: 120}]}, options: {printWidth: 120}},
   {rules: {quotes: [2, 'double']}, options: {singleQuote: false}},
+  {
+    rules: {
+      'comma-dangle': [
+        2,
+        {
+          imports: 'never',
+          exports: 'never',
+        },
+      ],
+    },
+    options: {trailingComma: 'none'},
+  },
 
   // If an ESLint rule is disabled fall back to prettier defaults.
   {rules: {'max-len': [0, {code: 120}]}, options: {}},