prettier / prettier/vim-prettier

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

Open
#290 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Vim Script
Stars
1.8k
Forks
137
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the discrepancy using the package.json excerpt, Prettier 2.2.1, vim-prettier 1.0.0-beta, and the shown print_width setting. Compare output from yarn prettier package.json --write with Vim's formatting at width 80, then inspect the plugin's handling of print width. Done means both tools produce matching line breaks at the same width.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, vim
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.