FSharpLint icon indicating copy to clipboard operation
FSharpLint copied to clipboard

FL0065: False positive with boolean named arguments

Open OkkeHendriks opened this issue 4 years ago • 3 comments

Description

In certain cases FL0065 seems to give a false positive with boolean named arguments (sometimes).

Repro steps

 Log.Logger <-
        LoggerConfiguration()
            .ReadFrom.AppSettings()
            .WriteTo
            .File(
                logFilePath,
                rollOnFileSizeLimit = true,
                outputTemplate = "[{Timestamp:HH:mm:ss}{Level:u3}][{Context}] {Message:lj}{NewLine}{Exception}"
            )
            .CreateLogger ()

Gives: image

However, when trying to make a simpler example without using the Serilogger stuff I am not directly able to reproduce this. For example this:

type TestClass() =
    member this.TestFunction (namedArgument1: string, ?namedArgument2: bool, ?namedArgument3: string) =
        namedArgument1.Length = 0 && namedArgument2.IsSome && namedArgument3.IsSome

let test =
    let tc = TestClass ()
    let logFilePath = ""

    tc.TestFunction (
        logFilePath,
        namedArgument2 = false,
        namedArgument3 = "[{Timestamp:HH:mm:ss}{Level:u3}][{Context}] {Message:lj}{NewLine}{Exception}"
    )

Just works: image

Fyi, tooltip of File: image

Expected behavior

rollOnFileSizeLimit = true, does not trigger Warning FL0065 'x = true' might be able to be refactored into x.

Actual behavior

FL0065 is triggered.

Known workarounds

None

Related information

FSharpLint VS extenstion v0.6, default configuration .Net 5.0.203 Windows 10

OkkeHendriks avatar Aug 11 '21 14:08 OkkeHendriks

Workaround is to disable linting for this line using // fsharplint:disable-line

let private writeRollingFile path config =
    async config (fun sink ->
        sink.File(
            path,
            fileSizeLimitBytes = Nullable FileSizeLimit,
            retainedFileCountLimit = Nullable RetainedFileCount,
            rollOnFileSizeLimit = true, // fsharplint:disable-line
            outputTemplate = Template
        ))

peterhirn avatar Nov 19 '21 15:11 peterhirn

This is also the case for nullable arguments:

busCfg.AddConsumer(consumerType = t, consumerDefinitionType = null)

Gives:

Warning FL0065 FSharpLint: 'x = null' might be able to be refactored into 'isNull x'.

cmeeren avatar Oct 18 '22 13:10 cmeeren

The counter-example above suggests that with F# code it doesn't trigger, but if it's an F# library, it does trigger. For instance, using the excellent FSharp.SystemTextJson, the following snippet raises this error as well:

/// Erases the single-case union case and un-tags (that is, removes the case itself, just shows the fields)
let untaggedAndErased =
    JsonFSharpOptions(
        unionTagCaseInsensitive = true,  // <--- this triggers warning FL0065
        unionEncoding =
            (JsonUnionEncoding.Untagged
                ||| JsonUnionEncoding.UnwrapFieldlessTags
                ||| JsonUnionEncoding.EraseSingleCaseUnions)
    )

Since this kind of code is just about everywhere, esp if you do a lot of interop with C#-targeting libs, it doesn't really make sense to disable this rule line by line. It's unfortunately a little too broken to be useful, better to disable this rule altogether for now.

abelbraaksma avatar Oct 21 '22 17:10 abelbraaksma