All Projects → fsprojects → Fantomas

fsprojects / Fantomas

Licence: other
FSharp source code formatter

Programming Languages

fsharp
127 projects

Projects that are alternatives of or similar to Fantomas

Unimport
A linter, formatter for finding and removing unused import statements.
Stars: ✭ 96 (-79.79%)
Mutual labels:  ast, formatter
Prettier
Prettier is an opinionated code formatter.
Stars: ✭ 41,411 (+8618.11%)
Mutual labels:  ast, formatter
unimport
A linter, formatter for finding and removing unused import statements.
Stars: ✭ 119 (-74.95%)
Mutual labels:  formatter, ast
Astexplorer
A web tool to explore the ASTs generated by various parsers.
Stars: ✭ 4,330 (+811.58%)
Mutual labels:  ast
Google Java Format
Reformats Java source code to comply with Google Java Style.
Stars: ✭ 4,250 (+794.74%)
Mutual labels:  formatter
Debundle
🗃 A javascript debundler. Takes a Browserify or Webpack bundle and recreates the initial, pre-bundled source.
Stars: ✭ 420 (-11.58%)
Mutual labels:  ast
Qone
Next-generation web query language, extend .NET LINQ for javascript.
Stars: ✭ 463 (-2.53%)
Mutual labels:  ast
I18nize React
Internationalize react apps within a lunch break
Stars: ✭ 389 (-18.11%)
Mutual labels:  ast
Exfmt
🌸 An opinionated Elixir source code formatter
Stars: ✭ 445 (-6.32%)
Mutual labels:  formatter
Elm Analyse
A tool that allows you to analyse your Elm code, identify deficiencies and apply best practices.
Stars: ✭ 418 (-12%)
Mutual labels:  ast
Orgajs
parse org-mode content into AST
Stars: ✭ 417 (-12.21%)
Mutual labels:  ast
Php Parser
🌿 NodeJS PHP Parser - extract AST or tokens (PHP5 and PHP7)
Stars: ✭ 400 (-15.79%)
Mutual labels:  ast
Tiny Compiler
A tiny compiler for a language featuring LL(2) with Lexer, Parser, ASM-like codegen and VM. Complex enough to give you a flavour of how the "real" thing works whilst not being a mere toy example
Stars: ✭ 425 (-10.53%)
Mutual labels:  ast
Coolformat
CoolFormat Source Code Formatter
Stars: ✭ 392 (-17.47%)
Mutual labels:  formatter
Black
The uncompromising Python code formatter
Stars: ✭ 23,973 (+4946.95%)
Mutual labels:  formatter
Prettier Vscode
Visual Studio Code extension for Prettier
Stars: ✭ 4,085 (+760%)
Mutual labels:  formatter
Unist
Universal Syntax Tree used by @unifiedjs
Stars: ✭ 438 (-7.79%)
Mutual labels:  ast
Latexindent.pl
Perl script to add indentation (leading horizontal space) to LaTeX files. It can modify line breaks before, during and after code blocks; it can perform text wrapping and paragraph line break removal. It can also perform string-based and regex-based substitutions/replacements. The script is customisable through its YAML interface.
Stars: ✭ 415 (-12.63%)
Mutual labels:  formatter
Rector
Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
Stars: ✭ 4,739 (+897.68%)
Mutual labels:  ast
Cst
🌿 JavaScript Concrete Syntax Tree
Stars: ✭ 417 (-12.21%)
Mutual labels:  ast

Fantomas

Fantomas logo

F# source code formatter, inspired by scalariform for Scala, ocp-indent for OCaml and PythonTidy for Python.

Build Status Github Actions Build Status AppVeyor Join the chat at https://gitter.im/fsprojects/fantomas

How to use

Command line tool / API

Use this command to install Fantomas as a .NET 5 SDK global tool:

dotnet tool install -g fantomas-tool

For detailed guidelines, please read Fantomas: How to use.

FAKE build system

Fantomas can be easily integrated with FAKE build system.
Check out the sample.

JetBrains Rider

The resharper-fsharp uses fantomas under the hood to format the source code. No need for any additional plugins.

Using the latest version inside Rider

For technical reasons Rider cannot always use the latest version of Fantomas found on NuGet. As a workaround you could install fantomas-tool locally with dotnet tool install fantomas-tool and configure it as an External tool.

Rider external tool window

Rider action window

This will have an impact on your editing experiencing in Rider, the external change to the file by the command line application might trigger more internal logic inside Rider than necessary. It could be noticeable in regards to the default formatting experience.

Visual Studio Code

The recommended way to use Fantomas is by using the Ionide plugin. Fantomas is integrated in FSAutoComplete which is the language server used by Ionide.

Alternatively, you can install the fantomas-fmt extension.

Visual Studio

The F# Formatting extension sets up Fantomas as the default formatter for F# files, configurable from Visual Studio's options.

Online

Try the Fantomas online.

Early builds

Every once in a while an alpha or beta version is published to https://www.nuget.org/. Our previous MyGet feed is now deprecated.

Benchmarks

Some figures can be found at https://fsprojects.github.io/fantomas/
We use BenchmarkDotNet to collect data for each build on the master branch.

Purpose

This project aims at formatting F# source files based on a given configuration. Fantomas will ensure correct indentation and consistent spacing between elements in the source files. We assume that the source files are parsable by F# compiler before feeding into the tool. Fantomas follows the formatting guideline being described in A comprehensive guide to F# Formatting Conventions.

Use cases

The project is developed with the following use cases in mind:

  • Reformatting an unfamiliar code base. It gives readability when you are not the one originally writing the code. To illustrate, the following example

    type Type
        = TyLam of Type * Type
        | TyVar of string
        | TyCon of string * Type list
        with override this.ToString () =
                match this with
                | TyLam (t1, t2) -> sprintf "(%s -> %s)" (t1.ToString()) (t2.ToString())
                | TyVar a -> a
                | TyCon (s, ts) -> s
    

    will be rewritten to

    type Type =
        | TyLam of Type * Type
        | TyVar of string
        | TyCon of string * Type list
        override this.ToString() =
            match this with
            | TyLam(t1, t2) -> sprintf "(%s -> %s)" (t1.ToString()) (t2.ToString())
            | TyVar a -> a
            | TyCon(s, ts) -> s
    
  • Converting from verbose syntax to light syntax. Feeding a source file in verbose mode, Fantomas will format it appropriately in light mode. This might be helpful for code generation since generating verbose source files is much easier. For example, this code fragment

    let Multiple9x9 () =
        for i in 1 .. 9 do
            printf "\n";
            for j in 1 .. 9 do
                let k = i * j in
                printf "%d x %d = %2d " i j k;
            done;
        done;;
    Multiple9x9 ();;
    

    is reformulated to

    let Multiple9x9() =
        for i in 1..9 do
            printf "\n"
            for j in 1..9 do
                let k = i * j
                printf "%d x %d = %2d " i j k
    
    Multiple9x9()
    
  • Formatting F# signatures, especially those generated by F# compiler and F# Interactive.

For more complex examples, please take a look at F# outputs of 20 language shootout programs and 10 CodeReview.SE source files.

Why the name "Fantomas"?

There are a few reasons to choose the name as such. First, it starts with an "F" just like many other F# projects. Second, Fantomas is my favourite character in the literature. Finally, Fantomas has the same Greek root as "phantom"; coincidentally F# ASTs and formatting rules are so mysterious to be handled correctly.

Contributing Guidelines

See the Contribution Guidelines.

Credits

We would like to gratefully thank the following persons for their contributions.

License

The library and tool are available under Apache 2.0 license. For more information see the License file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].