Skip to content

Commit

Permalink
silence GRA-STRING-002
Browse files Browse the repository at this point in the history
  • Loading branch information
dawedawe committed Oct 12, 2023
1 parent e47d96e commit 1955eab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
14 changes: 10 additions & 4 deletions src/Fantomas.Core/ASTTransformer.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module internal rec Fantomas.Core.ASTTransformer

open System.Collections.Generic
open System.Globalization
open System.Text.RegularExpressions
open Fantomas.FCS.Text
open Fantomas.FCS.Text.Range
Expand Down Expand Up @@ -485,7 +486,9 @@ let (|SameInfixApps|_|) expr =
match expr with
| InfixApp(_, operator, _) ->
let isRight =
Set.exists (fun (rOp: string) -> operator.Text.StartsWith(rOp)) rightOperators
Set.exists
(fun (rOp: string) -> operator.Text.StartsWith(rOp, false, CultureInfo.InvariantCulture))
rightOperators

let head, xs =
if isRight then
Expand Down Expand Up @@ -1497,7 +1500,7 @@ let mkExpr (creationAide: CreationAide) (e: SynExpr) : Expr =
stn
(creationAide.TextFromSource
(fun () ->
if idx = 0 && not (v.StartsWith("$")) then
if idx = 0 && not (v.StartsWith("$", false, CultureInfo.InvariantCulture)) then
$"$\"%s{v}{{"
elif idx = lastIndex && not (v.EndsWith("\"")) then
$"}}%s{v}\""
Expand Down Expand Up @@ -1548,7 +1551,7 @@ let mkExpr (creationAide: CreationAide) (e: SynExpr) : Expr =
let hasSpaces =
let rec (|AtomicExpr|_|) e =
match e with
| ConstNumberExpr(v, _) when v.StartsWith("-") -> None
| ConstNumberExpr(v, _) when v.StartsWith("-", false, CultureInfo.InvariantCulture) -> None
| SynExpr.Ident _
| SynExpr.Const(SynConst.Int32 _, _)
| SynExpr.IndexRange(expr1 = Some(AtomicExpr _); expr2 = Some(AtomicExpr _))
Expand Down Expand Up @@ -1598,7 +1601,10 @@ let mkExprQuote creationAide isRaw e range : ExprQuoteNode =
let (|ParenStarSynIdent|_|) =
function
| IdentTrivia.OriginalNotationWithParen(lpr, originalNotation, rpr) ->
if originalNotation.Length > 1 && originalNotation.StartsWith("*") then
if
originalNotation.Length > 1
&& originalNotation.StartsWith("*", false, CultureInfo.InvariantCulture)
then
Some(lpr, originalNotation, rpr)
else
None
Expand Down
18 changes: 12 additions & 6 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module internal rec Fantomas.Core.CodePrinter

open System
open System.Globalization
open Fantomas.Core.Context
open Fantomas.Core.SyntaxOak
open Microsoft.FSharp.Core.CompilerServices
Expand Down Expand Up @@ -750,7 +751,9 @@ let genExpr (e: Expr) =

match node.Expr with
| Expr.Constant _
| Expr.InterpolatedStringExpr _ when not (node.Operator.Text.StartsWith("%")) ->
| Expr.InterpolatedStringExpr _ when
not (node.Operator.Text.StartsWith("%", false, CultureInfo.InvariantCulture))
->
genSingleTextNode node.Operator +> sepSpace +> genExpr node.Expr
| Expr.AppSingleParenArg appNode ->
genSingleTextNode node.Operator
Expand Down Expand Up @@ -1838,7 +1841,7 @@ let genArrayOrList (preferMultilineCramped: bool) (node: ExprArrayOrListNode) =
let (|YieldLikeExpr|_|) e =
match e with
| Expr.Single singleNode ->
if singleNode.Leading.Text.StartsWith("yield") then
if singleNode.Leading.Text.StartsWith("yield", false, CultureInfo.InvariantCulture) then
Some e
else
None
Expand Down Expand Up @@ -2260,7 +2263,7 @@ let colGenericTypeParameters typeParameters =
coli sepComma typeParameters (fun idx t ->
let leadingSpace =
match t with
| Type.Var n when idx = 0 && n.Text.StartsWith("^") -> sepSpace
| Type.Var n when idx = 0 && n.Text.StartsWith("^", false, CultureInfo.InvariantCulture) -> sepSpace
| _ -> sepNone

leadingSpace +> genType t)
Expand Down Expand Up @@ -2511,7 +2514,10 @@ let genPatLeftMiddleRight (node: PatLeftMiddleRight) =

let genTyparDecl (isFirstTypeParam: bool) (td: TyparDeclNode) =
genOnelinerAttributes td.Attributes
+> onlyIf (isFirstTypeParam && td.TypeParameter.Text.StartsWith("^")) sepSpace
+> onlyIf
(isFirstTypeParam
&& td.TypeParameter.Text.StartsWith("^", false, CultureInfo.InvariantCulture))
sepSpace
+> genSingleTextNode td.TypeParameter
|> genNode td

Expand Down Expand Up @@ -3105,7 +3111,7 @@ let genType (t: Type) =
let addExtraSpace =
match node.Arguments with
| [] -> sepNone
| Type.Var node :: _ when node.Text.StartsWith "^" -> sepSpace
| Type.Var node :: _ when node.Text.StartsWith("^", false, CultureInfo.InvariantCulture) -> sepSpace
| t :: _ -> addSpaceIfSynTypeStaticConstantHasAtSignBeforeString t

genType node.Identifier
Expand Down Expand Up @@ -3207,7 +3213,7 @@ let addSpaceIfSynTypeStaticConstantHasAtSignBeforeString (t: Type) =
match t with
| Type.StaticConstant sc ->
match sc with
| Constant.FromText node -> onlyIf (node.Text.StartsWith("@")) sepSpace
| Constant.FromText node -> onlyIf (node.Text.StartsWith("@", false, CultureInfo.InvariantCulture)) sepSpace
| _ -> sepNone
| _ -> sepNone

Expand Down
5 changes: 3 additions & 2 deletions src/Fantomas.Core/Trivia.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module internal Fantomas.Core.Trivia

open System.Globalization
open Fantomas.FCS.Syntax
open Fantomas.FCS.SyntaxTrivia
open Fantomas.FCS.Text
Expand Down Expand Up @@ -46,9 +47,9 @@ let internal collectTriviaFromCodeComments
let content =
let trimmedLine = line.TrimStart(' ', ';')

if index = 0 && trimmedLine.StartsWith("#!") then // shebang
if index = 0 && trimmedLine.StartsWith("#!", false, CultureInfo.InvariantCulture) then // shebang
CommentOnSingleLine content
else if trimmedLine.StartsWith("//") then
else if trimmedLine.StartsWith("//", false, CultureInfo.InvariantCulture) then
CommentOnSingleLine content
else
LineCommentAfterSourceCode content
Expand Down

0 comments on commit 1955eab

Please sign in to comment.