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

Prettier and Vim-Prettier don't break lines the same when set to the same print width #290

Open
rschristian opened this issue Mar 29, 2021 · 8 comments

Comments

@rschristian
Copy link
Contributor

Do you want to request a feature or report a bug?

Bug

What is the current/expected behavior?

I'd like vim-prettier to match the output of prettier, but it does not. It seems like the print_width of vim-prettier needs to be much less in order to get the same output.

This is just an excerpt of a package.json file, formatted with Prettier via yarn prettier package.json --write

{
  "eslintConfig": {
    "parser": "@typescript-eslint/parser",
    "extends": [
      "preact",
      "plugin:@typescript-eslint/recommended"
    ],
    "rules": {
      "@typescript-eslint/explicit-module-boundary-types": "off",
      "@typescript-eslint/no-explicit-any": "off"
    }
  },
  "prettier": {
    "singleQuote": true,
    "trailingComma": "none",
    "useTabs": true,
    "arrowParens": "avoid"
  },
  "jest": {
    "preset": "ts-jest",
    "testPathIgnorePatterns": [
      "<rootDir>/{dist,src}"
    ],
    "setupFilesAfterEnv": [
      "<rootDir>/test/setup-tests.ts"
    ],
    "collectCoverageFrom": [
      "<rootDir>/src/**/*.{ts,tsx}",
      "!<rootDir>/src/types/**/*"
    ],
    "moduleNameMapper": {
      "^react$": "preact/compat",
      "^react-dom/test-utils$": "preact/test-utils",
      "^react-dom$": "preact/compat"
    }
  }
}

And this is the following after saving with vim-prettier:

{
  "eslintConfig": {
    "parser": "@typescript-eslint/parser",
    "extends": ["preact", "plugin:@typescript-eslint/recommended"],
    "rules": {
      "@typescript-eslint/explicit-module-boundary-types": "off",
      "@typescript-eslint/no-explicit-any": "off"
    }
  },
  "prettier": {
    "singleQuote": true,
    "trailingComma": "none",
    "useTabs": true,
    "arrowParens": "avoid"
  },
  "jest": {
    "preset": "ts-jest",
    "testPathIgnorePatterns": ["<rootDir>/{dist,src}"],
    "setupFilesAfterEnv": ["<rootDir>/test/setup-tests.ts"],
    "collectCoverageFrom": [
      "<rootDir>/src/**/*.{ts,tsx}",
      "!<rootDir>/src/types/**/*"
    ],
    "moduleNameMapper": {
      "^react$": "preact/compat",
      "^react-dom/test-utils$": "preact/test-utils",
      "^react-dom$": "preact/compat"
    }
  }
}

As you can see, the output formatting is incorrect.

I noticed I have to set vim-prettier to have about a print_width of 60 in order to get output that better resembles 80 with prettier, though still has some issues. Something's not calculated right.

What version of vim-prettier are you using - (output of :PrettierVersion) ?

1.0.0-beta

What version of prettier are you using - (output of :PrettierCliVersion) ?

2.2.1

What is your prettier executable path - (output of :PrettierCliPath) ?

/home/username/Projects/project-name/node_modules/.bin/prettier

Did this work in previous versions of vim-prettier and/or prettier ?

Not that I see, no

Vim-Prettier config

" --- Prettier ---
let g:prettier#autoformat = 1
let g:prettier#autoformat_require_pragma = 0
let g:prettier#config#print_width = 80
@kecerud
Copy link

kecerud commented Jan 23, 2022

Have you fixed this somehow in the meantime? Having the same issue..

@rschristian
Copy link
Contributor Author

No, sorry, had to uninstall vim-prettier as I couldn't find a way to get them to agree :/

@kecerud
Copy link

kecerud commented Jan 23, 2022

@rschristian That's a shame...! What did you decide to use instead, or did you end up just not using a formatter completely?

@rschristian
Copy link
Contributor Author

Still use prettier, just not tied to vim. Manual runs, precommit hooks, etc. do the trick for me.

There might be good alternative solutions out there, not sure! I don't think I looked for other options, just cut it out and moved on.

@pilagod
Copy link

pilagod commented Jul 5, 2022

Same here and cannot find a workaround too. 😓

It seems prettier has exceptional rules for package.json that it always splits array into multiple lines. But not sure why vim-prettier doesn't consume those rules.

Since I personally have coc.nvim plugin installed, I finally switch to coc-prettier and it solves this problem.

@domvo
Copy link

domvo commented Jan 12, 2023

Running into the same issue, unfortunately I can't find a solution.

@ofmendez
Copy link

ofmendez commented Sep 5, 2023

same issue

@szilardhuber
Copy link

Hey, is there any chance this gets addressed anytime soon? It kind of makes vim-prettier unusable in a team environment.

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

6 participants