-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
feat(format): lint formatting of a single file #226
Comments
Hey @jameshearttech, For linting single files there are probably a few things missing as syncpack is expecting to check that a whole project is correct. What kind of things did you have in mind for a single file? That its formatting matches? Or something more? |
@JamieMason I looked through the help for each command. Looks like |
I think you're saying you only want to check formatting and that sounds good, I'll take a look so that can be supported for single files. Thanks a lot |
I apologize for not being more concise. What does Check formatting: Check semver ranges: Check versions: Here's a mock up of my // lint-staged.config.mjs
export default {
check: {
'*.{js,cjs,mjs}': ['eslint', 'prettier --check'],
'*.{scss,css,json,yaml,yml,html}': ['prettier --check'],
'*.md': ['remark', 'prettier --check'],
'package.json': [
// 'syncpack check-format --source',
'syncpack lint-semver-ranges --source',
'syncpack list-mismatches --source'
]
},
fix: {
'*.{js,cjs,mjs}': ['eslint --fix', 'prettier --write'],
'*.{scss,css,json,yaml,yml,html}': ['prettier --write'],
'*.md': ['remark --output', 'prettier --write'],
'package.json': ['syncpack format --source', 'syncpack fix-mismatches --source']
}
}; |
Thanks a lot for this detail @jameshearttech and yes you're absolutely right, your lint-staged config looks good but there are some gaps in syncpack, I'll summarise: What syncpack can/can't do currently:
If you or someone reading this has multiple package.json files, I would check all package.json files whenever any of them change, which should be possible with something like: // lint-staged.config.mjs
export default {
check: {
"*.{js,cjs,mjs}": ["eslint", "prettier --check"],
"*.{scss,css,json,yaml,yml,html}": ["prettier --check"],
"*.md": ["remark", "prettier --check"],
"**/package.json": () => "syncpack lint",
},
fix: {
"*.{js,cjs,mjs}": ["eslint --fix", "prettier --write"],
"*.{scss,css,json,yaml,yml,html}": ["prettier --write"],
"*.md": ["remark --output", "prettier --write"],
"**/package.json": () => ["syncpack format", "syncpack fix-mismatches"],
},
}; For the missing functionality of checking formatting of a single file, I'm working on a rewrite in #222 and will make that possible as part of that work. I'll keep this open to track that. Let me know if I've missed anything, thanks. |
I'm using |
Can you clarify what you mean, are you referring to the globs in the lint-staged config? or globs that you might pass to syncpack via |
Oh, I was thinking of the globs I might pass to |
I use lint-staged in local development for linting files in Git staging prior to commit. I would like to lint package.json files using syncpack using the same approach. It would be great if I could do something like
pnpm exec syncpack lint /path/to/package.json
and it would override--source
using the config from the root project in the monorepo.The text was updated successfully, but these errors were encountered: