Skip to content

Commit

Permalink
silence the GRA-INTERPOLATED-001 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dawedawe committed Dec 20, 2023
1 parent 47e5197 commit 268f88e
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/Fantomas.Client.Tests/EndToEndTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type EndToEndTests() =

do!
dotnet
$"tool install fantomas -v d --version {version} --add-source https://api.nuget.org/v3/index.json"
$"tool install fantomas -v d --version %s{version} --add-source https://api.nuget.org/v3/index.json"

let fsharpFile = Path.Combine(subDirectory.FullName, "File.fs")
File.Create(fsharpFile).Dispose()
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Client/FantomasToolLocator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ let createFor (startInfo: FantomasToolStartInfo) : Result<RunningFantomasTool, P
let error =
if daemonProcess.HasExited then
let stdErr = daemonProcess.StandardError.ReadToEnd()
$"Daemon std error: {stdErr}.\nJsonRpc exception:{ex.Message}"
$"Daemon std error: %s{stdErr}.\nJsonRpc exception:%s{ex.Message}"
else
ex.Message

Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Client/LSPFantomasService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ let private daemonNotFoundResponse filePath (error: GetDaemonError) : Task<Fanto
workingDirectory,
pathEnvironmentVariable,
error)) ->
$"Fantomas.Client tried to run `%s{executableFile} %s{arguments}` inside working directory \"{workingDirectory}\" but could not find \"%s{executableFile}\" on the PATH (%s{pathEnvironmentVariable}). Error: %s{error}",
$"Fantomas.Client tried to run `%s{executableFile} %s{arguments}` inside working directory \"%s{workingDirectory}\" but could not find \"%s{executableFile}\" on the PATH (%s{pathEnvironmentVariable}). Error: %s{error}",
FantomasResponseCode.DaemonCreationFailed
| GetDaemonError.DotNetToolListError(DotNetToolListError.ProcessStartError(ProcessStartError.UnExpectedException(executableFile,
arguments,
Expand All @@ -205,7 +205,7 @@ let private daemonNotFoundResponse filePath (error: GetDaemonError) : Task<Fanto
arguments,
exitCode,
error)) ->
$"Fantomas.Client tried to run `%s{executableFile} %s{arguments}` but exited with code {exitCode} {error}",
$"Fantomas.Client tried to run `%s{executableFile} %s{arguments}` but exited with code %i{exitCode} %s{error}",
FantomasResponseCode.DaemonCreationFailed
| GetDaemonError.InCompatibleVersionFound ->
"Fantomas.Client did not found a compatible dotnet tool version to launch as daemon process",
Expand Down
8 changes: 4 additions & 4 deletions src/Fantomas.Core.Tests/CodePrinterHelperFunctionsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let ``!- add a single WriterEvent.Write`` () =

match events with
| [ Write "one new event" ] -> Assert.Pass()
| events -> Assert.Fail $"Expected one event, got: ${events}"
| events -> Assert.Fail $"Expected one event, got: %A{events}"

[<Test>]
let ``+> will compose two functions`` () =
Expand Down Expand Up @@ -125,7 +125,7 @@ let ``traversing collections`` () =
let items = [ 2; 3; 4 ]
// The `col` function will traverse the collection and apply the first function between elements and the last function for each individual element.
let f (items: int seq) : Context -> Context =
col (!- " + ") items (fun (item: int) -> !- $"{item}")
col (!- " + ") items (fun (item: int) -> !- $"%i{item}")

// Note that there are some variants of `col` that can be used to process a collection in a different way.
// coli, colEx, ...
Expand Down Expand Up @@ -170,7 +170,7 @@ let ``newlines and indentation`` () =

match events with
| [ Write "first line"; IndentBy 4; WriteLine; Write "second line"; UnIndentBy 4 ] -> Assert.Pass()
| events -> Assert.Fail $"Expected one event, got: ${events}"
| events -> Assert.Fail $"Expected one event, got: %A{events}"

[<Test>]
let ``trying multiple code paths`` () =
Expand Down Expand Up @@ -493,7 +493,7 @@ let ``locking the indentation at a fixed column`` () =
WriterEvent.RestoreAtColumn 0
WriterEvent.RestoreIndent 0
WriterEvent.Write ")" ] -> Assert.Pass()
| events -> Assert.Fail $"Expected one event, got: ${events}"
| events -> Assert.Fail $"Expected one event, got: %A{events}"

// There is also a variation of `atCurrentColumn`: `atCurrentColumnIndent`
// This locks the column and also applies indentation from that column.
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Core.Tests/InterpolatedStringTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ let ``very long triple-quoted strings do not cause the interpolated string activ
1000
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n\n"

formatSourceString $"let value = \"\"\"{loremIpsum}\"\"\"" config
formatSourceString $"let value = \"\"\"%s{loremIpsum}\"\"\"" config
|> should
equal
$"let value =
\"\"\"{loremIpsum}\"\"\"
\"\"\"%s{loremIpsum}\"\"\"
"
4 changes: 2 additions & 2 deletions src/Fantomas.Core.Tests/OperatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,14 +1204,14 @@ let operator_application_literal_values =
let ``operators maintain spacing from literal values`` (literalValue: string) =
formatSourceString
$"""
let subtractTwo = + {literalValue}
let subtractTwo = + %s{literalValue}
"""
config
|> prepend newline
|> should
equal
$"""
let subtractTwo = + {literalValue}
let subtractTwo = + %s{literalValue}
"""
[<Test>]
Expand Down
32 changes: 16 additions & 16 deletions src/Fantomas.Core/ASTTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let mkIdent (ident: Ident) =
let text =
if ident.idText.Length + 4 = width then
// add backticks
$"``{ident.idText}``"
$"``%s{ident.idText}``"
else
ident.idText

Expand All @@ -39,8 +39,8 @@ let mkSynIdent (SynIdent(ident, trivia)) =
match trivia with
| None -> mkIdent ident
| Some(IdentTrivia.OriginalNotation text) -> stn text ident.idRange
| Some(IdentTrivia.OriginalNotationWithParen(_, text, _)) -> stn $"({text})" ident.idRange
| Some(IdentTrivia.HasParenthesis _) -> stn $"({ident.idText})" ident.idRange
| Some(IdentTrivia.OriginalNotationWithParen(_, text, _)) -> stn $"(%s{text})" ident.idRange
| Some(IdentTrivia.HasParenthesis _) -> stn $"(%s{ident.idText})" ident.idRange

let mkSynLongIdent (sli: SynLongIdent) =
match sli.IdentsWithTrivia with
Expand Down Expand Up @@ -148,7 +148,7 @@ let mkConstant (creationAide: CreationAide) c r : Constant =
let content =
System.String(Array.map (fun (byte: byte) -> System.Convert.ToChar(byte)) bytes)

$"\"{content}\"B"
$"\"%s{content}\"B"

stn (creationAide.TextFromSource fallback r) r |> Constant.FromText
| SynConst.Measure(c, numberRange, measure, trivia) ->
Expand Down Expand Up @@ -377,7 +377,7 @@ let mkSynMatchClause creationAide (SynMatchClause(p, eo, e, range, _, trivia)) :
let arrowRange =
match trivia.ArrowRange with
| Some r -> r
| None -> failwith $"unable to get the arrow range from trivia in {nameof mkSynMatchClause}"
| None -> failwith $"unable to get the arrow range from trivia in %s{nameof mkSynMatchClause}"

MatchClauseNode(
Option.map (stn "|") trivia.BarRange,
Expand Down Expand Up @@ -1512,7 +1512,7 @@ let mkExpr (creationAide: CreationAide) (e: SynExpr) : Expr =
elif idx = lastIndex && not (String.endsWithOrdinal "\"" v) then
$"}}%s{v}\""
else
$"}}{v}{{")
$"}}%s{v}{{")
r)
r
|> Choice1Of2
Expand Down Expand Up @@ -1642,7 +1642,7 @@ let mkPat (creationAide: CreationAide) (p: SynPat) =
match p with
| SynPat.OptionalVal(ident, _) ->
let identNode = mkIdent ident
SingleTextNode($"?{identNode.Text}", patternRange) |> Pattern.OptionalVal
SingleTextNode($"?%s{identNode.Text}", patternRange) |> Pattern.OptionalVal
| PatParameter(ats, pat, t) ->
PatParameterNode(
mkAttributes creationAide ats,
Expand Down Expand Up @@ -1745,7 +1745,7 @@ let mkPat (creationAide: CreationAide) (p: SynPat) =
|> Pattern.IsInst
| SynPat.QuoteExpr(SynExpr.Quote(_, isRaw, e, _, _), _) ->
mkExprQuote creationAide isRaw e patternRange |> Pattern.QuoteExpr
| pat -> failwith $"unexpected pattern: {pat}"
| pat -> failwith $"unexpected pattern: %A{pat}"

let mkBindingReturnInfo creationAide (returnInfo: SynBindingReturnInfo option) =
Option.bind
Expand All @@ -1759,7 +1759,7 @@ let mkBindingReturnInfo creationAide (returnInfo: SynBindingReturnInfo option) =
let (|OperatorWithStar|_|) (si: SynIdent) =
match si with
| SynIdent(ident, Some(ParenStarSynIdent(_, text, _))) ->
Some(IdentifierOrDot.Ident(stn $"( {text} )" ident.idRange))
Some(IdentifierOrDot.Ident(stn $"( %s{text} )" ident.idRange))
| _ -> None

let mkBinding
Expand Down Expand Up @@ -1802,7 +1802,7 @@ let mkBinding
let equalsRange =
match trivia.EqualsRange with
| Some r -> r
| None -> failwith $"failed to get equals range in {nameof mkBinding}"
| None -> failwith $"failed to get equals range in %s{nameof mkBinding}"

stn "=" equalsRange

Expand Down Expand Up @@ -1910,7 +1910,7 @@ let mkExternBinding
|> List.mapWithLast id (function
| IdentifierOrDot.KnownDot dot -> IdentifierOrDot.KnownDot dot
| IdentifierOrDot.UnknownDot -> IdentifierOrDot.UnknownDot
| IdentifierOrDot.Ident ident -> IdentifierOrDot.Ident(stn $"{ident.Text}{suffix}" ident.Range))
| IdentifierOrDot.Ident ident -> IdentifierOrDot.Ident(stn $"%s{ident.Text}%s{suffix}" ident.Range))

Type.LongIdent(IdentListNode(lidPieces, t.Range))
| SynType.App(typeName = typeName; isPostfix = true; typeArgs = [ argType ]) ->
Expand Down Expand Up @@ -2101,13 +2101,13 @@ let mkSynTypar (SynTypar(ident, req, _)) =
let width = ident.idRange.EndColumn - ident.idRange.StartColumn
// 5 because of ^ or ' and `` on each side
if ident.idText.Length + 5 = width then
$"``{ident.idText}``"
$"``%s{ident.idText}``"
else
ident.idText

match req with
| TyparStaticReq.None -> stn $"'{identText}" range
| TyparStaticReq.HeadType -> stn $"^{identText}" range
| TyparStaticReq.None -> stn $"'%s{identText}" range
| TyparStaticReq.HeadType -> stn $"^%s{identText}" range

let mkSynTypeConstraint (creationAide: CreationAide) (tc: SynTypeConstraint) : TypeConstraint =
match tc with
Expand Down Expand Up @@ -2259,7 +2259,7 @@ let mkType (creationAide: CreationAide) (t: SynType) : Type =
if not isOptional then
identNode
else
SingleTextNode($"?{identNode.Text}", ident.idRange))
SingleTextNode($"?%s{identNode.Text}", ident.idRange))

TypeSignatureParameterNode(mkAttributes creationAide attrs, identNode, mkType creationAide t, typeRange)
|> Type.SignatureParameter
Expand All @@ -2286,7 +2286,7 @@ let mkType (creationAide: CreationAide) (t: SynType) : Type =
yield Choice1Of2(mkType creationAide t) ]

TypeIntersectionNode(typesAndSeparators, m) |> Type.Intersection
| t -> failwith $"unexpected type: {t}"
| t -> failwith $"unexpected type: %A{t}"

let rec (|OpenL|_|) =
function
Expand Down
6 changes: 3 additions & 3 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ let genSingleTextNodeWithSpaceSuffix (addSpace: Context -> Context) (node: Singl
let genSingleTextNodeSuffixDelimiter (node: SingleTextNode) =
genSingleTextNodeWithSpaceSuffix addSpaceIfSpaceAroundDelimiter node

let genSingleTextNodeWithLeadingDot (node: SingleTextNode) = !- $".{node.Text}" |> genNode node
let genSingleTextNodeWithLeadingDot (node: SingleTextNode) = !- $".%s{node.Text}" |> genNode node

let genMultipleTextsNode (node: MultipleTextsNode) =
col sepSpace node.Content genSingleTextNode |> genNode node
Expand Down Expand Up @@ -2074,7 +2074,7 @@ let genClause (isLastItem: bool) (node: MatchClauseNode) =
// In the weird case where the arrow has content before it and there is no multiline whenExpr,
// we need to ensure a space was written before the arrow to avoid offset errors.
// See https://github.com/fsprojects/fantomas/issues/2888
!- $" {node.Arrow.Text} " |> genNode node.Arrow
!- $" %s{node.Arrow.Text} " |> genNode node.Arrow

(sepArrow
+> ifElse
Expand Down Expand Up @@ -3052,7 +3052,7 @@ let genTypeConstraint (tc: TypeConstraint) =
| TypeConstraint.EnumOrDelegate node ->
genSingleTextNode node.Typar
+> sepColon
+> !- $"{node.Verb}<"
+> !- $"%s{node.Verb}<"
+> col sepComma node.Types genType
+> !- ">"
|> genNode node
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Core/MultipleDefineCombinations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ let mergeMultipleFormatResults config (results: (DefineCombination * FormatResul
FormatException(
$"""Fantomas is trying to format the input multiple times due to the detection of multiple defines.
There is a problem with merging all the code back together.
{chunkReport}
%s{chunkReport}
Please raise an issue at https://fsprojects.github.io/fantomas-tools/#/fantomas/preview."""
)
)
Expand Down
6 changes: 3 additions & 3 deletions src/Fantomas.Tests/IgnoreFileTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ let ``IgnoreFile.find preferentially finds the fantomasignore next to the source
let ignoreFile =
match IgnoreFile.find fs loadIgnoreList source with
| Some f -> f
| None -> failwith $"calling {nameof IgnoreFile.find} failed"
| None -> failwith $"calling %s{nameof IgnoreFile.find} failed"

ignoreFile.Location.FullName |> shouldEqual target
getLoads () |> shouldEqual (Set.ofList [ target ])
Expand All @@ -126,7 +126,7 @@ let ``IgnoreFile.find can find the fantomasignore one layer up from the source f
let ignoreFile =
match IgnoreFile.find fs loadIgnoreList source with
| Some f -> f
| None -> failwith $"calling {nameof IgnoreFile.find} failed"
| None -> failwith $"calling %s{nameof IgnoreFile.find} failed"

ignoreFile.Location.FullName |> shouldEqual target
getLoads () |> shouldEqual (Set.ofList [ target ])
Expand All @@ -152,7 +152,7 @@ let ``IgnoreFile.current' does not load more than once`` () =
let forced =
match ignoreFile.Force() with
| Some f -> f
| None -> failwith $"calling {nameof ignoreFile.Force} failed"
| None -> failwith $"calling %s{nameof ignoreFile.Force} failed"

forced.Location.FullName |> shouldEqual target
// The second invocation would throw if we were somehow getting the
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/Integration/ConfigTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let ``uses end_of_line setting to write user newlines`` setting =
let newline =
match EndOfLineStyle.OfConfigString setting with
| Some nl -> nl.NewLineString
| None -> failwith $"unable to get {nameof EndOfLineStyle.OfConfigString}"
| None -> failwith $"unable to get %s{nameof EndOfLineStyle.OfConfigString}"

let sampleCode nln =
sprintf "let a = 9%s%slet b = 7%s" nln nln nln
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/Integration/ForceTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let ``code that was invalid should be still be written`` () =
use outputFixture = new OutputFile()

let { ExitCode = exitCode; Output = output } =
runFantomasTool $"{Verbosity} --force --out {outputFixture.Filename} {sourceFile}"
runFantomasTool $"%s{Verbosity} --force --out %s{outputFixture.Filename} %s{sourceFile}"

exitCode |> should equal 0
output |> should contain "was not valid after formatting"
Expand Down
18 changes: 9 additions & 9 deletions src/Fantomas/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ let private hasByteOrderMark file =
return false
}

let private invalidResultException file =
FormatException($"Formatting {file} leads to invalid F# code")
let private invalidResultException (file: string) =
FormatException($"Formatting %s{file} leads to invalid F# code")

/// Format a source string using given config and write to a text writer
let processSourceString (force: bool) (profile: bool) s (fileName: string) config =
Expand Down Expand Up @@ -363,7 +363,7 @@ let main argv =
(oks, ignores, unchanged, (file, ex) :: errors))

let reportFormatResults (results: #(FormatResult seq)) =
let reportError (file, exn: Exception) =
let reportError (file: string, exn: Exception) =
let message =
match verbosity with
| VerbosityLevel.Normal ->
Expand All @@ -377,9 +377,9 @@ let main argv =
if String.IsNullOrEmpty message then
message
else
$" : {message}"
$" : %s{message}"

elog $"Failed to format file: {file}{message}"
elog $"Failed to format file: %s{file}%s{message}"

let reportProfileInfos (results: (string * ProfileInfo option) list) =
if profile && not (List.isEmpty results) then
Expand All @@ -400,16 +400,16 @@ let main argv =

let reportProfileInfo (f, p: ProfileInfo option) =
match profile, p with
| true, Some pI -> stdlog $"%s{f} Line count: %d{pI.LineCount} Time taken {pI.TimeTaken}"
| true, Some pI -> stdlog $"%s{f} Line count: %d{pI.LineCount} Time taken %A{pI.TimeTaken}"
| _ -> ()

match singleResult with
| FormatResult.Formatted(f, _, p) ->
stdlog $"{fileName f} was formatted."
stdlog $"%s{fileName f} was formatted."
reportProfileInfo (f, p)
| FormatResult.IgnoredFile f -> stdlog $"{fileName f} was ignored."
| FormatResult.IgnoredFile f -> stdlog $"%s{fileName f} was ignored."
| FormatResult.Unchanged(f, p) ->
stdlog $"{fileName f} was unchanged."
stdlog $"%s{fileName f} was unchanged."
reportProfileInfo (f, p)
| FormatResult.Error(f, e) ->
reportError (fileName f, e)
Expand Down

0 comments on commit 268f88e

Please sign in to comment.