Skip to content

Improve: remove option break-string-literals#932

Merged
gpetiot merged 3 commits intoocaml-ppx:masterfrom
gpetiot:break-string-literals
Jul 26, 2019
Merged

Improve: remove option break-string-literals#932
gpetiot merged 3 commits intoocaml-ppx:masterfrom
gpetiot:break-string-literals

Conversation

@gpetiot
Copy link
Copy Markdown
Collaborator

@gpetiot gpetiot commented Jul 23, 2019

I did a quick check on github and it seems most projects currently use the wrap value for the option so they should not see too many changes (I fail to see why someone would want the strings to never wrap).

The diff of test_branch looks good:

diff --git a/src/Translation_unit.ml b/src/Translation_unit.ml
index 33481d3..b5588c3 100644
--- a/src/Translation_unit.ml
+++ b/src/Translation_unit.ml
@@ -242,38 +242,40 @@ let print_error ?(quiet_unstable = false) ?(quiet_comments = false)
                 | Normalize.Moved (loc_before, loc_after, msg) ->
                     if Location.compare loc_before Location.none = 0 then
                       Format.fprintf fmt
-                        "%!@{<loc>%a@}:@,@{<error>Error@}: Docstring (** \
-                         %s *) added.\n\
+                        "%!@{<loc>%a@}:@,\
+                         @{<error>Error@}: Docstring (** %s *) added.\n\
                          %!"
                         Location.print_loc loc_after (ellipsis_cmt msg)
                     else if Location.compare loc_after Location.none = 0
                     then
                       Format.fprintf fmt
-                        "%!@{<loc>%a@}:@,@{<error>Error@}: Docstring (** \
-                         %s *) dropped.\n\
+                        "%!@{<loc>%a@}:@,\
+                         @{<error>Error@}: Docstring (** %s *) dropped.\n\
                          %!"
                         Location.print_loc loc_before (ellipsis_cmt msg)
                     else
                       Format.fprintf fmt
-                        "%!@{<loc>%a@}:@,@{<error>Error@}: Docstring (** \
-                         %s *) moved to @{<loc>%a@}.\n\
+                        "%!@{<loc>%a@}:@,\
+                         @{<error>Error@}: Docstring (** %s *) moved to \
+                         @{<loc>%a@}.\n\
                          %!"
                         Location.print_loc loc_before (ellipsis_cmt msg)
                         Location.print_loc loc_after
                 | Normalize.Unstable (loc, s) ->
                     Format.fprintf fmt
-                      "%!@{<loc>%a@}:@,@{<error>Error@}: Formatting of (** \
-                       %s *) is unstable (e.g. parses as a list or not \
-                       depending on the margin), please tighten up this \
-                       comment in the source or disable the formatting \
-                       using the option --no-parse-docstrings.\n\
+                      "%!@{<loc>%a@}:@,\
+                       @{<error>Error@}: Formatting of (** %s *) is \
+                       unstable (e.g. parses as a list or not depending on \
+                       the margin), please tighten up this comment in the \
+                       source or disable the formatting using the option \
+                       --no-parse-docstrings.\n\
                        %!"
                       Location.print_loc loc (ellipsis_cmt s))
           | `Comment_dropped l when not conf.Conf.quiet ->
               List.iter l ~f:(fun (loc, msg) ->
                   Format.fprintf fmt
-                    "%!@{<loc>%a@}:@,@{<error>Error@}: Comment (* %s *) \
-                     dropped.\n\
+                    "%!@{<loc>%a@}:@,\
+                     @{<error>Error@}: Comment (* %s *) dropped.\n\
                      %!"
                     Location.print_loc loc (ellipsis_cmt msg))
           | `Cannot_parse ((Syntaxerr.Error _ | Lexer.Error _) as exn) ->
diff --git a/infer/src/backend/BackendStats.ml b/infer/src/backend/BackendStats.ml
index 3b685cdf1..7bf521356 100644
--- a/infer/src/backend/BackendStats.ml
+++ b/infer/src/backend/BackendStats.ml
@@ -95,8 +95,12 @@ let pp f stats =
   in
   F.fprintf f
     "@[Backend stats:@\n\
-     @[<v2>  file_try_load= %d@;read_from_disk= %d@;cache_hits= %d (%t)@;cache_misses= \
-     %d@;has_model_queries= %d@;@]@]@."
+     @[<v2>  file_try_load= %d@;\
+     read_from_disk= %d@;\
+     cache_hits= %d (%t)@;\
+     cache_misses= %d@;\
+     has_model_queries= %d@;\
+     @]@]@."
     summary_file_try_load summary_read_from_disk summary_cache_hits
     (pp_hit_percent summary_cache_hits summary_cache_misses)
     summary_cache_misses summary_has_model_queries
diff --git a/infer/src/pulse/PulseAbductiveDomain.ml b/infer/src/pulse/PulseAbductiveDomain.ml
index a71ce4b8d..b95ced5be 100644
--- a/infer/src/pulse/PulseAbductiveDomain.ml
+++ b/infer/src/pulse/PulseAbductiveDomain.ml
@@ -326,8 +326,11 @@ module PrePost = struct
 
   let pp_call_state fmt {astate; subst; rev_subst; visited} =
     F.fprintf fmt
-      "@[<v>{ astate=@[<hv2>%a@];@, subst=@[<hv2>%a@];@, rev_subst=@[<hv2>%a@];@, \
-       visited=@[<hv2>%a@]@, }@]"
+      "@[<v>{ astate=@[<hv2>%a@];@,\
+      \ subst=@[<hv2>%a@];@,\
+      \ rev_subst=@[<hv2>%a@];@,\
+      \ visited=@[<hv2>%a@]@,\
+      \ }@]"
       pp astate
       (AddressMap.pp ~pp_value:AbstractAddress.pp)
       subst

Copy link
Copy Markdown
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

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

I agree newlines-and-wrap is better than newlines and wrap and could have been the default.
But this is a huge breaking change. What do you think of using newlines-and-wrap as default and deprecating the option, to be removed in the release after ?
If we want to reduce the number of options we will need a depreciation mechanism and the feedback from users will help us sanitize the options without breaking their workflow.

@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented Jul 25, 2019

I deprecated the option but kept the values. I'm sure we could factorize the functions defined in Config_option, but it could be done in another PR.

@gpetiot gpetiot requested a review from Julow July 25, 2019 06:36
Copy link
Copy Markdown
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

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

We should print a warning when the option is set on the command line or in an .ocamlformat file. Otherwise users won't notice.

@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented Jul 26, 2019

I added a warning, and checked it is printed when the option is set with command line, attributes, .ocamlformat files or environment, but not with a preset profile.

@gpetiot gpetiot merged commit 2b985af into ocaml-ppx:master Jul 26, 2019
@gpetiot gpetiot deleted the break-string-literals branch July 26, 2019 04:00
@gpetiot gpetiot mentioned this pull request Jul 31, 2019
12 tasks
@Wilfred
Copy link
Copy Markdown
Contributor

Wilfred commented Oct 8, 2019

FWIW this is a feature we definitely want to keep using. We use break-string-literals = never and our tests are much less readable if we allow ocamlformat to reformat strings:

-let sum = "<?hh
-function sum($a, $b) {
-  return $a + $b;
-}"
+let sum = "<?hh\nfunction sum($a, $b) {\n  return $a + $b;\n}"
 let a_contents =
-  "<?hh // strict
-
-type my_shape = shape(
-  'outer' => shape(
-    B::KEY => string
-  ),
-);
-"
-
-let b_contents = "<?hh // strict
-class B {
-  const string KEY = \"KEY\";
-}
-"
+  "<?hh // strict\n\n\
+   type my_shape = shape(\n\
+  \  'outer' => shape(\n\
+  \    B::KEY => string\n\
+  \  ),\n\
+   );\n"
+
+let b_contents =
+  "<?hh // strict\nclass B {\n  const string KEY = \"KEY\";\n}\n"
     | SMUtils.Server_dormant_out_of_retries ->
       Printf.eprintf
-        ( "Ran out of retries while waiting for Mercurial to finish rebase. Starting "
-        ^^ "the server in the middle of rebase is strongly not recommended and you should "
+        ( "Ran out of retries while waiting for Mercurial to finish rebase. \
+           Starting "
+        ^^ "the server in the middle of rebase is strongly not recommended \
+            and you should "
         ^^ "first finish the rebase before retrying. If you really "

I'd assumed 'deprecated' meant "there's a newer option that does this" but it looks like the intent is "we plan to remove this option"?

@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented Oct 8, 2019

Yes we planned to remove this option and not replace it.

To explain further, the new policy we would like to enforce is to have less options to maintain, as it is getting more and more difficult to maintain it, and we often encounter weird bugs with specific combinations of some options.

One of the goal of ocamlformat is to enforce a unique style (or at least very few number of styles), but it seems like everyone wants their own style to be the unique style, or at least to have an option for it, negating this goal and again, too many options makes it difficult to maintain and improve this tool.

This option has been the first victim of this policy, but since this option is not especially difficult to maintain we can revert this one (@Julow what do you think?).

@Julow
Copy link
Copy Markdown
Collaborator

Julow commented Oct 8, 2019

It may make sense to keep the option, with never and newlines-and-wrap only.

@Wilfred For this you should use {| .. |} quotes, they won't be wrapped. It formats like this:

let a_contents =
  {|<?hh // strict

type my_shape = shape(
  'outer' => shape(
    B::KEY => string
  ),
);
|}

For your last example, it's because of the margin, you should let the string wrap:

    | SMUtils.Server_dormant_out_of_retries ->
        Printf.eprintf
          "Ran out of retries while waiting for Mercurial to finish rebase. \
           Starting the server in the middle of rebase is strongly not \
           recommended and you should first finish the rebase before \
           retrying. If you really "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants