Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dkonchekov's file list cli params #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

poita66
Copy link

@poita66 poita66 commented Jul 24, 2020

This PR adds dkonchekov's changes to support specifying the files to be checked, instead of the whole folder.
This is especially useful for pre-commit hooks, where you don't want all of the files checked, just those that have changed.

For those looking to set up their own pre-commit hooks, here's what I added to my package.json:

"husky": {
  "hooks": {
    "pre-commit": "lint-staged"
  }
},
"lint-staged": {
  "src/**/*.{js,ts,vue}": "eslint --cache --fix",
  "src/**/*.vue": "vue-type-check --onlyTemplate --workspace ."
}

@poita66
Copy link
Author

poita66 commented Jul 24, 2020

@dkonchekov I hope it's OK that I put this PR together, I couldn't figure out how to ask you first 😅

`file://${file}`,
"vue",
0,
fs.readFileSync(file, "utf8")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be better to read the file asynchronously:

Suggested change
fs.readFileSync(file, "utf8")
await fs.readFile(file, "utf8")

Also, this block should better be extracted to an async function enumerate, just like traverse.

const cwd = process.cwd();

check({
workspace: path.resolve(cwd, workspace),
workspace: path.resolve(cwd, workspace || "."),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be possible to reuse cwd for this?

Suggested change
workspace: path.resolve(cwd, workspace || "."),
workspace: path.resolve(cwd, workspace || cwd),

It would be more readable to keep the !workspace block, but move it after the cwd assignment:

const cwd = process.cwd();

if (!workspace) {
  workspace = cwd;
}

@@ -8,6 +8,7 @@
"vtc": "dist/cli.js"
},
"scripts": {
"prepare": "npm run compile",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that really necessary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants