require "fileutils"

module Ragnarson
  module Stylecheck
    # helper to nicely update rubocop config
    module RubocopHelpers
      class << self
        def config
          File.join(Ragnarson::Stylecheck.root, "config", "rubocop.yml")
        end
      end
    end
  end
end

require "fileutils"

module Ragnarson
  module Stylecheck
    # helper to nicely update rubocop config
    module RubocopHelpers
      class << self
        def config
          if project_config_exists?
            project_config_path
          else
            stylecheck_config_path
          end
        end

        def project_config_exists?
          File.exist?(project_config_path)
        end

        def project_config_path
          File.join(Dir.pwd, "config", "rubocop.yml")
        end

        def stylecheck_config_path
          File.join(Ragnarson::Stylecheck.root, "config", "rubocop.yml")
        end
      end
    end
  end
end

Allow to use local rubocop config by rake task.
Allow to use local rubocop config by rake task.

In some projects rubocop returns:
```
(Using Ruby 2.0 parser; configure using TargetRubyVersion parameter, under AllCops)
```

Different projects using different ruby versions. To fix this problem user should set TargetRubyVersion inside rubocop config.

```
inherit_gem:
  ragnarson-stylecheck: config/rubocop.yml

AllCops:
  TargetRubyVersion: 2.3
```
