Question

We would like to use Rubocop to validate our ruby is syntaxicaly correct and follow basic code guidelines.

Appart from that we have this rule : we indent using tabs to allow anybody to decided how they want them to be rendered (display them like 2 or 4 spaces)

The problem is that rubocop seems designed to refuse tabs for indentation AT ALL.

How can we override all theses rules to be space complients ?

EDIT: I'm thinking of overriding this module https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/source_parser.rb to replace all tabs from my files by 2 spaces to create the illusion for the gem...

Was it helpful?

Solution 4

I overrid this module https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/source_parser.rb to replace all tabs from my files by 2 spaces to create the illusion for the gem...

OTHER TIPS

Add to your .rubocop.yml:

Style/Tab:
  Enabled: false

to disable the tabs rule.

You can write your own custom cop to check proper indentation.

As an evil unrepentant tab user, I ended up hacking it like so. This diff for 0.32.1:

--- processed_source.rb.orig    2015-07-28 05:53:52.199418557 +0100
+++ processed_source.rb 2015-07-28 05:54:04.750420458 +0100
@@ -13,7 +13,7 @@
                 :parser_error, :raw_source

     def self.from_file(path)
-      file = File.read(path)
+      file = File.read(path).gsub(/^(\t+)/) {|m| '  ' * m.size }
       new(file, path)
     rescue
       abort("#{Rainbow('rubocop: No such file or directory').red} -- #{path}")

You should now blend in perfectly. Bwahahaha.

For the latest version, add this to your .rubocop.yml file:

Layout/Tab:
  Enabled: false

You can find all default options listed here:

https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml

And, the rule is defined here:

https://github.com/rubocop-hq/rubocop/blob/master/lib/rubocop/cop/layout/tab.rb

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top