Skip to content

Commit 827ee18

Browse files
committed
Formatting configuration
1 parent 10a1439 commit 827ee18

File tree

8 files changed

+91
-88
lines changed

8 files changed

+91
-88
lines changed

.git-blame-ignore-revs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 2023
2+
########################################
3+
4+
# Format the source with fourmolu
5+
10a14397e7295f79bb65ff505e52895f4864270a
6+
17
# 2022
28
########################################
39

@@ -33,3 +39,4 @@ b0333ec5b73ba8f7a18223b203d999b38c75281d
3339

3440
# Move source files under 'src/'.
3541
52d506bb4e25489f40cb5eb594dda5595aeb93ed
42+

.githooks/pre-push

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
if [[ $(uname -s) != "Linux" ]]
6+
then
7+
PROCS=$(sysctl -n hw.logicalcpu)
8+
else
9+
PROCS=$(nproc)
10+
fi
11+
12+
if which fourmolu > /dev/null ; then
13+
find Cabal Cabal-syntax cabal-install -name '*.hs' -print0 \
14+
! -path Cabal-syntax/src/Distribution/Fields/Lexer.hs \
15+
! -path Cabal-syntax/src/Distribution/SPDX/LicenseExceptionId.hs \
16+
! -path Cabal-syntax/src/Distribution/SPDX/LicenseId.hs \
17+
! -path Cabal/src/Distribution/Simple/Build/Macros/Z.hs \
18+
! -path Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs \
19+
| xargs -P "${PROCS}" -I {} fourmolu -q --mode check {}
20+
else
21+
echo "Fourmolu not found, aborting."
22+
exit 1
23+
fi

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
---
33
Please include the following checklist in your PR:
44

5-
* [ ] Patches conform to the [coding conventions](https://github.com/haskell/cabal/blob/master/CONTRIBUTING.md#conventions).
5+
* [ ] Patches conform to the [coding conventions](https://github.com/haskell/cabal/blob/master/CONTRIBUTING.md#other-conventions).
66
* [ ] Any changes that could be relevant to users [have been recorded in the changelog](https://github.com/haskell/cabal/blob/master/CONTRIBUTING.md#changelog).
77
* [ ] The documentation has been updated, if necessary.
88
* [ ] Include [manual QA notes](https://github.com/haskell/cabal/blob/master/CONTRIBUTING.md#qa-notes) if your PR relates to cabal-install.

.github/workflows/linting.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Linting
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: ["master"]
7+
8+
jobs:
9+
fourmolu:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: haskell-actions/run-fourmolu@v8
14+
with:
15+
pattern: |
16+
Cabal/**/*.hs
17+
Cabal-syntax/**/*.hs
18+
Cabal-install/**/*.hs
19+
!Cabal-syntax/src/Distribution/Fields/Lexer.hs
20+
!Cabal-syntax/src/Distribution/SPDX/LicenseExceptionId.hs
21+
!Cabal-syntax/src/Distribution/SPDX/LicenseId.hs
22+
!Cabal/src/Distribution/Simple/Build/Macros/Z.hs
23+
!Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs

.github/workflows/whitespace.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -137,38 +137,16 @@ For instance:
137137
Manual QA is not expected to find every possible bug, but to really challenge the assumptions of the contributor, and to verify that their own testing
138138
of their patch is not influenced by their setup or implicit knowledge of the system.
139139

140-
Whitespace Conventions
141-
----------------------
142-
143-
* No tab characters allowed.
144-
* No trailing whitespace allowed.
145-
* File needs to be terminated by a newline character.
146-
147-
These conventions are enforced by the
148-
[fix-whitespace](https://hackage.haskell.org/package/fix-whitespace)
149-
tool. Install it from hackage as usual (`cabal install fix-whitespace`)
150-
and run it in the project root to fix whitespace violations.
151-
152-
The files included in the automatic whitespace check are specified in
153-
`fix-whitespace.yaml`. Please add to this file if you add textfiles
154-
to this repository that are not included by the rules given there.
155-
Note that files that make essential use of tab characters (like `Makefile`)
156-
should _not_ be included in the automatic check.
157-
158-
Whitespace conventions are enforced by
159-
[CI](https://github.com/haskell/cabal/actions/workflows/whitespace.yml).
160-
If you push a fix of a whitespace violation, please do so in a
161-
_separate commit_.
162-
163140

141+
Code Style
142+
---------------
164143

144+
We use automated formatting with Fourmolu to enforce a unified style across the code bases. It is checked in the CI process.
145+
You can automatically format the code bases with `make style` at the top level of the project.
165146

166147
Other Conventions
167148
-----------------
168149

169-
* Try to follow style conventions of a file you are modifying, and
170-
avoid gratuitous reformatting (it makes merges harder!)
171-
172150
* Format your commit messages [in the standard way](https://chris.beams.io/posts/git-commit/#seven-rules).
173151

174152
* A lot of Cabal does not have top-level comments. We are trying to
@@ -227,10 +205,6 @@ Other Conventions
227205
#endif
228206
```
229207

230-
We like [this style guide][guide].
231-
232-
[guide]: https://github.com/tibbe/haskell-style-guide/blob/master/haskell-style.md
233-
234208
GitHub Ticket Conventions
235209
-------------------
236210

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ lib : $(LEXER_HS)
1414
exe : $(LEXER_HS)
1515
$(CABALBUILD) cabal-install:exes
1616

17+
init: ## Set up git hooks and ignored revisions
18+
@git config core.hooksPath .githooks
19+
## TODO
20+
21+
style: ## Run the code styler
22+
@find Cabal Cabal-syntax cabal-install -name '*.hs' \
23+
! -path Cabal-syntax/src/Distribution/Fields/Lexer.hs \
24+
! -path Cabal-syntax/src/Distribution/SPDX/LicenseExceptionId.hs \
25+
! -path Cabal-syntax/src/Distribution/SPDX/LicenseId.hs \
26+
! -path Cabal/src/Distribution/Simple/Build/Macros/Z.hs \
27+
! -path Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs \
28+
| xargs -P $(PROCS) -I {} fourmolu -q -i {}
29+
1730
# source generation: Lexer
1831

1932
LEXER_HS:=Cabal-syntax/src/Distribution/Fields/Lexer.hs
@@ -227,3 +240,9 @@ users-guide-requirements: doc/requirements.txt
227240
doc/requirements.txt: .python-sphinx-virtualenv
228241
. .python-sphinx-virtualenv/bin/activate \
229242
&& make -C doc build-and-check-requirements
243+
244+
ifeq ($(UNAME), Darwin)
245+
PROCS := $(shell sysctl -n hw.logicalcpu)
246+
else
247+
PROCS := $(shell nproc)
248+
endif

fourmolu.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
indentation: 2
2+
comma-style: leading # for lists, tuples etc. - can also be 'trailing'
3+
import-export-style: leading
4+
record-brace-space: false # rec {x = 1} vs. rec{x = 1}
5+
indent-wheres: true # 'false' means save space by only half-indenting the 'where' keyword
6+
respectful: true # don't be too opinionated about newlines etc.
7+
haddock-style: single-line # '--' vs. '{-'
8+
haddock-style-module: single-line
9+
newlines-between-decls: 1 # number of newlines between top-level declarations
10+
fixities: []
11+
function-arrows: leading
12+
single-constraint-parens: never
13+
in-style: right-align
14+
let-style: auto

0 commit comments

Comments
 (0)