Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eslint config based prettying #48

Closed
sirpeas opened this issue Mar 13, 2017 · 7 comments
Closed

Eslint config based prettying #48

sirpeas opened this issue Mar 13, 2017 · 7 comments

Comments

@sirpeas
Copy link
Contributor

sirpeas commented Mar 13, 2017

Hey,
based on:
prettier/prettier-atom#85 (comment)

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
@kentcdodds
Copy link
Member

Hi there! Here's the problem. These should probably have a default value (learn more about destructuring here, learn about default values specifically here). arrays, objects, and functions should default to an empty string. Either that, or we should add a default param here (learn more about that here) where val defaults to an empty string.

How would you like to add another test case or two here and implement those fixes?

Thanks!

@sirpeas
Copy link
Contributor Author

sirpeas commented Mar 14, 2017

@kentcdodds sounds like a plan for spare time at the weekend ;)

@kentcdodds
Copy link
Member

That line of code has moved to here do you still wanna do this?

@sirpeas
Copy link
Contributor Author

sirpeas commented Apr 17, 2017

@kentcdodds sure but unfortunately I didn't have spare time, I will do it this week

@sirpeas
Copy link
Contributor Author

sirpeas commented Apr 23, 2017

@kentcdodds is there any way of testing if my code is fixing that in action and I probably will need your help with test coverage :)

@kentcdodds
Copy link
Member

Add a test case or so here:

{rules: {indent: [2, 'tab']}, options: {useTabs: true}},

Thanks!

@sirpeas
Copy link
Contributor Author

sirpeas commented Apr 24, 2017

@kentcdodds thanks for opportunity and apologize for delay :)

kentcdodds pushed a commit that referenced this issue Apr 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants