Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HLint-like tool for F# code?

Tags:

lint

f#

HLint is a command line static analysis tool for Haskell code, that even suggests the appropriate refactored version of the code. Anyone know of similar command line tools for linting F# code?

like image 304
mcandre Avatar asked Nov 01 '13 04:11

mcandre


1 Answers

Short answer:

No, there is no such tool yet.

Long answer:

Let's discuss how to build it then.

I did some background research which might be useful.

References

There are a few lint tools in functional languages, which can be used as sources of inspiration. However, they tend to go to different directions.

HLint is an advanced tool and its refactoring capability is amazing. Refactoring suggestion is more tricky in F# due to (1) F# code might have side effects so equational reasoning is unsound (2) When doing point-free transformation, value restriction could eliminate some good suggestions. If we accept false positives, it might become a bit easier.

In Scala's world, you have Wart Remover and Scala Style. The former focuses on common functional programming mistakes in Scala. The latter has its focus on human errors and inconsistencies (e.g. naming, convention, etc.). I guess Wart Remover is more relevant to F# as it is a functional-first programming language. However, a style checker tool is useful on a big code base with multiple developers.

The most relevant lint tool for F# is probably OCaml's style checker, Mascot. It has a big and extensible rule set. Many of these rules are applicable to F# with minor adaptation.

Resources (and the lack thereof)

What we have:

  • F# compiler is on GitHub. The relevant component - F# compiler service has a NuGet package so bootstrapping is easy. F# compiler source code is a good resource since F# compiler's warnings are very good and informative.
  • There are recent works using F# compiler e.g. language binding, refactoring, code formatting, etc. so we have experience to build up on.
  • We have other lint tools to learn from.

What we don't have:

  • Good documentation on recommended styles and practices in F# is missing. The design guideline has been useful, but it isn't complete enough.
  • Building lint tool is time-consuming and difficult. Even with simple and single-purpose tool like Fantomas; it takes a lot of time to process F#'s ASTs in a correct way.

To sum up, if we define a right scope, creating a simple yet useful tool for F# is within reach.

Updates

There is an actively-developing linter for F# available at https://github.com/duckmatt/FSharpLint. It seems that my analysis is not too far off :).

like image 50
pad Avatar answered Oct 21 '22 17:10

pad