question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Current use of semver not applicable to prettier

See original GitHub issue

First off, thanks for a great library and fantastic effort for the community.

This is a suggestion about the versioning scheme used by prettier.

I would argue that using the minor version of semver for changes isn’t applicable to prettier. Why? Any changes that leads to different formatting isn’t really compatible with the previous version. For instance, if package.json specifies ^1.2.2 (where a caret version is the default when installing with npm), one repo user could still be at 1.2.2 and another repo user could be at 1.4.4, and they would have different formatting applied the sources leading to an inconsistent style across the project (and following commit wars until the version difference is resolved).

A workaround would be to use a tilde (~) version in package.json to only allow automatic patch upgrades, but since this is not the default behaviour of npm it will probably lead to problems for many people who are not aware of the issue.

My suggestion is to always increment the major version whenever a change that leads to different formatting is applied.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
lydellcommented, Jun 10, 2018

In a way, the API of Prettier is “string in, string out” without saying much about what those strings look like. So in theory we can do any changes we like and release them as patch releases as long as the string -> string contract is preserved. But of course we don’t do that since it wouldn’t be very nice to users 😃

What is the semver change when previously formatted code is formatted differently?

Any. Depends on the case. The more impact, the more bump. Technically, you could say that any change whatsoever is a breaking change. But only doing major releases won’t help anyone. And it would mask actual API breaking changes. This is also why it can make sense to think of the API more of like string -> string where the strings are black boxes like I mentioned above.

What is the semver change when previously rejected code is now formatted?

Most likely minor. (New feature.)

What is the semver change when previously formatted code is now rejected?

This is a tough one. We have this problem for decorators (#2630). There was a similar situation with GraphQL (#4012), where we ended up parsing both old and new syntax but only outputting the new.

For example, if a bug were discovered in the parser that allowed it to be too permissive.

That could likely be a patch release.


In summary, the above is how I have understood how things work so far. Basically, Prettier is a hard thing to version. Which is why we recommend pinning the version in package.json. We try to use our best judgement to make the experience smooth for the majority of people.

2reactions
azzcommented, Nov 14, 2017

Because almost every PR changes the formatting slightly, which means every release would be major, no minors or patches.

I don’t think it makes sense to bump major for formatting changes. The API is that prettier.format(string) returns a string. If that contract changes, that would be a breaking change, and it would make sense on that occasion to bump the major version.

If Prettier was to overhaul the CLI, remove an option, or change the API itself, those would all be breaking changes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I'm running into this issue with “prettier”, a JavaScript pretty ...
SemVer is all about trying to convey what changes to a package are backward-compatible and thus are safe to upgrade to new versions....
Read more >
Hanging/stuck reify:prettier: timing reifyNode:node_modules ...
I have tried successfully. Version you can use latest or if not working with them use npm version 8 and node 16.11. npm...
Read more >
semver-isvalid - Go Packages
Semantic Version Validator. This tiny application and go library enable you to test if a semantic version is valid or not.
Read more >
package.json - npm Docs
Description. This document is all you need to know about what's required in your package.json file. It must be actual JSON, not just...
Read more >
How does semantic versioning apply to programs without API?
In consumer applications, the version is not only a version, but also a marketing asset. Firefox and Chrome release new versions comparatively ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found