Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

state_record_and_type false positive when record includes defines from header file #295

Closed
Licenser opened this issue Nov 17, 2015 · 2 comments

Comments

@Licenser
Copy link
Contributor

The following error is printed

  - state_record_and_type
    - This module implements an OTP behavior but is missing a 'state' record.

as a false positive under the following conditions:

  • a state record exists
  • the state record uses a macro as a default value
  • the macro in question is defined in a .hrl file that the source file includes

example.hrl

-define(TIMEOUT, 1000).

example.erl

-module(example).
-behaviour(gen_fsm).
-include("example.hrl").
-record(state, {timeout = ?TIMEOUT}).
%% ...
@harenson
Copy link
Member

harenson commented Jan 6, 2016

Hey @Licenser, I am unable to reproduce this issue with the current version of elvis, can you try this with the latest version of elvis and confirm if this issue was already solved?

I am using your example for the tests.

This is the output when I run elvis:

$ erl -noshell -pa deps/*/ebin -pa ebin -s elvis_core rock -s init stop
Loading files...
Loading src/example.erl
Applying rules...
# src/example.erl [OK]
Loading files...
Loading Makefile
Applying rules...
# Makefile [OK]
Loading files...
Applying rules...
Loading files...
Loading elvis.config
Applying rules...
# elvis.config [OK]

Example Project:

$ tree
.
├── Makefile
├── elvis.config
├── erlang.mk
├── example.d
└── src
    ├── example.erl
    └── example.hrl

1 directory, 6 files

Files content:

Makefile

PROJECT = example

DEPS = lager katana elvis_core

dep_lager = git https://github.com/basho/lager.git 2.0.3
dep_katana = git https://github.com/inaka/erlang-katana.git 0.2.18
dep_elvis_core = git https://github.com/inaka/elvis_core 0.2.6-alpha2

include erlang.mk

elvis.config

[
 {
   elvis,
   [
    {config,
     [#{dirs => ["src"],
        filter => "*.erl",
        rules => [{elvis_style, line_length, #{limit => 80,
                                               skip_comments => false}},
                  {elvis_style, no_tabs},
                  {elvis_style, no_trailing_whitespace},
                  {elvis_style, macro_names},
                  {elvis_style, macro_module_names},
                  {elvis_style, operator_spaces, #{rules => [{right, ","},
                                                             {right, "++"},
                                                             {left, "++"}]}},
                  {elvis_style, nesting_level, #{level => 3}},
                  {elvis_style, god_modules, #{limit => 25}},
                  {elvis_style, no_if_expression},
                  {elvis_style, invalid_dynamic_call, #{ignore => [elvis_core]}},
                  {elvis_style, used_ignored_variable},
                  {elvis_style, no_behavior_info},
                  {
                    elvis_style,
                    module_naming_convention,
                    #{regex => "^([a-z][a-z0-9]*_?)*(_SUITE)?$",
                      ignore => []}
                  },
                  {
                    elvis_style,
                    variable_naming_convention,
                    #{regex => "^([A-Z][0-9a-zA-Z]*)$", ignore => []}
                  },
                  {elvis_style, state_record_and_type},
                  {elvis_style, no_spec_with_records},
                  {elvis_style, dont_repeat_yourself, #{min_complexity => 20}},
                  {elvis_style, no_debug_call, #{ignore => [elvis,
                                                            elvis_utils]}},
                  {elvis_style, no_nested_try_catch}
                 ]
       },
      #{dirs => ["."],
        filter => "Makefile",
        rules => [{elvis_project, no_deps_master_erlang_mk, #{ignore => []}},
                  {elvis_project, protocol_for_deps_erlang_mk, #{ignore => []}}]
       },
      #{dirs => ["."],
        filter => "rebar.config",
        rules => [{elvis_project, no_deps_master_rebar, #{ignore => []}},
                  {elvis_project, protocol_for_deps_rebar, #{ignore => []}}]
       },
      #{dirs => ["."],
        filter => "elvis.config",
        rules => [{elvis_project, old_configuration_format}]
       }
     ]
    }
   ]
 }
].

erlang.mk (ERLANG_MK_VERSION = 2.0.0-pre.2-60-g1e6fc7b)
src/example.erl

-module(example).
-include("example.hrl").
-record(state, {timeout = ?TIMEOUT}).

-export([get_state/0]).

get_state() -> #state{}.

src/example.hrl

-define(TIMEOUT, 1000).

@elbrujohalcon
Copy link
Member

Closing this issue, it seems fixed to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants