Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the max line length of Layout/LineLength to 120 #7952

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Changes

* [#7952](https://github.com/rubocop-hq/rubocop/pull/7952): **(Breaking)** Change the max line length of `Layout/LineLength` to 120 by default. ([@koic][])

## 0.83.0 (2020-05-11)

### New features
Expand Down
4 changes: 2 additions & 2 deletions config/default.yml
Expand Up @@ -861,9 +861,9 @@ Layout/LineLength:
StyleGuide: '#80-character-limits'
Enabled: true
VersionAdded: '0.25'
VersionChanged: '0.78'
VersionChanged: '1.0'
AutoCorrect: false
Max: 80
Max: 120
# To make it possible to copy or click on URIs in the code, we allow lines
# containing a URI to be longer than Max.
AllowHeredoc: true
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop.rb
Expand Up @@ -216,7 +216,7 @@
require_relative 'rubocop/cop/layout/empty_lines_around_begin_body'
require_relative 'rubocop/cop/layout/empty_lines_around_block_body'
require_relative 'rubocop/cop/layout/empty_lines_around_class_body'
require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords' # rubocop:disable Layout/LineLength
require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords'
require_relative 'rubocop/cop/layout/empty_lines_around_method_body'
require_relative 'rubocop/cop/layout/empty_lines_around_module_body'
require_relative 'rubocop/cop/layout/empty_lines'
Expand Down Expand Up @@ -468,11 +468,9 @@
require_relative 'rubocop/cop/style/lambda_call'
require_relative 'rubocop/cop/style/line_end_concatenation'
require_relative 'rubocop/cop/style/method_call_without_args_parentheses'
# rubocop:disable Layout/LineLength
require_relative 'rubocop/cop/style/method_call_with_args_parentheses'
require_relative 'rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses'
require_relative 'rubocop/cop/style/method_call_with_args_parentheses/require_parentheses'
# rubocop:enable Layout/LineLength
require_relative 'rubocop/cop/style/method_called_on_do_end_block'
require_relative 'rubocop/cop/style/method_def_parentheses'
require_relative 'rubocop/cop/style/method_missing_super'
Expand Down
8 changes: 2 additions & 6 deletions lib/rubocop/cli/command/show_cops.rb
Expand Up @@ -42,18 +42,14 @@ def print_cops_of_department(registry, department, show_all)
selected_cops_of_department(registry, department)
end

if show_all
puts "# Department '#{department}' (#{selected_cops.length}):"
end
puts "# Department '#{department}' (#{selected_cops.length}):" if show_all

print_cop_details(selected_cops)
end

def print_cop_details(cops)
cops.each do |cop|
if cop.new(@config).support_autocorrect?
puts '# Supports --auto-correct'
end
puts '# Supports --auto-correct' if cop.new(@config).support_autocorrect?
puts "#{cop.cop_name}:"
puts config_lines(cop)
puts
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/config.rb
Expand Up @@ -86,9 +86,7 @@ def add_excludes_from_higher_level(highest_config)

excludes = for_all_cops['Exclude'] ||= []
highest_config.for_all_cops['Exclude'].each do |path|
unless path.is_a?(Regexp) || absolute?(path)
path = File.join(File.dirname(highest_config.loaded_path), path)
end
path = File.join(File.dirname(highest_config.loaded_path), path) unless path.is_a?(Regexp) || absolute?(path)
excludes << path unless excludes.include?(path)
end
end
Expand Down
12 changes: 3 additions & 9 deletions lib/rubocop/config_loader.rb
Expand Up @@ -95,9 +95,7 @@ def configuration_from_file(config_file)
end

merge_with_default(config, config_file).tap do |merged_config|
unless possible_new_cops?(config)
warn_on_pending_cops(merged_config.pending_cops)
end
warn_on_pending_cops(merged_config.pending_cops) unless possible_new_cops?(config)
end
end

Expand Down Expand Up @@ -207,9 +205,7 @@ def existing_configuration(config_file)
def write_config_file(file_name, file_string, rubocop_yml_contents)
File.open(file_name, 'w') do |f|
f.write "inherit_from:#{file_string}\n"
if /\S/.match?(rubocop_yml_contents)
f.write "\n#{rubocop_yml_contents}"
end
f.write "\n#{rubocop_yml_contents}" if /\S/.match?(rubocop_yml_contents)
end
end

Expand All @@ -227,9 +223,7 @@ def load_yaml_configuration(absolute_path)

puts "configuration from #{absolute_path}" if debug?

unless hash.is_a?(Hash)
raise(TypeError, "Malformed configuration in #{absolute_path}")
end
raise(TypeError, "Malformed configuration in #{absolute_path}") unless hash.is_a?(Hash)

hash
end
Expand Down
8 changes: 2 additions & 6 deletions lib/rubocop/config_loader_resolver.rb
Expand Up @@ -71,9 +71,7 @@ def merge_with_default(config, config_file, unset_nil:)
end
end

if disabled_by_default
config = handle_disabled_by_default(config, default_configuration)
end
config = handle_disabled_by_default(config, default_configuration) if disabled_by_default

opts = { inherit_mode: config['inherit_mode'] || {},
unset_nil: unset_nil }
Expand Down Expand Up @@ -117,9 +115,7 @@ def override_department_setting_for_cops(base_hash, derived_hash)
# internal setting that's not documented in the manual. It will cause a
# cop to be enabled later, when logic surrounding enabled/disabled it
# run, even though its department is disabled.
if derived_hash[key]['Enabled']
derived_hash[key]['Enabled'] = 'override_department'
end
derived_hash[key]['Enabled'] = 'override_department' if derived_hash[key]['Enabled']
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/corrector.rb
Expand Up @@ -85,9 +85,7 @@ def remove(node_or_range)
def insert_before(node_or_range, content)
range = to_range(node_or_range)
# TODO: Fix Cops using bad ranges instead
if range.end_pos > @source_buffer.source.size
range = range.with(end_pos: @source_buffer.source.size)
end
range = range.with(end_pos: @source_buffer.source.size) if range.end_pos > @source_buffer.source.size

@source_rewriter.insert_before(range, content)
end
Expand Down
8 changes: 2 additions & 6 deletions lib/rubocop/cop/correctors/alignment_corrector.rb
Expand Up @@ -48,9 +48,7 @@ def autocorrect_line(corrector, line_begin_pos, expr, column_delta,
return if taboo_ranges.any? { |t| within?(range, t) }

if column_delta.positive?
unless range.resize(1).source == "\n"
corrector.insert_before(range, ' ' * column_delta)
end
corrector.insert_before(range, ' ' * column_delta) unless range.resize(1).source == "\n"
elsif /\A[ \t]+\z/.match?(range.source)
remove(range, corrector)
end
Expand Down Expand Up @@ -92,9 +90,7 @@ def block_comment_within?(expr)
end

def calculate_range(expr, line_begin_pos, column_delta)
if column_delta.positive?
return range_between(line_begin_pos, line_begin_pos)
end
return range_between(line_begin_pos, line_begin_pos) if column_delta.positive?

starts_with_space =
expr.source_buffer.source[line_begin_pos].start_with?(' ')
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/correctors/parentheses_corrector.rb
Expand Up @@ -10,9 +10,7 @@ def correct(node)
corrector.remove(node.loc.begin)
corrector.remove(node.loc.end)

if ternary_condition?(node) && next_char_is_question_mark?(node)
corrector.insert_after(node.loc.end, ' ')
end
corrector.insert_after(node.loc.end, ' ') if ternary_condition?(node) && next_char_is_question_mark?(node)
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/correctors/space_corrector.rb
Expand Up @@ -35,9 +35,7 @@ def remove_space(processed_source, corrector, left_token, right_token)

def add_space(processed_source, corrector, left_token, right_token)
@processed_source = processed_source
unless left_token.space_after?
corrector.insert_after(left_token.pos, ' ')
end
corrector.insert_after(left_token.pos, ' ') unless left_token.space_after?
return if right_token.space_before?

corrector.insert_before(right_token.pos, ' ')
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/gemspec/ordered_dependencies.rb
Expand Up @@ -68,9 +68,7 @@ def investigate(processed_source)
gem_name(current),
gem_name(previous)
)
unless get_dependency_name(previous) == get_dependency_name(current)
next
end
next unless get_dependency_name(previous) == get_dependency_name(current)

register_offense(previous, current)
end
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/ignored_node.rb
Expand Up @@ -10,9 +10,7 @@ def ignore_node(node)

def part_of_ignored_node?(node)
ignored_nodes.map(&:loc).any? do |ignored_loc|
if ignored_loc.expression.begin_pos > node.source_range.begin_pos
next false
end
next false if ignored_loc.expression.begin_pos > node.source_range.begin_pos

ignored_end_pos = if ignored_loc.respond_to?(:heredoc_body)
ignored_loc.heredoc_end.end_pos
Expand Down
8 changes: 2 additions & 6 deletions lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb
Expand Up @@ -99,9 +99,7 @@ def autocorrect(node)
lambda do |corrector|
line = range_by_whole_lines(node.source_range)

unless previous_line_empty?(node.first_line)
corrector.insert_before(line, "\n")
end
corrector.insert_before(line, "\n") unless previous_line_empty?(node.first_line)

correct_next_line_if_denied_style(corrector, node, line)
end
Expand All @@ -120,9 +118,7 @@ def allowed_only_before_style?(node)
def correct_next_line_if_denied_style(corrector, node, line)
case style
when :around
unless next_line_empty?(node.last_line)
corrector.insert_after(line, "\n")
end
corrector.insert_after(line, "\n") unless next_line_empty?(node.last_line)
when :only_before
if next_line_empty?(node.last_line)
range = next_empty_line_range(node)
Expand Down
2 changes: 0 additions & 2 deletions lib/rubocop/cop/layout/first_argument_indentation.rb
Expand Up @@ -2,7 +2,6 @@

module RuboCop
module Cop
# rubocop:disable Layout/LineLength
module Layout
# This cop checks the indentation of the first argument in a method call.
# Arguments after the first one are checked by Layout/ArgumentAlignment,
Expand Down Expand Up @@ -143,7 +142,6 @@ module Layout
# second_param
#
class FirstArgumentIndentation < Cop
# rubocop:enable Layout/LineLength
include Alignment
include ConfigurableEnforcedStyle
include RangeHelp
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/layout/first_array_element_indentation.rb
Expand Up @@ -125,9 +125,7 @@ def check(array_node, left_parenthesis)

def check_right_bracket(right_bracket, left_bracket, left_parenthesis)
# if the right bracket is on the same line as the last value, accept
if /\S/.match?(right_bracket.source_line[0...right_bracket.column])
return
end
return if /\S/.match?(right_bracket.source_line[0...right_bracket.column])

expected_column = base_column(left_bracket, left_parenthesis)
@column_delta = expected_column - right_bracket.column
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/layout/first_method_argument_line_break.rb
Expand Up @@ -36,9 +36,7 @@ def on_send(node)
# ...then each key/value pair is treated as a method 'argument'
# when determining where line breaks should appear.
if (last_arg = args.last)
if last_arg.hash_type? && !last_arg.braces?
args = args.concat(args.pop.children)
end
args = args.concat(args.pop.children) if last_arg.hash_type? && !last_arg.braces?
end

check_method_line_break(node, args)
Expand Down
Expand Up @@ -98,13 +98,9 @@ def autocorrect(node)
lambda do |corrector|
fix_closing_parenthesis(node, corrector)

if internal_trailing_comma?(node)
remove_internal_trailing_comma(node, corrector)
end
remove_internal_trailing_comma(node, corrector) if internal_trailing_comma?(node)

if external_trailing_comma?(node)
fix_external_trailing_comma(node, corrector)
end
fix_external_trailing_comma(node, corrector) if external_trailing_comma?(node)
end
end

Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/layout/indentation_width.rb
Expand Up @@ -263,9 +263,7 @@ def check_indentation(base_loc, body_node, style = 'normal')
def offense(body_node, indentation, style)
# This cop only auto-corrects the first statement in a def body, for
# example.
if body_node.begin_type? && !parentheses?(body_node)
body_node = body_node.children.first
end
body_node = body_node.children.first if body_node.begin_type? && !parentheses?(body_node)

# Since autocorrect changes a number of lines, and not only the line
# where the reported offending range is, we avoid auto-correction if
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/layout/multiline_block_layout.rb
Expand Up @@ -81,9 +81,7 @@ def autocorrect(node)

expr_before_body ||= node.loc.begin

if expr_before_body.line == node.body.first_line
autocorrect_body(corrector, node, node.body)
end
autocorrect_body(corrector, node, node.body) if expr_before_body.line == node.body.first_line
end
end

Expand Down
Expand Up @@ -37,9 +37,7 @@ def on_send(node)
# ...then each key/value pair is treated as a method 'argument'
# when determining where line breaks should appear.
if (last_arg = args.last)
if last_arg.hash_type? && !last_arg.braces?
args = args.concat(args.pop.children)
end
args = args.concat(args.pop.children) if last_arg.hash_type? && !last_arg.braces?
end

check_line_breaks(node, args)
Expand Down
8 changes: 2 additions & 6 deletions lib/rubocop/cop/layout/space_around_method_call_operator.rb
Expand Up @@ -72,9 +72,7 @@ def check_and_add_offense(node, add_left_offense = true)
left = previous_token(operator)
right = next_token(operator)

if !right.comment? && valid_right_token?(right, operator)
no_space_offenses(node, operator, right, MSG)
end
no_space_offenses(node, operator, right, MSG) if !right.comment? && valid_right_token?(right, operator)
return unless valid_left_token?(left, operator)

no_space_offenses(node, left, operator, MSG) if add_left_offense
Expand Down Expand Up @@ -121,9 +119,7 @@ def left_token_for_auto_correction(node, operator)

def right_token_for_auto_correction(operator)
right_token = next_token(operator)
if !right_token.comment? && valid_right_token?(right_token, operator)
return right_token
end
return right_token if !right_token.comment? && valid_right_token?(right_token, operator)

operator
end
Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/layout/space_before_comment.rb
Expand Up @@ -20,9 +20,7 @@ def investigate(processed_source)
next unless token2.comment?
next unless token1.line == token2.line

if token1.pos.end == token2.pos.begin
add_offense(token2.pos, location: token2.pos)
end
add_offense(token2.pos, location: token2.pos) if token1.pos.end == token2.pos.begin
end
end

Expand Down
Expand Up @@ -78,9 +78,7 @@ def on_array(node)
return unless node.square_brackets?

left, right = array_brackets(node)
if empty_brackets?(left, right)
return empty_offenses(node, left, right, EMPTY_MSG)
end
return empty_offenses(node, left, right, EMPTY_MSG) if empty_brackets?(left, right)

start_ok = next_to_newline?(node, left)
end_ok = node.single_line? ? false : end_has_own_line?(right)
Expand Down
8 changes: 2 additions & 6 deletions lib/rubocop/cop/layout/space_inside_reference_brackets.rb
Expand Up @@ -72,9 +72,7 @@ def on_send(node)

right_token = closing_bracket(tokens, left_token)

if empty_brackets?(left_token, right_token)
return empty_offenses(node, left_token, right_token, EMPTY_MSG)
end
return empty_offenses(node, left_token, right_token, EMPTY_MSG) if empty_brackets?(left_token, right_token)

if style == :no_space
no_space_offenses(node, left_token, right_token, MSG)
Expand Down Expand Up @@ -130,9 +128,7 @@ def closing_bracket(tokens, opening_bracket)
tokens[i..-1].each do |token|
inner_left_brackets_needing_closure += 1 if token.left_bracket?
inner_left_brackets_needing_closure -= 1 if token.right_bracket?
if inner_left_brackets_needing_closure.zero? && token.right_bracket?
return token
end
return token if inner_left_brackets_needing_closure.zero? && token.right_bracket?
end
end

Expand Down
8 changes: 2 additions & 6 deletions lib/rubocop/cop/lint/erb_new_arguments.rb
Expand Up @@ -141,13 +141,9 @@ def override_by_legacy_args(kwargs, node)
arguments = node.arguments
overridden_kwargs = kwargs.dup

if arguments[2]
overridden_kwargs[0] = "trim_mode: #{arguments[2].source}"
end
overridden_kwargs[0] = "trim_mode: #{arguments[2].source}" if arguments[2]

if arguments[3] && !arguments[3].hash_type?
overridden_kwargs[1] = "eoutvar: #{arguments[3].source}"
end
overridden_kwargs[1] = "eoutvar: #{arguments[3].source}" if arguments[3] && !arguments[3].hash_type?

overridden_kwargs
end
Expand Down