Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
elvis on cowboy

Using this elvis.config file:

$ cat elvis.config
[
 {
   elvis,
   [
    {config,
      #{src_dirs => ["src"],
        rules    => [{elvis_style, line_length, [80]},
%                     {elvis_style, no_tabs, []},
                     {elvis_style, macro_names, []},
                     {elvis_style, macro_module_names, []},
                     {elvis_style, operator_spaces, [{right, ","},
                                                     {right, "++"},
                                                     {left, "++"}]},
                     {elvis_style, nesting_level, [3]},
                     {elvis_style, god_modules, [25]},
                     {elvis_style, no_if_expression, []},
%                     {elvis_style, invalid_dynamic_call, [elvis]},
                     {elvis_style, used_ignored_variable, []},
                     {elvis_style, no_behavior_info, []},
                     {
                       elvis_style,
                       module_naming_convention,
                       ["^([a-z][a-z0-9]*_?)*(_SUITE)?$", []]
                     }
                    ]
       }
    }
   ]
 }
].

We get the following result:

# src/cowboy.erl [OK]
# src/cowboy_app.erl [OK]
# src/cowboy_bstr.erl [OK]
# src/cowboy_clock.erl [OK]
# src/cowboy_handler.erl [FAIL]
  - used_ignored_variable
    - Ignored variable is being used on line 259 and column 7.
    - Ignored variable is being used on line 259 and column 16.
  - no_if_expression
    - Replace the 'if' expression on line 181 with a 'case' expression or function clauses.
    - Replace the 'if' expression on line 184 with a 'case' expression or function clauses.
    - Replace the 'if' expression on line 236 with a 'case' expression or function clauses.
  - nesting_level
    - The expression on line 184 and column 10 is nested beyond the maximum level of 3.
# src/cowboy_http.erl [FAIL]
  - nesting_level
    - The expression on line 75 and column 7 is nested beyond the maximum level of 3.
    - The expression on line 89 and column 7 is nested beyond the maximum level of 3.
    - The expression on line 264 and column 6 is nested beyond the maximum level of 3.
    - The expression on line 264 and column 6 is nested beyond the maximum level of 3.
    - The expression on line 308 and column 21 is nested beyond the maximum level of 3.
    - The expression on line 340 and column 9 is nested beyond the maximum level of 3.
    - The expression on line 356 and column 6 is nested beyond the maximum level of 3.
    - The expression on line 376 and column 9 is nested beyond the maximum level of 3.
    - The expression on line 399 and column 9 is nested beyond the maximum level of 3.
    - The expression on line 418 and column 9 is nested beyond the maximum level of 3.
    - The expression on line 719 and column 7 is nested beyond the maximum level of 3.
    - The expression on line 762 and column 20 is nested beyond the maximum level of 3.
    - The expression on line 783 and column 22 is nested beyond the maximum level of 3.
    - The expression on line 786 and column 7 is nested beyond the maximum level of 3.
    - The expression on line 818 and column 8 is nested beyond the maximum level of 3.
    - The expression on line 844 and column 9 is nested beyond the maximum level of 3.
  - operator_spaces
    - Missing space after "," on line 72
    - Missing space after "," on line 76
    - Missing space after "," on line 658
    - Missing space after "," on line 870
    - Missing space after "," on line 902
    - Missing space after "," on line 1014
    - Missing space after "," on line 1040
    - Missing space after "," on line 1042
    - Missing space after "," on line 1052
    - Missing space after "," on line 1056
    - Missing space after "," on line 1058
    - Missing space after "," on line 1062
  - line_length
    - Line 224 is too long: "-spec language_range_ret(binary(), fun(), '*' | {binary(), [binary()]}) -> any().".
    - Line 824 is too long: "-spec parameterized_tokens_params(binary(), fun(), [binary() | {binary(), binary()}]) -> any().".
    - Line 1014 is too long: "\t\t{<<\"bar; baz=2;bat=\\\"z=1,2;3\\\"\">>, [{<<\"bar\">>, [{<<\"baz\">>, <<\"2\">>}, {<<\"bat\">>, <<\"z=1,2;3\">>}]}]},".
    - Line 1015 is too long: "\t\t{<<\"foo, bar; baz=2\">>, [{<<\"foo\">>, []}, {<<\"bar\">>, [{<<\"baz\">>, <<\"2\">>}]}]}".
# src/cowboy_http_handler.erl [OK]
# src/cowboy_loop_handler.erl [OK]
# src/cowboy_middleware.erl [OK]
# src/cowboy_protocol.erl [FAIL]
  - no_if_expression
    - Replace the 'if' expression on line 123 with a 'case' expression or function clauses.
    - Replace the 'if' expression on line 485 with a 'case' expression or function clauses.
  - nesting_level
    - The expression on line 486 and column 6 is nested beyond the maximum level of 3.
# src/cowboy_req.erl [FAIL]
  - no_if_expression
    - Replace the 'if' expression on line 822 with a 'case' expression or function clauses.
    - Replace the 'if' expression on line 832 with a 'case' expression or function clauses.
    - Replace the 'if' expression on line 846 with a 'case' expression or function clauses.
    - Replace the 'if' expression on line 854 with a 'case' expression or function clauses.
    - Replace the 'if' expression on line 858 with a 'case' expression or function clauses.
    - Replace the 'if' expression on line 874 with a 'case' expression or function clauses.
    - Replace the 'if' expression on line 1136 with a 'case' expression or function clauses.
    - Replace the 'if' expression on line 1139 with a 'case' expression or function clauses.
    - Replace the 'if' expression on line 1145 with a 'case' expression or function clauses.
  - god_modules
    - This module has too many functions (64). Consider breaking it into a number of modules.
  - nesting_level
    - The expression on line 184 and column 6 is nested beyond the maximum level of 3.
    - The expression on line 532 and column 6 is nested beyond the maximum level of 3.
    - The expression on line 855 and column 17 is nested beyond the maximum level of 3.
    - The expression on line 858 and column 6 is nested beyond the maximum level of 3.
    - The expression on line 917 and column 7 is nested beyond the maximum level of 3.
  - operator_spaces
    - Missing space after "," on line 1363
    - Missing space after "," on line 1364
    - Missing space after "," on line 1365
    - Missing space after "," on line 1366
    - Missing space after "," on line 1367
    - Missing space after "," on line 1368
    - Missing space after "," on line 1369
    - Missing space after "," on line 1370
    - Missing space after "," on line 1371
    - Missing space after "," on line 1372
    - Missing space after "," on line 1373
    - Missing space after "," on line 1375
  - line_length
    - Line 738 is too long: "stream_multipart(Req=#http_req{body_state=BodyState, multipart={_, <<>>}}, Opts) ->".
    - Line 1089 is too long: "set([{resp_headers, Val}|Tail], Req) -> set(Tail, Req#http_req{resp_headers=Val});".
# src/cowboy_rest.erl [FAIL]
  - used_ignored_variable
    - Ignored variable is being used on line 241 and column 12.
  - no_if_expression
    - Replace the 'if' expression on line 789 with a 'case' expression or function clauses.
  - nesting_level
    - The expression on line 102 and column 32 is nested beyond the maximum level of 3.
    - The expression on line 129 and column 7 is nested beyond the maximum level of 3.
    - The expression on line 131 and column 25 is nested beyond the maximum level of 3.
    - The expression on line 592 and column 6 is nested beyond the maximum level of 3.
  - operator_spaces
    - Missing space after "," on line 891
    - Missing space after "," on line 892
  - line_length
    - Line 688 is too long: "\t\t\tis_post_to_missing_resource(Req2, State#state{handler_state=HandlerState}, 410);".
# src/cowboy_router.erl [FAIL]
  - operator_spaces
    - Missing space before "++" on line 96
    - Missing space after "," on line 386
    - Missing space after "," on line 387
    - Missing space after "," on line 388
    - Missing space after "," on line 389
    - Missing space after "," on line 396
    - Missing space after "," on line 397
    - Missing space after "," on line 398
    - Missing space after "," on line 399
    - Missing space after "," on line 507
    - Missing space after "," on line 508
    - Missing space after "," on line 525
    - Missing space after "," on line 526
    - Missing space after "," on line 527
  - line_length
    - Line 253 is too long: "match_path([{<<\"*\">>, _Constraints, Handler, Opts}|_Tail], HostInfo, <<\"*\">>, Bindings) ->".
    - Line 526 is too long: "\t\t\t<<47,208,191,209,131,209,130,209,140,47,208,180,208,190,208,188,208,190,208,185>>,".
    - Line 527 is too long: "\t\t\t{ok, match_path, [], [], undefined, [<<208,180,208,190,208,188,208,190,208,185>>]}}".
# src/cowboy_spdy.erl [FAIL]
  - no_if_expression
    - Replace the 'if' expression on line 124 with a 'case' expression or function clauses.
    - Replace the 'if' expression on line 288 with a 'case' expression or function clauses.
    - Replace the 'if' expression on line 368 with a 'case' expression or function clauses.
# src/cowboy_static.erl [FAIL]
  - operator_spaces
    - Missing space before "++" on line 74
# src/cowboy_sub_protocol.erl [OK]
# src/cowboy_sup.erl [OK]
# src/cowboy_websocket.erl [FAIL]
  - no_if_expression
    - Replace the 'if' expression on line 703 with a 'case' expression or function clauses.
  - line_length
    - Line 113 is too long: "\t\t\t\t\tok = zlib:deflateInit(Deflate, best_compression, deflated, -15, 8, default),".
    - Line 287 is too long: "websocket_data(State, Req, HandlerState, << _:8, 1:1, 127:7, 1:1, _:7, _/binary >>) ->".
    - Line 406 is too long: "\t{Unmasked3, State2} = websocket_inflate_frame(Unmasked2, Rsv, Fin =:= fin, State),".
    - Line 698 is too long: "websocket_send({Type, Payload0}, State=#state{socket=Socket, transport=Transport}) ->".
    - Line 700 is too long: "\t{Payload, Rsv, State2} = websocket_deflate_frame(Opcode, iolist_to_binary(Payload0), State),".
# src/cowboy_websocket_handler.erl [FAIL]
  - line_length
    - Line 39 is too long: "\t| {reply, cowboy_websocket:frame() | [cowboy_websocket:frame()], Req, State, hibernate}".
    - Line 46 is too long: "\t| {reply, cowboy_websocket:frame() | [cowboy_websocket:frame()], Req, State, hibernate}".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.