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

Something wrong with spaces between curly braces #440

Closed
lcdss opened this issue Mar 18, 2020 · 2 comments
Closed

Something wrong with spaces between curly braces #440

lcdss opened this issue Mar 18, 2020 · 2 comments

Comments

@lcdss
Copy link

lcdss commented Mar 18, 2020

When xo is executed, for some reason, it thinks all curly braces shouldn't have spaces and it can't fix the code even if there is nothing to fix. If I remove the spaces, it complain about the object-curly-spacing rule, and if I add the spaces (prettier already add them automatically on save), it still fails. Anyone knows why this is happening?

import { render, unmountComponentAtNode } from 'react-dom';
import { render } from 'react-dom';
import React, { useEffect, useState } from 'react';

const letters = { a: 'a', b: 'b' };
var/www/client $ yarn lint
yarn run v1.21.1
$ xo

  tests/app.test.js:3:9
  ✖  3:9   Replace ·render,·unmountComponentAtNode· with render,·unmountComponentAtNode  prettier/prettier

  ✖  10:20  Replace ·a:·'a',·b:·'b'· with a:·'a',·b:·'b'                                  prettier/prettier

  src/index.js:4:9
  ✖  4:9   Replace ·render· with render                                                  prettier/prettier

  src/app.js:3:16
  ✖  3:16  Replace ·useEffect,·useState· with useEffect,·useState                        prettier/prettier

  3 errors
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
{
  "xo": {
    "envs": [
      "browser",
      "es2020",
      "mocha"
    ],
    "extends": [
      "xo-react"
    ],
    "prettier": true,
    "rules": {
      "import/extensions": [
        "error",
        {
          "css": "always"
        }
      ],
      "import/no-unassigned-import": [
        "error",
        {
          "allow": [
            "**/*.css"
          ]
        }
      ],
      "object-curly-spacing": [
        "error",
        "always"
      ],
      "unicorn/catch-error-name": "off"
    }
  }
}
{
  "printWidth": 80,
  "useTabs": false,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "all"
}
@papb
Copy link

papb commented Jun 22, 2020

Hello, I have just faced this problem as well, and found the solution. Sadly, XO infers rules from prettier in a way that I don't think is correct. From readme:

prettier

Type: boolean
Default: false

Format code with Prettier.

The Prettier options will be read from the Prettier config and if not set will be determined as follow:

If contradicting options are set for both Prettier and XO an error will be thrown.

Instead of using prettier defaults, XO has basically overwritten some of them. So you have to update your prettier config, adding bracketSpacing explicitly:

{
  "printWidth": 80,
  "useTabs": false,
  "semi": true,
  "singleQuote": true,
+ "bracketSpacing": true,
  "trailingComma": "all"
}

@lcdss
Copy link
Author

lcdss commented Jun 23, 2020

Thanks for sharing the solution. I opted to configure eslint + prettier manually for this specific project but next time I'Il try it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants