codeclimate-community/codeclimate-flog

CodeClimate analysis crashes. Running flog by hand works.

Closed this issue · 10 comments

RoryO commented

Failure from the build:

Location is not formatted correctly;
File does not exist: '';
Path is not a file: '';
Path must be present;
Path must be relative to the project directory: `{
"type"=>"issue",
"check_name"=>"Flog Score",
"description"=>"Complex method namespace(grape)::task#routes (97.6)",
"categories"=>["Complexity"],
"content"=>{"body"=>"Flog calculates the ABC score for methods.\nThe ABC score is based on assignments, branches (method calls), and conditions.\n\nYou can read more about [ABC metrics](http://c2.com/cgi/wiki?AbcMetric) or\n[the flog tool](http://www.zenspider.com/projects/flog.html)\"\n"},
"remediation_points"=>5081617,
"fingerprint"=>"be6684fa61abf5a203151488dc79eac3",
"location"=>{"path"=>nil, "lines"=>{"begin"=>nil, "end"=>nil}}}`.

Running flog on the entire project is successful locally:

▶ flog **/*.rb 21&>/dev/null; echo $?
0

Locally I have these gems:

▶ ruby --version
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
▶ gem list | egrep "flog|sexp_processor|ruby_parser|path_expander"
flog (4.6.0)
path_expander (1.0.1)
ruby_parser (3.8.4)
sexp_processor (4.8.0)

The strangest thing is if I run the above flog analysis for all ruby files in the project and check the output for namespace(grape)::task it does not appear. I do not know where that is defined in this project as I cannot find it.

I don't have any more information. Willing to provide anything you may possibly need.

[reformatted by @zenspider]

@RoryO hi, thanks for opening this issue!

Wondering if this has to do with this TODO comment 🤔.

From reading the code, I can see a path toward avoiding this error, so I've opened PR #4. It might make more sense to do an upstream fix in flog, though... I'll defer to @zenspider on that

Looks like we're getting an empty string back for location... I'd like to understand why first. But yeah. there needs to be a better guard.

RoryO commented

Since it is within our codebase is there anything I can do to help debug? I have also filed an issue with CC support if someone at CC can use to analyze.

You can do this: CODECLIMATE_DEBUG=1 codeclimate analyze and that'll output all the stderr stuff you don't normally see. That won't necessarily pinpoint the issue, because I don't have any extra logging but something might be visible.

From that, I'd like to see the paths or globs that it outputs, if any...

You can also grep/ag around for task.*routes in your code. I'd like to see that file, if possible. We can anonymize the actual content if you need.

RoryO commented

That helped completely. It is a rake task:

[DEBUG] flog:stable engine output: 
{"type":"issue",
"check_name":"Flog Score",
"description":"namespace(grape)::task#routes scored 97.6",
"categories":["Complexity"],
"remediation":97.63234927523101,
"fingerprint":"be6684fa61abf5a203151488dc79eac3",
"location":{"path":"lib/tasks/grape.rake","lines":{"begin":3,"end":3}}}
== lib/tasks/grape.rake (14 issues) ==
3: namespace(grape)::task#routes scored 97.6 [flog]
7: Space between { and | missing. [rubocop]
8: Space missing to the left of {. [rubocop]
8: Space between { and | missing. [rubocop]
9: Space missing to the left of {. [rubocop]
9: Space between { and | missing. [rubocop]
10: Space missing to the left of {. [rubocop]
10: Space between { and | missing. [rubocop]
11: Space between { and | missing. [rubocop]
11: Space missing to the left of {. [rubocop]
12: Space missing to the left of {. [rubocop]
12: Space between { and | missing. [rubocop]
21: Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument. [rubocop]
37: Surrounding space missing for operator `-`. [rubocop]

Rake tasks should be removed from analysis and I'll fix that part on my end. What is interesting is the CC CLI is able to resolve the file while the web analysis does not.

Can you "unfix" the rake file and show me the code or at least the structure of the code? I'd like a repro on my end so I can figure out how it passed my nil guard in the engine. Happy to NDA and/or take this out-of-band to keep you safe.

or... you can hop in our slack and just talk to me realtime http://seattlerbslack.herokuapp.com

This was fixed, right?

RoryO commented

Yes. @zenspider committed some changes to flog(seattlerb/flog@572df6d). After CC updated their analysis containers I have not seen this exception. We have been getting incorrect reports from flog's line number location which Abby at CC is aware of. While possibly related, that is a separate issue. This one can be closed.