-
Notifications
You must be signed in to change notification settings - Fork 431
Detection and warning for common typos in package dependency constraints #11600
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
Conversation
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.
Nice work so far! In addition to the comments, please add some cram tests (see the contents of test/blackbox-tests/test-cases/ for examples).
README.md
Outdated
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.
Avoid including unrelated changes in PRs. If you want to update the readme file, it's more appropriate to do it in a separate PR.
boot/libs.ml
Outdated
@@ -1,4 +1,4 @@ | |||
let external_libraries = [ "unix"; "threads" ] | |||
let external_libraries = [ "threads.posix" ] |
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.
Dune's build process is a little annoying in that it sometimes changes this file. Get into the habit of not staging changes to this file when making commits to this repo.
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.
Noted.
class.sol
Outdated
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.
What is this file? Please remove it from the PR.
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.
ok my bad, will do
src/dune_pkg/package_dependency.ml
Outdated
(* Function to emit warnings for common typos when processing dependencies *) | ||
let warn_on_typos ~loc dependency = | ||
(* We'll implement a copy of the check_for_version_typo function here | ||
since it's not directly accessible from the other module *) |
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.
See if you can come up with a way to avoid this duplication. You're welcome to extend the interface to Dune_lange.Package_dependency
if necessary.
src/dune_lang/package_dependency.ml
Outdated
( sprintf | ||
"Possible typo in package dependency for %s: '(= version)' might be a mistake." | ||
(Package_name.to_string name) | ||
, "Did you mean to use the `:version` variable instead? Use: (depends (bar :version))" ) |
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.
In the example, instead of (depends (bar :version))
it would be better to reproduce the text of the constraint the user actually used, but corrected.
src/dune_lang/package_dependency.ml
Outdated
(* Check for typos and emit warnings *) | ||
(match check_for_version_typo result with | ||
| Some (msg, suggestion) -> | ||
User_warning.emit [Pp.text msg; Pp.text suggestion] |
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.
Take a look at User_message.make
. You can create a message, possibly including hints which are formatted differently from the regular warning body and would be suitable for the "Did you mean..." parts of the warning. The message can then be printed as a warning with User_warning.emit_message
.
So concretely I'm suggesting that you change the check_for_version_type
function to return a User_message.t option
.
src/dune_lang/package_dependency.ml
Outdated
"Possible typo in package dependency for %s: '(= version)' might be a mistake." | ||
(Package_name.to_string name) | ||
, "Did you mean to use the `:version` variable instead? Use: (depends (bar :version))" ) | ||
| Some (Bop (Relop.Eq, Value.String_literal "version", _)) -> |
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.
I think we only expect version comparisons to use the Uop
constructor.
src/dune_lang/package_dependency.ml
Outdated
| Some (Uop (Relop.Eq, Value.String_literal "version")) -> | ||
Some | ||
( sprintf | ||
"Possible typo in package dependency for %s: '(= version)' might be a mistake." |
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.
I think it would be more accurate to say "Possible typo in constraint for dependency %S: ...".
src/dune_pkg/package_dependency.ml
Outdated
(match Constraint.opt_of_opam_condition condition with | ||
| Ok constraint_ -> | ||
let dep = { name; constraint_ } in | ||
warn_on_typos ~loc dep; |
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.
Will this print warnings for projects that don't use dune package management?
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.
I think printing the warning in decode
is sufficient, since for all operations dune will need to decode the dune-project file anyway.
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.
I'll look at it again and give feedback.
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.
@gridbugs , I've added fixes based on your suggestions apart from cram tests, I'm currently working on that. Please kindly review and let me know if I'm on track, thanks.
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.
Looking pretty good. I've left several minor suggestions. Looking forward to seeing the tests.
README.md
Outdated
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.
Try to keep the diff to just contain the meaningful part of your change (e.g. explicitly stage individual files rather than doing git commit -a
).
src/dune_lang/package_dependency.ml
Outdated
@@ -63,4 +96,4 @@ let to_dyn { name; constraint_ } = | |||
let equal { name; constraint_ } t = | |||
Package_name.equal name t.name | |||
&& Option.equal Package_constraint.equal constraint_ t.constraint_ | |||
;; | |||
;; |
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.
Try to avoid adding/removing the trailing newline from the diff (ie. only include the meaningful part of your change). Some editors automatically mess with file endings. The problem with checking this in is that the next person who touches the file will have to deal with the changed line ending from their editor and so on. My advice would be to configure your editor to leave file endings alone, and also to use git add -p
or similar to only stage the meaningful changes.
src/dune_lang/package_dependency.ml
Outdated
"Possible typo in constraint for dependency %S: '(= version)' might be a mistake." | ||
(Package_name.to_string name) | ||
] | ||
~hints:[ Pp.text "Did you mean to use the `:version` variable instead? Example: (depends (bar :version))" ] |
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.
Instead of (depends (bar :version))
, it would be better to print the actual package name from the user's dune-project. Also (depends (bar :version))
isn't the right syntax; it should be (depends (bar (= :version)))
.
src/dune_lang/package_dependency.ml
Outdated
"Possible typo in constraint for dependency %S: ':with_test' might be a mistake." | ||
(Package_name.to_string name) | ||
] | ||
~hints:[ Pp.text "Did you mean to use ':with-test' instead? Example: (depends (bar :with-test))" ] |
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.
Replace the bar
with the package name from the offending line.
src/dune_pkg/package_dependency.ml
Outdated
| Ok constraint_ -> { name; constraint_ } | ||
| Ok constraint_ -> | ||
let dep = { name; constraint_ } in | ||
(* We don't need to check for typos here since it's already handled in decode *) |
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.
I don't think this comment is necessary.
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.
@gridbugs Thanks for the feedback, I've noted all requested changes and will adjust accordingly.
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.
@gridbugs
, here are my updates, attached to this comment is a screenshot showing the result of running the test
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.
Nice. Please include the test in this PR.
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.
Nice. Please include the test in this PR.
Added , please kindly review
src/dune_pkg/package_dependency.ml
Outdated
@@ -229,7 +229,9 @@ let list_of_opam_disjunction loc filtered_formula = | |||
| Atom (name, condition) -> | |||
let name = Package_name.of_opam_package_name name in | |||
(match Constraint.opt_of_opam_condition condition with | |||
| Ok constraint_ -> { name; constraint_ } | |||
| Ok constraint_ -> | |||
let dep = { name; constraint_ } in |
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.
There's no need for this let binding anymore. You can just revert this file to its original state.
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.
There's no need for this let binding anymore. You can just revert this file to its original state.
@gridbugs Updated.
src/dune_pkg/package_dependency.ml
Outdated
@@ -229,7 +229,7 @@ let list_of_opam_disjunction loc filtered_formula = | |||
| Atom (name, condition) -> | |||
let name = Package_name.of_opam_package_name name in | |||
(match Constraint.opt_of_opam_condition condition with | |||
| Ok constraint_ -> { name; constraint_ } | |||
| Ok constraint_ -> {name; constraint_} |
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.
Run dune fmt
to automatically fix the style.
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.
Alright @gridbugs, thanks for your guiding me all the way. Implementing final changes now.
This is getting pretty close to done. A few things left before I'll consider merging it:
I'll mark this as not a draft so others can take a look if they want. |
efdef19
to
d7af4b7
Compare
@gridbugs all done, please kindly review |
README.md
Outdated
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.
Please remove unrelated changes from the readme.
Looks like your commit is not signed (the "DCO" test is failing). Run |
Okay thanks, let me try again. |
One more thing I'll ask of you is to add a file to doc/changes describing the change (follow the example of the other files in that directory). |
Alright mentor, on it. |
d7af4b7
to
e62f5df
Compare
@gridbugs I've added the docs. Please kindly review. Thanks. |
doc/changes/11575.md
Outdated
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.
Thanks for the detailed explanation, but this just needed to be a single line for our change log. You're welcome to write more docs elsewhere but I think for this particular change it won't be necessary. I'll fix up this file to match other changelog entries before and merge this PR today.
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.
Alright, noted with thanks.
8ab32bc
to
debedeb
Compare
4eeb981
to
97f4491
Compare
61aca2c
to
c6bb552
Compare
@gridbugs , added updates, please kindly review, thanks |
Signed-off-by: kemsguy7 <[email protected]>
c6bb552
to
38b9b8d
Compare
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.
Since this is related to package management, shouldn't we move this to an experimental subfolder or not add a changelog?
@gridbugs, Here's my draft PR for issue. #11575, please kindly review and give feedback let me know if I'm on track.