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 support for file-based configuration #75
Conversation
This is wonderful @mtlewis, thanks for working on this ❤️ I'll review it shortly |
packages/lockfile-lint/src/config.js
Outdated
|
||
let fileConfig | ||
if (cosmiconfigResult) { | ||
fileConfig = validateConfig(cosmiconfigResult.config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mtlewis is this a synchronous operation? what happens if it throws?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's synchronous since we're using cosmiconfigSync
. I hadn't spotted that it could throw though, thanks for pointing it out. Newest version of the code now handles errors, ignoring file-based config and logging an error.
@mtlewis I'm happy to land this. |
Codecov Report
@@ Coverage Diff @@
## master #75 +/- ##
==========================================
+ Coverage 95.08% 96.87% +1.79%
==========================================
Files 11 11
Lines 183 192 +9
Branches 29 31 +2
==========================================
+ Hits 174 186 +12
+ Misses 8 5 -3
Partials 1 1
Continue to review full report at Codecov.
|
bdbe3c1
to
81459e3
Compare
Hey @lirantal, thanks for your review! I've added some tests. I also did a bit of refactoring of the PR, since the way it was before made it harder to retain the argument validation that's configured in yargs. Instead, we now load the cosmiconfig first, then pass it into yargs as the base config. This allows us to keep the configuration rules in yargs. Let me know what you think! |
By the way - I'm not sure coverage is currently working in cli.js. I believe I've covered all the new code in cli.js in tests, but both before and after this change, the detected coverage in cli.js is 0. I suspect this could be something to do with the fact that the tests for cli.js are currently executing in a separate process. I guess the reason CI is failing in this PR is that cli.js now has more lines of code, which means its 0% coverage contributes more to the overall number. |
Yep, I see what you mean there about the cli.js not being covered in unit tests (and indeed in a different process they aren't being counted for). What if you move this code lockfile-lint/packages/lockfile-lint/src/cli.js Lines 5 to 20 in 0a90e42
config.js module, add unit test coverage to it, and then require it in cli.js?
Tip: to better understand what lines of code are missing coverage, you can run |
Hey @lirantal thanks for the feedback and suggestion - how about this: 76df197? Since the whole of cli.js was previously uncovered, I figured it might be good to refactor the whole thing so that it's testable without launching a child process, and then separate out the testing of the option parsing/validation from the cli tests in cli.js. |
Ok, taking a look ;-) |
this looks overall good, thanks @mtlewis 🙏 |
Description
This PR adds support for loading lockfile-lint configuration from a file, rather than supplying it on the command line. It uses cosmiconfig, which gives us a bunch of sensible configuration file support for free. Command-line options always override options specified in config files.
Types of changes
Related Issue
Welp - I didn't notice that only PRs with open issues would be accepted before I worked on this, so I created one (#74). Sorry for not quite following the guidelines!
Motivation and Context
See #74.
How Has This Been Tested?
So far, I've only tested this manually. I'll be happy to circle back and add tests if there's a positive reaction to #74.
Checklist: