cql icon indicating copy to clipboard operation
cql copied to clipboard

Code formatting and styling

Open marcosh opened this issue 7 years ago • 10 comments

To avoid code written in too different styles, I would encourage the use of hlint and hindent and also compiling with stack --pedantic.

If you have any other styling rule you'd like to be followed, that would be nice to share

**Update 2018-05-31 by @epost and @marcosh **: https://www.tweag.io/posts/2019-05-27-ormolu.html and https://github.com/ennocramer/floskell

marcosh avatar Sep 18 '18 05:09 marcosh

Yesh! Glad you asked. This is work in progress but it does tackle some important points: https://hackmd.io/U8vrBv94TqK413F0GIEAfg.

We probably also want to use an .editorconfig file, see https://editorconfig.org.

What would be a good place to hook in your suggested linting?

epost avatar Sep 18 '18 09:09 epost

I'll take a look at editorconfig.

I'm using hlint and hindent at every save in my editor. I think that would be the best option (or anyway, anybody makes sures that he pushes code after linting it). Violations should be catched in code review.

Otherwise we could setup something which formats the code as soon as it is pushed, so we are sure that in code review everything is written nicely

marcosh avatar Sep 18 '18 09:09 marcosh

Yeah that seems like a good idea for now. I was thinking we could validate it during the automated build, but not sure how easy that is, since our .travis.yml basically only says 'use Nix'.

The .editorconfig would look something like this I guess:

# see https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2

epost avatar Sep 18 '18 09:09 epost

There are also some tab warnings, see https://travis-ci.com/statebox/aql/builds/85998010

tg-x avatar Sep 26 '18 12:09 tg-x

oh the tab issue seems to be fixed already in master: https://travis-ci.com/statebox/aql/builds/86003480

tg-x avatar Sep 26 '18 13:09 tg-x

yeah I just merged Marco's commit.

epost avatar Sep 26 '18 14:09 epost

stack build --pedantic adds the -Wall -Werror flags, shall we put these in package.yaml so that it affects nix-build and thus Travis builds as well?

tg-x avatar Sep 28 '18 18:09 tg-x

Based on our rocketchat discussions of last night and before, we're investigating code formatters, and the extent to which they can help us produce readable code in the spirit of the stuff discussed above.

epost avatar Oct 23 '18 12:10 epost

Is anyone besides me using a Mac? Getting ‘stack build’ to recognize ‘—pedantic’ would remove the cycle where I have to commit and push to read error messages from Travis CI.

On Oct 23, 2018, at 8:12 AM, Erik Post [email protected] wrote:

Based on our rocketchat discussions of last night and before, we're investigating code formatters, and the extent to which they can help us produce readable code in the spirit of the stuff discussed above.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub, or mute the thread.

wisnesky avatar Oct 23 '18 23:10 wisnesky

@wisnesky Yep, moi. Let's try and figure that out. (I've heard some harsh criticism of Stack so this may be an example of how it's not so nice; I'm not sure.) Anyway, I created https://github.com/statebox/aql/issues/108 for this.

epost avatar Oct 24 '18 11:10 epost