Comments (11)
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.
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 wastrue
, but default tofalse
, - I'd have this rule disabled by default.
from elvis_core.
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.
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.
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.
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.
@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.
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.
(I'm tentatively assigning this to me lest I forget about it)
from elvis_core.
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.
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)
- Unused Variable Names HOT 5
- no_match_in_condition reports a warning even when the condition includes a valid match
- Bug (?) in atom_naming_convention HOT 2
- Using ets:fun2ms without including ms_transform.hrl should be an error HOT 3
- New ruleset `gitignore`
- Propose `gen_server` et all "no-timeout" functions as `no_common_caveats`?
- Have a simple way to run `all` checks (even optional ones) HOT 8
- New rule: consistent file names HOT 2
- New Rule: No Import Type
- New Rule: Unsafe usage of application HOT 1
- Wildcards in no_call_functions MFA HOT 4
- Potential new rule: only call internal_export'ed functions from test code HOT 2
- No consecutive strings
- Rule: Do not use lists on start_link/3,4 and init/1 HOT 3
- no_successive_maps obsolete due to Erlang change?
- New rule: consistent deps applications HOT 3
- max_function_length counts multiple function clauses as a single function HOT 2
- Count `_to_atom` as common caveats? HOT 2
- Should `no_macros` consider `LOG_...` as allowed? HOT 3
- no_successive_maps doesn't work when nested
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elvis_core.