AtomLinter / linter-codeclimate

An Atom Linter plugin for the Code Climate CLI
http://github.com/codeclimate/codeclimate
MIT License
10 stars 5 forks source link

Running cli twice on save, improve performance #81

Closed cgalvarez closed 6 years ago

cgalvarez commented 6 years ago

Right now the cli is being run twice on each file save.

You can check your open processes with ps aux | grep 'codeclimate analyze' or by taking a look at the Atom's dev console (ctrl + alt + i) messages.

I think the approach is just plain wrong. Right now, the command executed is codeclimate analyze -f json path/to/changed/file, and as such, only analyzes the changed file. We're missing some useful and invaluable issues reported by CodeClimate, as duplicated code detection (since this can affect more than one file).

Each time a new save takes place, a new cli executions is spawned. I think it would be preferable to spawn only one cli execution per project (if any of its files is changed), and drop issues of closed files (to avoid errors when calculating range from the textEditor).

With this approach, I think keeping a dictionary with each project root and its associated promise (of its spawned cli execution) would allow to kill the ongoing analysis and start the new one on consecutive savings, without having multiple parallel executions in the background per project.

Also, it would be desirable to debounce the execution, so we could avoid the double current execution (I have no idea of which is causing it).

cgalvarez commented 6 years ago

I'm working on a PR to address this issue. Any insight/help will be welcome :wink:

With that PR I will refactor the code and will try to improve its maintainability. It's not as good as it could be, according to its own CodeClimate report.

As additional note, this package could get code coverage if switching to mocha instead of jasmine for tests and using a package that I released a few days ago: atom-coverage.