Skip to content

Commit

Permalink
Merge pull request #67 from serokell/diogo/#26-stylish-hlint
Browse files Browse the repository at this point in the history
[#26] Add stylish-haskell and hlint
  • Loading branch information
dcastro authored Apr 14, 2022
2 parents 33390ff + f600d2e commit 631db98
Show file tree
Hide file tree
Showing 33 changed files with 566 additions and 231 deletions.
6 changes: 6 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ steps:
- label: validate cabal files
command: nix run -f ci.nix stack2cabal -c ./scripts/validate-cabal-files.sh

- label: stylish
command: nix run -f ci.nix pkgs.gnumake pkgs-stylish.stylish-haskell -c ./scripts/validate-stylish.sh

- label: lint
command: nix run -f ci.nix pkgs.haskellPackages.hlint -c hlint .

- label: build
key: build
command: nix-build ci.nix -A lib -A cli
Expand Down
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
#
# SPDX-License-Identifier: Unlicense

# top-most EditorConfig file
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space

[*.hs]
indent_size = 2
max_line_length = 100
31 changes: 11 additions & 20 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
[//]: # (This is a template of a pull request template.)
[//]: # (You should modify it considering specifics of a particular repository and put it there.)
[//]: # (Comments like this are meta-comments, they shouldn't be present in the final template.)
[//]: # (Comments starting with '<!---' are intended to stay in the final template.)

[//]: # (Keep in mind that it's only a template which contains items relevant to almost all conceivable repository.)
[//]: # (There can be other important items relevant to your repository that you can add here.)

## Description

<!--
Expand All @@ -14,21 +6,22 @@ further subdivide this into a section describing the problem you are solving and
another describing your solution.
-->

[//]: # (Here you can add a link to the corresponding issue tracker, e. g. https://issues.serokell.io/issue/AD-)
[//]: # (For GitHub/GitLab issues it is better to use just hash symbol or exclamation mark as it is more resistant to repo movements)
[//]: # (In this case please also prefix the link with "Resolves" keyword)
[//]: # (See https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
[//]: # (See https://help.github.com/en/github/managing-your-work-on-github/closing-issues-using-keywords)
## Related issue(s)

<!--
- Short description of how the PR relates to the issue, including an issue link.
For example
Short description of how the PR relates to the issue, including an issue link.
For example:
- Fixed #100500 by adding lenses to exported items
Write 'None' if there are no related issues (which is discouraged).
If this PR does not fully resolve the linked issue and is not meant to close it,
replace `Fixed #` with `Fixed part of #`.
-->

Fixed #

## :white_check_mark: Checklist for your Pull Request

<!--
Expand All @@ -48,24 +41,22 @@ you must be able to justify that.
- [ ] If I fixed a bug, I added a regression test to prevent the bug from
silently reappearing again.

[//]: # (Add more docs here if you have them in the repository)
- Documentation
- [ ] I checked whether I should update the docs and did so if necessary:
- [README](../tree/master/README.md)
- Haddock

[//]: # (Mostly for public repositories)
[//]: # (Recording changes is optional, depends on repository, useful for some libs)
<!-- TODO: uncomment this after the first release. -->
<!--
- Public contracts
- [ ] Any modifications of public contracts comply with the [Evolution
of Public Contracts](https://www.notion.so/serokell/Evolution-of-Public-Contracts-2a3bf7971abe4806a24f63c84e7076c5) policy.
- [ ] I added an entry to the [changelog](../tree/master/CHANGES.md) if my changes are visible to the users
and
- [ ] provided a migration guide for breaking changes if possible
-->

#### Stylistic guide (mandatory)

[//]: # (Update link to style guide if necesary or remove if it's not present)

- [ ] My commits comply with [the policy used in Serokell](https://www.notion.so/serokell/Where-and-how-to-commit-your-work-58f8973a4b3142c8abbd2e6fd5b3a08e).
- [ ] My code complies with the [style guide](../tree/master/docs/code-style.md).
100 changes: 100 additions & 0 deletions .hlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
#
# SPDX-License-Identifier: Unlicense

###########################################################################
# Settings
###########################################################################

- arguments: [-XTypeApplications, -XRecursiveDo, -XBlockArguments]

# These are just too annoying
- ignore: { name: Redundant do }
- ignore: { name: Redundant bracket }
- ignore: { name: Redundant lambda }
- ignore: { name: Redundant $ }
- ignore: { name: Redundant flip }
- ignore: { name: Move brackets to avoid $ }
- ignore: { name: Avoid lambda using `infix` }

# Losing variable names can be not-nice
- ignore: { name: Eta reduce }
- ignore: { name: Avoid lambda }

# Humans know better
- ignore: { name: Use camelCase }
- ignore: { name: Use const }
- ignore: { name: Use section }
- ignore: { name: Use if }
- ignore: { name: Use notElem }
- ignore: { name: Use fromMaybe }
- ignore: { name: Replace case with fromMaybe }
- ignore: { name: Use maybe }
- ignore: { name: Use fmap }
- ignore: { name: Use foldl }
- ignore: { name: "Use :" }
- ignore: { name: Use ++ }
- ignore: { name: Use || }
- ignore: { name: Use && }
- ignore: { name: 'Use ?~' }
- ignore: { name: Use <$> }
- ignore: { name: Use unless }

# Sometimes [Char] is okay (if it means "a sequence of characters")
- ignore: { name: Use String }

# Sometimes TemplateHaskell is needed to please stylish-haskell
- ignore: { name: Unused LANGUAGE pragma }

# Some 'data' records will be extended with more fields later,
# so they shouldn't be replaced with 'newtype' blindly
- ignore: { name: Use newtype instead of data }

###########################################################################
# Various stuff
###########################################################################

- warn:
name: "Avoid 'both'"
lhs: both
rhs: Control.Lens.each
note: |
If you use 'both' on a 2-tuple and later it's accidentally
replaced with a longer tuple, 'both' will be silently applied to only
the *last two elements* instead of failing with a type error.
* If you want to traverse all elements of the tuple, use 'each'.
* If 'both' is used on 'Either' here, replace it with 'chosen'.
- warn: { lhs: either (const True) (const False), rhs: isLeft }
- warn: { lhs: either (const False) (const True), rhs: isRight }

- warn: { lhs: map fst &&& map snd, rhs: unzip }

- warn:
name: "'fromIntegral' is unsafe without type annotations."
lhs: fromIntegral x
rhs: fromIntegral @t1 @t2 x
- warn:
name: "'fromIntegral' is unsafe without TWO type annotations."
lhs: fromIntegral @t1 x
rhs: fromIntegral @t1 @t2 x
- warn:
name: "Avoid the use of '(+||)' and '(||+)'"
lhs: '(Fmt.+||)'
rhs: '(Fmt.+|)'
note: "The use of '(+||)' may result in outputting raw Haskell into user-facing code"
- warn:
name: "Avoid the use of '(+||)' and '(||+)'"
lhs: '(Fmt.||+)'
rhs: '(Fmt.|+)'
note: "The use of '(||+)' may result in outputting raw Haskell into user-facing code"
- warn:
name: "Avoid the use of '(||++||)'"
lhs: '(Fmt.||++||)'
rhs: '(Fmt.|++|)'
note: "The use of '(||++||)' may result in outputting raw Haskell into user-facing code"
- warn:
name: "Avoid the use of '(||++|)'"
lhs: '(Fmt.||++|)'
rhs: '(Fmt.|++|)'
note: "The use of '(||++|)' may result in outputting raw Haskell into user-facing code"
73 changes: 73 additions & 0 deletions .stylish-haskell.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
#
# SPDX-License-Identifier: Unlicense

steps:
- simple_align:
cases: false
top_level_patterns: false
records: false
multi_way_if: false
- imports:
align: none
list_align: after_alias
pad_module_names: false
long_list_align: new_line
empty_list_align: inherit
list_padding: 2
separate_lists: false
space_surround: false
post_qualify: true
- trailing_whitespace: {}
columns: 100
newline: native
language_extensions:
- AllowAmbiguousTypes
- ApplicativeDo
- BangPatterns
- BlockArguments
- ConstraintKinds
- DataKinds
- DefaultSignatures
- DeriveAnyClass
- DeriveDataTypeable
- DeriveFoldable
- DeriveFunctor
- DeriveGeneric
- DeriveTraversable
- DerivingStrategies
- DerivingVia
- EmptyCase
- FlexibleContexts
- FlexibleInstances
- FunctionalDependencies
- GADTs
- GeneralizedNewtypeDeriving
- ImportQualifiedPost
- LambdaCase
- MultiParamTypeClasses
- MultiWayIf
- NamedFieldPuns
- NegativeLiterals
- NumDecimals
- NumericUnderscores
- OverloadedLabels
- OverloadedStrings
- PatternSynonyms
- PolyKinds
- QuantifiedConstraints
- QuasiQuotes
- RankNTypes
- RecordWildCards
- RecursiveDo
- ScopedTypeVariables
- StandaloneDeriving
- StrictData
- TemplateHaskell
- TupleSections
- TypeApplications
- TypeFamilies
- TypeOperators
- UndecidableInstances
- UndecidableSuperClasses
- ViewPatterns
78 changes: 78 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!--
- SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
-
- SPDX-License-Identifier: Unlicense
-->

# Contribution Guidelines

## Reporting Issues

Please [open an issue](https://github.com/serokell/coffer/issues/new/choose)
if you find a bug or have a feature request.
Note: you need to login (e. g. using your GitHub account) first.
Before submitting a bug report or feature request, check to make sure it hasn't already been submitted

The more detailed your report is, the faster it can be resolved.
If you report a bug, please provide steps to reproduce this bug and revision of code in which this bug reproduces.


## Code

If you would like to contribute code to fix a bug, add a new feature, or
otherwise improve our project, pull requests are most welcome.

Our pull request template contains a [checklist](.github/pull_request_template.md#white_check_mark-checklist-for-your-pull-request) of acceptance criteria for your pull request.
Please read it before you start contributing and make sure your contributions adhere to this checklist.

## Makefile

We have a [Makefile](/Makefile) which provides shortcuts for the most
common developers' activities, like building with flags suitable for
development, testing, applying `stylish-haskell` and `hlint`, building
Haddock documentation.


## Legal

We want to make sure that our projects come with correct licensing information
and that this information is machine-readable, thus we are following the
[REUSE Practices][reuse] – feel free to click the link and read about them,
but, basically, it all boils down to the following:

* Add the following header at the very top (but below the shebang, if there
is one) of each source file in the repository (yes, each and every source
file – it is not as hard as it might sound):

```haskell
-- SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io/>
--
-- SPDX-License-Identifier: MPL-2.0
```

(This is an example for Haskell; adapt it as needed for other languages.)

The license identifier should be the same as the one in the `LICENSE` file.

* If you are copying any source files from some other project, and they do not
contain a header with a copyright and a machine-readable license identifier,
add it, but be extra careful and make sure that information you are recording
is correct.

If the license of the file is different from the one used in the project and
you do not plan to relicense it, use the appropriate license identifier and
make sure the license text exists in the `LICENSES` directory.

If the file contains the entire license in its header, it is best to move the
text to a separate file in the `LICENSES` directory and leave a reference.

* If you are copying pieces of code from some other project, leave a note in the
comments, stating where you copied it from, who is the copyright owner, and
what license applies.

* All the same rules apply to documentation that is stored in the repository.

These simple rules should cover most of situation you are likely to encounter.
In case of doubt, consult the [REUSE Practices][reuse] document.

[reuse]: https://reuse.software/spec/
24 changes: 24 additions & 0 deletions LICENSES/Unlicense.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ haddock-no-deps:
clean:
$(MAKE_PACKAGE) clean

stylish:
find . -name '.stack-work' -prune -o -name '.dist-newstyle' -prune -o -name '*.hs' -exec stylish-haskell -i '{}' \;

lint:
hlint .

# Usage:
# * make bats
# * make bats FILTER="test name"
Expand Down
Loading

0 comments on commit 631db98

Please sign in to comment.