Class: HamlLint::Linter::RuboCop::Runner
- Inherits:
-
RuboCop::Runner
- Object
- RuboCop::Runner
- HamlLint::Linter::RuboCop::Runner
- Defined in:
- lib/haml_lint/linter/rubocop.rb
Overview
Processes a ruby file and reports RuboCop offenses
Instance Attribute Summary collapse
-
#offenses ⇒ Object
readonly
Returns the value of attribute offenses.
Instance Method Summary collapse
-
#cached_run? ⇒ Boolean
RuboCop caches results by taking a hash of the file contents & path, among other things.
- #corrected_code ⇒ Object
-
#file_finished(_file, offenses) ⇒ Object
Executed when a file has been scanned by RuboCop, adding the reported offenses to our collection.
- #run(haml_path, ruby_code, config:, allow_cache: false) ⇒ Object
Instance Attribute Details
#offenses ⇒ Object (readonly)
Returns the value of attribute offenses.
21 22 23 |
# File 'lib/haml_lint/linter/rubocop.rb', line 21 def offenses @offenses end |
Instance Method Details
#cached_run? ⇒ Boolean
RuboCop caches results by taking a hash of the file contents & path, among other things. It disables its cache when working on file-content from stdin. Unfortunately we always use RuboCop’s stdin, even when we’re linting a file on-disk. So, override RuboCop::Runner#cached_run? so that it’ll allow caching results, so long as haml-lint itself isn’t being invoked with files on stdin.
49 50 51 52 53 54 55 56 |
# File 'lib/haml_lint/linter/rubocop.rb', line 49 def cached_run? return false unless @allow_cache @cached_run ||= ([:cache] == 'true' || ([:cache] != 'false' && @config_store.for_pwd.for_all_cops['UseCache'])) && ![:auto_gen_config] end |
#corrected_code ⇒ Object
31 32 33 |
# File 'lib/haml_lint/linter/rubocop.rb', line 31 def corrected_code [:stdin] end |
#file_finished(_file, offenses) ⇒ Object
Executed when a file has been scanned by RuboCop, adding the reported offenses to our collection.
40 41 42 |
# File 'lib/haml_lint/linter/rubocop.rb', line 40 def file_finished(_file, offenses) @offenses = offenses end |
#run(haml_path, ruby_code, config:, allow_cache: false) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/haml_lint/linter/rubocop.rb', line 23 def run(haml_path, ruby_code, config:, allow_cache: false) @allow_cache = allow_cache @offenses = [] @config_store.instance_variable_set(:@options_config, config) [:stdin] = ruby_code super([haml_path]) end |