Skip to content

Commit 87d6889

Browse files
committed
Lint
1 parent 38b3ee1 commit 87d6889

File tree

8 files changed

+247
-46
lines changed

8 files changed

+247
-46
lines changed

Diff for: .editorconfig

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
[*]
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
indent_style = space
10+
indent_size = 2
11+
12+
[*.erl]
13+
max_line_length = 180
14+
15+
[*.py]
16+
indent_style = space
17+
indent_size = 4
18+
19+
[Makefile,*.mk]
20+
indent_style = tab
21+
22+
[*.md]
23+
trim_trailing_whitespace = false
24+

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ ext
1515
kafe.d
1616
test/eunit/
1717
docker-compose.yml
18+
/doc
19+

Diff for: Makefile

+4-32
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,7 @@
1-
REBAR = ./rebar3
2-
MIX = mix
1+
HAS_ELIXIR=1
32

4-
compile-erl:
5-
@$(REBAR) compile
3+
include bu.mk
64

7-
compile-ex: elixir
8-
@$(MIX) deps.get
9-
@$(MIX) compile
10-
11-
elixir:
12-
@$(REBAR) elixir generate_mix
13-
@$(REBAR) elixir generate_lib
14-
15-
tests:
16-
@$(REBAR) eunit
17-
18-
dist: release-ex release-erl
19-
20-
release: release-ex release-erl
21-
@$(REBAR) hex publish
22-
23-
release-erl: distclean-erl compile-erl tests
24-
25-
distclean-erl: distclean
26-
@rm -f rebar.lock
27-
28-
release-ex: distclean-ex compile-ex
29-
30-
distclean-ex: distclean
31-
@rm -f mix.lock
32-
33-
distclean:
34-
@rm -rf _build test/eunit deps
5+
release: dist
6+
$(verbose) $(REBAR) hex publish
357

Diff for: bu.mk

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Copyright (c) 2013-2015, Loïc Hoguin <[email protected]>
2+
# Copyright (c) 2016, Grégoire Lejeune
3+
#
4+
# Permission to use, copy, modify, and/or distribute this software for any
5+
# purpose with or without fee is hereby granted, provided that the above
6+
# copyright notice and this permission notice appear in all copies.
7+
#
8+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
16+
.PHONY: doc
17+
18+
all: compile-erl
19+
20+
# Verbosity.
21+
22+
V ?= 0
23+
24+
verbose_0 = @
25+
verbose_2 = set -x;
26+
verbose = $(verbose_$(V))
27+
28+
# Utils
29+
30+
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
31+
current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))
32+
33+
# Common
34+
35+
CP = cp
36+
CP_R = cp -r
37+
RM = rm
38+
RM_RF = rm -rf
39+
RM_F = rm -f
40+
MKDIR_P = mkdir -p
41+
42+
# Config
43+
44+
ifneq ("$(wildcard config/$(current_dir).config)","")
45+
ERL_CONFIG="-config config/$(current_dir).config"
46+
else
47+
ERL_CONFIG=
48+
endif
49+
50+
# Core functions.
51+
52+
empty :=
53+
space := $(empty) $(empty)
54+
tab := $(empty) $(empty)
55+
comma := ,
56+
57+
define newline
58+
59+
60+
endef
61+
62+
# Template
63+
64+
define render_template
65+
$(verbose) printf -- '$(subst $(newline),\n,$(subst %,%%,$(subst ','\'',$(subst $(tab),$(WS),$(call $(1))))))\n' > $(2)
66+
endef
67+
68+
ifndef WS
69+
ifdef SP
70+
WS = $(subst a,,a $(wordlist 1,$(SP),a a a a a a a a a a a a a a a a a a a a))
71+
else
72+
WS = $(tab)
73+
endif
74+
endif
75+
76+
# rebar3
77+
78+
FIND_REBAR = \
79+
REBAR_BIN=; \
80+
for x in ./rebar3 rebar3; do \
81+
if type "$${x%% *}" >/dev/null 2>/dev/null; then REBAR_BIN=$$x; break; fi; \
82+
done; \
83+
if [ -z "$$REBAR_BIN" ]; then echo 1>&2 "Unable to find rebar3"; exit 2; fi
84+
REBAR = $(FIND_REBAR); $$REBAR_BIN
85+
86+
# mix
87+
88+
MIX = mix
89+
90+
# Default tasks
91+
ifeq ($(HAS_ELIXIR), 1)
92+
93+
compile-ex: elixir clean
94+
$(verbose) $(MIX) deps.get
95+
$(verbose) $(MIX) compile
96+
97+
elixir:
98+
$(verbose) $(REBAR) elixir generate_mix
99+
$(verbose) $(REBAR) elixir generate_lib
100+
101+
distclean-ex: clean-ex
102+
$(verbose) $(RM_F) mix.lock
103+
104+
clean-ex:
105+
$(verbose) $(RM_RF) _build deps
106+
107+
dist-ex: clean compile-ex
108+
109+
COMPILE=compile-erl compile-ex
110+
CLEAN=clean-erl clean-ex
111+
DISTCLEAN=distclean-erl distclean-ex
112+
DIST=dist-erl dist-ex
113+
else
114+
COMPILE=compile-erl
115+
CLEAN=clean-erl
116+
DISTCLEAN=distclean-erl
117+
DIST=dist-erl
118+
endif
119+
120+
ifdef NO_LINT
121+
LINT=
122+
else
123+
lint:
124+
$(verbose) $(REBAR) lint
125+
126+
LINT=lint
127+
endif
128+
129+
compile-erl:
130+
$(verbose) $(REBAR) update
131+
$(verbose) $(REBAR) compile
132+
133+
tests:
134+
$(verbose) $(REBAR) eunit
135+
136+
doc:
137+
$(verbose) $(REBAR) as doc edoc
138+
139+
dist: $(DIST)
140+
141+
clean: $(CLEAN)
142+
143+
distclean: $(DISTCLEAN)
144+
145+
dev: compile-erl
146+
$(verbose) erl -pa _build/default/lib/*/ebin _build/default/lib/*/include $(ERL_CONFIG)
147+
148+
dist-erl: clean compile-erl tests $(LINT) doc
149+
150+
clean-erl:
151+
$(verbose) $(RM_RF) _build test/eunit
152+
153+
distclean-erl: clean-erl
154+
$(verbose) $(RM_F) rebar.lock
155+

Diff for: mix.exs

+28-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ defmodule Lager.Json.Formatter.Mixfile do
88
elixir: "~> 1.2",
99
build_embedded: Mix.env == :prod,
1010
start_permanent: Mix.env == :prod,
11-
deps: deps
11+
deps: deps,
12+
aliases: aliases
1213
]
1314
end
1415

@@ -25,4 +26,30 @@ defmodule Lager.Json.Formatter.Mixfile do
2526
{:jsx, "~> 2.6"}
2627
]
2728
end
29+
30+
defp aliases do
31+
[compile: [&pre_compile_hooks/1, "compile", &post_compile_hooks/1]]
32+
end
33+
34+
defp pre_compile_hooks(_) do
35+
run_hook_cmd [
36+
]
37+
end
38+
39+
defp post_compile_hooks(_) do
40+
run_hook_cmd [
41+
]
42+
end
43+
44+
defp run_hook_cmd(commands) do
45+
{_, os} = :os.type
46+
for command <- commands, do: (fn
47+
({regex, cmd}) ->
48+
if Regex.match?(Regex.compile!(regex), Atom.to_string(os)) do
49+
Mix.Shell.cmd cmd, [], fn(x) -> Mix.Shell.IO.info(String.strip(x)) end
50+
end
51+
(cmd) ->
52+
Mix.Shell.cmd cmd, [], fn(x) -> Mix.Shell.IO.info(String.strip(x)) end
53+
end).(command)
54+
end
2855
end

Diff for: rebar.config

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{erl_opts, [debug_info, warn_export_vars, warn_shadow_vars, warn_obsolete_guard]}.
2-
{plugins, [rebar3_elixir, rebar3_hex]}.
2+
{plugins, [
3+
rebar3_elixir,
4+
rebar3_hex,
5+
{rebar3_lint, {git, "https://github.com/project-fifo/rebar3_lint.git", {tag, "0.1.6"}}}
6+
]}.
37

48
{deps, [
59
{lager, "~> 3.2"},
@@ -10,3 +14,20 @@
1014
verbose, {report, {eunit_surefire, [{dir, "test/eunit"}]}}
1115
]}.
1216
{pre_hooks, [{eunit, "mkdir -p test/eunit"}]}.
17+
18+
{elvis,
19+
[#{dirs => ["src", "test"],
20+
filter => "*.erl",
21+
rules => [{elvis_style, line_length, #{limit => 180}},
22+
{elvis_style, no_tabs},
23+
{elvis_style, no_trailing_whitespace},
24+
{elvis_style, macro_names},
25+
{elvis_style, macro_module_names},
26+
{elvis_style, dont_repeat_yourself, #{min_complexity => 25}},
27+
{elvis_style, operator_spaces, #{rules => [{right, ","},
28+
{right, "++"},
29+
{left, "++"}]}}]},
30+
#{dirs => ["."],
31+
filter => "rebar.config",
32+
rules => [{elvis_project, no_deps_master_rebar, []}]}]}.
33+

Diff for: rebar.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.8">>},1},
22
{<<"jsx">>,{pkg,<<"jsx">>,<<"2.8.0">>},0},
3-
{<<"lager">>,{pkg,<<"lager">>,<<"3.2.0">>},0}].
3+
{<<"lager">>,{pkg,<<"lager">>,<<"3.2.1">>},0}].

Diff for: src/lager_json_formatter.erl

+11-11
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
-export([format/2]).
99

10-
-define(DEFAULT_CONFIG, [{date, [date, " ", time]},
11-
message,
12-
pid,
13-
severity,
10+
-define(DEFAULT_CONFIG, [{date, [date, " ", time]},
11+
message,
12+
pid,
13+
severity,
1414
{component, [{module, "-"}, ":", {function, "-"}, "/", {line, "-"}]}]).
1515

16-
-spec format(lager_msg:lager_msg(),list()) -> any().
16+
-spec format(lager_msg:lager_msg(), list()) -> any().
1717
format(Message, []) ->
1818
format(Message, ?DEFAULT_CONFIG);
1919
format(Message, Config) ->
@@ -61,11 +61,11 @@ to_binary(O) -> list_to_binary(io_lib:format("~p", [O])).
6161

6262
-ifdef(TEST).
6363
format_test() ->
64-
Msg = lager_msg:new("hello", {1465, 900000, 0}, info,
65-
[{pid, c:pid(0, 0, 0)},
66-
{module, ?MODULE},
64+
Msg = lager_msg:new("hello", {1465, 900000, 0}, info,
65+
[{pid, c:pid(0, 0, 0)},
66+
{module, ?MODULE},
6767
{function, test},
68-
{line, 123}],
68+
{line, 123}],
6969
[]),
7070
?assertEqual(<<"{\"component\":\"lager_json_formatter:test/123\","
7171
"\"date\":\"2016-06-14 12:26:40.000\","
@@ -80,8 +80,8 @@ format_test() ->
8080
{msg, message},
8181
{sev, severity}])).
8282
special_chars_test() ->
83-
Msg = lager_msg:new("hello\r\n\t\"wor\\d!", {1465, 900000, 0}, info,
84-
[],
83+
Msg = lager_msg:new("hello\r\n\t\"wor\\d!", {1465, 900000, 0}, info,
84+
[],
8585
[]),
8686
?assertEqual(<<"{\"component\":\"-:-/-\","
8787
"\"date\":\"2016-06-14 12:26:40.000\","

0 commit comments

Comments
 (0)