8000 feat: add configurable typo detection for package dependency constraints by kemsguy7 · Pull Request #11759 · ocaml/dune · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kemsguy7
Copy link
Contributor
@kemsguy7 kemsguy7 commented May 5, 2025

No description provided.

Copy link
Collaborator
@Leonidas-from-XIV Leonidas-from-XIV left a 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.

@kemsguy7
Copy link
Contributor Author
kemsguy7 commented May 5, 2025

@gridbugs , here's updates I made for issue #11629 .

@maiste maiste added config Everything related to dune configuration (workspace, project, dune, env) cli Command line related labels May 5, 2025
@kemsguy7
Copy link
Contributor Author
kemsguy7 commented May 7, 2025

@Leonidas-from-XIV @gridbugs , I've created updates for this pr here: #11766 . Please kindly review.

@kemsguy7 kemsguy7 marked this pull request as draft May 7, 2025 04:46
@Leonidas-from-XIV
Copy link
Collaborator

@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.

@kemsguy7 kemsguy7 force-pushed the disabled_warnings branch from 3af87dc to 5d88a1c Compare May 19, 2025 06:12
@kemsguy7
Copy link
Contributor Author

@Leonidas-from-XIV @gridbugs , please kindly review, I've applied updates ass suggested in the comments above

@Leonidas-from-XIV
Copy link
Collaborator

@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 package_dependency.ml.

@kemsguy7
Copy link
Contributor Author

@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 package_dependency.ml.

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

@Leonidas-from-XIV
Copy link
Collaborator

Sure, please do you mind pointing out the parts that have been unaddressed If you have the time?

Sure. I checked the current state of the PR and these are still unaddressed:

  1. This one
  2. This one
  3. This one
  4. This one
  5. And this one

@gridbugs
Copy link
Collaborator

@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 git pull origin main --rebase (and dealing with any conflicts) will update your branch so that all your recent changes are applied to the current tip of origin/main.

@kemsguy7 kemsguy7 force-pushed the disabled_warnings branch from 81c8c90 to 2219401 Compare May 20, 2025 09:54
@kemsguy7
Copy link
Contributor Author

@kemsguy7 the branch this PR 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 git pull origin main --rebase (and dealing with any conflicts) will update your branch so that all your recent changes are applied to the current tip of origin/main.

Thank you for this.
@Leonidas-from-XIV , @gridbugs please kindly review, I've updated with origin main and also implemented changes as requested

Copy link
Collaborator
@Leonidas-from-XIV Leonidas-from-XIV left a 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.

]
~hints:
(* Early return if warnings are disabled *)
if Dune_config.Config.(get typo_warnings) <> `Enabled then None
Copy link
Collaborator

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 *)

(* Early return if warnings are disabled *)
if Dune_config.Config.(get typo_warnings) <> `Enabled then None
else
let open Package_constraint in
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

Copy link
Contributor Author

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

@kemsguy7 kemsguy7 force-pushed the disabled_warnings branch from 8daef1b to fc0d681 Compare May 22, 2025 02:22
@@ -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 =
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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.

Copy link
Collaborator

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.

@kemsguy7 kemsguy7 force-pushed the disabled_warnings branch 4 times, most recently from 00d5f6b to 21496b1 Compare June 2, 2025 06:22
@@ -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
Copy link
Collaborator

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?

@kemsguy7 kemsguy7 force-pushed the disabled_warnings branch 3 times, most recently from 7735143 to 7b05815 Compare June 2, 2025 07:30
@kemsguy7 kemsguy7 changed the title Disabled warnings package_dependency_typo_warnings Jun 2, 2025
@kemsguy7 kemsguy7 force-pushed the disabled_warnings branch from 7b05815 to 8d4aa1a Compare June 2, 2025 07:41
@kemsguy7 kemsguy7 changed the title package_dependency_typo_warnings feat: add configurable typo detection for package dependency constraints Jun 2, 2025
@kemsguy7 kemsguy7 marked this pull request as ready for review June 2, 2025 10:10
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
Copy link
Collaborator

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.

Copy link
Contributor Author
@kemsguy7 kemsguy7 Jun 4, 2025

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@kemsguy7 kemsguy7 force-pushed the disabled_warnings branch from 8d4aa1a to 475823f Compare June 4, 2025 08:34
@kemsguy7 kemsguy7 force-pushed the disabled_warnings branch from 7e9cba8 to 854c75e Compare June 17, 2025 01:27
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 *)
Copy link
Collaborator

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.

(* 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 *)
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Collaborator
@gridbugs gridbugs left a 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.

(* 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 *)
Copy link
Collaborator

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.

@kemsguy7 kemsguy7 force-pushed the disabled_warnings branch 2 times, most recently from de12c7e to 2a70998 Compare June 19, 2025 07:29
Copy link
Collaborator
@Leonidas-from-XIV Leonidas-from-XIV left a 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
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this change necessary?

Copy link
Contributor Author
@kemsguy7 kemsguy7 Jun 19, 2025

Choose a reason for hiding this comment

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

reverted.

Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

kemsguy7 added 2 commits June 19, 2025 10:05
…ith main

Signed-off-by: kemsguy7 <mattidungafa@gmail.com>
…moved unnecessary comments

Signed-off-by: kemsguy7 <mattidungafa@gmail.com>
@kemsguy7 kemsguy7 force-pushed the disabled_warnings branch from 2a70998 to 659a6dc Compare June 19, 2025 09:05
Copy link
Collaborator
@gridbugs gridbugs left a 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

Copy link
Collaborator

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
Copy link
Collaborator

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Command line related config Everything related to dune configuration (workspace, project, dune, env)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0