flyerhzm / rails_best_practices

a code metric tool for rails projects
http://rails-bestpractices.com
MIT License
4.17k stars 276 forks source link

Are there any way to call checks from program? #334

Open kazuooooo opened 6 years ago

kazuooooo commented 6 years ago

Hi, I'm making rails_best_practices plugin for pre-commit gem.

So, I want to call rails_best_practices checks from program like this code. https://github.com/jish/pre-commit/blob/master/lib/plugins/pre_commit/checks/rubocop.rb#L32

::RuboCop::CLI.new.run(args) == 0

I check command.rb file and it looks it can't be called from program.

Are there some way to call from program? or if it need CLI class, I'm glad to make it :)

thanks,

flyerhzm commented 6 years ago

@kazuooooo I think you can simply call like

  analyzer = RailsBestPractices::Analyzer.new(path, options)
  analyzer.analyze
# analyzer.runner.errors.empty?  if true, there's no violation.

A PR to create CLI class is welcome

kazuooooo commented 6 years ago

@filiptepper Thank you for your reply!

Yes, but to call this method, it need option parse like in command.rb

analyzer = RailsBestPractices::Analyzer.new(path, options)

I'll try to create CLI class, thank you 👍