Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress F# Compiler Warning: Possible incorrect indentation: this token is offside of context

I have some xunit tests I would like to layout as follows for readability:

[<Fact>] let ``Has Hash Code 2``()          = target.GetHashCode().ShouldBe 2
[<Fact>] let ``ToString yields two``()      = target.ToString().ShouldBe "two"
[<Fact>] let ``Has underlysing type int``() = target.GetUnderlyingType().ShouldBe typeof<int>

I'm getting a compiler warning on the let statements: "Possible incorrect indentation: this token is offside of context started at position %s. Try indenting this token further or using standard formatting conventions."

I tried #nowarn "lexfltTokenIsOffsideOfContextStartedEarlier" but that just generated another compiler warning "Invalid warning number".

There isn't a warning number listed for this error in https://github.com/fsharp/fsharp/blob/057dbf77df7355321c3c18137c2d552bdfa1272b/src/fsharp/FSComp.txt

Is there a way to suppress this warning?

like image 551
Craig Avatar asked May 15 '15 23:05

Craig


2 Answers

I apologize for answering in a style, "you don't need it", but this seems to be the case. Also, this question apparently becomes a FAQ for those who write Unit Tests in F#. Yet another case is for [<Literal>]'s.

Anyway, disabling warnings on a project- or even file-level seems to be a bad idea, unless you have a good reason to do that.

As far as I understood, you'd like to have the statements to be one-liners (e.g., [<Fact>] did not occupy an entire line). There are two ways to accomplish that in VS2013:

  1. Place the attribute inside let:

    let [<Fact>] ``Has Hash Code 2``()          = target.GetHashCode().ShouldBe 2
    
  2. Write a double-semicolon after the declaration:

    [<Fact>] let ``Has Hash Code 2``()          = target.GetHashCode().ShouldBe 2;;
    
like image 186
bytebuster Avatar answered Sep 22 '22 06:09

bytebuster


Try this:

#nowarn "0058"

To find out what the correct warning number is, just build the thing in command line (or in VS and then go to View -> Output -> Build), it will tell you. Here is what I see:

Program.fs(7,3): warning FS0058: Possible incorrect indentation: this token is offside of context started at position (5:25). Try indenting this token further or using standard formatting conventions.
like image 30
Fyodor Soikin Avatar answered Sep 26 '22 06:09

Fyodor Soikin