-
Notifications
You must be signed in to change notification settings - Fork 437
feat: add configurable typo detection for package dependency constraints #11759
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
base: main
Are you sure you want to change the base?
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.
Looks overall pretty good, but I have some suggestions that could improve readability of the code.
@Leonidas-from-XIV @gridbugs , I've created updates for this pr here: #11766 . Please kindly review. |
@kemsguy7 Why is that a separate PR? It would be better to push your improvements in this PR as then we can refer to the comments that were made in previous reviews. |
3af87dc
to
5d88a1c
Compare
@Leonidas-from-XIV @gridbugs , please kindly review, I've applied updates ass suggested in the comments above |
@kemsguy7 There are still review comments that I wrote that are unadressed, could you handle them please? Also, it seems you need to solve a merge conflict in |
Sure, please do you mind pointing out the parts that have been unaddressed If you have the time? I did a lot of rebasing, patching e.t.c to fix my PR as it got messy at some point so I might have reverted some of the files. I'll take a second look though and also fix the merge conflict |
Sure. I checked the current state of the PR and these are still unaddressed: |
@kemsguy7 the branch this P 8000 R is coming from does not include df45715, since it's based on a version of origin/main from before your previous PR was merged. This is why it looks like the changes from your previous PR are duplicated in this PR which is making it hard to review. Running |
81c8c90
to
2219401
Compare
Thank you for this. |
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 improvements. There's still some things that I think needs adjusting before they can be merged.
In particular you also need to run dune fmt
to reformat the code to our preferred formatting setting.
src/dune_lang/package_dependency.ml
Outdated
] | ||
~hints: | ||
(* Early return if warnings are disabled *) | ||
if Dune_config.Config.(get typo_warnings) <> `Enabled then None |
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'd probably suggest matching on `Enabled
and the other case, that avoids code that reads oddly:
match Dune_config.Config.(get typo_warnings) with
| `Disabled -> None
| `Enabled -> (* your else branch *)
src/dune_lang/package_dependency.ml
Outdated
(* Early return if warnings are disabled *) | ||
if Dune_config.Config.(get typo_warnings) <> `Enabled then None | ||
else | ||
let open Package_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.
This still has the local open. Can you please remove it?
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.
Sure
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.
@Leonidas-from-XIV please kindly review
8daef1b
to
fc0d681
Compare
@@ -147,3 +147,7 @@ let threaded_console_frames_per_second = | |||
| None -> Error (sprintf "could not parse %S as an integer" x)) | |||
~default:`Default | |||
;; 6D40 | |||
|
|||
let typo_warnings = |
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 this should have a more descriptive name, as it only enables checking for a very specific type of typo.
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.
Do you mean this file config.ml?
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 mean the variable typo_warnings
.
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.
This isn't resolved. The variable is still named typo_warnings
. It should have a more descriptive name reflecting the nature of typos which it enables warnings for, since it only warns about typos in a very specific situation.
00d5f6b
to
21496b1
Compare
@@ -28,61 +28,73 @@ module Well_formed_name = struct | |||
module TT = Dune_util.Stringlike.Make (T) | |||
|
|||
let decode = | |||
let open Decoder in | |||
let open Dune_sexp.Decoder 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.
Did something change to make this addition necessary now?
7735143
to
7b05815
Compare
7b05815
to
8d4aa1a
Compare
src/dune_lang/package_dependency.ml
Outdated
let dependency_constraint_variable_typo_warnings ~loc { name; constraint_ } = | ||
(* Handle case where config system isn't initialized yet *) | ||
let warnings_enabled = | ||
try Dune_config.Config.(get typo_warnings) = `Enabled with |
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 the exception here? I think for the most part we try not to use exceptions.
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.
@Leonidas-from-XIV I wrote this in response to a failing test that was working before my PR test/blackbox-tests/test-cases/pkg/additional-constraints.t
.
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, but does Dune_config.Config.get
throw an exception? If so, which one and why? If so, the with
case should mention the exception and not just blanket-catch every exception. If not, then this try
line should be removed.
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 the exception here? I think for the most part we try not to use exceptions.
@Leonidas-from-XIV i've updated this , please check.
8d4aa1a
to
475823f
Compare
7e9cba8
to
854c75e
Compare
src/dune_lang/package_dependency.ml
Outdated
try Dune_config.Config.(get typo_warnings) = `Enabled with | ||
| Code_error.E _ -> true (* Only catches Code_error.E exceptions *) | ||
in | ||
(* Early return if warnings are disabled *) |
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.
Nitpick about terminology, but this is not an early return. I don't think this comment adds information that isn't obvious reading the code.
src/dune_lang/package_dependency.ml
Outdated
(* Handle case where config system isn't initialized yet *) | ||
let warnings_enabled = | ||
try Dune_config.Config.(get typo_warnings) = `Enabled with | ||
| Code_error.E _ -> true (* Only catches Code_error.E exceptions *) |
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.
We definitely shouldn't ever be catching Code_error
exceptions. The intention of these types of exceptions is to catch programming mistakes inside dune, similar to an assert statement. Did you find that calling Dune_config.Config.(get typo_warnings)
raised a Code_error.E
exception?
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.
@Leonidas-from-XIV please can you review the change i did here? it's making the additional constraint test fail
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.
Left a few suggestions for improving the readability. Also the current approach to handling exceptions raised by Dune_config.Config.(get typo_warnings)
doesn't look correct to me.
src/dune_lang/package_dependency.ml
Outdated
(* Handle case where config system isn't initialized yet *) | ||
let warnings_enabled = | ||
try Dune_config.Config.(get typo_warnings) = `Enabled with | ||
| Code_error.E _ -> true (* Only catches Code_error.E exceptions *) |
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.
Possibly moot because this line will be removed/changed while applying feedback from this review, but try to avoid comments that don't add any clarity. Assume readers know ocaml syntax, in which case they already understand that | Code_error.E _ -> ...
in the context of a try
statement means to catch Code_error.E
exceptions. A more useful comment would explain why it's necessary to catch such exceptions, or perhaps why other exceptions are not caught. The comment should explain your intent so readers understand it, and maintainers can preserve your intent through changes in the future, or understand the consequence of deleting this code if necessary.
But as I said, it doesn't really matter in this specific instance since I suspect this line will be deleted anyway and as @Leonidas-from-XIV said above, we try to avoid using exceptions as much as possible in dune.
de12c7e
to
2a70998
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.
Please make sure to run dune fmt
to format the source code automatically and take a look at the outstanding review comments.
> EOF | ||
|
||
$ DUNE_CONFIG__TYPO_WARNINGS=disabled dune pkg lock | ||
$ # No warnings should be produced when the feature is disabled |
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 is no command being run here, so it is missing the test.
TT.decode >>| T.to_package_name | ||
;; | ||
end | ||
|
||
let encode { name; constraint_ } = | ||
let open Encoder in | ||
let open Dune_sexp.Encoder 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.
Is this change 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.
reverted.
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 still see the change in the diff. Can you remove this change (and the one above that I commented on).
(** Before any configuration value is accessed, this function must be called | ||
with all the configuration values from the relevant config file | ||
([dune-workspace], or [dune-config]). | ||
|
||
Note that environment variables take precedence over the values passed here | ||
for easy overriding. *) | ||
val init : (Loc.t * string) String.Map.t -> unit | ||
val init : (Loc.t * string) String.Map.t -> unit |
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 do not remove the trailing newlines. It creates changed lines where there are no changes actually.
…ith main Signed-off-by: kemsguy7 <mattidungafa@gmail.com>
…moved unnecessary comments Signed-off-by: kemsguy7 <mattidungafa@gmail.com>
2a70998
to
659a6dc
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.
Left a few more comments about formatting. Also please make sure to address some of the older comments still outstanding (use the "Files changed" tab to easily see them).
@@ -86,6 +86,7 @@ let make ~name ~of_string ~default = | |||
;; | |||
|
|||
let make_toggle ~name ~default = make ~name ~default ~of_string:Toggle.of_string | |||
|
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 try to remember to run the autoformatter on your changes. I thought we set up your vscode to automatically format files when you save them. Did that stop working?
TT.decode >>| T.to_package_name | ||
;; | ||
end | ||
|
||
let encode { name; constraint_ } = | ||
let open Encoder in | ||
let open Dune_sexp.Encoder 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.
I still see the change in the diff. Can you remove this change (and the one above that I commented on).
No description provided.