elixir_style_guide icon indicating copy to clipboard operation
elixir_style_guide copied to clipboard

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

Open sergiotapia opened this issue 7 years ago • 12 comments

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?

sergiotapia avatar May 09 '17 21:05 sergiotapia

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

optikfluffel avatar May 09 '17 23:05 optikfluffel

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 ?

christopheradams avatar May 10 '17 03:05 christopheradams

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?!

sergiotapia avatar May 10 '17 04:05 sergiotapia

@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!

christopheradams avatar May 10 '17 05:05 christopheradams

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.

ericmj avatar May 10 '17 08:05 ericmj

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 avatar Jun 03 '18 21:06 bamorim

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

bamorim avatar Jun 03 '18 21:06 bamorim

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

Stratus3D avatar Oct 02 '18 23:10 Stratus3D

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!

xtian avatar Sep 05 '19 17:09 xtian

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

Stratus3D avatar Dec 31 '21 16:12 Stratus3D

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

Stratus3D avatar Jan 05 '22 22:01 Stratus3D

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.

christopheradams avatar Jan 06 '22 04:01 christopheradams