F# F中的格式警告#

F# F中的格式警告#,f#,formatting,F#,Formatting,以下代码在每个let(“可能不正确的缩进”)上触发格式警告: 模块UTILTEST= []让simpleWithNth()=true |>应该为true []让negIndex()=true |>应该为true []让tooBigIndex()=true |>应该为true []让lastIndex()=true |>应该为true 以下情况不适用: module UtilTests = [<Test>] let simpleWithNth ()= true |> s

以下代码在每个
let
(“可能不正确的缩进”)上触发格式警告:

模块UTILTEST=
[]让simpleWithNth()=true |>应该为true
[]让negIndex()=true |>应该为true
[]让tooBigIndex()=true |>应该为true
[]让lastIndex()=true |>应该为true
以下情况不适用:

module UtilTests =
    [<Test>] let simpleWithNth ()= true |> should be True
     [<Test>] let negIndex () = true |> should be True
      [<Test>] let tooBigIndex () = true |> should be True
       [<Test>] let lastIndex () = true |> should be True
模块UTILTEST=
[]让simpleWithNth()=true |>应该为true
[]让negIndex()=true |>应该为true
[]让tooBigIndex()=true |>应该为true
[]让lastIndex()=true |>应该为true

为什么它要让每个
都比上面的缩进更多?(有没有办法让Visual Studio 2012自动格式化?

正如Brian在评论中所说,将属性应用于
let
函数的通常方法是在
let
绑定之前的行上写入属性。我还希望您编写的代码能够正常工作,因为函数体位于同一行,但显然编译器不这么认为

但是,还有另一种方法可以将属性应用于
let
函数,在您的示例中效果很好:

module UtilTests = 
  let [<Test>] simpleWithNth ()= true |> should be True 
  let [<Test>] negIndex () = true |> should be True 
  let [<Test>] tooBigIndex () = true |> should be True 
  let [<Test>] lastIndex () = true |> should be True 
模块UtilTests=
设[]simpleWithNth()=true |>应为true
设[]negIndex()=true |>应为true
让[]tooBigIndex()=true |>应该为true
设[]lastIndex()=true |>应为true

如果您正在编写递归函数,则需要使用此样式-然后前几行中的属性不起作用,您需要编写
let rec[]foo()=。。。和[]bar()=…

我认为这是一个错误,因为我们的原始代码应该是有效的,但属性位于let上方的一行。@Brian-虽然这修复了警告,但许多文档示例的属性位于同一行-字段和属性的属性示例的属性位于同一行
module UtilTests = 
  let [<Test>] simpleWithNth ()= true |> should be True 
  let [<Test>] negIndex () = true |> should be True 
  let [<Test>] tooBigIndex () = true |> should be True 
  let [<Test>] lastIndex () = true |> should be True