pretty-quick icon indicating copy to clipboard operation
pretty-quick copied to clipboard

pretty quick format unstaged files

Open clembo590 opened this issue 5 years ago • 9 comments

I managed to format the code of staged files adding this to my package.json scripts: "scripts": { "pretty-quick": "pretty-quick --staged", then I run npm run pretty-quick and voila my staged files are formated.

But for me it would actually be much more usefull to do the same but for "unstaged". So How to do the same for the files that are "unstaged"?

clembo590 avatar Jul 22 '19 20:07 clembo590

you can always run npm run prettier --write "**/*.*(js|jsx|ts|tsx)"

daviseford avatar Aug 08 '19 15:08 daviseford

well the scenario is this: I do a git clone. then I modify 2 files, then I would like to format only those 2 files. how to do that ? (of course without knowing the name of the files that have been modified...)

clembo590 avatar Aug 09 '19 14:08 clembo590

@clembou590 Isn't that what happens when you run pretty-quick, with no arguments?

hawkrives avatar Aug 10 '19 23:08 hawkrives

@hawkrives I installed using this command: npm install --save-dev prettier pretty-quick

If I put in my package.json file the following script "pretty-quick": "pretty-quick --staged"

then when I do npm run pretty-quick --> all my staged files are formatted.

but if in my package.json I put "pretty-quick": "pretty-quick --staged" (ie without the --staged) then when I do npm run pretty-quick --> nothing is formatted and there is error in command line

_"/Users/test/testCode/weqrorder/node_modules/pretty-quick/dist/scms/git.js:43 throw error; ^

Error: fatal: Not a valid object name master

at Function.module.exports.sync (/Users/test/testCode/weqrorder/node_modules/pretty-quick/node_modules/execa/index.js:303:26)
at runGit (/Users/test/testCode/weqrorder/node_modules/pretty-quick/dist/scms/git.js:29:53)
at Object.exports.getSinceRevision (/Users/test/testCode/weqrorder/node_modules/pretty-quick/dist/scms/git.js:37:40)
at exports.default (/Users/test/testCode/weqrorder/node_modules/pretty-quick/dist/index.js:52:33)
at Object.<anonymous> (/Users/test/testCode/weqrorder/node_modules/pretty-quick/bin/pretty-quick.js:12:27)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:839:10)

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] pretty-quick: pretty-quick npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] pretty-quick script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /Users/test/.npm/logs/2019-08-19T14_57_29_232Z-debug.log"

--> again what I would like to do is just format the files that are not yet staged...

clembo590 avatar Aug 19 '19 14:08 clembo590

You are getting the error because you don't have master branch pulled down locally.

daviseford avatar Aug 19 '19 15:08 daviseford

@daviseford what do you mean extactly? (I do not have master branch pulled down locally: are you talking about my code or the "pretty-quick code"?) Help would be really appreciated.

clembo590 avatar Aug 20 '19 19:08 clembo590

You need to have the master branch of your code pulled down locally. pretty-quick compares your changes against the master branch.

daviseford avatar Aug 20 '19 19:08 daviseford

@daviseford thanks a lot . that is correct... But that is a very strange behavior in my opinion.

I mean it s strange that I need to have the master branch locally to format the branch on which I am working....

Can you explain why that is necessary. (If I run git status then I have the list of files that I have modified.... I do not need to have the master branch for that...)

clembo590 avatar Nov 01 '19 15:11 clembo590

Hi @clembou590 , it's by default, see https://github.com/azz/pretty-quick#--branch , you can try with another branch 👍

erni93 avatar Dec 29 '19 21:12 erni93