Giter VIP home page Giter VIP logo

pretty-quick's Introduction

pretty-quick

GitHub Actions Codecov type-coverage npm GitHub Release

Conventional Commits Renovate enabled JavaScript Style Guide Code Style: Prettier changesets

Get Pretty Quick

Runs Prettier on your changed files.

demo

Supported source control managers:

  • Git
  • Mercurial

Install

# npm
npm install -D prettier pretty-quick
# yarn
yarn add -D prettier pretty-quick

Usage

# npx
npx pretty-quick

# yarn
yarn pretty-quick

Pre-Commit Hook

You can run pretty-quick as a pre-commit hook using simple-git-hooks.

# npm
npm install -D simple-git-hooks

# yarn
yarn add -D simple-git-hooks

In package.json, add:

"simple-git-hooks": {
  "pre-commit": "yarn pretty-quick --staged" // or "npx pretty-quick --staged"
}

CLI Flags

--staged (only git)

Pre-commit mode. Under this flag only staged files will be formatted, and they will be re-staged after formatting.

Partially staged files will not be re-staged after formatting and pretty-quick will exit with a non-zero exit code. The intent is to abort the git commit and allow the user to amend their selective staging to include formatting fixes.

--no-restage (only git)

Use with the --staged flag to skip re-staging files after formatting.

--branch

When not in staged pre-commit mode, use this flag to compare changes with the specified branch. Defaults to master (git) / default (hg) branch.

--pattern

Filters the files for the given minimatch pattern. For example pretty-quick --pattern "**/*.*(js|jsx)" or pretty-quick --pattern "**/*.js" --pattern "**/*.jsx"

--verbose

Outputs the name of each file right before it is processed. This can be useful if Prettier throws an error and you can't identify which file is causing the problem.

--bail

Prevent git commit if any files are fixed.

--check

Check that files are correctly formatted, but don't format them. This is useful on CI to verify that all changed files in the current branch were correctly formatted.

--no-resolve-config

Do not resolve prettier config when determining which files to format, just use standard set of supported file types & extensions prettier supports. This may be useful if you do not need any customization and see performance issues.

By default, pretty-quick will check your prettier configuration file for any overrides you define to support formatting of additional file extensions.

Example .prettierrc file to support formatting files with .cmp or .page extensions as html.

{
  "printWidth": 120,
  "bracketSpacing": false,
  "overrides": [
    {
      "files": "*.{cmp,page}",
      "options": { "parser": "html" }
    }
  ]
}

--ignore-path

Check an alternative file for ignoring files with the same format as .prettierignore. For example pretty-quick --ignore-path .gitignore

Configuration and Ignore Files

pretty-quick will respect your .prettierrc, .prettierignore, and .editorconfig files if you don't use --ignore-path . Configuration files will be found by searching up the file system. .prettierignore files are only found from the repository root and the working directory that the command was executed from.

pretty-quick's People

Contributors

alber70g avatar azz avatar benwiley4000 avatar bob-laz avatar cjanietz avatar dependabot[bot] avatar fisker avatar flurmbo avatar github-actions[bot] avatar jantimon avatar jounqin avatar kocal avatar lukeapage avatar michaeldeboey avatar pshrmn avatar roggervalf avatar smably avatar sukkaw avatar swwind avatar timdouglas avatar tobiastimm avatar typicode avatar ullasholla avatar ustramooner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pretty-quick's Issues

Error when commiting

I was using pretty-quick and it was working fine, but since yesterday i'm getting this error:

C:\Users\davi.carvalho\Documents\afe-pipeline\node_modules\pretty-quick\dist\scms\git.js:43
    throw error;
    ^

Error
    at Function.module.exports.sync (C:\Users\davi.carvalho\Documents\afe-pipeline\node_modules\pretty-quick\node_modules\execa\index.js:303:26)
    at runGit (C:\Users\davi.carvalho\Documents\afe-pipeline\node_modules\pretty-quick\dist\scms\git.js:29:53)
    at Object.exports.getSinceRevision (C:\Users\davi.carvalho\Documents\afe-pipeline\node_modules\pretty-quick\dist\scms\git.js:38:12)
    at exports.default (C:\Users\davi.carvalho\Documents\afe-pipeline\node_modules\pretty-quick\dist\index.js:44:33)
    at Object.<anonymous> (C:\Users\davi.carvalho\Documents\afe-pipeline\node_modules\pretty-quick\bin\pretty-quick.js:13:1)
    at Module._compile (internal/modules/cjs/loader.js:707:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
    at Module.load (internal/modules/cjs/loader.js:605:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
    at Function.Module._load (internal/modules/cjs/loader.js:536:3)
husky > pre-commit hook failed (add --no-verify to bypass)

I tried reinstalling the dependencies but it didn't work

pretty-quick --staged should give better indication of which file failed

🔍  Finding changed files since git revision 1973849.
🎯  Found 26 changed files.
/Users/jcol53/work/orders/node_modules/prettier/index.js:24285
      throw error;
      ^

SyntaxError: Unexpected token (1:1)
> 1 | 
    | ^
    at createError (/Users/jcol53/work/orders/node_modules/prettier/parser-babylon.js:1:110)
    at Object.parse (/Users/jcol53/work/orders/node_modules/prettier/parser-babylon.js:1:986)
   at Object.parse$4 [as parse] (/Users/jcol53/work/orders/node_modules/prettier/index.js:24274:19)
    at formatWithCursor (/Users/jcol53/work/orders/node_modules/prettier/index.js:33650:27)
    at format (/Users/jcol53/work/orders/node_modules/prettier/index.js:33695:10)
    at format (/Users/jcol53/work/orders/node_modules/prettier/index.js:33945:12)
    at exports.default (/Users/jcol53/work/orders/node_modules/pretty-quick/dist/formatFiles.js:18:41)
    at exports.default (/Users/jcol53/work/orders/node_modules/pretty-quick/dist/index.js:47:29)
    at Object.<anonymous> (/Users/jcol53/work/orders/node_modules/pretty-quick/bin/pretty-quick.js:12:1)

Seems clear that there is a syntax error but I have 25 files staged (big merge). It would be helpful if there was a --verbose flag that would output the name of each file as they were processed, that way I can quickly figure out which file is causing the issues.

SyntaxError: ';' expected in package.json

I'm trying to commit the following:

⋊> ~/W/web-app on prettier ⨯   git diff --staged                                                                                                                              14:20:30
diff --git a/package.json b/package.json
index b7801607..703581e1 100644
--- a/package.json
+++ b/package.json
@@ -15,7 +15,7 @@
     "buildwatcher": "ng build --watch",
     "pree2e": "webdriver-manager update",
     "e2e": "ng e2e",
-    "precommit": "pretty-quick --staged"
+    "precommit": "pretty-quick --staged",
     "tslint-check": "tslint-config-prettier-check ./tslint.json"
   },
   "private": true,

but I get the following error:

⋊> ~/W/web-app on prettier ⨯   git commit -m "Add missing comma"                                                                                                              14:16:32
husky > npm run -s precommit (node v6.10.2)

🔍  Finding changed files since git revision 9cb1833d.
🎯  Found 1 changed file.
/home/user/Workspace/web-app/node_modules/prettier/index.js:24285
      throw error;
      ^

SyntaxError: ';' expected. (2:9)
  1 | {
> 2 |   "name": "web-app",
    |         ^
  3 |   "version": "0.0.0",
  4 |   "license": "MIT",
  5 |   "angular-cli": {},
    at createError (/home/user/Workspace/web-app/node_modules/prettier/parser-typescript.js:1:194)
    at Object.parse (/home/user/Workspace/web-app/node_modules/prettier/parser-typescript.js:1:18102)
    at Object.parse$4 [as parse] (/home/user/Workspace/web-app/node_modules/prettier/index.js:24274:19)
    at formatWithCursor (/home/user/Workspace/web-app/node_modules/prettier/index.js:33650:27)
    at format (/home/user/Workspace/web-app/node_modules/prettier/index.js:33695:10)
    at format (/home/user/Workspace/web-app/node_modules/prettier/index.js:33945:12)
    at exports.default (/home/user/Workspace/web-app/node_modules/pretty-quick/dist/formatFiles.js:18:41)
    at exports.default (/home/user/Workspace/web-app/node_modules/pretty-quick/dist/index.js:48:29)
    at Object.<anonymous> (/home/user/Workspace/web-app/node_modules/pretty-quick/bin/pretty-quick.js:12:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:393:7)

husky > pre-commit hook failed (add --no-verify to bypass)

Unable to detect a source control manager in worktree outside of source repo

Similar to #90.

git worktree allows one to use a single git repo with multiple working directories.

The .git in the worktree is a file that looks like this:

gitdir: /Users/emily/code/pubrepos/husky/.git/worktrees/husky-worktree

and the worktree can be in a different directory than inside the repo, so the findup solution doesn't work.

~pubrepos/husky forivall/workdir-and-multi-repo
» git worktree add ../husky-worktree
Preparing worktree (new branch 'husky-worktree')
HEAD is now at f3d8af1 add reproduction attempt for workdir issue #580

~pubrepos/husky forivall/workdir-and-multi-repo
» git st
## forivall/workdir-and-multi-repo...forivall/forivall/workdir-and-multi-repo

~pubrepos/husky forivall/workdir-and-multi-repo
» cd ../husky-worktree

~pubrepos/husky-worktree husky-worktree
» pretty-quick
/Users/emily/.config/yarn/global/node_modules/pretty-quick/dist/index.js:40
    throw new Error('Unable to detect a source control manager.');
    ^

Error: Unable to detect a source control manager.
    at _default (/Users/emily/.config/yarn/global/node_modules/pretty-quick/dist/index.js:40:11)
    at Object.<anonymous> (/Users/emily/.config/yarn/global/node_modules/pretty-quick/bin/pretty-quick.js:12:27)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Pretty-quick error if JSON file is empty

Hello,

We created a new package with lerna and storybook that generates an empty config.js by default and pretty-quick crashes in this case.
Is this the way to behave if the file has no code inside?

"prettier": "prettier --write \"packages/**/src/**/*.{ts,tsx,scss,json,js}\"",
"prettyquick": "pretty-quick",

Best regards.

Configure Prettier to lint all sort of files

On my code base, I run Prettier with the following yarn task:

"prettier": "prettier --write \"**/*.{js,json,css,md}\""

When pretty-quick is run, it only apply Prettier on .js files, not the other types of file (e.g. .json, .css, .md...).

Is there a way I can instruct pretty-quick to work on these file types as well?

prettierignore not working correctly in mono repo project

Hi,

I have an issue that is similar to #14

My project folder structure is:

root/
  .git
  webapp/
    package.json
    .prettierignore  
    index.js
    foo/
      test.js

.prettierignore contains:

# ignore everything except foo dir
/*
!/foo

My problem is that pretty-quick does not seem to read .prettierignore rule correctly.

When I run npx pretty-quick --check, it fails to find foo/test.js as changed file. However, when i run npx prettier --check "**/*.js", it will pick up foo/test.js

$ npx pretty-quick --check
�🔍  Finding changed files since git revision 77e111a.
�🎯  Found 0 changed files.
✅  Everything is awesome!

$ npx prettier --check "**/*.js"
Checking formatting...
foo\test.js
Code style issues found in the above file(s). Forgot to run Prettier?

If I remove the rules in .prettierignore, pretty-quick is able to pick up the changed files:

$ npx pretty-quick --check
�🎯  Finding changed files since git revision 77e111a.
�🎯  Found 2 changed files.
⛔️  Check failed: webapp/foo/test.js
⛔️  Check failed: webapp/index.js

So it seems to me that pretty-quick is not reading the ignore rules correctly or am I missing something?

Is it possible to limit the files being checked?

Using Prettier in an ordinary fashion you'd often want to whitelist the files that Prettier should be concerned with:

prettier [opts] [filename ...]

Is it possible to do the same with pretty-quick?

--check may not be working properly (CircleCI)

I'm using pretty-quick@^1.11.1 with Yarn.

I have the following script in package.json: "format-check": "pretty-quick --check --verbose"

My .circleci/config.yml file contains:

jobs:
  build:
    ...
    steps:
      ...
      - run: yarn format-check
      ...

--check is supposed to be "useful on CI to verify that all changed files in the current branch were correctly formatted".

But when I push or add changes to a PR (using GitHub) and CircleCi runs the job, it finds 0 changed files (so the check always passes). See for example https://circleci.com/gh/iterative/dvc.org/1000 which includes a change with a badly formatted file (iterative/dvc.org@be661b5).

Running the same command locally (pretty-quick --check --verbose) finds 12 changed files (no idea why 12) which does include the one badly formatted file, and errors out accordingly.

What am I going wrong? Thanks

--pattern not works

Hi, i am trying replace lint-staged with pretty-quick
Before

"lint-staged": {
        "*.{js,jsx}": [
            "prettier --print-width 120 --tab-width 2 --trailing-comma none --write \"src/main/js/**/*.js\"",
            "git add"
        ]
    },

After:

"husky": {
        "hooks": {
            "pre-commit": "pretty-quick --pattern \"src/main/js/**/*.js\" --staged --verbose"
        }
    },

But now files are not changed in this path.
P.S. i have monorepo, so it is very important to fix files only in this folder and path...

Thanks in advance.

Pretty-quick seems to consider all files, not only currently modified ones

Hi Team!

I have been using pretty-quick since day one, and I find it awesome because it allows formatting only modified files.

In my understanding, pretty-quick identifies the changed files running git diff --name-only ebc8169 HEAD - ebc8169 being the hash of the commit last I pushed.
I would rather prefer see it running git diff --name-only HEAD~1 HEAD and run only on currently modified files, as the Git hooks are taking care of formatting anything that gets commited.

Here is an example of the output I get:

C:\Projects-Repositories\cms>yarn run pretty-quick
yarn run v1.7.0
$ pretty-quick
🔍  Finding changed files since git revision ebc8169.
🎯  Found 247 changed files.
✍️  Fixing up src/organisms/Slider/SliderEdit.js.
✅  Everything is awesome!
Done in 9.40s.

C:\Projects-Repositories\cms>git status
On branch dev
Your branch is ahead of 'origin/dev' by 57 commits.
  (use "git push" to publish your local commits)
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   package.json
        modified:   src/organisms/Slider/SlideEdit.js
        modified:   src/organisms/Slider/SlideRender.js
        modified:   src/organisms/Slider/SliderEdit.js
        modified:   src/organisms/Slider/SliderRender.js

no changes added to commit (use "git add" and/or "git commit -a")

C:\Projects-Repositories\cms>

Here is my whole configuration. This project is under create-react-app v2.

package.json

{
    ...
  "dependencies": {
    "react": "^16.6.3",
    ...
  },
  "devDependencies": {
    "@types/react": "^16.7.7",
    "@types/react-dom": "^16.0.10",
    "babel-cli": "^6.26.0",
    "babel-literal-to-ast": "^2.0.0",
    "babel-preset-es2015": "^6.24.1",
    "husky": "^1.2.0",
    "prettier": "^1.15.2",
    "pretty-quick": "^1.8.0",
    ...
  },
  "husky": {
    "hooks": {
      "pre-commit": "pretty-quick --staged"
    }
  },
  "scripts": {
    ...
    "prettier": "prettier --write src/**/*.{js,jsx}",
    "pretty-quick": "pretty-quick",
    ...
  }
}

.prettierrc

{
  "bracketSpacing": true,
  "jsxBracketSameLine": true,
  "parser": "flow",
  "printWidth": 120,
  "singleQuote": true,
  "trailingComma": "all",
  "semi": false,
  "tabWidth": 2,
  "arrowParens": "avoid",
  "proseWrap": "always",
  "overrides": [
    {
      "files": [".prettierrc", "*.json", "yarn.lock"],
      "options": { "parser": "json" }
    },
    {
      "files": ["*.md", "*.yml"],
      "options": { "parser": "markdown" }
    },
    {
      "files": "*.graphql",
      "options": { "parser": "graphql" }
    },
    {
      "files": "*.css",
      "options": { "parser": "postcss" }
    }
  ]
}

.prettierignore

*.yml
CloudFromation/cloudformation-*

Let me know what you think

Happy Thanksgiving!

Pretty-quick --staged not picking .prettierrc

Hi All,

I have.prettiertrcfile in the root of my project where the package.json file is present as well.

and I have the following configuration in the file

{ "trailingComma": "es5", "tabWidth": 2, "semi": true, "singleQuote": true }

but still, pretty-quick is not picking up the file. The .prettierrc file was added newly do I need to do anything for it to pick it up?

Pretty-quick --staged not picking .prettierrc

Hi

i'm running pretty-quick --staged from the root of my project where i also have the .prettierrc and i have printWidth: 80 (as the default) and pretty quick is not taking this into consideration.

and also have a script that runs prettier on save so i get the same files added to the stage over and over again.

Nested whitelisting is broken while used in .prettierignore

"prettier": "1.18.2"
"pretty-quick": "1.11.1"

Hi everyone,

We're using pretty-quick and got a following issue.
We have two different codebases:

/src/a/
/src/b/

and many folders with different helpers, tests, mocks in folders above /src/

I want to use pretty-qucik only on /src/b/

I followed the .gitignore guildlines for negating rules and come up with something like this:

/*
!/src/b/

But it hasn't worked. I also tried

!src/b, !/src/b/, !/src/b/**/*.js, !/*/b/*

and many others, but it fails.
But if I try to exclude folder from the root without going into nested folders it works.

/*
!/src/

This works.

Could you specify if nested exclusions are supposed to be supported?

Wrong curl string, in yaml, prettyfier

"curl -X POST '__some-address__' -H 'content-type: application/json; charset=UTF-8' -d '{\"text\" : \"Some example text\"}'"

When run npm run prettify-quick:

'curl -X POST '__some-address__'' -H 'content-type: application/json; charset=UTF-8' -d '{"text" : "Some example text"}''

which is obviously bad.

How to ignore node_modules from pretty-quick

Tried creating .prettierignore file having node_modules defined inside it

Have config setup rule like this below:
`"lint": "pretty-quick & eslint "src/**/*.{js,jsx}" --quiet --fix"

Giving error as:

SyntaxError: Nested mappings are not allowed in compact mappings (8:9)
  6 | artifact: 'file://dcs.tar.gz'
  7 | deploymentStrategy: default
> 8 | config: artifact:
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 9 |
    | ^
    at e (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/parser-yaml.js:1:323)
    at Object.parse (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/parser-yaml.js:1:156977)
    at Object.parse$2 [as parse] (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/index.js:7138:19)
    at coreFormat (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/index.js:10398:23)
    at format (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/index.js:10570:16)
    at formatWithCursor (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/index.js:10582:12)
    at /Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/index.js:34924:15
    at format (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/prettier/index.js:34943:12)
    at exports.default (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/pretty-quick/dist/formatFiles.js:18:41)
    at exports.default (/Users/mithha/Documents/dcs/ui/ui-plugins/dcs/node_modules/pretty-quick/dist/index.js:54:29)
✨  Done in 4.19s.

Also tried configuring like this:

"lint": "pretty-quick --ignore-path=.prettierignore & eslint \"src/**/*.{js,jsx}\" --quiet --fix"

But no luck :( Can anyone help?

Requires master branch?

When I try to run pretty-quick on a project with no local branch named master , I get:

/Users/oscar/.../node_modules/pretty-quick/dist/scms/git.js:43
    throw error;
    ^

Error: fatal: Not a valid object name master

Failure in submodule due to filepath mixup

I am using prettier and pretty-quick in both the main repository and the submodule. Both have their own package.json with a pre-commit hook defined. When using pretty-quick inside the submodule, I get an error. The fileservice tries to acces a directory where the root path of the submodule seems to be replaced by the root path of the main repository. For example:

Main repository is at /Users/peter.meinhardt/GIT/Customer/Project/, submodule is at /Users/peter.meinhardt/GIT/Customer/Project/projects/core-module. I try to commit a file inside the submodule at /Users/peter.meinhardt/GIT/Customer/Project/projects/core-module/src/lib/elements/specific-element and will get the following error:

🔍  Finding changed files since git revision 7c9ea477.
🎯  Found 1 changed file.
fs.js:115
    throw err;
    ^

Error: ENOENT: no such file or directory, scandir '/Users/peter.meinhardt/GIT/Customer/Project/src/lib/elements/specific-element'
    at Object.readdirSync (fs.js:783:3)
    at traverseFolder (/Users/peter.meinhardt/GIT/Customer/Project/projects/core-module/node_modules/prettier/index.js:40340:18)
    at findRoot (/Users/peter.meinhardt/GIT/Customer/Project/projects/core-module/node_modules/prettier/index.js:40356:10)
    at maybeParse (/Users/peter.meinhardt/GIT/Customer/Project/projects/core-module/node_modules/prettier/index.js:40368:16)
    at editorconfigSyncNoCache (/Users/peter.meinhardt/GIT/Customer/Project/projects/core-module/node_modules/prettier/index.js:40381:35)
    at editorconfigSyncNoCache (/Users/peter.meinhardt/GIT/Customer/Project/projects/core-module/node_modules/prettier/index.js:36212:20)
    at /Users/peter.meinhardt/GIT/Customer/Project/projects/core-module/node_modules/prettier/index.js:42627:14
    at Array.map (<anonymous>)
    at _resolveConfig (/Users/peter.meinhardt/GIT/Customer/Project/projects/core-module/node_modules/prettier/index.js:42626:40)
    at Function.resolveConfig.sync (/Users/peter.meinhardt/GIT/Customer/Project/projects/core-module/node_modules/prettier/index.js:42662:12)
husky > pre-commit hook failed (add --no-verify to bypass)```

--staged broken?

Apologies if I am incorrect, but I don't think that --staged is working as intended. Currently, pretty-quick finds the last commit (git rev-parse --short HEAD) and then calls git diff --name-only --diff-filter=ACMRTUB <hash> to determine which files have been changed since the last commit. However, that filter finds all files, not just the staged ones. I think that getChangedFiles should be receiving the staged value and when it is truthy, calling git diff --name-only --staged to just get a list of staged files.

Flow question.

So currently commit should be done twice ?
Is flow correct or am I missing something ?

  1. Commit files.
  2. Files got fixed.
  3. Commit fixed files again.

Isn't it suppose to be:

  1. Try to commit files.
  2. Files got fixed.
  3. Commit fixed files.

.prettierignore location

Hi, i have this problem:

My directory structure is:

root
  .git
  web-app
    package.json
    .prettierignore

In that package.json i have the script "format:fix": "pretty-quick --staged", however it is not taking the .prettierignore file. I have to place the file in the root folder of the repo so that it works.

Is there a way to avoid copying that file to the root of the repo and take the one inside the web-app folder?

Return 1 if any file is fixed

In my precommit workflow, i would like to fail the commit if any file has to be fixed.

  "precommit": "yarn pretty-quick --no-restage"

Currently if there is any file is fixed, it will commit, but i want to abort the current commit.

Don't auto-commit changed files

Is it possible to tell pretty-quick to not commit files that have been changed automatically? I would prefer to be able to review the changes before committing them.

I tried the --no-restage option as implemented with #39, but that ended up committing the file any way. Am I misunderstanding that flag?

I am happy to do this as a PR, but wanted to make sure that I understood the problem and make sure it wasn't already fixed.

Is it used with Prettier or in place of it?

hi there 👋

I see in the README.md that you install it as a dev dependency is that alongside an install of Pettier?

I have Prettier as a dev dependency and an npm script:

    "format":
      "prettier --trailing-comma none --no-semi --single-quote --write \"src/**/*.js\"",

Is that going to be any use if I use pretty-quick?

Custom config?

How can I use pretty-quick with a custom eslint-prettier (.eslintrc) config?
My commits code is different than my development environment... 😅

npx usage

Running npx pretty-quick errors with "Cannot find module 'prettier'".

This works though: npx -p prettier -p pretty-quick pretty-quick

Add option to look only for certain file extensions

We use a shared repository with our backend team and we would have to ignore backend files and assets.

Can we have something like prettier --write \"**/*.*(js|jsx|json)\" for prettier-quick?

So it would check only staged files that actually match the minimatch pattern?

Unexpected behavior in Webstorm on Mac OS Siera.

I am using the latest version of the Webstorm.

  1. After commit (it is done via IDE (cmd + K) shorthand), the files seems to be added to the commit with fixes but in the Webstorm they are still in the staged mode after the commit was done (but there is no changes in that files if looking to the diff). After trying to commit that files again the rules applies for them again (i.e the second empty line at the end of the file despite there is already one present).

  2. after the file was already prettied and for some reason some formatting changes were made in that file and after the commit command was made only for that file - the prettier task run for that file and creates an empty commit without any changes (which makes sense but it would be better to prevent that commit instead).

Probably this is a result of the known issue lint-staged/lint-staged#151

How can I specify glob included path

You can specify glob included path with prettier prettier --write 'src/**/*.{js,css}'

There's a way to specify glob included path with pretty-quick ?

if not, it'd be great for user to pass glob included path via cli and I'm willing to open pr.

One file remains unstaged, all other files get staged and committed successfully.

I am unable to stage one file, all other files are successfully staged and committed. I am using pretty-quick as a precommit githook. If its necessary to debug the issue, I first ran prettier --single-quote --write "src/**/*.ts?(x) to prettify all the files. I am unable to revert changes too.

Let me know If other additional information is needed.

If is initial commit, pretty-quick throw e error.

env

  • pretty-quick: 1.2.2
  • husky: 0.14.3
  • node: 8.9.3
  • yarn: 1.3.2
  • System: macOS 10.13.2

description

If is initial commit, pretty-quick throw e error:

husky > npm run -s precommit (node v8.9.3)

~/demo/node_modules/execa/index.js:303
		throw (result.error || new Error(result.stderr === '' ? result.stdout : result.stderr));
		^

Error: fatal: Needed a single revision

    at Function.module.exports.sync (~/demo/node_modules/execa/index.js:303:26)
    at runGit (~/demo/node_modules/pretty-quick/dist/scms/git.js:29:53)
    at Object.exports.getSinceRevision (~/demo/node_modules/pretty-quick/dist/scms/git.js:37:10)
    at exports.default (~/demo/node_modules/pretty-quick/dist/index.js:39:33)
    at Object.<anonymous> (~/demo/node_modules/pretty-quick/bin/pretty-quick.js:12:1)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

Partially staged files

Am I misunderstanding what is meant by partially staged files? If I stage all my changes for a commit and one of those files requires formatting, then when I run pretty-quick --staged it errors, doesn't restaged the file and tells me it Found partially staged file. On the other hand if no staged files required formatting then it proceeds without error.

I would have not expected this behavior unless one of the changed files had remaining unstaged changes prior to running pretty-quick

pretty quick format unstaged files

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"?

Silent flag for when nothing is done

Example currently, when there are no changes to be made:

❯ yarn -s pretty-quick
🔍  Finding changed files since git revision 2b1de96.
🎯  Found 4 changed files.
✅  Everything is awesome!

I propose there be a cli flag --silent-noop that, when nothing is done, nothing is printed.

Would you accept a PR for this?

Error when a staged file is deleted (no such file or directory)

Q A
Node 9.4.0
Pretty-quick 1.2.1
Husky 0.14.3

Hey!
First let me thanks you for this incredible package, it's so easy to install, to configure, and to use 😄

I recently encountered a bug when I'm staging a deleted file.
As show the screen below, I deleted the file /home/hugo/<...>/container/edit.vue, but pretty-quick still try to read it. Since this file does not exist anymore, pretty-quick fails.

selection_032

Here is my package.json if needed:

{
  "scripts": {
    "precommit": "pretty-quick --staged"
  }
}

Stages entire file even if it was only partially staged

Hi, we are using pretty-quick with git/husky as a pre-commit hook. If I partially stage a file, then commit that change, pretty-quick runs against that file and then stages the entire file instead of running against the staged version of the file only.

For example, I have an empty file "test.js"...

  1. printf "ONE;\r\n" >> test.js
  2. printf "TWO;\r\n" >> test.js
  3. git add -p (add only the first line of the file)
  4. git commit -m "one" (husky/pretty-quick runs)

husky > npm run -s precommit (node v10.0.0)

🔍 Finding changed files since git revision 3864e2e.
🎯 Found 1 changed file.
✍️ Fixing up ui/test.js.
✅ Everything is awesome!
[test 95c4d5d] 1
1 file changed, 2 insertions(+)

  1. git status (shows nothing staged or changed)
  2. git diff HEAD~1..HEAD (shows both ONE and TWO lines were committed in the "one" commit)

This is incorrect because I only staged part of the file, not the whole thing. Please let me know if I'm missing something. Here is the NPM script we're using: pretty-quick --staged

Console font compatibility

Hi,
some symbols in pretty-quick's output are shown as rectangles [], e.g. the ✔️ which is supposed to appear next to "Everything is awesome".

This happens on Konsole (kde).
Do I have to install a certain font for the symbols to show up correctly?

pattern doesn't work as expected

Hi there,

I've been trying to get pretty-quick for my project but I'm having a hard time. I did test a few scenarios to try and have as much info before opening this ticket.

First of all I run a simple yarn prettier --check './src/v2/**/*.ts' it brought back many files, all of them ending in .ts as expected.

Then I got one of them, added a white space and staged it. Then I run the following.

yarn pretty-quick --staged --verbose pattern './src/v2/**/*.(ts|tsx)'

Since it was my only file staged it pick it up correctly.

Then for the sake of testing all functionalities, I changed a .js file and staged it. And to my surprise it actually tries and fix the js file. This is the cli output

yarn run v1.17.3
$ /Users/cainaleao/Development/project/node_modules/.bin/pretty-quick --staged --verbose pattern './src/v2/**/*.ts'
🔍  Finding changed files since git revision d81a571f11.
🎯  Found 2 changed files.
🔍  Examining front-end-build/planner-deps.js.
🔍  Examining front-end-build/src/v2/__tests__/_utils.ts.
✅  Everything is awesome!
✨  Done in 1.89s.```

Then I run the same first line again just to make sure prettier would not also try and change a `.js` file and it work as expected.

Not quite sure what is going on. If you need more information just let me know.

Cheers,
Cai





Path for prettierrc

How do I add in script the location/path of my prettierrc? My prettierrc is located in node_modules not in the root folder

pretty-quick uses a different version of prettier than the installed in the repo

I found a mismatch between the fixes pretty-quick was doing on commit (the husky setup) and when running prettier directly.

I couldn't figure out what was causing the mismatch. Turns out the prettier version I have installed is quite old and is not the same version pretty-quick is using.

asciicast

First format the file with prettier, it generates some changes. Then run pretty-quick, changes aren't there anymore (since the commit was done with pretty-quick so the fix basically returns repo to initial state).

So then I check the versions of prettier and turns out they are different.

I looked a bit at the code of pretty-quick and cannot figure out why it is using a different version of prettier than the installed one (thought it could be a global version, but I don't have one).

Issue with unicode in gnome-terminal

Hi pretty-quick team,

I've got a display error of some unicode characters on gnome-terminal.

2018-02-09-121339_1920x1848_scrot

Would you know how to solve them ?

thanks and have a nice day,

Alex

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.