fsprojects / FSharpLint

Lint tool for F#
https://fsprojects.github.io/FSharpLint/
MIT License
303 stars 73 forks source link

favourStaticEmptyFields: the suggestion of empty arrays is incorrect #630

Closed Mersho closed 9 months ago

Mersho commented 9 months ago

Description

Make sure favourStaticEmptyFields is enabled in fsharplint.json.

FSharpLint suggests using List.Empty, which is wrong since it's not a List. Instead, it should suggest using Array.empty.

Steps To Reproduce

dotnet fsharplint lint ..\ConsoleApp\ConsoleApp\ConsoleApp.fsproj

ConsoleApp.fsproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
    <WarnOn>3390;$(WarnOn)</WarnOn>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="Program.fs" />
  </ItemGroup>

</Project>

Program.fs

open System

printfn "%A" [| 1; 2; 3 |]
printfn "%A" [||]

Current Results

========== Linting C:\Users\PC\source\repos\ConsoleApp\ConsoleApp\obj\Debug\net5.0\ConsoleApp.AssemblyInfo.fs ==========
========== Finished: 0 warnings ==========
========== Linting C:\Users\PC\source\repos\ConsoleApp\ConsoleApp\Program.fs ==========
Consider using 'List.Empty' instead.
Error on line 4 starting at column 13
printfn "%A" [||]
             ^   
--------------------------------------------------------------------------------
========== Finished: 1 warnings ==========
========== Summary: 1 warnings ==========

Expected behavior

FsharpLint is expected to suggest to use Array.empty.

Related information