haskell/stylish-haskell — 1.0k★ trên GitHub (Haskell). Haskell code prettifier
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
A simple Haskell code prettifier. The goal is not to format all of the code in
a file, since I find those kind of tools often "get in the way". However,
manually cleaning up import statements etc. gets tedious very quickly.
This tool tries to help where necessary without getting in the way.
Installation
You can install it using stack install stylish-haskell or cabal install stylish-haskell.
You can also install it using your package manager:
Debian 9 or later: apt-get install stylish-haskell
Ubuntu 16.10 or later: apt-get install stylish-haskell
Arch Linux: pacman -S stylish-haskell
Features
Aligns and sorts import statements
Groups and wraps {-# LANGUAGE #-} pragmas, can remove (some) redundant
pragmas
Removes trailing whitespace
Aligns branches in case and fields in records
Converts line endings (customizable)
Replaces tabs by four spaces (turned off by default)
Replaces some ASCII sequences by their Unicode equivalents (turned off by
default)
Format data constructors and fields in records.
Feature requests are welcome! Use the issue tracker for that.
Example
Turns:
{-# LANGUAGE ViewPatterns, TemplateHaskell #-}
{-# LANGUAGE GeneralizedNewtypeDeriving,
ViewPatterns,
ScopedTypeVariables #-}
module Bad where
import Control.Applicative ((<$>))
import System.Directory (doesFileExist)
import qualified Data.Map as M
import Data.Map ((!), keys, Map)
data Point = Point { pointX, pointY :: Double , pointName :: String} deriving (Show)
into:
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
module Bad where
import Control.Applicative ((<$>))
import System.Directory (doesFileExist)
import Data.Map (Map, keys, (!))
import qualified Data.Map as M
data Point = Point
{ pointX, pointY :: Double
, pointName :: String
} deriving (Show)
Configuration
The tool is customizable to some extent. It tries to find a config file in the
following order:
A file passed to the tool using the -c/--config argument
.stylish-haskell.yaml in the current directory (useful for per-directory
settings)
.stylish-haskell.yaml in the nearest ancestor directory (useful for
per-project settings)
stylish-haskell/config.yaml in the platform’s configuration directory
(on Windows, it is %APPDATA%, elsewhere it defaults to ~/.config and
can be overridden by the XDG_CONFIG_HOME environment variable;
useful for user-wide settings)
.stylish-haskell.yaml in your home directory (useful for user-wide
settings)
The default settings.
Use stylish-haskell --defaults > .stylish-haskell.yaml to dump a
well-documented default configuration to a file, this way you can get started
quickly.
Record formatting
Basically, stylish-haskell supports 4 different styles of records, controlled by records
in the config file.
Here's an example of all four styles:
-- equals: "indent 2", "first_field": "indent 2"
data Foo a
= Foo
{ a :: Int
, a2 :: String
-- ^ some haddock
}
| Bar
{ b :: a
}
deriving (Eq, Show)
deriving (ToJSON) via Bar Foo
-- equals: "same_line", "first_field": "indent 2"
data Foo a = Foo
{ a :: Int
, a2 :: String
-- ^ some haddock
}
| Bar
{ b :: a
}
deriving (Eq, Show)
deriving (ToJSON) via Bar Foo
-- equals: "same_line", "first_field": "same_line"
data Foo a = Foo { a :: Int
, a2 :: String
-- ^ some haddock
}
| Bar { b :: a
}
deriving (Eq, Show)
deriving (ToJSON) via Bar Foo
-- equals: "indent 2", first_field: "same_line"
data Foo a
= Foo { a :: Int
, a2 :: String
-- ^ some haddock
}
| Bar { b :: a
}
deriving (Eq, Show)
deriving (ToJSON) via Bar Foo
Editor integration
Haskell Language Server
Haskell Language Server(HLS) includes a plugin
for stylish-haskell. By changing the formatting provider option
(haskell.formattingProvider) to stylish-haskell as described in
HLS options, any editors that support Language Server Protocol
can use stylish-haskell for formatting.
VIM integration
Since it works as a filter it is pretty easy to integrate this with VIM.
You can call
:%!stylish-haskell
and add a keybinding for it.
Or you can define formatprg
:set formatprg=stylish-haskell
and then use gq.
Alternatively, [vim-autoformat] supports stylish-haskell. To have it
automatically reformat the files on save, add to your vimrc:
autocmd BufWrite *.hs :Autoformat
" Don't automatically indent on save, since vim's autoindent for haskell is buggy
autocmd FileType haskell let b:autoformat_autoindent=0
There are also plugins that run stylish-haskell automatically when you save a
Haskell file:
vim-stylish-haskell
vim-stylishask
Emacs integration
haskell-mode for Emacs supports stylish-haskell. For configuration,
see the “Using external formatters” section of the
haskell-mode manual.
Atom integration
ide-haskell for Atom supports stylish-haskell.
atom-beautify for Atom supports Haskell using stylish-haskell.
Visual Studio Code integration
stylish-haskell-vscode for VSCode supports stylish-haskell.
Using with Continuous Integration
You can quickly grab the latest binary and run stylish-haskell like so:
curl -sL https://raw.github.com/haskell/stylish-haskell/master/scripts/latest.sh | sh -s .
Where the . can be replaced with the arguments you pass to stylish-haskell.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/haskell/stylish-haskell là nguồn chính thức.
haskell/stylish-haskell có bao nhiêu sao?
haskell/stylish-haskell có 1.0k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/haskell/stylish-haskell. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
haskell/stylish-haskell có phải mã nguồn mở không?
TopGit chưa ghi nhận license cho haskell/stylish-haskell. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
haskell/stylish-haskell còn đang phát triển không?
Commit gần nhất trên haskell/stylish-haskell là 10 tháng trước (theo timestamp GitHub). Repo có 153 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
haskell/stylish-haskell là gì?
haskell/stylish-haskell (haskell/stylish-haskell) là dự án Haskell trên GitHub. Theo mô tả gốc: Haskell code prettifier
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về stylish-haskell?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về stylish-haskell.