Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: EncodePanda/stylish-haskell
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: haskell/stylish-haskell
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Able to merge. These branches can be automatically merged.
Loading
Showing with 7,969 additions and 2,681 deletions.
  1. +22 −63 .github/workflows/ci.yml
  2. +1 −0 .gitignore
  3. +116 −0 CHANGELOG
  4. +2 −4 Makefile
  5. +26 −7 README.markdown
  6. +3 −0 cabal.project
  7. +200 −5 data/stylish-haskell.yaml
  8. +26 −0 default.nix
  9. +20 −0 haskell-pkgs.nix
  10. +24 −16 lib/Language/Haskell/Stylish.hs
  11. +28 −29 lib/Language/Haskell/Stylish/Align.hs
  12. +18 −18 lib/Language/Haskell/Stylish/Block.hs
  13. +145 −0 lib/Language/Haskell/Stylish/Comments.hs
  14. +121 −46 lib/Language/Haskell/Stylish/Config.hs
  15. +72 −33 lib/Language/Haskell/Stylish/Config/Cabal.hs
  16. +14 −1 lib/Language/Haskell/Stylish/Config/Internal.hs
  17. +144 −64 lib/Language/Haskell/Stylish/Editor.hs
  18. +91 −0 lib/Language/Haskell/Stylish/GHC.hs
  19. +150 −0 lib/Language/Haskell/Stylish/Module.hs
  20. +71 −0 lib/Language/Haskell/Stylish/Ordering.hs
  21. +91 −56 lib/Language/Haskell/Stylish/Parse.hs
  22. +346 −0 lib/Language/Haskell/Stylish/Printer.hs
  23. +1 −13 lib/Language/Haskell/Stylish/Step.hs
  24. +541 −98 lib/Language/Haskell/Stylish/Step/Data.hs
  25. +559 −345 lib/Language/Haskell/Stylish/Step/Imports.hs
  26. +84 −44 lib/Language/Haskell/Stylish/Step/LanguagePragmas.hs
  27. +229 −0 lib/Language/Haskell/Stylish/Step/ModuleHeader.hs
  28. +148 −79 lib/Language/Haskell/Stylish/Step/SimpleAlign.hs
  29. +59 −34 lib/Language/Haskell/Stylish/Step/Squash.hs
  30. +1 −1 lib/Language/Haskell/Stylish/Step/TrailingWhitespace.hs
  31. +25 −92 lib/Language/Haskell/Stylish/Step/UnicodeSyntax.hs
  32. +94 −25 lib/Language/Haskell/Stylish/Util.hs
  33. +4 −2 scripts/latest.sh
  34. +1 −1 scripts/stylish-haskell.sh
  35. +33 −0 shell.nix
  36. +29 −8 src/Main.hs
  37. +0 −9 stack.yaml
  38. +0 −40 stack.yaml.lock
  39. +84 −95 stylish-haskell.cabal
  40. +119 −64 tests/Language/Haskell/Stylish/Config/Tests.hs
  41. +40 −24 tests/Language/Haskell/Stylish/Parse/Tests.hs
  42. +34 −0 tests/Language/Haskell/Stylish/Regressions.hs
  43. +1,201 −337 tests/Language/Haskell/Stylish/Step/Data/Tests.hs
  44. +321 −0 tests/Language/Haskell/Stylish/Step/Imports/FelixTests.hs
  45. +1,079 −601 tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
  46. +165 −150 tests/Language/Haskell/Stylish/Step/LanguagePragmas/Tests.hs
  47. +935 −0 tests/Language/Haskell/Stylish/Step/ModuleHeader/Tests.hs
  48. +227 −111 tests/Language/Haskell/Stylish/Step/SimpleAlign/Tests.hs
  49. +70 −78 tests/Language/Haskell/Stylish/Step/Squash/Tests.hs
  50. +15 −18 tests/Language/Haskell/Stylish/Step/Tabs/Tests.hs
  51. +15 −18 tests/Language/Haskell/Stylish/Step/TrailingWhitespace/Tests.hs
  52. +32 −27 tests/Language/Haskell/Stylish/Step/UnicodeSyntax/Tests.hs
  53. +19 −11 tests/Language/Haskell/Stylish/Tests.hs
  54. +68 −14 tests/Language/Haskell/Stylish/Tests/Util.hs
  55. +6 −0 tests/TestSuite.hs
85 changes: 22 additions & 63 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -4,54 +4,39 @@ on: ['pull_request', 'push']

jobs:
build:
name: Build on ${{ matrix.os }}
name: Build on ${{ matrix.os }} with GHC ${{ matrix.ghc }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
stack: ["2.1.3"]
ghc: ["8.8.3"]
ghc: ["9.10", "9.12"]

steps:
- name: Get the version
id: get_version
run: 'echo ::set-output name=version::${GITHUB_REF#refs/tags/}'
- uses: actions/checkout@v4

- uses: actions/checkout@v2

- uses: actions/setup-haskell@v1.1
name: Setup Haskell Stack
- uses: haskell-actions/setup@v2
id: setup
with:
ghc-version: ${{ matrix.ghc }}
stack-version: ${{ matrix.stack }}

- uses: actions/cache@v2
name: Cache ~/.stack
- uses: actions/cache@v3
with:
path: ~/.stack
key: ${{ runner.os }}-${{ matrix.ghc }}-v2

- name: Add ~/.local/bin to PATH
run: echo "::add-path::$HOME/.local/bin"
path: ${{ steps.setup.outputs.cabal-store }}
key: ${{ runner.os }}-${{ matrix.ghc }}-v2-${{ hashFiles('*.cabal') }}
restore-keys: |
${{ runner.os }}-${{ matrix.ghc }}-v2-
- name: Build
run: make build
id: build
- run: make build
- run: make test

- name: Test
run: make test

- name: Build artifact
if: startsWith(github.ref, 'refs/tags')
- if: startsWith(github.ref, 'refs/tags') && startsWith(matrix.ghc, '9.10')
run: make artifact
env:
PATAT_TAG: ${{ steps.get_version.outputs.version }}

- uses: actions/upload-artifact@v2
if: startsWith(github.ref, 'refs/tags')
- uses: actions/upload-artifact@v4
if: startsWith(github.ref, 'refs/tags') && startsWith(matrix.ghc, '9.10')
with:
path: artifacts/*
name: artifacts
name: artifacts-${{ runner.os }}

release:
name: Release
@@ -60,41 +45,15 @@ jobs:
if: startsWith(github.ref, 'refs/tags')

steps:
- name: Get the version
id: get_version
run: 'echo ::set-output name=version::${GITHUB_REF#refs/tags/}'

- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: artifacts

- name: Display structure of downloaded files
run: ls -R
pattern: artifacts-*

- uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.version }}
release_name: ${{ steps.get_version.outputs.version }}

- name: Upload Linux Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./stylish-haskell-${{ steps.get_version.outputs.version }}-linux-x86_64.tar.gz
asset_name: stylish-haskell-${{ steps.get_version.outputs.version }}-linux-x86_64.tar.gz
asset_content_type: application/gzip
- run: ls -R
- run: 'sha256sum artifacts-*/*'

- name: Upload MacOS Asset
uses: actions/upload-release-asset@v1
- uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./stylish-haskell-${{ steps.get_version.outputs.version }}-darwin-x86_64.zip
asset_name: stylish-haskell-${{ steps.get_version.outputs.version }}-darwin-x86_64.zip
asset_content_type: application/zip
files: 'artifacts-*/stylish-haskell-*'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -17,5 +17,6 @@ cabal-dev
cabal.config
cabal.sandbox.config
cabal.sandbox.config
cabal.project.local
dist
/dist-newstyle/
116 changes: 116 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,121 @@
# CHANGELOG

- 0.15.1.0 (2025-04-13)
* #491 Support GHC 9.12 (By GuillaumedeVolpiano)

- 0.15.0.1 (2025-04-13)
* #493 Support Cabal 3.12 again (By GuillaumedeVolpiano)

- 0.15.0.0 (2025-04-13)
* #480 Support with GHC 9.10 (By Jan Hrček)

* #482 Add `ConfigSearchStrategy` to allow avoiding `getCurrentDirectory`
when loading config (by Jan Hrček)

This is breaking API change that can be fixed like this:

```diff
-format Nothing maybeFile contents
+format SearchFromCurrentDirectory maybeFile contents

-format (Just cfgFile) maybeFile content
+format (UseConfig cfgFile) maybeFile content
```

* Bump `Cabal` lower bound to 3.14

- 0.14.6.0 (2024-01-19)
* #471 Support GHC 9.8 (by Michael Peyton Jones)
* #440 Fix dissappearing `DEPRECATED` pragma on module (by Lev Dvorkin)
* #464 Fix compilation issue with GHC 9.4

- 0.14.5.0 (2023-06-23)
* #459 Support GHC 9.6 (by Michael Peyton Jones)
* #445 Default `ghc-lib` flag to True (by amesgen)

- 0.14.4.0 (2023-01-09)
* #421 Support GHC 9.4 (by Lei Zhu)
* #439 Fix NoXyz extension issues for .cabal files (by Lev Dvorkin)
* #424 Deriving alignment for enums (by Lev Dvorkin)
* #416 Support Safe/Trustworthy/Unsafe extensions

- 0.14.3.0 (2022-09-28)
* Fix parsing of NoXyz extensions
* Bump `Cabal` upper bound to 4.0
* Add option to automatically group imports (by Tikhon Jelvis)

- 0.14.2.0 (2022-04-27)
* Add a build flag to force the use of ghc-lib-parser

- 0.14.1.0 (2022-03-31)
* Unify the Editor modules, deal with overlap better

- 0.14.0.1 (2022-03-17)
* Use GHC API directly if >= 9.2.2
* Bump `bytestring` upper bound to 0.12

- 0.14.0.0 (2022-03-16)
* Port to GHC 9.2 AST (by jaspervdj)
* Case insensitive import sort (by vlatkoB)
* Fix issue with dissappearing GADT kind signatures (by Łukasz Gołębiewski)

- 0.13.0.0 (2021-09-15)
* Don't remove ticks on promoted data types (by Jim McStanton)
* Add break_only_where option (by 1Computer1)
* Keep wildcard if present in IEThingWith (by Moisés Ackerman)
* Generalise break_only_where to allow single-line module headers
(by Thomas Winant)
* Add new configuration to ModuleHeader step (by Pawel Szulc)
* Add a language pragma style "vertical_compact" (by Javran Cheng)
* Don't remove existential quantification (by Imuli)
* Add support for post qualified import formatting (by Moisés Ackerman)
* Bump `optparse-applicative` upper bound to 0.17

- 0.12.2.0 (2020-10-08)
* align: Add a new option for aligning only adjacent items (by 1Computer1)
* align: Add support for aligning MultiWayIf syntax (by 1Computer1)
* data: Fix some issues with record field padding
* module_header: Add separate_lists option
* imports: Respect separate_lists for (..) imports
* data: Make sorting deriving list optional (by Maxim Koltsov)

- 0.12.1.0 (2020-10-05)
* Bump Cabal-version to 2.4 (by Łukasz Gołębiewski)
* Fix "group" import sort with multi-line imports (by Maxim Koltsov)

- 0.12.0.0 (2020-10-02)
* Use ghc-lib-parser rather than haskell-src-exts

This patch swaps out the parsing library from `haskell-src-exts` to
`ghc-lib-parser`, which gives us better compatibility with GHC.

Because almost every module heavily used the Haskell AST provided by
`haskell-src-exts`, this was a huge effort and it would not have been
possible without Felix Mulder doing an initial port, GSoC student
Beatrice Vergani porting several other steps, and Łukasz Gołębiewski and
Paweł Szulc who helped me finish up things in the home stretch.

I've generally tried to keep styling 100% compatible with what was there
before, but some issues may have unintentionally slipped in so please
report those.

This introduces one new import styling contributed by Felix: when
wrapping import lists over multiple lines, you can repeat the module
name, e.g.:

import Control.Monad.Except as X (ExceptT (..), MonadError (..))
import Control.Monad.Except as X (runExceptT, withExceptT)

This is activated by using `import_align: repeat`.

Secondly, a new Step was added, `module_header`, which formats the
export list of a module, including the trailing `where` clause. Details
for this new step can be found in the `data/stylish-haskell.yaml`.

* Remove `semigroup` dependency for GHC >= 8.0
* Bump `strict` upper bound to 0.4
* Bump `Cabal` upper bound to 3.3 for test suite

- 0.11.0.3 (2020-08-02)
* Set default-language to Haskell2010

6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -27,8 +27,6 @@ COMPRESS_BIN_DEPS=$(UPX_BINARY)
COMPRESS_BIN=upx
endif

STACK=stack --system-ghc

# Default target.
.PHONY: build
build: $(STYLISH_BINARY)
@@ -49,7 +47,7 @@ $(STYLISH_PACKAGE).$(ARCHIVE): $(STYLISH_BINARY) $(COMPRESS_BIN_DEPS)
$(ARCHIVE_CREATE) $(STYLISH_PACKAGE).$(ARCHIVE) $(STYLISH_PACKAGE)

$(STYLISH_BINARY):
$(STACK) build --copy-bins
cabal install --installdir="$(dir $(STYLISH_BINARY))"

# UPX is used to compress the resulting binary. We currently don't use this on
# Mac OS.
@@ -62,4 +60,4 @@ $(UPX_BINARY):

.PHONY: test
test:
stack build --test
cabal test
33 changes: 26 additions & 7 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -2,7 +2,8 @@

<img src="./assets/Logo/SVG/RoundedLogo.svg" width="100px">

[![Build Status](https://img.shields.io/circleci/project/github/jaspervdj/stylish-haskell.svg)](https://circleci.com/gh/jaspervdj/stylish-haskell)
![Stack Build Status](https://github.com/jaspervdj/stylish-haskell/workflows/CI/badge.svg)
![Cabal Build Status](https://github.com/jaspervdj/stylish-haskell/workflows/Cabal/badge.svg)

## Introduction

@@ -37,7 +38,7 @@ You can also install it using your package manager:

Feature requests are welcome! Use the [issue tracker] for that.

[issue tracker]: https://github.com/jaspervdj/stylish-haskell/issues
[issue tracker]: https://github.com/haskell/stylish-haskell/issues

## Example

@@ -158,7 +159,21 @@ data Foo a
deriving (ToJSON) via Bar Foo
```

## VIM integration
## Editor integration

### Haskell Language Server
[Haskell Language Server(HLS)][HLS] includes a [plugin][HLS stylish-haskell Plugin]
for stylish-haskell. By changing the formatting provider option
(`haskell.formattingProvider`) to `stylish-haskell` as described in
[HLS options][HLS option], any editors that support [Language Server Protocol][LSP]
can use stylish-haskell for formatting.

[HLS]: https://github.com/haskell/haskell-language-server
[HLS option]: https://haskell-language-server.readthedocs.io/en/latest/configuration.html#language-specific-server-options
[HLS stylish-haskell Plugin]: https://github.com/haskell/haskell-language-server/blob/master/plugins/hls-stylish-haskell-plugin/src/Ide/Plugin/StylishHaskell.hs
[LSP]: https://microsoft.github.io/language-server-protocol/

### VIM integration

Since it works as a filter it is pretty easy to integrate this with VIM.

@@ -192,7 +207,7 @@ Haskell file:
[vim-stylish-haskell]: https://github.com/nbouscal/vim-stylish-haskell
[vim-stylishask]: https://github.com/alx741/vim-stylishask
## Emacs integration
### Emacs integration
[haskell-mode] for Emacs supports `stylish-haskell`. For configuration,
see [the “Using external formatters” section][haskell-mode/format] of the
@@ -201,7 +216,7 @@ haskell-mode manual.
[haskell-mode]: https://github.com/haskell/haskell-mode
[haskell-mode/format]: http://haskell.github.io/haskell-mode/manual/latest/Autoformating.html
## Atom integration
### Atom integration
[ide-haskell] for Atom supports `stylish-haskell`.
@@ -210,7 +225,7 @@ haskell-mode manual.
[ide-haskell]: https://atom.io/packages/ide-haskell
[atom-beautify]: Https://atom.io/packages/atom-beautify
## Visual Studio Code integration
### Visual Studio Code integration
[stylish-haskell-vscode] for VSCode supports `stylish-haskell`.
@@ -220,7 +235,7 @@ haskell-mode manual.
You can quickly grab the latest binary and run `stylish-haskell` like so:
curl -sL https://raw.github.com/jaspervdj/stylish-haskell/master/scripts/latest.sh | sh -s .
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`.
@@ -235,3 +250,7 @@ Contributors:
- Leonid Onokhov
- Michael Snoyman
- Mikhail Glushenkov
- Beatrice Vergani
- Paweł Szulc
- Łukasz Gołębiewski
- Felix Mulder
3 changes: 3 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .

tests: true
Loading