Code Formatter — The big feature in Elixir v1.6.0

Blackode
Blackode
Dec 26, 2017 · 6 min read

Main Intention

A single style to follow consistently as a whole.

Usage

$ mix format filename
mix format mix.exs “lib/**/*.{ex,exs}” “test/**/*.{ex,exs}”

Indentation & Brackets

before mix format — indentation/brackets
after mix format — indentation/brackets

Breaking and Joining lines

Joining a Line

before mix format multi line to single function
after mix format multi line to single function

Breaking a Line

before mix format single line to multi function
after mix format single to multi line

White Spaces

left side — before and right side — after mix format

Blank Lines or Empty lines

.formatter.exs

How to configure ?

.formatter.exs

Line: 5

locals_without_parens: [hello: 2, get_user: 1, addtion: :*],
def hello user,country do
IO.inspect("hello #{user} from #{country}")
end
def hello(user, country) do
IO.inspect("hello #{user} from #{country}")
end

Line: 7

inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"],

Line: 9

line_length: 80

Line: 11

import_deps: [:dependency1, :dependency2]

Line: 13

export: [
[
locals_without_parens: [hello: 2, get_user: 1, addtion: *]
]
]
if worthClapping, do: clap, else: nil

blackode

Coding, thoughts, and ideas.

Blackode

Written by

Blackode

Wrong CODE takes U to the right BUG 🐞 coding, thoughts & ideas

blackode

blackode

Coding, thoughts, and ideas.