抑制 F# 编译器警告:缩进可能不正确:此标记超出上下文
Suppress F# Compiler Warning: Possible incorrect indentation: this token is offside of context
我有一些 xunit 测试,为了便于阅读,我想按如下方式布局:
[<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>
我在 let 语句上收到编译器警告:"Possible incorrect indentation: this token is offside of context started at position %s. Try indenting this token further or using standard formatting conventions."
我尝试了 #nowarn "lexfltTokenIsOffsideOfContextStartedEarlier"
,但这只是生成了另一个编译器警告 "Invalid warning number"。
https://github.com/fsharp/fsharp/blob/057dbf77df7355321c3c18137c2d552bdfa1272b/src/fsharp/FSComp.txt
中没有针对此错误列出的警告编号
有没有办法抑制这个警告?
试试这个:
#nowarn "0058"
要找出正确的警告号是什么,只需在命令行中构建它(或在 VS 中,然后转到“查看”->“输出”->“构建”),它会告诉您。这是我看到的:
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.
我很抱歉以一种风格回答,"you don't need it",但情况似乎是这样。此外,这个问题显然成为那些在 F# 中编写单元测试的人的常见问题解答。还有一个例子是 [<Literal>]
's.
无论如何,在项目级甚至文件级禁用警告似乎不是一个好主意,除非您有充分的理由这样做。
据我了解,您希望语句是单行的(例如,[<Fact>]
没有占据整行)。在 VS2013 中有两种方法可以实现:
将属性放在 let
:
let [<Fact>] ``Has Hash Code 2``() = target.GetHashCode().ShouldBe 2
在声明后写一个双分号:
[<Fact>] let ``Has Hash Code 2``() = target.GetHashCode().ShouldBe 2;;
我有一些 xunit 测试,为了便于阅读,我想按如下方式布局:
[<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>
我在 let 语句上收到编译器警告:"Possible incorrect indentation: this token is offside of context started at position %s. Try indenting this token further or using standard formatting conventions."
我尝试了 #nowarn "lexfltTokenIsOffsideOfContextStartedEarlier"
,但这只是生成了另一个编译器警告 "Invalid warning number"。
https://github.com/fsharp/fsharp/blob/057dbf77df7355321c3c18137c2d552bdfa1272b/src/fsharp/FSComp.txt
中没有针对此错误列出的警告编号有没有办法抑制这个警告?
试试这个:
#nowarn "0058"
要找出正确的警告号是什么,只需在命令行中构建它(或在 VS 中,然后转到“查看”->“输出”->“构建”),它会告诉您。这是我看到的:
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.
我很抱歉以一种风格回答,"you don't need it",但情况似乎是这样。此外,这个问题显然成为那些在 F# 中编写单元测试的人的常见问题解答。还有一个例子是 [<Literal>]
's.
无论如何,在项目级甚至文件级禁用警告似乎不是一个好主意,除非您有充分的理由这样做。
据我了解,您希望语句是单行的(例如,[<Fact>]
没有占据整行)。在 VS2013 中有两种方法可以实现:
将属性放在
let
:let [<Fact>] ``Has Hash Code 2``() = target.GetHashCode().ShouldBe 2
在声明后写一个双分号:
[<Fact>] let ``Has Hash Code 2``() = target.GetHashCode().ShouldBe 2;;