Dvc.org: add command for formatting a single file

Created on 21 May 2019  路  4Comments  路  Source: iterative/dvc.org

It will be good if the guide mentions a way to format specified files only. This can be done in two ways:

  • npx --write <pattern to match required files>: npx is a package which comes with npm. It simply executes node packages if found in ./node_modules. If this doesn't work you may install it using sudo npm install -g npx otherwise follow the other method.
  • ./node_modules/prettier/bin-prettier.js --write <pattern to match required files>: This command runs prettier installed in the node_modules.

pattern to match required files examples:

  • src/Diagram/index.js
  • static/docs/command-reference/add.md
  • static/docs/**/*.md
doc-content enhancement good first issue

Most helpful comment

I guess this info would go in the contributing documentation guide. I vote for npx.

p.s. I often git add my changes and then use git diff --staged --name-only | xargs npx prettier --write to lint only the staged files. But that shouldn't be necessary anymore now that we have automatic pretty-quick (kudos @algomaster99 in #386)

All 4 comments

I guess this info would go in the contributing documentation guide. I vote for npx.

p.s. I often git add my changes and then use git diff --staged --name-only | xargs npx prettier --write to lint only the staged files. But that shouldn't be necessary anymore now that we have automatic pretty-quick (kudos @algomaster99 in #386)

We have added a mention already how to run it for a single Markdown file. Do we need anything else here? Add a command for JS?

@shcheklein It's the same. You just need to write js files in <files> instead of md files.

ok, closing it then. Feel free to reopen it if you feel we are missing something here.

Was this page helpful?
0 / 5 - 0 ratings