Skip to content

Commit

Permalink
Format with Fantomas 4.4.0-alpha-004. (#1312)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Dec 22, 2020
1 parent f924f58 commit aac3975
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 229 deletions.
2 changes: 1 addition & 1 deletion build.fsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#r "paket:
nuget Fantomas.Extras 4.4.0-alpha-003
nuget Fantomas.Extras 4.4.0-alpha-004
nuget Microsoft.Azure.Cosmos.Table
nuget Fake.BuildServer.AppVeyor
nuget Fake.Core.ReleaseNotes
Expand Down
6 changes: 3 additions & 3 deletions build.fsx.lock
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ NUGET
Fake.Core.Trace (>= 5.20.3)
Fake.IO.FileSystem (>= 5.20.3)
FSharp.Core (>= 4.7.2)
Fantomas (4.4.0-alpha-003)
Fantomas (4.4.0-alpha-004)
FSharp.Compiler.Service (>= 38.0)
FSharp.Core (>= 5.0)
Fantomas.Extras (4.4.0-alpha-003)
Fantomas.Extras (4.4.0-alpha-004)
editorconfig (>= 0.12.2)
Fantomas (>= 4.4.0-alpha-003)
Fantomas (>= 4.4.0-alpha-004)
FSharp.Core (>= 5.0)
MAB.DotIgnore (>= 3.0.2)
FParsec (1.1.1)
Expand Down
11 changes: 6 additions & 5 deletions src/Fantomas.Extras/FakeHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ let createParsingOptionsFromFile fileName =
{ FSharpParsingOptions.Default with
SourceFiles = [| fileName |] }

let private formatContentInternalAsync (compareWithoutLineEndings: bool)
(config: FormatConfig)
(file: string)
(originalContent: string)
: Async<FormatResult> =
let private formatContentInternalAsync
(compareWithoutLineEndings: bool)
(config: FormatConfig)
(file: string)
(originalContent: string)
: Async<FormatResult> =
if IgnoreFile.isIgnoredFile file then
async { return IgnoredFile file }
else
Expand Down
15 changes: 9 additions & 6 deletions src/Fantomas.Tests/FormatAstTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ let b = 1"""
let b = 1"""

[<Test>]
let ``default implementations in abstract classes should be emited as override from AST without origin source, 742`` ()
=
let ``default implementations in abstract classes should be emited as override from AST without origin source, 742``
()
=
"""[<AbstractClass>]
type Foo =
abstract foo: int
Expand All @@ -93,8 +94,9 @@ type Foo =
override __.foo = 1"""

[<Test>]
let ``default implementations in abstract classes with `default` keyword should be emited as it was before from AST with origin source, 742`` ()
=
let ``default implementations in abstract classes with `default` keyword should be emited as it was before from AST with origin source, 742``
()
=
"""[<AbstractClass>]
type Foo =
abstract foo: int
Expand All @@ -108,8 +110,9 @@ type Foo =
default __.foo = 1"""

[<Test>]
let ``default implementations in abstract classes with `override` keyword should be emited as it was before from AST with origin source, 742`` ()
=
let ``default implementations in abstract classes with `override` keyword should be emited as it was before from AST with origin source, 742``
()
=
"""[<AbstractClass>]
type Foo =
abstract foo: int
Expand Down
10 changes: 6 additions & 4 deletions src/Fantomas.Tests/LetBindingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,9 @@ let ``should keep space before :`` () =
"

[<Test>]
let ``newline trivia before simple sequence doesn't force remaining to get offset by last expression column index, 513`` ()
=
let ``newline trivia before simple sequence doesn't force remaining to get offset by last expression column index, 513``
()
=
formatSourceString
false
"""let a() =
Expand All @@ -377,8 +378,9 @@ let a () =
"""

[<Test>]
let ``comment trivia before simple sequence doesn't force remaining to get offset by last expression column index, 513`` ()
=
let ``comment trivia before simple sequence doesn't force remaining to get offset by last expression column index, 513``
()
=
formatSourceString
false
"""let a() =
Expand Down
5 changes: 3 additions & 2 deletions src/Fantomas.Tests/NumberOfItemsListOrArrayTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,9 @@ h [
"""

[<Test>]
let ``number of items sized Elmish lists with single argument web mode and multiline block brackets on same column are formatted properly`` ()
=
let ``number of items sized Elmish lists with single argument web mode and multiline block brackets on same column are formatted properly``
()
=
formatSourceString
false
"""
Expand Down
20 changes: 12 additions & 8 deletions src/Fantomas.Tests/NumberOfItemsRecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,9 @@ type S = { AReallyLongExpressionThatIsMuchLongerThan50Characters: int }
"""

[<Test>]
let ``number of items sized record definitions with multiline block brackets on same column are formatted properly`` ()
=
let ``number of items sized record definitions with multiline block brackets on same column are formatted properly``
()
=
formatSourceString
false
"""
Expand Down Expand Up @@ -936,8 +937,9 @@ g s' { s with AReallyLongExpressionThatIsMuchLongerThan50Characters = 1 }
"""

[<Test>]
let ``number of items sized record expressions with multiline block brackets on same column are formatted properly`` ()
=
let ``number of items sized record expressions with multiline block brackets on same column are formatted properly``
()
=
formatSourceString
false
"""
Expand Down Expand Up @@ -1060,8 +1062,9 @@ g s' {| s with AReallyLongExpressionThatIsMuchLongerThan50Characters = 1 |}
"""

[<Test>]
let ``number of items sized anonymous record expressions with multiline block brackets on same column are formatted properly`` ()
=
let ``number of items sized anonymous record expressions with multiline block brackets on same column are formatted properly``
()
=
formatSourceString
false
"""
Expand Down Expand Up @@ -1159,8 +1162,9 @@ type B = {| x: AReallyLongTypeThatIsMuchLongerThan40Characters |}
// FIXME: See https://github.com/fsprojects/fantomas/issues/1167
[<Test>]
[<Ignore("Issue #1167")>]
let ``number of items sized anonymous record types with multiline block brackets on same column are formatted properly`` ()
=
let ``number of items sized anonymous record types with multiline block brackets on same column are formatted properly``
()
=
formatSourceString
false
"""
Expand Down
20 changes: 12 additions & 8 deletions src/Fantomas.Tests/SpaceBeforeClassConstructorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ type t() =
"""

[<Test>]
let ``SpaceBeforeUnitParameterInLowercaseClassConstructor should add space before unit in lowercase class definition`` ()
=
let ``SpaceBeforeUnitParameterInLowercaseClassConstructor should add space before unit in lowercase class definition``
()
=
formatSourceString
false
"""type t() =
Expand Down Expand Up @@ -97,8 +98,9 @@ type Animal(length: int) =
"""

[<Test>]
let ``SpaceBeforeParenthesisParameterInUppercaseClassConstructor should add space before uppercase constructor of class`` ()
=
let ``SpaceBeforeParenthesisParameterInUppercaseClassConstructor should add space before uppercase constructor of class``
()
=
formatSourceString
false
"""
Expand Down Expand Up @@ -136,8 +138,9 @@ type animal(length: int) =
"""

[<Test>]
let ``SpaceBeforeParenthesisParameterInLowercaseClassConstructor should add space before lowercase constructor of class`` ()
=
let ``SpaceBeforeParenthesisParameterInLowercaseClassConstructor should add space before lowercase constructor of class``
()
=
formatSourceString
false
"""
Expand Down Expand Up @@ -291,8 +294,9 @@ type DerivedClass =
"""

[<Test>]
let ``should add space before inherit on constructor of class with multiline record, MultilineBlockBracketsOnSameColumn`` ()
=
let ``should add space before inherit on constructor of class with multiline record, MultilineBlockBracketsOnSameColumn``
()
=
formatSourceString
false
"""
Expand Down
5 changes: 3 additions & 2 deletions src/Fantomas.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -858,8 +858,9 @@ type CustomGraphControl() =
"""

[<Test>]
let ``should preserve orders on field declarations - attribute without parentheses and multiple spaces between attribute args`` ()
=
let ``should preserve orders on field declarations - attribute without parentheses and multiple spaces between attribute args``
()
=
formatSourceString
false
"""
Expand Down
59 changes: 31 additions & 28 deletions src/Fantomas/CodeFormatterImpl.fs
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,20 @@ let isValidAST ast =
| SynMemberDefn.ImplicitCtor _ -> true
| SynMemberDefn.ImplicitInherit (_, expr, _, _) -> validateExpr expr

and validateBinding (Binding (_access,
_bindingKind,
_isInline,
_isMutable,
_attrs,
_xmldoc,
_valData,
headPat,
_retTy,
expr,
_bindingRange,
_seqPoint))
=
and validateBinding
(Binding (_access,
_bindingKind,
_isInline,
_isMutable,
_attrs,
_xmldoc,
_valData,
headPat,
_retTy,
expr,
_bindingRange,
_seqPoint))
=
validateExpr expr && validatePattern headPat

and validateClause (Clause (pat, expr, exprOpt)) =
Expand Down Expand Up @@ -535,14 +536,15 @@ let private stringPos (r: range) (sourceCode: string) =

(start, finish)

let private formatRange (checker: FSharpChecker)
(parsingOptions: FSharpParsingOptions)
returnFormattedContentOnly
(range: range)
(lines: _ [])
config
({ Source = sourceCode } as formatContext)
=
let private formatRange
(checker: FSharpChecker)
(parsingOptions: FSharpParsingOptions)
returnFormattedContentOnly
(range: range)
(lines: _ [])
config
({ Source = sourceCode } as formatContext)
=
let startLine = range.StartLine
let startCol = range.StartColumn
let endLine = range.EndLine
Expand Down Expand Up @@ -681,13 +683,14 @@ let private formatRange (checker: FSharpChecker)

/// Format a part of source string using given config, and return the (formatted) selected part only.
/// Beware that the range argument is inclusive. If the range has a trailing newline, it will appear in the formatted result.
let formatSelection (checker: FSharpChecker)
(parsingOptions: FSharpParsingOptions)
(range: range)
config
({ Source = sourceCode
FileName = fileName } as formatContext)
=
let formatSelection
(checker: FSharpChecker)
(parsingOptions: FSharpParsingOptions)
(range: range)
config
({ Source = sourceCode
FileName = fileName } as formatContext)
=
let lines =
String.normalizeThenSplitNewLine sourceCode

Expand Down
Loading

0 comments on commit aac3975

Please sign in to comment.