Code Monkey home page Code Monkey logo

hasklean's Introduction

Hasklean

Introduction

This formater is a fork of stylish-haskell. It has been adapted to strictly apply Smart-Chain Haskell team style. It is therefore not as flexible as stylish-haskell and does not aim to be.

Installation

  1. Install Nix by going to the Nix download page.

  2. Enable Flakes by following this instructions.

  3. Enter the Nix shell:

nhenin@ubuntu ~/d/hasklean (main)> nix develop
  1. Build the project
[nix-shell:~/dev/hasklean]$ cabal build all
  1. Install for current user:
[nix-shell:~/dev/hasklean]$ install -D $(cabal list-bin hasklean) $HOME/.local/bin/hasklean
  1. Open a new terminal or source your .profile file to have the executable in your PATH.

  2. Apply formatting on some file:

nhenin@ubuntu ~/d/hasklean (main)> hasklean -- ./test/Test.hs

Features

  • Aligns and sorts import statements
  • Groups and wraps {-# LANGUAGE #-} pragmas, can remove (some) redundant pragmas
  • Aligns and sorts module statement
  • Replaces tabs by eight spaces (turned off by default)
  • Removes trailing whitespace

Smart-Chain Haskell team style

For now, we only have guidelines for module header, that is pragma list, module statement and import statements.

Module header

{-# LANGUAGE ImportQualifiedPost            #-}
{-# LANGUAGE LambdaCase                     #-}
{-# LANGUAGE OverloadedStrings              #-}
{-# LANGUAGE RecordWildCards                #-}
{-# LANGUAGE TypeApplications               #-}
--                                          ^
module Hasklean.Step.ModuleHeader   --      |
  ( Config (..)                     --      |
  , BreakWhere (..)                 --      |
  , OpenBracket (..)                --      | end of pragma and start of module list are aligned
  , defaultConfig                   --      | with a customizable padding
  , step                            --      |
  ) where                           --      |
--                                          |
--                                          v
import Control.Applicative                  ((<|>))

import Control.Monad as M
--                   ^ alias follows module name when import list is empty

--                    we use ImportQualifiedPost
--                    v
import Data.Aeson qualified
    as Aeson                                ( Value(..) )
--   ^ alias are on new line with
--     module name and alias aligned when
--     import list is not empty

import Plutus.Contract
    ( Contract
    , EmptySchema
    , logInfo
    , ownAddress
    , utxosAt
    )
--  ^ long import list are on new lines on the left with leading comas

Note: Rules for grouping import statements are on a per-project basis using POSIX extended regular expressions patterns. Those rules are specified in a configuration file.

Configuration

The tool is customizable to some extent:

  1. You can pass a file to the tool using the -c/--config argument
  2. Otherwise the default settings will be used.

Use hasklean --defaults > .hasklean.yaml to dump a well-documented default configuration to a file, this way you can get started quickly.

Editor integration

VIM integration

Since it works as a filter it is pretty easy to integrate this with VIM.

You can call

:%!hasklean

and add a keybinding for it.

Or you can define formatprg

:set formatprg=hasklean

and then use gq.

hasklean's People

Contributors

jaspervdj avatar zlondrej avatar lukasz-golebiewski avatar augucharles avatar encodepanda avatar felixonmars avatar maksbotan avatar nightuser avatar spwhitton avatar phadej avatar nbouscal avatar themoritz avatar langston-barrett avatar konn avatar chris-martin avatar cblp avatar tikhonjelvis avatar peterbecich avatar akrmn avatar 23skidoo avatar lev135 avatar sopvop avatar july541 avatar danburton avatar fosskers avatar 1computer1 avatar shayne-fletcher avatar scottfreecode avatar ruhatch avatar sideeffffect avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.