Skip to content
Snippets Groups Projects
Commit 827ee18e authored by Hécate Moonlight's avatar Hécate Moonlight
Browse files

Formatting configuration

parent 10a14397
No related branches found
No related tags found
No related merge requests found
# 2023
########################################
# Format the source with fourmolu
10a14397e7295f79bb65ff505e52895f4864270a
# 2022
########################################
......@@ -33,3 +39,4 @@ b0333ec5b73ba8f7a18223b203d999b38c75281d
# Move source files under 'src/'.
52d506bb4e25489f40cb5eb594dda5595aeb93ed
#!/usr/bin/env bash
set -euxo pipefail
if [[ $(uname -s) != "Linux" ]]
then
PROCS=$(sysctl -n hw.logicalcpu)
else
PROCS=$(nproc)
fi
if which fourmolu > /dev/null ; then
find Cabal Cabal-syntax cabal-install -name '*.hs' -print0 \
! -path Cabal-syntax/src/Distribution/Fields/Lexer.hs \
! -path Cabal-syntax/src/Distribution/SPDX/LicenseExceptionId.hs \
! -path Cabal-syntax/src/Distribution/SPDX/LicenseId.hs \
! -path Cabal/src/Distribution/Simple/Build/Macros/Z.hs \
! -path Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs \
| xargs -P "${PROCS}" -I {} fourmolu -q --mode check {}
else
echo "Fourmolu not found, aborting."
exit 1
fi
......@@ -2,7 +2,7 @@
---
Please include the following checklist in your PR:
* [ ] Patches conform to the [coding conventions](https://github.com/haskell/cabal/blob/master/CONTRIBUTING.md#conventions).
* [ ] Patches conform to the [coding conventions](https://github.com/haskell/cabal/blob/master/CONTRIBUTING.md#other-conventions).
* [ ] Any changes that could be relevant to users [have been recorded in the changelog](https://github.com/haskell/cabal/blob/master/CONTRIBUTING.md#changelog).
* [ ] The documentation has been updated, if necessary.
* [ ] Include [manual QA notes](https://github.com/haskell/cabal/blob/master/CONTRIBUTING.md#qa-notes) if your PR relates to cabal-install.
......
name: Linting
on:
pull_request:
push:
branches: ["master"]
jobs:
fourmolu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: haskell-actions/run-fourmolu@v8
with:
pattern: |
Cabal/**/*.hs
Cabal-syntax/**/*.hs
Cabal-install/**/*.hs
!Cabal-syntax/src/Distribution/Fields/Lexer.hs
!Cabal-syntax/src/Distribution/SPDX/LicenseExceptionId.hs
!Cabal-syntax/src/Distribution/SPDX/LicenseId.hs
!Cabal/src/Distribution/Simple/Build/Macros/Z.hs
!Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs
name: Assorted
on:
push:
branches:
- master
pull_request:
release:
types:
- created
jobs:
check:
name: Whitespace
runs-on: ubuntu-latest
env:
fix-whitespace-ver: '0.0.10'
steps:
- uses: actions/checkout@v3
name: Checkout sources
- name: Create directory for binary
run: |
mkdir -p $HOME/.local/bin
- uses: actions/cache@v3
name: Cache the binary
id: cache
with:
path: "~/.local/bin"
key: fix-whitespace-${{ env.fix-whitespace-ver }}
# See https://github.com/haskell/cabal/pull/8739
- name: Sudo chmod to permit ghcup to update its cache
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
sudo mkdir -p /usr/local/.ghcup/cache
sudo chown -R $USER /usr/local/.ghcup
sudo chmod -R 777 /usr/local/.ghcup
fi
- uses: haskell/actions/setup@v2
if: ${{ !steps.cache.outputs.cache-hit }}
with:
ghc-version: '9.2'
cabal-version: latest
- name: Install fix-whitespace
if: ${{ !steps.cache.outputs.cache-hit }}
run: |
cabal install --ignore-project --install-method=copy --installdir=$HOME/.local/bin fix-whitespace-${{ env.fix-whitespace-ver }}
strip $HOME/.local/bin/fix-whitespace
- name: Check the whitespace issue
run: |
$HOME/.local/bin/fix-whitespace --check
......@@ -137,38 +137,16 @@ For instance:
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
of their patch is not influenced by their setup or implicit knowledge of the system.
Whitespace Conventions
----------------------
* No tab characters allowed.
* No trailing whitespace allowed.
* File needs to be terminated by a newline character.
These conventions are enforced by the
[fix-whitespace](https://hackage.haskell.org/package/fix-whitespace)
tool. Install it from hackage as usual (`cabal install fix-whitespace`)
and run it in the project root to fix whitespace violations.
The files included in the automatic whitespace check are specified in
`fix-whitespace.yaml`. Please add to this file if you add textfiles
to this repository that are not included by the rules given there.
Note that files that make essential use of tab characters (like `Makefile`)
should _not_ be included in the automatic check.
Whitespace conventions are enforced by
[CI](https://github.com/haskell/cabal/actions/workflows/whitespace.yml).
If you push a fix of a whitespace violation, please do so in a
_separate commit_.
Code Style
---------------
We use automated formatting with Fourmolu to enforce a unified style across the code bases. It is checked in the CI process.
You can automatically format the code bases with `make style` at the top level of the project.
Other Conventions
-----------------
* Try to follow style conventions of a file you are modifying, and
avoid gratuitous reformatting (it makes merges harder!)
* Format your commit messages [in the standard way](https://chris.beams.io/posts/git-commit/#seven-rules).
* A lot of Cabal does not have top-level comments. We are trying to
......@@ -227,10 +205,6 @@ Other Conventions
#endif
```
We like [this style guide][guide].
[guide]: https://github.com/tibbe/haskell-style-guide/blob/master/haskell-style.md
GitHub Ticket Conventions
-------------------
......
......@@ -14,6 +14,19 @@ lib : $(LEXER_HS)
exe : $(LEXER_HS)
$(CABALBUILD) cabal-install:exes
init: ## Set up git hooks and ignored revisions
@git config core.hooksPath .githooks
## TODO
style: ## Run the code styler
@find Cabal Cabal-syntax cabal-install -name '*.hs' \
! -path Cabal-syntax/src/Distribution/Fields/Lexer.hs \
! -path Cabal-syntax/src/Distribution/SPDX/LicenseExceptionId.hs \
! -path Cabal-syntax/src/Distribution/SPDX/LicenseId.hs \
! -path Cabal/src/Distribution/Simple/Build/Macros/Z.hs \
! -path Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs \
| xargs -P $(PROCS) -I {} fourmolu -q -i {}
# source generation: Lexer
LEXER_HS:=Cabal-syntax/src/Distribution/Fields/Lexer.hs
......@@ -227,3 +240,9 @@ users-guide-requirements: doc/requirements.txt
doc/requirements.txt: .python-sphinx-virtualenv
. .python-sphinx-virtualenv/bin/activate \
&& make -C doc build-and-check-requirements
ifeq ($(UNAME), Darwin)
PROCS := $(shell sysctl -n hw.logicalcpu)
else
PROCS := $(shell nproc)
endif
indentation: 2
comma-style: leading # for lists, tuples etc. - can also be 'trailing'
import-export-style: leading
record-brace-space: false # rec {x = 1} vs. rec{x = 1}
indent-wheres: true # 'false' means save space by only half-indenting the 'where' keyword
respectful: true # don't be too opinionated about newlines etc.
haddock-style: single-line # '--' vs. '{-'
haddock-style-module: single-line
newlines-between-decls: 1 # number of newlines between top-level declarations
fixities: []
function-arrows: leading
single-constraint-parens: never
in-style: right-align
let-style: auto
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment