on master help sign in
Merge pull request #3475 from enolan/stylish-travis

Check Stylishness in Travis

commit024663c4b3d10fbde813089c6379925eac0ac8fc authorEdwin Brady <edwin.brady@gmail.com> dateFri 13 Jan 2017, 13:40 (10 years ago) parent6d90b546d9659c
13 files changed+247−44
.stylish-haskell.yaml+154 .travis.yml+4 HLint.hs+1 Makefile+5−2 src/Idris/ASTUtils.hs+1 src/Idris/Core/Constraints.hs+1 src/Idris/Core/TT.hs+2−2 src/Idris/Elab/Clause.hs+1−1 src/Idris/Elab/Implementation.hs+2−2 src/Idris/Elab/Interface.hs+6−6 src/Idris/Parser/Expr.hs+27−26 src/Idris/PartialEval.hs+5−5 stylize.sh+38
.stylish-haskell.yamlnew file+154
@@ -0,0 +1,154 @@
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.
7+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+ # Import cleanup
19+ - imports:
20+ # There are different ways we can align names and lists.
21+ #
22+ # - global: Align the import names and import list throughout the entire
23+ # file.
24+ #
25+ # - file: Like global, but don't add padding when there are no qualified
26+ # imports in the file.
27+ #
28+ # - group: Only align the imports per group (a group is formed by adjacent
29+ # import lines).
30+ #
31+ # - none: Do not perform any alignment.
32+ #
33+ # Default: global.
34+ align: none
35+
36+ # Folowing options affect only import list alignment.
37+ #
38+ # List align has following options:
39+ #
40+ # - after_alias: Import list is aligned with end of import including
41+ # 'as' and 'hiding' keywords.
42+ #
43+ # > import qualified Data.List as List (concat, foldl, foldr, head,
44+ # > init, last, length)
45+ #
46+ # - with_alias: Import list is aligned with start of alias or hiding.
47+ #
48+ # > import qualified Data.List as List (concat, foldl, foldr, head,
49+ # > init, last, length)
50+ #
51+ # - new_line: Import list starts always on new line.
52+ #
53+ # > import qualified Data.List as List
54+ # > (concat, foldl, foldr, head, init, last, length)
55+ #
56+ # Default: after_alias
57+ list_align: after_alias
58+
59+ # Long list align style takes effect when import is too long. This is
60+ # determined by 'columns' setting.
61+ #
62+ # - inline: This option will put as much specs on same line as possible.
63+ #
64+ # - new_line: Import list will start on new line.
65+ #
66+ # - new_line_multiline: Import list will start on new line when it's
67+ # short enough to fit to single line. Otherwise it'll be multiline.
68+ #
69+ # - multiline: One line per import list entry.
70+ # Type with contructor list acts like single import.
71+ #
72+ # > import qualified Data.Map as M
73+ # > ( empty
74+ # > , singleton
75+ # > , ...
76+ # > , delete
77+ # > )
78+ #
79+ # Default: inline
80+ long_list_align: inline
81+
82+ # List padding determines indentation of import list on lines after import.
83+ # This option affects 'list_align' and 'long_list_align'.
84+ list_padding: 4
85+
86+ # Separate lists option affects formating of import list for type
87+ # or class. The only difference is single space between type and list
88+ # of constructors, selectors and class functions.
89+ #
90+ # - true: There is single space between Foldable type and list of it's
91+ # functions.
92+ #
93+ # > import Data.Foldable (Foldable (fold, foldl, foldMap))
94+ #
95+ # - false: There is no space between Foldable type and list of it's
96+ # functions.
97+ #
98+ # > import Data.Foldable (Foldable(fold, foldl, foldMap))
99+ #
100+ # Default: true
101+ separate_lists: false
102+
103+ # Language pragmas
104+ - language_pragmas:
105+ # We can generate different styles of language pragma lists.
106+ #
107+ # - vertical: Vertical-spaced language pragmas, one per line.
108+ #
109+ # - compact: A more compact style.
110+ #
111+ # - compact_line: Similar to compact, but wrap each line with
112+ # `{-#LANGUAGE #-}'.
113+ #
114+ # Default: vertical.
115+ style: compact
116+
117+ # Align affects alignment of closing pragma brackets.
118+ #
119+ # - true: Brackets are aligned in same collumn.
120+ #
121+ # - false: Brackets are not aligned together. There is only one space
122+ # between actual import and closing bracket.
123+ #
124+ # Default: true
125+ align: true
126+
127+ # stylish-haskell can detect redundancy of some language pragmas. If this
128+ # is set to true, it will remove those redundant pragmas. Default: true.
129+ remove_redundant: true
130+
131+ # Align the types in record declarations
132+ # - records: {}
133+
134+ # Replace tabs by spaces. This is disabled by default.
135+ - tabs:
136+ # # Number of spaces to use for each tab. Default: 8, as specified by the
137+ # # Haskell report.
138+ spaces: 8
139+
140+ # Remove trailing whitespace
141+ - trailing_whitespace: {}
142+
143+# A common setting is the number of columns (parts of) code will be wrapped
144+# to. Different steps take this into account. Default: 80.
145+columns: 80
146+
147+# Sometimes, language extensions are specified in a cabal file or from the
148+# command line instead of using language pragmas in the file. stylish-haskell
149+# needs to be aware of these, so it can parse the file correctly.
150+#
151+# No language extensions are enabled by default.
152+# language_extensions:
153+ # - TemplateHaskell
154+ # - QuasiQuotes
.travis.yml+4
@@ -8,6 +8,8 @@ env:
88
99matrix:
1010 include:
11+ - env: STYLISH=YES
12+ addons: {apt: {packages: [ghc-8.0.1], sources: [hvr-ghc]}}
1113 - os: osx
1214 env: CABALVER="1.24" GHCVER="8.0.1" TESTS="test_c"
1315 compiler: ": #GHC 8.0.1"
@@ -45,6 +47,7 @@ cache:
4547 directories:
4648 - $HOME/.cabsnap
4749 - $HOME/.cabal/packages
50+ - $HOME/.stack
4851
4952before_cache:
5053 - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
@@ -68,6 +71,7 @@ before_install:
6871 export ZCAT=gzcat;
6972 export PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig:$PKG_CONFIG_PATH;
7073 fi
74+ - if [ -n "$STYLISH" ]; then ./stylize.sh; exit $?; fi
7175
7276install:
7377 - which cabal
HLint.hs+1
@@ -1,3 +1,4 @@
1+{-# LANGUAGE TemplateHaskell #-}
12-- --------------------------------------------------------------- [ HLint.hs ]
23-- HLint suggestions we like.
34--
Makefile+5−2
@@ -1,4 +1,4 @@
1−.PHONY: build configure doc install linecount nodefault pinstall lib_clean relib fast test_js test_c test test_clean lib_doc lib_doc_clean user_doc_html user_doc_pdf user_docs
1+.PHONY: build configure doc install linecount nodefault pinstall lib_clean relib fast test_js test_c stylize test test_clean lib_doc lib_doc_clean user_doc_html user_doc_pdf user_docs
22
33ARGS=
44TEST-JOBS=
@@ -24,7 +24,10 @@ pinstall: dist/setup-config
2424build: dist/setup-config
2525 $(CABAL) build $(CABALFLAGS)
2626
27−test: doc test_c
27+test: doc test_c stylize
28+
29+stylize:
30+ ./stylize.sh
2831
2932test_c:
3033 $(CABAL) test $(ARGS) --test-options \
src/Idris/ASTUtils.hs+1
@@ -1,3 +1,4 @@
1+{-# LANGUAGE MultiParamTypeClasses #-}
12{-|
23Module : Idris.ASTUtils
34Description : This implements just a few basic lens-like concepts to ease state updates. Similar to fclabels in approach, just without the extra dependency.
src/Idris/Core/Constraints.hs+1
@@ -1,3 +1,4 @@
1+{-# LANGUAGE FlexibleContexts, MultiParamTypeClasses #-}
12{-|
23Module : Idris.Core.Constraints
34Description : Check universe constraints.
src/Idris/Core/TT.hs+2−2
@@ -22,7 +22,7 @@ TT is the core language of Idris. The language has:
2222 * We have a simple collection of tactics which we use to elaborate source
2323 programs with implicit syntax into fully explicit terms.
2424-}
25−{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, DeriveGeneric,
25+{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, DeriveGeneric, FlexibleContexts,
2626 FunctionalDependencies, MultiParamTypeClasses, PatternGuards #-}
2727{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
2828module Idris.Core.TT(
@@ -1503,7 +1503,7 @@ substRetTy (Bind n (PVar _ ty) sc) = substRetTy (substV (P Ref n ty) sc)
15031503substRetTy (Bind n (PVTy ty) sc) = substRetTy (substV (P Ref n ty) sc)
15041504substRetTy (Bind n (Pi _ _ ty _) sc) = substRetTy (substV (P Ref n ty) sc)
15051505substRetTy sc = sc
1506−
1506+
15071507
15081508uniqueNameFrom :: [Name] -> [Name] -> Name
15091509uniqueNameFrom [] hs = uniqueName (nextName (sUN "x")) hs
src/Idris/Elab/Clause.hs+1−1
@@ -508,7 +508,7 @@ elabPE info fc caller r =
508508 | (P Ref n _, _) <- unApply tm = Just (n, Just (if simpl then 1 else 0))
509509 specName simpl (ExplicitS, tm)
510510 | (P Ref n _, _) <- unApply tm = Just (n, Just (if simpl then 1 else 0))
511− specName simpl (ConstraintS, tm)
511+ specName simpl (ConstraintS, tm)
512512 | (P Ref n _, _) <- unApply tm = Just (n, Just (if simpl then 1 else 0))
513513 specName simpl _ = Nothing
514514
src/Idris/Elab/Implementation.hs+2−2
@@ -93,7 +93,7 @@ elabImplementation info syn doc argDocs what fc cs parents acc opts n nfc ps pex
9393 -- if the implementation type matches any of the implementations we have already,
9494 -- and it's not a named implementation, then it's overlapping, so report an error
9595 case expn of
96− Nothing
96+ Nothing
9797 | OverlappingDictionary `notElem` opts ->
9898 do mapM_ (maybe (return ()) overlapping . findOverlapping ist (interface_determiners ci) (delab ist nty))
9999 (map fst $ interface_implementations ci)
@@ -130,7 +130,7 @@ elabImplementation info syn doc argDocs what fc cs parents acc opts n nfc ps pex
130130 Just ty -> (map (\n -> (n, getTypeIn ist n ty)) headVars, ty)
131131 _ -> (zip headVars (repeat Placeholder), Erased)
132132
133− let impps = getImpParams ist (interface_impparams ci)
133+ let impps = getImpParams ist (interface_impparams ci)
134134 (snd (unApply (substRetTy ty)))
135135 let iimpps = zip (interface_impparams ci) impps
136136
src/Idris/Elab/Interface.hs+6−6
@@ -81,16 +81,16 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
8181 syn_in { using = addToUsing (using syn_in)
8282 [(pn, pt) | (pn, _, pt) <- ps]
8383 }
84−
84+
8585 -- Calculate implicit parameters
8686 ist <- getIState
8787 let impps_ns = nub $ map (\n -> (n, emptyFC, Placeholder)) $
88− concatMap (implicitNamesIn [] ist)
88+ concatMap (implicitNamesIn [] ist)
8989 (map (\ (_,_,x) -> x) ps)
90− let impps = filter (\ (n, _, _) ->
90+ let impps = filter (\ (n, _, _) ->
9191 n `notElem` (map (\ (n, _, _) -> n) ps)) impps_ns
9292
93− let tty = impbind (map (\(n, _, ty) -> (n, ty)) impps) $
93+ let tty = impbind (map (\(n, _, ty) -> (n, ty)) impps) $
9494 pibind (map (\(n, _, ty) -> (n, ty)) ps) (PType fc)
9595
9696 logElab 5 $ "Implicit parameters are " ++ show impps
@@ -129,9 +129,9 @@ elabInterface info syn_in doc fc constraints tn tnfc ps pDocs fds ds mcn cd
129129 elabData info (syn { no_imp = no_imp syn ++ mnames,
130130 imp_methods = mnames }) doc pDocs fc [] ddecl
131131 dets <- findDets cn (map fst fds)
132− addInterface tn (CI cn (map nodoc imethods) defaults idecls
132+ addInterface tn (CI cn (map nodoc imethods) defaults idecls
133133 (map (\(n, _, _) -> n) impps)
134− (map (\(n, _, _) -> n) ps)
134+ (map (\(n, _, _) -> n) ps)
135135 (map snd constraints)
136136 [] dets)
137137
src/Idris/Parser/Expr.hs+27−26
@@ -5,38 +5,39 @@ Copyright :
55License : BSD3
66Maintainer : The Idris Community.
77-}
8−{-# LANGUAGE GeneralizedNewtypeDeriving, ConstraintKinds #-}
9−{-# LANGUAGE PatternGuards, TupleSections #-}
8+{-# LANGUAGE ConstraintKinds, GeneralizedNewtypeDeriving, PatternGuards,
9+ TupleSections #-}
1010module Idris.Parser.Expr where
1111
1212import Idris.AbsSyntax
13+import Idris.Core.TT
14+import Idris.DSL
1315import Idris.Parser.Helpers
1416import Idris.Parser.Ops
15−import Idris.DSL
16−import Idris.Core.TT
1717
1818import Prelude hiding (pi)
1919
20−import Text.Trifecta.Delta
21−import Text.Trifecta hiding (span, stringLiteral, charLiteral, natural, symbol, char, string, whiteSpace, Err)
22−import Text.Parser.LookAhead
23−import Text.Parser.Expression
24−import qualified Text.Parser.Token as Tok
25−import qualified Text.Parser.Char as Chr
26−import qualified Text.Parser.Token.Highlight as Hi
2720import Control.Applicative
2821import Control.Monad
2922import Control.Monad.State.Strict
23+import qualified Data.ByteString.UTF8 as UTF8
24+import Data.Char
3025import Data.Function (on)
31−import Data.Maybe
32−import qualified Data.List.Split as Spl
26+import qualified Data.HashSet as HS
3327import Data.List
28+import qualified Data.List.Split as Spl
29+import Data.Maybe
3430import Data.Monoid
35−import Data.Char
36−import qualified Data.HashSet as HS
3731import qualified Data.Text as T
38−import qualified Data.ByteString.UTF8 as UTF8
3932import Debug.Trace
33+import qualified Text.Parser.Char as Chr
34+import Text.Parser.Expression
35+import Text.Parser.LookAhead
36+import qualified Text.Parser.Token as Tok
37+import qualified Text.Parser.Token.Highlight as Hi
38+import Text.Trifecta hiding (Err, char, charLiteral, natural, span, string,
39+ stringLiteral, symbol, whiteSpace)
40+import Text.Trifecta.Delta
4041
4142-- | Allow implicit type declarations
4243allowImp :: SyntaxInfo -> SyntaxInfo
@@ -678,16 +679,16 @@ app syn = do f <- simpleExpr syn
678679 f
679680 (PMatchApp fc ff)
680681 (PRef fc [] (sMN 0 "match")))
681− <?> "matching application expression") <|> (do
682− fc <- getFC
683− i <- get
684− args <- many (do notEndApp; arg syn)
685− wargs <- if withAppAllowed syn && not (inPattern syn)
686− then many (do notEndApp; reservedOp "|"; expr' syn)
687− else return []
688− case args of
689− [] -> return f
690− _ -> return (withApp fc (flattenFromInt fc f args) wargs))
682+ <?> "matching application expression") <|>
683+ (do fc <- getFC
684+ i <- get
685+ args <- many (do notEndApp; arg syn)
686+ wargs <- if withAppAllowed syn && not (inPattern syn)
687+ then many (do notEndApp; reservedOp "|"; expr' syn)
688+ else return []
689+ case args of
690+ [] -> return f
691+ _ -> return (withApp fc (flattenFromInt fc f args) wargs))
691692 <?> "function application"
692693 where
693694 -- bit of a hack to deal with the situation where we're applying a
src/Idris/PartialEval.hs+5−5
@@ -276,7 +276,7 @@ mkPE_TermDecl :: IState
276276 -> [(PEArgType, Term)]
277277 -> PEDecl
278278mkPE_TermDecl ist newname sname specty ns
279− {- We need to erase the *dynamic* arguments
279+ {- We need to erase the *dynamic* arguments
280280 where their *name* appears in the *type* of a later argument
281281 in specty.
282282 i.e. if a later dynamic argument depends on an earlier dynamic
@@ -285,12 +285,12 @@ mkPE_TermDecl ist newname sname specty ns
285285 on the RHS.
286286 -}
287287 = let deps = getDepNames (eraseRet specty)
288− lhs = eraseDeps deps $
288+ lhs = eraseDeps deps $
289289 PApp emptyFC (PRef emptyFC [] newname) (mkp ns)
290290 rhs = eraseDeps deps $
291291 delab ist (mkApp (P Ref sname Erased) (map snd ns))
292292 patdef = -- trace (showTmImpls specty ++ "\n" ++ showTmImpls lhs ++ "\n"
293− -- ++ showTmImpls rhs) $
293+ -- ++ showTmImpls rhs) $
294294 lookupCtxtExact sname (idris_patdefs ist)
295295 newpats = case patdef of
296296 Nothing -> PEDecl lhs rhs [(lhs, rhs)] True
@@ -305,7 +305,7 @@ mkPE_TermDecl ist newname sname specty ns
305305
306306 -- Get names used in later arguments; assume we've called eraseRet so there's
307307 -- no names going to appear in return type
308− getDepNames (PPi _ n _ _ sc)
308+ getDepNames (PPi _ n _ _ sc)
309309 | n `elem` allNamesIn sc = n : getDepNames sc
310310 | otherwise = getDepNames sc
311311 getDepNames tm = []
@@ -337,7 +337,7 @@ getSpecApps ist env tm = ga env (explicitNames tm) where
337337 | Just n <- imparg imp = (ImplicitS n, tm)
338338 | constrarg imp = (ConstraintS, tm)
339339 | otherwise = (ExplicitS, tm)
340−
340+
341341 staticArg env False imp tm n
342342 | Just nm <- imparg imp = (ImplicitD nm, (P Ref (sUN (show n ++ "arg")) Erased))
343343 | constrarg imp = (ConstraintD, tm)
stylize.shnew file+38
@@ -0,0 +1,38 @@
1+#!/bin/bash
2+
3+set -e
4+
5+if [ -n "$TRAVIS" ];
6+then
7+ mkdir -p ~/.local/bin
8+ export PATH=$HOME/.local/bin:/opt/ghc/8.0.1/bin:$PATH
9+ curl --retry 3 -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
10+ stack install --resolver lts-7.2 stylish-haskell --no-terminal
11+fi
12+
13+
14+find . -name \*.hs -and \( -not \( -name Setup.hs -or -path ./dist/\* \) \) | xargs stylish-haskell -i > stylish-out 2>&1
15+
16+# It doesn't do exit codes properly, so we just check if it outputted anything.
17+if [ -s stylish-out ];
18+then
19+ echo "Stylish-haskell reported an error :("
20+ cat stylish-out
21+ exit 1
22+fi
23+
24+rm stylish-out
25+
26+if git status --porcelain|grep .; # true if there was any output
27+then
28+ echo "Git tree is dirty after stylizing.";
29+ if [ -n "$TRAVIS" ];
30+ then
31+ echo "Since we're on Travis, this is a build failure."
32+ echo "Run ./stylize.sh to stylize your tree and push the changes."
33+ exit 1
34+ fi
35+else
36+ echo "Stylish didn't change anything :)"
37+ exit 0;
38+fi