Giter Club home page Giter Club logo

elvis's Issues

if

Rule

Don't use if

DRY

Rule

don't repeat yourself

Implementation

Find exactly the same code repeated in the same module

Missing link in README

There's a link missing in the README.md.

There's also a way to use elvis as a GitHub [webhook][webhooks] for pull request (PR) events by calling the webhook/1 function. This will add a comment for each rule that is broken by a line in the files associated wiith the PR.

Elvis crashes in `erl_parse:abstract/2`

Again with respect to https://github.com/lavrin/dcsp/ after I changed include directives to sidestep #75 Elvis crashes:

> elvis:rock(#{src_dirs => ["src", "include", "test"], rules => []}).
** exception error: no function clause matching erl_parse:abstract(undefined,{5,19}) (erl_parse.yrl, line 935)
     in function  erl_parse:record_fields/1 (erl_parse.yrl, line 792)
     in call from erl_parse:build_typed_attribute/2 (erl_parse.yrl, line 623)
     in call from erl_parse:yeccpars2_483/7 (erl_parse.yrl, line 80)
     in call from erl_parse:yeccpars0/5 (/net/isildur/ldisk/daily_build/17_prebuild_master-opu_o.2014-04-07_20/otp_src_17/bootstrap/lib/parsetools/include/yeccpre.hrl, line 56)
     in call from lists:map/2 (lists.erl, line 1237)
     in call from lists:map/2 (lists.erl, line 1237)
     in call from elvis_code:parse_tree/1 (src/elvis_code.erl, line 68)

Please see this gist for a dbg trace - unfortunately, the trace doesn't tell me much.

Dynamic Functions

Rule

Don't use dynamic function calling outside of behaviour modules with callbacks

Options
  • Ignore modules

Nesting Level

Rule

Nest your code no more than N levels.

Options
  • Max nesting level

Macros in module/function names

Rule

Don't use macros for module or function names

Implementation

check for ?MACROS that translate to an atom and are used in expressions like ?MACRO:something or something:?MACRO

Naming convention

Rule

stick to one convention when naming modules (i.e: prefix_module1 vs module2 vs anotherprefix_module3)

Options
  • Regex with which to validate module names
  • Excluded modules

#state records

Rule

name your state records #state and use -type state():: #state{} in all your OTP modules.

Indentation Format

Rule

Indent using {N spaces|tabs}

Options
  • Indentation character
  • (if using spaces) number of spaces
Implementation

Check in each line, how much more indented it is against the previous one.

Elvis can't find header files

With the following repo layout:

.
├── Makefile
├── README.md
├── include
│   └── dcsp.hrl
├── src
│   ├── dcsp.app.src
│   ├── dcsp.erl
│   ├── dcsp_agent.erl
│   ├── dcsp_problem.erl
│   ├── dcsp_problem_logic.erl
│   ├── dcsp_solver.erl
│   ├── dcsp_sup.erl
│   ├── ex1.erl
│   └── nqueens.erl
└── test
    └── dcsp_SUITE.erl

and dcsp.erl (and others) including dcsp.hrl like this (note no leading include/):

-include("dcsp.hrl").

Elvis (commit 647fd5a) can't find dcsp.hrl:

> elvis:rock(#{src_dirs => ["src", "include", "test"], rules => []}).
** exception error: no match of right hand side value {error,{not_found,"dcsp.hrl"}}
     in function  elvis_code:parse_tree/1 (src/elvis_code.erl, line 65)
     in call from elvis_utils:parse_tree/1 (src/elvis_utils.erl, line 56)
     in call from elvis_utils:load_file_data/1 (src/elvis_utils.erl, line 68)
     in call from lists:map/2 (lists.erl, line 1237)
     in call from elvis:rock/1 (src/elvis.erl, line 52)

The repo in question is https://github.com/lavrin/dcsp/.

Code width

Rule

Stick to N chars per line

Options
  • Max line length

God Modules

Rule

Don't design your system using god modules

Options
  • Max number of exported functions
  • Max number of expressions in the generated code
  • Max number of lines of code
Implementation

The number of exported functions and expressions in generated code can be obtained using beam_lib-related functions
The number of lines of code, maybe too

Macro Names

Rule

Macros should be named in ALL_UPPER_CASE

Options

No options

-callback

Rule

use -callback instead of behavior_info/1 for your behavior definitions

Options
  • None

CLI tool

Create an escript that basically runs elvis:rock(…). Use the tool for CLI getopt.

master in deps

Rule

in your rebar.config or Erlang.mk, specify a tag or commit, but not master

Executable Path Length

Rule

Write functions with executable paths no longer than N.

Options
  • N: max length of executable paths.
  • Ignored modules

Exported vs. Non-exported

Rule

Try to always separate NON-EXPORTED and EXPORTED functions in groups, with the exported ones first, unless it helps readability and code discovery.

http://elvis.inakalabs.com doesn't advertise character encoding

My name's Radosław, but the site displays it as RadosÅ‚aw. There's no mention of "encoding" or "charset" in the page source, so the browser-default encoding is used, and that's ISO-8859-2 in my case (I'm from Poland), but the site is in fact in UTF-8. I guess <meta charset='utf-8'> in the head section would suffice.

Elvis crashes when running on processone/ejabberd

Error message:

escript: exception error: no match of right hand side value
                 {error,{{49,36},
                         aleppo_parser,
                         ["syntax error before: ","..."]}}
  in function  elvis_code:parse_tree/2 (src/elvis_code.erl, line 67)
  in call from elvis_utils:parse_tree/2 (src/elvis_utils.erl, line 57)
  in call from elvis_utils:load_file_data/2 (src/elvis_utils.erl, line 69)
  in call from lists:map/2 (lists.erl, line 1237)
  in call from lists:map/2 (lists.erl, line 1237)
  in call from elvis:rock/1 (src/elvis.erl, line 53)
  in call from elvis:process_commands/2 (src/elvis.erl, line 152)
  in call from elvis:process_options/2 (src/elvis.erl, line 131)

Rules wiki page

Create a wiki page listing the rules with their options and samples.

Checkstyle compatible output

How about making the output compatible with the CheckStyle file format? This will allow to run the tool from jenkins and publish the results of the build without any translations

Improve feedback when using Elvis on the command line

For big projects (e.g. erlang/otp, ejabberd), the initial processing of files takes too long and the user is left waiting without any feedback. It would be nice to display information related to what file is being processed before showing the actual output.

Erlang console tool

Make the system run with

elvis:rock(…)

or something similar (i.e. let it be ready to run from an Erlang console), following these rules:

  • The code to be analysed should be src/*.erl or given as a param
  • The list of rules to validate should be configurable by app.config and only one or two very simple rules (e.g. 80 chars a line) should be implemented
  • The results should be in the simplest possible form
  • Add Tests
  • Write Documentation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.