Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

favourStaticEmptyFields: the suggestion of empty arrays is incorrect #630

Closed
Mersho opened this issue Dec 13, 2023 · 0 comments · Fixed by #631
Closed

favourStaticEmptyFields: the suggestion of empty arrays is incorrect #630

Mersho opened this issue Dec 13, 2023 · 0 comments · Fixed by #631

Comments

@Mersho
Copy link
Contributor

Mersho commented Dec 13, 2023

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

  • Operating system Windows 11
  • Branch master
  • .NET Runtime, CoreCLR or Mono Version .NET 5
webwarrior-ws added a commit to webwarrior-ws/FSharpLint that referenced this issue Dec 13, 2023
Simplified code and fixed bug in FavourStaticEmptyFields rule.
Fixes fsprojects#630
webwarrior-ws added a commit to webwarrior-ws/FSharpLint that referenced this issue Dec 13, 2023
Simplified code and fixed bug in FavourStaticEmptyFields rule.
Fixes fsprojects#630
webwarrior-ws added a commit to webwarrior-ws/FSharpLint that referenced this issue Dec 13, 2023
Simplified code and fixed bug in FavourStaticEmptyFields rule.
Fixes fsprojects#630
webwarrior-ws added a commit to webwarrior-ws/FSharpLint that referenced this issue Dec 13, 2023
Simplified code and fixed bug in FavourStaticEmptyFields rule.

Fixes fsprojects#630
webwarrior-ws added a commit to webwarrior-ws/FSharpLint that referenced this issue Dec 14, 2023
Fixed bug in FavourStaticEmptyFields rule that caused wrong
suggestion for arrays (List.Empty instead of Array.empty).

Fixes fsprojects#630
webwarrior-ws added a commit to webwarrior-ws/FSharpLint that referenced this issue Dec 14, 2023
Simplified FavourStaticEmptyFields rule by removing
unnecessary code.

Fixes fsprojects#630
knocte added a commit that referenced this issue Dec 14, 2023
* Added checks for error message containing substitution that is appropriate for given data type (array or list) in FavourStaticEmptyFields tests. E.g. Array.empty should be suggested for replacing [||].

* Fixed bug in FavourStaticEmptyFields rule that caused wrong suggestion for arrays.

* Simplified FavourStaticEmptyFields rule by removing unnecessary code.

Fixes #630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant