Code Monkey home page Code Monkey logo

Comments (3)

hsribei avatar hsribei commented on May 18, 2024

This happens because prettier itself prints nothing and returns with exit code 0 (success) when passed a file as a parameter that is matched by the .prettierignore file.

This can be seen by running here:

mkdir test
cd test
npm init -y
echo "package.json" > .prettierignore

prettier package.json
# outputs nothing, goes straight to next prompt

mv .prettierignore .prettierignorebak
prettier package.json
# outputs this:
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

Since it returns empty without an error code, this condition is not caught by the if here:

https://github.com/prettier/prettier-emacs/blob/master/prettier-js.el#L185

My elisp-fu is non-existent, but checking if prettier's output isn't empty shouldn't be too hard, so I might try fixing it.

from prettier-emacs.

hsribei avatar hsribei commented on May 18, 2024

My immediate use case for .prettierignore, which was avoiding formatting conflicts between npm and prettier on package.json, has been resolved by prettier just special-casing for package.json and package-lock.json to match npm's use of JSON.stringify(data, null, 2).

https://twitter.com/hsribei/status/1001560322082263040

I'll still see if I can make prettier-js-mode not clobber other .prettierignored files in case that helps someone else.

from prettier-emacs.

hsribei avatar hsribei commented on May 18, 2024

Ok, nevermind. The whole issue is solved since December last year. It's always a good idea to keep your packages updated!

Now instead of returning an empty output for ignored files, prettier just prints them back as-is, solving the problem.

prettier/prettier#3590

from prettier-emacs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.