christopheradams / elixir_style_guide

A community driven style guide for Elixir
4.37k stars 299 forks source link

How do we use this style guide in an automated way? #143

Open sergiotapia opened 7 years ago

sergiotapia commented 7 years ago

Right now I have Atom, Credo, and the atom-credo linter package installed.

Is there a way for us Elixir devs to use this style guide in an automated way?

optikfluffel commented 7 years ago

Having something like https://atom.io/packages/elm-format would be pretty cool 😆

christopheradams commented 7 years ago

Is there a way for us Elixir devs to use this style guide in an automated way?

It should be possible to write custom Credo checks for many of the style recommendations in this guide, and package them up for use in any Elixir project. Would this be of interest? Do you think it would make sense to include them here, or to create a separate repo/project for that purpose?

Having something like https://atom.io/packages/elm-format would be pretty cool 😆

Not quite the same, but have you tried https://github.com/lpil/dogma ?

sergiotapia commented 7 years ago

I found this repo using the trending feature for Github, so I imagine that a lot of Elixir devs agree this this is a nice way to write Elixir. I would love to be able to install a package in Atom and run all these style checks against my open file.

In Javascript I use prettier. In Ruby I use rubocop. In Go I use go fmt. In Elixir...eh... wat do?!

christopheradams commented 7 years ago

@sergiotapia You already mentioned atom-credo. That runs mix credo and reports the output, right? In theory it should work with a customized Credo config.

It would be a fair amount of work to write credo checks for this style guide, and either upstream them to credo or create a separate package. But it should be doable!

ericmj commented 7 years ago

We have a google summer of code student working on an elixir formatter. It won't follow this style guide, but it will be fairly similar.

bamorim commented 6 years ago

First of all, sorry for posting in this old issue, but since it was open I though that would not be that bad.

I've been playing around with Credo and the Formatter to see what things are not automated. I detected a few things you can check on this repository

Source Code Layout

Neither credo nor formatter caught it

Formatter didn't caught, but Credo did

Syntax

Neither credo nor formatter caught it

Formatter didn't caught, but Credo did

Comments

Only problems with comment grammar (which is totally understandeable), as seen here

Modules

Almost nothing was caught. I think only space after defmodule was solved automatically.

I think that the order is something really nice to add to Credo. Will think about it

Typespecs

Neither credo nor formatter caught it

Structs

Neither credo nor formatter caught it

Improving

There is probably a lot of places we can improve that I haven't tested. I also dind't got into naming because it is a nasty space.

One thing we could do to automate it better is:

Add Checks to Credo

This is the list of checks I think is not that hard to implement on Credo

Maybe we should create some issues on Credo repo and see if they think these checks are reasonable and then we can try to implement the checks (we could ship the checks in a different repo as well)

What do you guys think?

bamorim commented 6 years ago

There is a discussion on rrene/credo#540 about the module ordering

Stratus3D commented 6 years ago

Looks like there is a PR out for module attribute ordering: https://github.com/rrrene/credo/pull/588 :tada:

xtian commented 5 years ago

I have a package called credo_contrib which implements a lot of the rules from this style guide (including module attribute ordering). I'll take a look at the list above and see if there are any more I can add. Contributions welcome also!

Stratus3D commented 2 years ago

I have created https://github.com/rrrene/credo/pull/933 to enforce https://github.com/christopheradams/elixir_style_guide#pipe-operator 🎉

Stratus3D commented 2 years ago

I have created https://github.com/rrrene/credo/pull/935 to enforce the https://github.com/christopheradams/elixir_style_guide#true-as-last-condition

christopheradams commented 2 years ago

I have created rrrene/credo#933 to enforce https://github.com/christopheradams/elixir_style_guide#pipe-operator tada

This is great work @Stratus3D, please keep us up to date on your credo PRs.