Patience, my dear colleagues, hopefully the PR into the Rubocop core to enable tabs indentation will be merged soon. For now you can create the following rb file somewhere in your project and require it when running rubocop.
rubocop [...] --require rubocop_tabs.rb
The rubocop_tabs.rb:
# frozen_string_literal: true
require 'rubocop'
require 'set'
RuboCop::ConfigLoader.default_configuration['Layout/Tab']['SupportedStyles'] = %w[tab space]
RuboCop::ConfigLoader.default_configuration['Layout/Tab']['EnforcedStyle'] = :space
module RuboCop
module Cop
module Layout
class Tab < Cop
include Alignment
include RangeHelp
include ConfigurableEnforcedStyle
MSG = '%<type>s detected.'
def investigate(processed_source)
str_ranges = string_literal_ranges(processed_source.ast)
processed_source.lines.each.with_index(1) do |line, lineno|
match = style == :tab ? line.match(/\A\s* +/) : line.match(/\A\t+/)
next unless match
range = source_range(processed_source.buffer, lineno, match.begin(0)...match.end(0))
next if in_string_literal?(str_ranges, range)
add_offense(range, location: range)
end
end
def autocorrect(range)
if style == :tab
lambda do |corrector|
corrector.replace(range, range.source.gsub(/\A\s+/) do |i|
"\t" * i.size
end)
end
else
lambda do |corrector|
spaces = ' ' * configured_indentation_width
corrector.replace(range, range.source.gsub(/\t/, spaces))
end
end
end
private
def message(_node)
format(MSG, type: style == :tab ? 'Space' : 'Tab')
end
end
end
end
end
Also add the following to your .rubocop.yml
Layout/Tab:
EnforcedStyle: tab