rubocop 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +3 -1
- data/CHANGELOG.md +44 -0
- data/CONTRIBUTING.md +40 -8
- data/Gemfile +6 -0
- data/README.md +65 -20
- data/Rakefile +0 -1
- data/config/default.yml +15 -3
- data/config/enabled.yml +143 -109
- data/lib/rubocop.rb +45 -26
- data/lib/rubocop/cli.rb +26 -27
- data/lib/rubocop/config.rb +0 -1
- data/lib/rubocop/config_loader.rb +16 -23
- data/lib/rubocop/cop/commissioner.rb +2 -7
- data/lib/rubocop/cop/cop.rb +24 -51
- data/lib/rubocop/cop/ignored_node.rb +31 -0
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +50 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +36 -0
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +3 -11
- data/lib/rubocop/cop/lint/block_alignment.rb +6 -20
- data/lib/rubocop/cop/lint/condition_position.rb +52 -0
- data/lib/rubocop/cop/lint/else_layout.rb +57 -0
- data/lib/rubocop/cop/lint/end_alignment.rb +33 -8
- data/lib/rubocop/cop/lint/invalid_character_literal.rb +37 -0
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +2 -4
- data/lib/rubocop/cop/lint/syntax.rb +6 -12
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +25 -0
- data/lib/rubocop/cop/mixin/array_syntax.rb +20 -0
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +76 -0
- data/lib/rubocop/cop/mixin/check_assignment.rb +26 -0
- data/lib/rubocop/cop/{check_methods.rb → mixin/check_methods.rb} +0 -0
- data/lib/rubocop/cop/mixin/code_length.rb +33 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +53 -0
- data/lib/rubocop/cop/mixin/configurable_max.rb +19 -0
- data/lib/rubocop/cop/mixin/configurable_naming.rb +45 -0
- data/lib/rubocop/cop/{style → mixin}/if_node.rb +0 -0
- data/lib/rubocop/cop/mixin/if_then_else.rb +23 -0
- data/lib/rubocop/cop/mixin/negative_conditional.rb +24 -0
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +34 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +19 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +32 -0
- data/lib/rubocop/cop/mixin/space_inside.rb +31 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +59 -0
- data/lib/rubocop/cop/mixin/string_help.rb +32 -0
- data/lib/rubocop/cop/mixin/surrounding_space.rb +42 -0
- data/lib/rubocop/cop/rails/default_scope.rb +3 -1
- data/lib/rubocop/cop/style/accessor_method_name.rb +4 -12
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +16 -1
- data/lib/rubocop/cop/style/case_indentation.rb +33 -16
- data/lib/rubocop/cop/style/character_literal.rb +10 -0
- data/lib/rubocop/cop/style/dot_position.rb +23 -6
- data/lib/rubocop/cop/style/empty_lines_around_body.rb +5 -5
- data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +1 -32
- data/lib/rubocop/cop/style/favor_until_over_negated_while.rb +20 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +5 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +34 -0
- data/lib/rubocop/cop/style/if_with_semicolon.rb +1 -1
- data/lib/rubocop/cop/style/indentation_consistency.rb +51 -0
- data/lib/rubocop/cop/style/indentation_width.rb +0 -26
- data/lib/rubocop/cop/style/lambda_call.rb +12 -5
- data/lib/rubocop/cop/style/method_def_parentheses.rb +29 -11
- data/lib/rubocop/cop/style/multiline_if_then.rb +4 -9
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +22 -0
- data/lib/rubocop/cop/style/{ternary_operator.rb → nested_ternary_operator.rb} +0 -15
- data/lib/rubocop/cop/style/numeric_literals.rb +30 -2
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -1
- data/lib/rubocop/cop/style/parameter_lists.rb +7 -3
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +9 -11
- data/lib/rubocop/cop/style/predicate_name.rb +4 -12
- data/lib/rubocop/cop/style/raise_args.rb +19 -11
- data/lib/rubocop/cop/style/regexp_literal.rb +19 -6
- data/lib/rubocop/cop/style/space_after_colon.rb +36 -0
- data/lib/rubocop/cop/style/space_after_comma.rb +16 -0
- data/lib/rubocop/cop/style/space_after_semicolon.rb +16 -0
- data/lib/rubocop/cop/style/space_around_block_braces.rb +38 -38
- data/lib/rubocop/cop/style/space_around_operators.rb +1 -2
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +6 -2
- data/lib/rubocop/cop/style/string_literals.rb +5 -5
- data/lib/rubocop/cop/style/trailing_comma.rb +94 -0
- data/lib/rubocop/cop/style/unless_else.rb +2 -2
- data/lib/rubocop/cop/style/while_until_modifier.rb +32 -0
- data/lib/rubocop/cop/style/word_array.rb +9 -1
- data/lib/rubocop/cop/util.rb +14 -0
- data/lib/rubocop/cop/variable_inspector.rb +11 -6
- data/lib/rubocop/cop/variable_inspector/scope.rb +4 -3
- data/lib/rubocop/file_inspector.rb +22 -6
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/colorizable.rb +37 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +27 -6
- data/lib/rubocop/formatter/progress_formatter.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +9 -5
- data/lib/rubocop/options.rb +19 -4
- data/lib/rubocop/target_finder.rb +4 -0
- data/lib/rubocop/version.rb +1 -1
- data/rubocop-todo.yml +10 -2
- data/rubocop.gemspec +3 -2
- data/spec/project_spec.rb +12 -7
- data/spec/rubocop/cli_spec.rb +262 -99
- data/spec/rubocop/config_loader_spec.rb +5 -5
- data/spec/rubocop/config_spec.rb +3 -3
- data/spec/rubocop/config_store_spec.rb +12 -11
- data/spec/rubocop/cop/commissioner_spec.rb +21 -5
- data/spec/rubocop/cop/cop_spec.rb +1 -1
- data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +113 -0
- data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +35 -0
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +2 -2
- data/spec/rubocop/cop/lint/condition_position_spec.rb +49 -0
- data/spec/rubocop/cop/lint/else_layout_spec.rb +65 -0
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +41 -1
- data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +33 -0
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +3 -3
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +12 -12
- data/spec/rubocop/cop/lint/syntax_spec.rb +2 -2
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +72 -54
- data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +48 -0
- data/spec/rubocop/cop/offence_spec.rb +1 -1
- data/spec/rubocop/cop/rails/default_scope_spec.rb +6 -0
- data/spec/rubocop/cop/rails/output_spec.rb +2 -1
- data/spec/rubocop/cop/style/align_hash_spec.rb +9 -9
- data/spec/rubocop/cop/style/align_parameters_spec.rb +1 -1
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +5 -0
- data/spec/rubocop/cop/style/case_indentation_spec.rb +53 -2
- data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +3 -3
- data/spec/rubocop/cop/style/documentation_spec.rb +0 -1
- data/spec/rubocop/cop/style/dot_position_spec.rb +18 -3
- data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +4 -4
- data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +13 -0
- data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +1 -1
- data/spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb +1 -1
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +5 -0
- data/spec/rubocop/cop/style/{favor_modifier_spec.rb → if_unless_modifier_spec.rb} +4 -111
- data/spec/rubocop/cop/style/indentation_consistency_spec.rb +490 -0
- data/spec/rubocop/cop/style/indentation_width_spec.rb +19 -91
- data/spec/rubocop/cop/style/lambda_call_spec.rb +18 -0
- data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +2 -2
- data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +35 -1
- data/spec/rubocop/cop/style/method_length_spec.rb +1 -0
- data/spec/rubocop/cop/style/method_name_spec.rb +27 -5
- data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +4 -4
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +2 -2
- data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +18 -0
- data/spec/rubocop/cop/style/{ternary_operator_spec.rb → nested_ternary_operator_spec.rb} +0 -15
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +18 -1
- data/spec/rubocop/cop/style/one_line_conditional_spec.rb +2 -1
- data/spec/rubocop/cop/style/parameter_lists_spec.rb +1 -0
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +13 -4
- data/spec/rubocop/cop/style/raise_args_spec.rb +22 -0
- data/spec/rubocop/cop/style/redundant_self_spec.rb +4 -4
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +4 -0
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +12 -4
- data/spec/rubocop/cop/style/space_after_method_name_spec.rb +2 -2
- data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +30 -1
- data/spec/rubocop/cop/style/{space_around_equals_in_default_parameter_spec.rb → space_around_equals_in_parameter_default_spec.rb} +0 -0
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +2 -1
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +20 -3
- data/spec/rubocop/cop/style/string_literals_spec.rb +33 -0
- data/spec/rubocop/cop/style/trailing_comma_spec.rb +200 -0
- data/spec/rubocop/cop/style/variable_name_spec.rb +27 -3
- data/spec/rubocop/cop/style/while_until_modifier_spec.rb +75 -0
- data/spec/rubocop/cop/style/word_array_spec.rb +1 -0
- data/spec/rubocop/cop/team_spec.rb +1 -1
- data/spec/rubocop/cop/variable_inspector/scope_spec.rb +3 -4
- data/spec/rubocop/file_inspector_spec.rb +1 -1
- data/spec/rubocop/formatter/base_formatter_spec.rb +12 -11
- data/spec/rubocop/formatter/colorizable_spec.rb +107 -0
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +2 -0
- data/spec/rubocop/formatter/formatter_set_spec.rb +1 -1
- data/spec/rubocop/formatter/json_formatter_spec.rb +4 -3
- data/spec/rubocop/formatter/progress_formatter_spec.rb +2 -2
- data/spec/rubocop/options_spec.rb +3 -1
- data/spec/rubocop/target_finder_spec.rb +13 -11
- data/spec/spec_helper.rb +5 -1
- data/spec/support/shared_examples.rb +2 -2
- data/spec/support/statement_modifier_helper.rb +41 -0
- metadata +88 -30
- data/lib/rubocop/cop/check_assignment.rb +0 -43
- data/lib/rubocop/cop/style/array_syntax.rb +0 -22
- data/lib/rubocop/cop/style/autocorrect_alignment.rb +0 -78
- data/lib/rubocop/cop/style/code_length.rb +0 -35
- data/lib/rubocop/cop/style/configurable_enforced_style.rb +0 -51
- data/lib/rubocop/cop/style/configurable_max.rb +0 -17
- data/lib/rubocop/cop/style/configurable_naming.rb +0 -41
- data/lib/rubocop/cop/style/favor_modifier.rb +0 -118
- data/lib/rubocop/cop/style/if_then_else.rb +0 -27
- data/lib/rubocop/cop/style/space_after_comma_etc.rb +0 -73
- data/lib/rubocop/cop/style/space_inside.rb +0 -33
- data/lib/rubocop/cop/style/string_help.rb +0 -30
- data/lib/rubocop/cop/style/surrounding_space.rb +0 -44
@@ -1,33 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Rubocop
|
4
|
-
module Cop
|
5
|
-
module Style
|
6
|
-
# Common functionality for checking for spaces inside various
|
7
|
-
# kinds of parentheses.
|
8
|
-
module SpaceInside
|
9
|
-
include SurroundingSpace
|
10
|
-
MSG = 'Space inside %s detected.'
|
11
|
-
|
12
|
-
def investigate(processed_source)
|
13
|
-
@processed_source = processed_source
|
14
|
-
left, right, kind = specifics
|
15
|
-
processed_source.tokens.each_cons(2) do |t1, t2|
|
16
|
-
if t1.type == left || t2.type == right
|
17
|
-
if t2.pos.line == t1.pos.line && space_between?(t1, t2)
|
18
|
-
range = Parser::Source::Range.new(processed_source.buffer,
|
19
|
-
t1.pos.end_pos,
|
20
|
-
t2.pos.begin_pos)
|
21
|
-
add_offence(range, range, format(MSG, kind))
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def autocorrect(range)
|
28
|
-
@corrections << ->(corrector) { corrector.remove(range) }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Rubocop
|
4
|
-
module Cop
|
5
|
-
module Style
|
6
|
-
# Classes that include this module just implement functions to determine
|
7
|
-
# what is an offence and how to do auto-correction. They get help with
|
8
|
-
# adding offences for the faulty string nodes, and with filtering out
|
9
|
-
# nodes.
|
10
|
-
module StringHelp
|
11
|
-
def on_str(node)
|
12
|
-
# Constants like __FILE__ are handled as strings,
|
13
|
-
# but don't respond to begin.
|
14
|
-
return unless node.loc.respond_to?(:begin) && node.loc.begin
|
15
|
-
return if part_of_ignored_node?(node)
|
16
|
-
|
17
|
-
add_offence(node, :expression) if offence?(node)
|
18
|
-
end
|
19
|
-
|
20
|
-
def on_dstr(node)
|
21
|
-
ignore_node(node)
|
22
|
-
end
|
23
|
-
|
24
|
-
def on_regexp(node)
|
25
|
-
ignore_node(node)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Rubocop
|
4
|
-
module Cop
|
5
|
-
module Style
|
6
|
-
# Common functionality for checking surrounding space.
|
7
|
-
module SurroundingSpace
|
8
|
-
def space_between?(t1, t2)
|
9
|
-
char_preceding_2nd_token =
|
10
|
-
@processed_source[t2.pos.line - 1][t2.pos.column - 1]
|
11
|
-
if char_preceding_2nd_token == '+' && t1.type != :tPLUS
|
12
|
-
# Special case. A unary plus is not present in the tokens.
|
13
|
-
char_preceding_2nd_token =
|
14
|
-
@processed_source[t2.pos.line - 1][t2.pos.column - 2]
|
15
|
-
end
|
16
|
-
t2.pos.line > t1.pos.line || char_preceding_2nd_token =~ /[ \t]/
|
17
|
-
end
|
18
|
-
|
19
|
-
def index_of_first_token(node)
|
20
|
-
b = node.loc.expression.begin
|
21
|
-
token_table[[b.line, b.column]]
|
22
|
-
end
|
23
|
-
|
24
|
-
def index_of_last_token(node)
|
25
|
-
e = node.loc.expression.end
|
26
|
-
(0...e.column).to_a.reverse.find do |c|
|
27
|
-
ix = token_table[[e.line, c]]
|
28
|
-
return ix if ix
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def token_table
|
33
|
-
@token_table ||= begin
|
34
|
-
table = {}
|
35
|
-
@processed_source.tokens.each_with_index do |t, ix|
|
36
|
-
table[[t.pos.line, t.pos.column]] = ix
|
37
|
-
end
|
38
|
-
table
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|