From 80e8751007814222149d58de1f4496cf7604d819 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philip=20H=C3=B6lzenspies?= Date: Tue, 3 Oct 2017 06:10:49 -0700 Subject: [PATCH] All pragmas are leading Summary: Like D5855548, but extend it to other pragmas, because ``` $x = /* HH_IGNORE_ERROR[2050]: using $GLOBALS */ idx($GLOBALS, 'FOO', ''); ``` happens. Differential Revision: D5910968 fbshipit-source-id: 9579291c69ce3b38368ee170d5c4ed0bc30bc75a --- hphp/hack/src/hackfmt/hack_format.ml | 11 ++++++++++- hphp/hack/src/parser/full_fidelity_lexer.ml | 8 ++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/hphp/hack/src/hackfmt/hack_format.ml b/hphp/hack/src/hackfmt/hack_format.ml index 42d31fa17fe..6749d1f8c33 100644 --- a/hphp/hack/src/hackfmt/hack_format.ml +++ b/hphp/hack/src/hackfmt/hack_format.ml @@ -2280,8 +2280,17 @@ let transform (env: Env.t) (node: Syntax.t) : Doc.t = let tl = List.tl_exn delimited_lines in let hd = Comment (hd, (String.length hd)) in + let should_break = + match Trivia.kind triv with + | TriviaKind.UnsafeExpression + | TriviaKind.FixMe + | TriviaKind.IgnoreError + -> false + | _ -> !currently_leading + in + last_comment := Some (Concat [ - if !currently_leading then Newline + if should_break then Newline else if preceded_by_whitespace then Space else Nothing; Concat (hd :: List.map tl ~f:map_tail); diff --git a/hphp/hack/src/parser/full_fidelity_lexer.ml b/hphp/hack/src/parser/full_fidelity_lexer.ml index afbc8886fa5..e3a4f220359 100644 --- a/hphp/hack/src/parser/full_fidelity_lexer.ml +++ b/hphp/hack/src/parser/full_fidelity_lexer.ml @@ -1252,7 +1252,8 @@ we use are: * The first newline trivia encountered is the last trailing trivia. * The newline which follows a // or # comment is not part of the comment but does terminate the trailing trivia. -* An /*UNSAFE_EXPR*/ is always a leading trivia. +* A pragma to turn checks off (HH_FIXME, HH_IGNORE_ERROR and UNSAFE_EXPR) is +* always a leading trivia. *) let scan_leading_trivia scanner lexer = @@ -1278,7 +1279,10 @@ let scan_trailing_trivia scanner lexer = | Some t -> begin match t.Trivia.kind with | TriviaKind.EndOfLine -> (lexer1, t :: acc) - | TriviaKind.UnsafeExpression -> (lexer, acc) + | TriviaKind.FixMe + | TriviaKind.IgnoreError + | TriviaKind.UnsafeExpression + -> (lexer, acc) | _ -> aux lexer1 (t :: acc) end in let (lexer, trivia_list) = aux lexer [] in -- 2.11.4.GIT