Giter Club home page Giter Club logo

Comments (11)

paulo-ferraz-oliveira avatar paulo-ferraz-oliveira commented on May 30, 2024 1

I've created an Erlang bugs - question to check if exposing warn_missing_spec and sibling warn_missing_spec_all is desirable.

from elvis_core.

paulo-ferraz-oliveira avatar paulo-ferraz-oliveira commented on May 30, 2024

I have mixed feelings about this.

I see value in the rule, but at the same time wouldn't the output be just as "complicated" as the compiler option's? Or are you just trying to bypass the warnings_as_errors bit?

If we go forward, you'd get the advantage of being able to disable on a per-module/per-function basis, which I guess would be the biggest advantage (couple with "no warnings as errors").

Let me write some notes for future discussion also:

  • I'd put this rule in the elvis_style module,
  • I'd name this rule missing_spec,
  • I'd add option all (boolean()) to this rule: it would evaluate private functions if it was true, but default to false,
  • I'd have this rule disabled by default.

from elvis_core.

robertoaloi avatar robertoaloi commented on May 30, 2024

Hi @paulo-ferraz-oliveira and thanks for the quick reply!

Our use case is a monolithic code base of 1.5 million lines of code where we adopt the warning_as_errors option and we therefore cannot enable the missing_spec as an option in a trivial way. The idea is to use Elvis for metrics and to avoid the introduction of new offenders compared to a "baseline". We used a similar approach with dialyzer which allowed us to fix a lot of issues (most of them in specs, some of them in code) in the code base and we plan to use the same approach with Elvis.

from elvis_core.

paulo-ferraz-oliveira avatar paulo-ferraz-oliveira commented on May 30, 2024

Sure.

I haven't looked into how the parsing of the -spec(_). directive is done yet, though. I'm unsure making sure -spec(_) exists prior to a function definition is enough, since I believe it is possible to have it in a header, but I'd have to check closer.

Would a rule like "if not immediately preceding the function definition, issue a warning" work for you? Or would it be OK (with the associated performance penalty) to check the whole file for functions, then the whole file for specs, then compare those lists? - assuming the compiler does everything else, of course.

You see...

-module(a).
-module(a).

-export([a/0, b/0]).

-spec a() -> ok.
b() ->
    ok.

a() ->
    ok.

compiles, but should probably issue an Elvis warning.

from elvis_core.

robertoaloi avatar robertoaloi commented on May 30, 2024

Hi. I assume Elvis can keep state while parsing the forms? Since the spec attribute contains the name of the function it refers to, it should be possible to go through the forms only once and match each function with the respective spec. At the end of the scan, raise a warning for all the functions without specs.

I can imagine how, for example in generated code, specs could be in a separate file, in which case we'd need to expand the surface to be scanned by including (transitively) all the included files. If Elvis does this already for other use cases, that would be ideal, otherwise we could start by checking for specs in the current module only.

Regarding your example, you have a point. Yes, I would expect a warning, too. So maybe just simplify the whole thing and check for specs/function in a strict sequence is the way to go.

from elvis_core.

elbrujohalcon avatar elbrujohalcon commented on May 30, 2024

Yeah… analyzing more than one file at a time is out of scope for elvis.
Also, analyzing more than one form at a time, even when not out of scope, it's something that elvis don't usually do.
If you check the code for elvis_style (for instance) you'll see that most rules are coded as just a simple code traversal that checks either the text of the module line by line or the AST of the module form by form.
Each rule has its own implementation and there is no single state-preserving file traversal.

from elvis_core.

jfacorro avatar jfacorro commented on May 30, 2024

@robertoaloi correct me if I'm wrong but the use case you shared seems specific to the code base and configuration you are working with. Have you considered writing your own user defined elvis rule?

from elvis_core.

paulo-ferraz-oliveira avatar paulo-ferraz-oliveira commented on May 30, 2024

Would it be possible to just parse the module, top to bottom, and make sure all functions have a previous spec declaration? I guess checking function name and arity should be enough - the rest is dialyzer's work.

from elvis_core.

paulo-ferraz-oliveira avatar paulo-ferraz-oliveira commented on May 30, 2024

(I'm tentatively assigning this to me lest I forget about it)

from elvis_core.

elbrujohalcon avatar elbrujohalcon commented on May 30, 2024

I'm closing this one. I don't see us implementing this in the near future, @paulo-ferraz-oliveira. Feel free to reopen it if you plan to work on it.

from elvis_core.

paulo-ferraz-oliveira avatar paulo-ferraz-oliveira commented on May 30, 2024

Hm... yeah. Since the compiler already has this as an option, somehow, I'm not sure repeating it in elvis_core wouldn't do more "damage" than not.

from elvis_core.

Related Issues (20)

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.