Xo: Integrate the `prettier` module

Created on 20 Jan 2017  路  8Comments  路  Source: xojs/xo

Most helpful comment

Maybe. I'm gonna give it some time to mature first. Right now it's very buggy. I'll keep this issue open.

All 8 comments

Maybe. I'm gonna give it some time to mature first. Right now it's very buggy. I'll keep this issue open.

Relevant: https://github.com/not-an-aardvark/eslint-plugin-prettier

(I use it and think it's great.)

@sindresorhus we will see this feature in a near future ? thanks!

Heads-up: Prettier has just hit v1.0!

I found this issue because I do not fully understand what differentiates Prettier from XO. Wouldn't a Prettier plugin duplicate XO's functionality?

@jangerhofer Prettier is a formatter and XO is a linter that uses ESLint underneath

Oh no. Every time I try prettier I don't like its tricks to shorten the lines.

Before prettier

xo

After prettier

prettier

Why.

Prettier is really mature now and can be easily integrated.. here is an example on how to use it with ESLint https://github.com/lipis/prettier-setup

Prettier is really stable for a while now and used in many large projects (in particular most of Facebook code).

It can be integrated with xo or eslint pretty easily with eslint-plugin-prettier and eslint-config-prettier:

  • eslint-config-prettier disable all the eslint formatting rules (rules related to comma, spaces etc but not the rules related to code issues) that are covered by prettier.
  • eslint-plugin-prettier report errors/warnings when some code is formatted differently than the prettier format and allow to automatically fix it with --fix.

In order to use it with xo it can be configured this way in package.json:

"devDependencies": {
  "eslint-config-prettier": "^2.8.0",
  "eslint-plugin-prettier": "^2.3.0",
  "prettier": "^1.8.2",
  "xo": "^0.18.2"
},
"prettier": {
  // Any other prettier options
  "singleQuote": true
},
"xo": {
  "extends": [
    "prettier"
  ],
  "plugins": [
    "prettier"
  ],
  "rules": {
    "prettier/prettier": "error"
  }
}

It works well but it requires some configuration and devDpendencies.

In xo we could:

  • Add a prettier option (true or false, false by default)
  • if prettier option is true add eslint-plugin-prettier and eslint-config-prettier and the rule "prettier/prettier": "error"

Would you be open to such PR?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pizzafox picture pizzafox  路  5Comments

lagden picture lagden  路  3Comments

sindresorhus picture sindresorhus  路  5Comments

niftylettuce picture niftylettuce  路  6Comments

dawsbot picture dawsbot  路  5Comments