Skip to content

Commit ffd619f

Browse files
authored
Change stylish-haskell defaults for more diff friendliness. (#41)
* new style * don't align pragmas * Add stylish-haskell.sh * add CI step * add to ci
1 parent 3c6ebd9 commit ffd619f

15 files changed

+167
-343
lines changed

.stylish-haskell.yaml

Lines changed: 11 additions & 216 deletions
Original file line numberDiff line numberDiff line change
@@ -1,224 +1,19 @@
1-
# stylish-haskell configuration file
2-
# ==================================
3-
4-
# The stylish-haskell tool is mainly configured by specifying steps. These steps
5-
# are a list, so they have an order, and one specific step may appear more than
6-
# once (if needed). Each file is processed by these steps in the given order.
71
steps:
8-
# Convert some ASCII sequences to their Unicode equivalents. This is disabled
9-
# by default.
10-
# - unicode_syntax:
11-
# # In order to make this work, we also need to insert the UnicodeSyntax
12-
# # language pragma. If this flag is set to true, we insert it when it's
13-
# # not already present. You may want to disable it if you configure
14-
# # language extensions using some other method than pragmas. Default:
15-
# # true.
16-
# add_language_pragma: true
17-
18-
# Align the right hand side of some elements. This is quite conservative
19-
# and only applies to statements where each element occupies a single
20-
# line.
21-
- simple_align:
22-
cases: true
23-
top_level_patterns: true
24-
records: true
25-
26-
# Import cleanup
272
- imports:
28-
# There are different ways we can align names and lists.
29-
#
30-
# - global: Align the import names and import list throughout the entire
31-
# file.
32-
#
33-
# - file: Like global, but don't add padding when there are no qualified
34-
# imports in the file.
35-
#
36-
# - group: Only align the imports per group (a group is formed by adjacent
37-
# import lines).
38-
#
39-
# - none: Do not perform any alignment.
40-
#
41-
# Default: global.
42-
align: global
43-
44-
# The following options affect only import list alignment.
45-
#
46-
# List align has following options:
47-
#
48-
# - after_alias: Import list is aligned with end of import including
49-
# 'as' and 'hiding' keywords.
50-
#
51-
# > import qualified Data.List as List (concat, foldl, foldr, head,
52-
# > init, last, length)
53-
#
54-
# - with_alias: Import list is aligned with start of alias or hiding.
55-
#
56-
# > import qualified Data.List as List (concat, foldl, foldr, head,
57-
# > init, last, length)
58-
#
59-
# - new_line: Import list starts always on new line.
60-
#
61-
# > import qualified Data.List as List
62-
# > (concat, foldl, foldr, head, init, last, length)
63-
#
64-
# Default: after_alias
65-
list_align: after_alias
66-
67-
# Right-pad the module names to align imports in a group:
68-
#
69-
# - true: a little more readable
70-
#
71-
# > import qualified Data.List as List (concat, foldl, foldr,
72-
# > init, last, length)
73-
# > import qualified Data.List.Extra as List (concat, foldl, foldr,
74-
# > init, last, length)
75-
#
76-
# - false: diff-safe
77-
#
78-
# > import qualified Data.List as List (concat, foldl, foldr, init,
79-
# > last, length)
80-
# > import qualified Data.List.Extra as List (concat, foldl, foldr,
81-
# > init, last, length)
82-
#
83-
# Default: true
84-
pad_module_names: true
85-
86-
# Long list align style takes effect when import is too long. This is
87-
# determined by 'columns' setting.
88-
#
89-
# - inline: This option will put as much specs on same line as possible.
90-
#
91-
# - new_line: Import list will start on new line.
92-
#
93-
# - new_line_multiline: Import list will start on new line when it's
94-
# short enough to fit to single line. Otherwise it'll be multiline.
95-
#
96-
# - multiline: One line per import list entry.
97-
# Type with constructor list acts like single import.
98-
#
99-
# > import qualified Data.Map as M
100-
# > ( empty
101-
# > , singleton
102-
# > , ...
103-
# > , delete
104-
# > )
105-
#
106-
# Default: inline
107-
long_list_align: inline
108-
109-
# Align empty list (importing instances)
110-
#
111-
# Empty list align has following options
112-
#
113-
# - inherit: inherit list_align setting
114-
#
115-
# - right_after: () is right after the module name:
116-
#
117-
# > import Vector.Instances ()
118-
#
119-
# Default: inherit
3+
align: none
4+
list_align: with_module_name
5+
pad_module_names: false
6+
long_list_align: new_line_multiline
1207
empty_list_align: inherit
121-
122-
# List padding determines indentation of import list on lines after import.
123-
# This option affects 'long_list_align'.
124-
#
125-
# - <integer>: constant value
126-
#
127-
# - module_name: align under start of module name.
128-
# Useful for 'file' and 'group' align settings.
129-
list_padding: 4
130-
131-
# Separate lists option affects formatting of import list for type
132-
# or class. The only difference is single space between type and list
133-
# of constructors, selectors and class functions.
134-
#
135-
# - true: There is single space between Foldable type and list of it's
136-
# functions.
137-
#
138-
# > import Data.Foldable (Foldable (fold, foldl, foldMap))
139-
#
140-
# - false: There is no space between Foldable type and list of it's
141-
# functions.
142-
#
143-
# > import Data.Foldable (Foldable(fold, foldl, foldMap))
144-
#
145-
# Default: true
146-
separate_lists: true
147-
148-
# Space surround option affects formatting of import lists on a single
149-
# line. The only difference is single space after the initial
150-
# parenthesis and a single space before the terminal parenthesis.
151-
#
152-
# - true: There is single space associated with the enclosing
153-
# parenthesis.
154-
#
155-
# > import Data.Foo ( foo )
156-
#
157-
# - false: There is no space associated with the enclosing parenthesis
158-
#
159-
# > import Data.Foo (foo)
160-
#
161-
# Default: false
8+
list_padding: 7 # length "import "
9+
separate_lists: false
16210
space_surround: false
163-
164-
# Language pragmas
16511
- language_pragmas:
166-
# We can generate different styles of language pragma lists.
167-
#
168-
# - vertical: Vertical-spaced language pragmas, one per line.
169-
#
170-
# - compact: A more compact style.
171-
#
172-
# - compact_line: Similar to compact, but wrap each line with
173-
# `{-#LANGUAGE #-}'.
174-
#
175-
# Default: vertical.
17612
style: vertical
177-
178-
# Align affects alignment of closing pragma brackets.
179-
#
180-
# - true: Brackets are aligned in same column.
181-
#
182-
# - false: Brackets are not aligned together. There is only one space
183-
# between actual import and closing bracket.
184-
#
185-
# Default: true
186-
align: true
187-
188-
# stylish-haskell can detect redundancy of some language pragmas. If this
189-
# is set to true, it will remove those redundant pragmas. Default: true.
13+
align: false
19014
remove_redundant: true
191-
192-
# Replace tabs by spaces. This is disabled by default.
193-
# - tabs:
194-
# # Number of spaces to use for each tab. Default: 8, as specified by the
195-
# # Haskell report.
196-
# spaces: 8
197-
198-
# Remove trailing whitespace
15+
- simple_align:
16+
cases: false
17+
top_level_patterns: false
18+
records: false
19919
- trailing_whitespace: {}
200-
201-
# A common setting is the number of columns (parts of) code will be wrapped
202-
# to. Different steps take this into account. Default: 80.
203-
columns: 80
204-
205-
# By default, line endings are converted according to the OS. You can override
206-
# preferred format here.
207-
#
208-
# - native: Native newline format. CRLF on Windows, LF on other OSes.
209-
#
210-
# - lf: Convert to LF ("\n").
211-
#
212-
# - crlf: Convert to CRLF ("\r\n").
213-
#
214-
# Default: native.
215-
newline: native
216-
217-
# Sometimes, language extensions are specified in a cabal file or from the
218-
# command line instead of using language pragmas in the file. stylish-haskell
219-
# needs to be aware of these, so it can parse the file correctly.
220-
#
221-
# No language extensions are enabled by default.
222-
# language_extensions:
223-
# - TemplateHaskell
224-
# - QuasiQuotes

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ before_install:
2525
- mkdir -p ~/.local/bin
2626
- export PATH=$HOME/.local/bin:$PATH
2727
- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
28+
- stack install stylish-haskell --resolver nightly-2020-03-14
2829

2930
services:
3031
- postgresql
@@ -37,7 +38,10 @@ before_script:
3738
# This line does all of the work: installs GHC if necessary, build the library,
3839
# executables, and test suites, and runs the test suites. --no-terminal works
3940
# around some quirks in Travis's terminal implementation.
40-
script: stack --no-terminal --install-ghc test
41+
script:
42+
- make imports
43+
- git diff --exit-code
44+
- stack --no-terminal --install-ghc test
4145

4246
# Caching so the next build will be fast too.
4347
cache:

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ ghcid-devel: ## Run the server in fast development mode. See DevelMain for detai
66
--command "stack ghci servant-persistent" \
77
--test "DevelMain.update"
88

9-
.PHONY: ghcid-devel help
9+
imports: ## Format all the imports that have changed since the master branch.
10+
./stylish-haskell.sh
11+
12+
.PHONY: ghcid-devel help imports

Setup.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import Distribution.Simple
1+
import Distribution.Simple
22
main = defaultMain

app/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Main where
22

3-
import Init (runApp)
3+
import Init (runApp)
44

55
-- | The 'main' function gathers the required environment information and
66
-- initializes the application.

src/Api.hs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
{-# LANGUAGE DataKinds #-}
1+
{-# LANGUAGE DataKinds #-}
22
{-# LANGUAGE TypeOperators #-}
33

44
module Api (app) where
55

6-
import Control.Monad.Reader (runReaderT)
7-
import Servant ((:<|>) ((:<|>)), Proxy (Proxy), Raw,
8-
Server, serve, serveDirectoryFileServer)
9-
import Servant.Server
10-
11-
import Api.User (UserAPI, userApi, userServer)
12-
import Config (AppT (..), Config (..))
6+
import Control.Monad.Reader (runReaderT)
7+
import Servant
8+
( (:<|>)((:<|>))
9+
, Proxy(Proxy)
10+
, Raw
11+
, Server
12+
, serve
13+
, serveDirectoryFileServer
14+
)
15+
import Servant.Server
16+
17+
import Api.User (UserAPI, userApi, userServer)
18+
import Config (AppT(..), Config(..))
1319

1420
-- | This is the function we export to run our 'UserAPI'. Given
1521
-- a 'Config', we return a WAI 'Application' which any WAI compliant server

src/Api/User.hs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
{-# LANGUAGE DataKinds #-}
1+
{-# LANGUAGE DataKinds #-}
22
{-# LANGUAGE OverloadedStrings #-}
3-
{-# LANGUAGE TypeOperators #-}
3+
{-# LANGUAGE TypeOperators #-}
44

55
module Api.User where
66

7-
import Control.Monad.Except (MonadIO, liftIO)
8-
import Control.Monad.Logger (logDebugNS)
9-
import qualified Control.Monad.Metrics as Metrics
10-
import Data.Int (Int64)
11-
import Database.Persist.Postgresql (Entity (..), fromSqlKey, insert,
12-
selectFirst, selectList, (==.))
13-
import Servant
14-
import Servant.JS (vanillaJS, writeJSForAPI)
7+
import Control.Monad.Except (MonadIO, liftIO)
8+
import Control.Monad.Logger (logDebugNS)
9+
import qualified Control.Monad.Metrics as Metrics
10+
import Data.Int (Int64)
11+
import Database.Persist.Postgresql
12+
(Entity(..), fromSqlKey, insert, selectFirst, selectList, (==.))
13+
import Servant
14+
import Servant.JS (vanillaJS, writeJSForAPI)
1515

16-
import Config (AppT (..))
17-
import Control.Monad.Metrics (increment, metricsCounters)
18-
import Data.HashMap.Lazy (HashMap)
19-
import Data.IORef (readIORef)
20-
import Data.Text (Text)
21-
import Lens.Micro ((^.))
22-
import Models (User (User), runDb, userEmail,
23-
userName)
24-
import qualified Models as Md
25-
import qualified System.Metrics.Counter as Counter
16+
import Config (AppT(..))
17+
import Control.Monad.Metrics (increment, metricsCounters)
18+
import Data.HashMap.Lazy (HashMap)
19+
import Data.IORef (readIORef)
20+
import Data.Text (Text)
21+
import Lens.Micro ((^.))
22+
import Models (User(User), runDb, userEmail, userName)
23+
import qualified Models as Md
24+
import qualified System.Metrics.Counter as Counter
2625

2726
type UserAPI =
2827
"users" :> Get '[JSON] [Entity User]

0 commit comments

Comments
 (0)