Skip to content

Commit

Permalink
Strip only \r to be able to detect a changed number of newlines (#2465)
Browse files Browse the repository at this point in the history
* - Strip only \r to be able to detect a changed number of newlines
- adjust tests and add a test for 2461

* format CheckTests.fs
  • Loading branch information
dawedawe committed Aug 31, 2022
1 parent 828336a commit d962305
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [Unreleased]

### Fixed
* --check should fail if the number of newlines is different. [#2461](https://github.com/fsprojects/fantomas/issues/2461)

## [5.0.0-beta-008] - 2022-08-30

### Fixed
Expand Down
1 change: 0 additions & 1 deletion src/Fantomas.Tests/CheckTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ let WithErrors = """let a"""
[<Literal>]
let CorrectlyFormatted =
"""module A
"""

[<Test>]
Expand Down
13 changes: 12 additions & 1 deletion src/Fantomas.Tests/Integration/CheckTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ let WithErrors = """let a ="""
[<Literal>]
let CorrectlyFormatted =
"""module A
"""

[<Test>]
Expand Down Expand Up @@ -135,3 +134,15 @@ let ``honor ignore file when processing a folder`` () =
runFantomasTool (sprintf "--check .%c%s" Path.DirectorySeparatorChar subFolder)

output |> should not' (contain "ignored")

[<Test>]
let ``check should fail if the number of newlines is different, 2461`` () =
let codeSnippet =
"""module A
"""

use fileFixture = new TemporaryFileCodeSample(codeSnippet)

let { ExitCode = exitCode } = checkCode [ fileFixture.Filename ]
exitCode |> should equal 99
2 changes: 1 addition & 1 deletion src/Fantomas/Format.fs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let private formatContentInternalAsync
let contentChanged =
if compareWithoutLineEndings then
let stripNewlines (s: string) =
System.Text.RegularExpressions.Regex.Replace(s, @"\n|\r", String.Empty)
System.Text.RegularExpressions.Regex.Replace(s, @"\r", String.Empty)

(stripNewlines originalContent) <> (stripNewlines formattedContent)
else
Expand Down

0 comments on commit d962305

Please sign in to comment.