ridecharge-rubocop 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/.travis.yml +14 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +22 -0
- data/bin/ridecharge-rubocop +49 -0
- data/config/0default.yml +8 -0
- data/config/fleet-magic-todo.yml +380 -0
- data/config/rc-todo.yml +190 -0
- data/config/ridecharge-rubocop_todo.yml +73 -0
- data/config/rubocop/default.yml +308 -0
- data/config/rubocop/disabled.yml +9 -0
- data/config/rubocop/enabled.yml +648 -0
- data/config/standard-todo.yml +24 -0
- data/config/tabs.yml +15 -0
- data/config/vehicle-todo.yml +195 -0
- data/lib/ridecharge/rubocop.rb +2 -0
- data/lib/ridecharge/rubocop/version.rb +5 -0
- data/lib/rubocop/config_loader_monkeypatch.rb +117 -0
- data/lib/rubocop/ridecharge.rb +1 -0
- data/ridecharge-rubocop.gemspec +25 -0
- data/spec/isolated_environment_spec.rb +24 -0
- data/spec/project_spec.rb +118 -0
- data/spec/rubocop/cli_spec.rb +1385 -0
- data/spec/rubocop/config_loader_spec.rb +328 -0
- data/spec/rubocop/config_spec.rb +179 -0
- data/spec/rubocop/config_store_spec.rb +53 -0
- data/spec/rubocop/cop/commissioner_spec.rb +83 -0
- data/spec/rubocop/cop/cop_spec.rb +114 -0
- data/spec/rubocop/cop/corrector_spec.rb +59 -0
- 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/assignment_in_condition_spec.rb +107 -0
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +411 -0
- data/spec/rubocop/cop/lint/condition_position_spec.rb +49 -0
- data/spec/rubocop/cop/lint/debugger_spec.rb +39 -0
- data/spec/rubocop/cop/lint/else_layout_spec.rb +65 -0
- data/spec/rubocop/cop/lint/empty_ensure_spec.rb +27 -0
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +136 -0
- data/spec/rubocop/cop/lint/end_in_method_spec.rb +29 -0
- data/spec/rubocop/cop/lint/ensure_return_spec.rb +39 -0
- data/spec/rubocop/cop/lint/eval_spec.rb +35 -0
- data/spec/rubocop/cop/lint/handle_exceptions_spec.rb +30 -0
- data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +33 -0
- data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +63 -0
- data/spec/rubocop/cop/lint/loop_spec.rb +27 -0
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +57 -0
- data/spec/rubocop/cop/lint/require_parentheses_spec.rb +82 -0
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +131 -0
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +237 -0
- data/spec/rubocop/cop/lint/syntax_spec.rb +34 -0
- data/spec/rubocop/cop/lint/unreachable_code_spec.rb +63 -0
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +1570 -0
- data/spec/rubocop/cop/lint/useless_comparison_spec.rb +30 -0
- data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +48 -0
- data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +149 -0
- data/spec/rubocop/cop/lint/void_spec.rb +57 -0
- data/spec/rubocop/cop/offence_spec.rb +133 -0
- data/spec/rubocop/cop/rails/default_scope_spec.rb +37 -0
- data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +13 -0
- data/spec/rubocop/cop/rails/output_spec.rb +41 -0
- data/spec/rubocop/cop/rails/read_attribute_spec.rb +13 -0
- data/spec/rubocop/cop/rails/validation_spec.rb +21 -0
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +361 -0
- data/spec/rubocop/cop/style/accessor_method_name_spec.rb +81 -0
- data/spec/rubocop/cop/style/alias_spec.rb +59 -0
- data/spec/rubocop/cop/style/align_array_spec.rb +75 -0
- data/spec/rubocop/cop/style/align_hash_spec.rb +310 -0
- data/spec/rubocop/cop/style/align_parameters_spec.rb +222 -0
- data/spec/rubocop/cop/style/and_or_spec.rb +57 -0
- data/spec/rubocop/cop/style/ascii_comments_spec.rb +22 -0
- data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +36 -0
- data/spec/rubocop/cop/style/attr_spec.rb +19 -0
- data/spec/rubocop/cop/style/begin_block_spec.rb +13 -0
- data/spec/rubocop/cop/style/block_comments_spec.rb +21 -0
- data/spec/rubocop/cop/style/block_nesting_spec.rb +156 -0
- data/spec/rubocop/cop/style/blocks_spec.rb +99 -0
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +284 -0
- data/spec/rubocop/cop/style/case_equality_spec.rb +12 -0
- data/spec/rubocop/cop/style/case_indentation_spec.rb +289 -0
- data/spec/rubocop/cop/style/character_literal_spec.rb +37 -0
- data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +40 -0
- data/spec/rubocop/cop/style/class_length_spec.rb +131 -0
- data/spec/rubocop/cop/style/class_methods_spec.rb +45 -0
- data/spec/rubocop/cop/style/class_vars_spec.rb +19 -0
- data/spec/rubocop/cop/style/collection_methods_spec.rb +48 -0
- data/spec/rubocop/cop/style/colon_method_call_spec.rb +60 -0
- data/spec/rubocop/cop/style/comment_annotation_spec.rb +86 -0
- data/spec/rubocop/cop/style/constant_name_spec.rb +65 -0
- data/spec/rubocop/cop/style/cyclomatic_complexity_spec.rb +204 -0
- data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +39 -0
- data/spec/rubocop/cop/style/documentation_spec.rb +123 -0
- data/spec/rubocop/cop/style/dot_position_spec.rb +94 -0
- data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +127 -0
- data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +56 -0
- data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +131 -0
- data/spec/rubocop/cop/style/empty_lines_spec.rb +40 -0
- data/spec/rubocop/cop/style/empty_literal_spec.rb +100 -0
- data/spec/rubocop/cop/style/encoding_spec.rb +56 -0
- data/spec/rubocop/cop/style/end_block_spec.rb +13 -0
- data/spec/rubocop/cop/style/end_of_line_spec.rb +47 -0
- data/spec/rubocop/cop/style/even_odd_spec.rb +75 -0
- data/spec/rubocop/cop/style/favor_join_spec.rb +31 -0
- data/spec/rubocop/cop/style/favor_sprintf_spec.rb +47 -0
- data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +76 -0
- data/spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb +41 -0
- data/spec/rubocop/cop/style/final_newline_spec.rb +30 -0
- data/spec/rubocop/cop/style/flip_flop_spec.rb +23 -0
- data/spec/rubocop/cop/style/for_spec.rb +105 -0
- data/spec/rubocop/cop/style/global_vars_spec.rb +34 -0
- data/spec/rubocop/cop/style/hash_methods_spec.rb +45 -0
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +131 -0
- data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +128 -0
- data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +19 -0
- data/spec/rubocop/cop/style/indentation_consistency_spec.rb +490 -0
- data/spec/rubocop/cop/style/indentation_width_spec.rb +470 -0
- data/spec/rubocop/cop/style/lambda_call_spec.rb +65 -0
- data/spec/rubocop/cop/style/lambda_spec.rb +41 -0
- data/spec/rubocop/cop/style/leading_comment_space_spec.rb +64 -0
- data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +34 -0
- data/spec/rubocop/cop/style/line_length_spec.rb +20 -0
- data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +59 -0
- data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +60 -0
- data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +106 -0
- data/spec/rubocop/cop/style/method_length_spec.rb +147 -0
- data/spec/rubocop/cop/style/method_name_spec.rb +125 -0
- data/spec/rubocop/cop/style/module_function_spec.rb +24 -0
- data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +78 -0
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +107 -0
- data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +18 -0
- data/spec/rubocop/cop/style/nested_ternary_operator_spec.rb +21 -0
- data/spec/rubocop/cop/style/nil_comparison_spec.rb +30 -0
- data/spec/rubocop/cop/style/not_spec.rb +22 -0
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +64 -0
- data/spec/rubocop/cop/style/one_line_conditional_spec.rb +13 -0
- data/spec/rubocop/cop/style/op_method_spec.rb +74 -0
- data/spec/rubocop/cop/style/parameter_lists_spec.rb +44 -0
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +122 -0
- data/spec/rubocop/cop/style/perl_backrefs_spec.rb +17 -0
- data/spec/rubocop/cop/style/predicate_name_spec.rb +25 -0
- data/spec/rubocop/cop/style/proc_spec.rb +27 -0
- data/spec/rubocop/cop/style/raise_args_spec.rb +82 -0
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +57 -0
- data/spec/rubocop/cop/style/redundant_exception_spec.rb +27 -0
- data/spec/rubocop/cop/style/redundant_return_spec.rb +171 -0
- data/spec/rubocop/cop/style/redundant_self_spec.rb +142 -0
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +83 -0
- data/spec/rubocop/cop/style/rescue_modifier_spec.rb +116 -0
- data/spec/rubocop/cop/style/semicolon_spec.rb +100 -0
- data/spec/rubocop/cop/style/signal_exception_spec.rb +266 -0
- data/spec/rubocop/cop/style/single_line_block_params_spec.rb +68 -0
- data/spec/rubocop/cop/style/single_line_methods_spec.rb +52 -0
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +38 -0
- data/spec/rubocop/cop/style/space_after_comma_spec.rb +30 -0
- data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +84 -0
- data/spec/rubocop/cop/style/space_after_method_name_spec.rb +70 -0
- data/spec/rubocop/cop/style/space_after_not_spec.rb +22 -0
- data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +23 -0
- data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +283 -0
- data/spec/rubocop/cop/style/space_around_equals_in_parameter_default_spec.rb +33 -0
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +325 -0
- data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +70 -0
- data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +52 -0
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +138 -0
- data/spec/rubocop/cop/style/space_inside_parens_spec.rb +34 -0
- data/spec/rubocop/cop/style/special_global_vars_spec.rb +56 -0
- data/spec/rubocop/cop/style/string_literals_spec.rb +212 -0
- data/spec/rubocop/cop/style/symbol_array_spec.rb +37 -0
- data/spec/rubocop/cop/style/tab_spec.rb +17 -0
- data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +43 -0
- data/spec/rubocop/cop/style/trailing_comma_spec.rb +230 -0
- data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +30 -0
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +415 -0
- data/spec/rubocop/cop/style/unless_else_spec.rb +25 -0
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +47 -0
- data/spec/rubocop/cop/style/variable_name_spec.rb +107 -0
- data/spec/rubocop/cop/style/when_then_spec.rb +41 -0
- data/spec/rubocop/cop/style/while_until_do_spec.rb +53 -0
- data/spec/rubocop/cop/style/while_until_modifier_spec.rb +75 -0
- data/spec/rubocop/cop/style/word_array_spec.rb +97 -0
- data/spec/rubocop/cop/team_spec.rb +156 -0
- data/spec/rubocop/cop/util_spec.rb +49 -0
- data/spec/rubocop/cop/variable_inspector/assignment_spec.rb +213 -0
- data/spec/rubocop/cop/variable_inspector/locatable_spec.rb +734 -0
- data/spec/rubocop/cop/variable_inspector/scope_spec.rb +184 -0
- data/spec/rubocop/cop/variable_inspector/variable_spec.rb +73 -0
- data/spec/rubocop/cop/variable_inspector/variable_table_spec.rb +269 -0
- data/spec/rubocop/cop/variable_inspector_spec.rb +29 -0
- data/spec/rubocop/file_inspector_spec.rb +78 -0
- data/spec/rubocop/formatter/base_formatter_spec.rb +191 -0
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +114 -0
- data/spec/rubocop/formatter/colorizable_spec.rb +107 -0
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +50 -0
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +62 -0
- data/spec/rubocop/formatter/file_list_formatter_spec.rb +33 -0
- data/spec/rubocop/formatter/formatter_set_spec.rb +132 -0
- data/spec/rubocop/formatter/json_formatter_spec.rb +148 -0
- data/spec/rubocop/formatter/offence_count_formatter_spec.rb +52 -0
- data/spec/rubocop/formatter/progress_formatter_spec.rb +182 -0
- data/spec/rubocop/formatter/simple_text_formatter_spec.rb +123 -0
- data/spec/rubocop/options_spec.rb +145 -0
- data/spec/rubocop/path_util_spec.rb +42 -0
- data/spec/rubocop/processed_source_spec.rb +114 -0
- data/spec/rubocop/source_parser_spec.rb +139 -0
- data/spec/rubocop/target_finder_spec.rb +180 -0
- data/spec/rubocop/token_spec.rb +25 -0
- data/spec/spec_helper.rb +136 -0
- data/spec/support/ast_helper.rb +15 -0
- data/spec/support/file_helper.rb +21 -0
- data/spec/support/isolated_environment.rb +34 -0
- data/spec/support/mri_syntax_checker.rb +73 -0
- data/spec/support/shared_context.rb +22 -0
- data/spec/support/shared_examples.rb +33 -0
- data/spec/support/statement_modifier_helper.rb +41 -0
- metadata +511 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'stringio'
|
|
5
|
+
|
|
6
|
+
module Rubocop
|
|
7
|
+
describe Formatter::ProgressFormatter do
|
|
8
|
+
subject(:formatter) { described_class.new(output) }
|
|
9
|
+
let(:output) { StringIO.new }
|
|
10
|
+
|
|
11
|
+
let(:files) do
|
|
12
|
+
%w(lib/rubocop.rb spec/spec_helper.rb bin/rubocop).map do |path|
|
|
13
|
+
File.expand_path(path)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe '#file_finished' do
|
|
18
|
+
before do
|
|
19
|
+
formatter.started(files)
|
|
20
|
+
formatter.file_started(files.first, {})
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
shared_examples 'calls #report_file_as_mark' do
|
|
24
|
+
it 'calls #report_as_with_mark' do
|
|
25
|
+
expect(formatter).to receive(:report_file_as_mark)
|
|
26
|
+
formatter.file_finished(files.first, offences)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context 'when no offences are detected' do
|
|
31
|
+
let(:offences) { [] }
|
|
32
|
+
include_examples 'calls #report_file_as_mark'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context 'when any offences are detected' do
|
|
36
|
+
let(:offences) { [double('offence').as_null_object] }
|
|
37
|
+
include_examples 'calls #report_file_as_mark'
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe '#report_file_as_mark' do
|
|
42
|
+
before do
|
|
43
|
+
formatter.report_file_as_mark(files.first, offences)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def offence_with_severity(severity)
|
|
47
|
+
source_buffer = Parser::Source::Buffer.new('test', 1)
|
|
48
|
+
source_buffer.source = "a\n"
|
|
49
|
+
Cop::Offence.new(severity,
|
|
50
|
+
Parser::Source::Range.new(source_buffer, 0, 1),
|
|
51
|
+
'message',
|
|
52
|
+
'CopName')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context 'when no offences are detected' do
|
|
56
|
+
let(:offences) { [] }
|
|
57
|
+
|
|
58
|
+
it 'prints "."' do
|
|
59
|
+
expect(output.string).to eq('.')
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context 'when a refactor severity offence is detected' do
|
|
64
|
+
let(:offences) { [offence_with_severity(:refactor)] }
|
|
65
|
+
|
|
66
|
+
it 'prints "R"' do
|
|
67
|
+
expect(output.string).to eq('R')
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context 'when a refactor convention offence is detected' do
|
|
72
|
+
let(:offences) { [offence_with_severity(:convention)] }
|
|
73
|
+
|
|
74
|
+
it 'prints "C"' do
|
|
75
|
+
expect(output.string).to eq('C')
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
context 'when different severity offences are detected' do
|
|
80
|
+
let(:offences) do
|
|
81
|
+
[
|
|
82
|
+
offence_with_severity(:refactor),
|
|
83
|
+
offence_with_severity(:error)
|
|
84
|
+
]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'prints highest level mark' do
|
|
88
|
+
expect(output.string).to eq('E')
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
describe '#finished' do
|
|
94
|
+
before do
|
|
95
|
+
formatter.started(files)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
context 'when any offences are detected' do
|
|
99
|
+
before do
|
|
100
|
+
source_buffer = Parser::Source::Buffer.new('test', 1)
|
|
101
|
+
source = 9.times.map do |index|
|
|
102
|
+
"This is line #{index + 1}."
|
|
103
|
+
end
|
|
104
|
+
source_buffer.source = source.join("\n")
|
|
105
|
+
line_length = source[0].length + "\n".length
|
|
106
|
+
|
|
107
|
+
formatter.file_started(files[0], {})
|
|
108
|
+
formatter.file_finished(files[0], [
|
|
109
|
+
Cop::Offence.new(
|
|
110
|
+
:convention,
|
|
111
|
+
Parser::Source::Range.new(source_buffer,
|
|
112
|
+
line_length + 2,
|
|
113
|
+
line_length + 3),
|
|
114
|
+
'foo',
|
|
115
|
+
'Cop'
|
|
116
|
+
)
|
|
117
|
+
])
|
|
118
|
+
|
|
119
|
+
formatter.file_started(files[1], {})
|
|
120
|
+
formatter.file_finished(files[1], [
|
|
121
|
+
])
|
|
122
|
+
|
|
123
|
+
formatter.file_started(files[2], {})
|
|
124
|
+
formatter.file_finished(files[2], [
|
|
125
|
+
Cop::Offence.new(
|
|
126
|
+
:error,
|
|
127
|
+
Parser::Source::Range.new(source_buffer,
|
|
128
|
+
4 * line_length + 1,
|
|
129
|
+
4 * line_length + 2),
|
|
130
|
+
'bar',
|
|
131
|
+
'Cop'
|
|
132
|
+
),
|
|
133
|
+
Cop::Offence.new(
|
|
134
|
+
:convention,
|
|
135
|
+
Parser::Source::Range.new(source_buffer,
|
|
136
|
+
5 * line_length,
|
|
137
|
+
5 * line_length + 1),
|
|
138
|
+
'foo',
|
|
139
|
+
'Cop'
|
|
140
|
+
)
|
|
141
|
+
])
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it 'reports all detected offences for all failed files' do
|
|
145
|
+
formatter.finished(files)
|
|
146
|
+
expect(output.string).to include([
|
|
147
|
+
'Offences:',
|
|
148
|
+
'',
|
|
149
|
+
'lib/rubocop.rb:2:3: C: foo',
|
|
150
|
+
'This is line 2.',
|
|
151
|
+
' ^',
|
|
152
|
+
'bin/rubocop:5:2: E: bar',
|
|
153
|
+
'This is line 5.',
|
|
154
|
+
' ^',
|
|
155
|
+
'bin/rubocop:6:1: C: foo',
|
|
156
|
+
'This is line 6.',
|
|
157
|
+
'^'
|
|
158
|
+
].join("\n"))
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
context 'when no offences are detected' do
|
|
163
|
+
before do
|
|
164
|
+
files.each do |file|
|
|
165
|
+
formatter.file_started(file, {})
|
|
166
|
+
formatter.file_finished(file, [])
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it 'does not report offences' do
|
|
171
|
+
formatter.finished(files)
|
|
172
|
+
expect(output.string).not_to include('Offences:')
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it 'calls #report_summary' do
|
|
177
|
+
expect(formatter).to receive(:report_summary)
|
|
178
|
+
formatter.finished(files)
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require 'stringio'
|
|
5
|
+
require 'tempfile'
|
|
6
|
+
|
|
7
|
+
module Rubocop
|
|
8
|
+
module Formatter
|
|
9
|
+
describe SimpleTextFormatter do
|
|
10
|
+
subject(:formatter) { described_class.new(output) }
|
|
11
|
+
let(:output) { StringIO.new }
|
|
12
|
+
|
|
13
|
+
describe '#report_file' do
|
|
14
|
+
before do
|
|
15
|
+
formatter.report_file(file, [offence])
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
let(:file) { '/path/to/file' }
|
|
19
|
+
|
|
20
|
+
let(:offence) do
|
|
21
|
+
Cop::Offence.new(:convention, location,
|
|
22
|
+
'This is a message.', 'CopName', corrected)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
let(:location) do
|
|
26
|
+
source_buffer = Parser::Source::Buffer.new('test', 1)
|
|
27
|
+
source_buffer.source = "a\n"
|
|
28
|
+
Parser::Source::Range.new(source_buffer, 0, 1)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
let(:corrected) { false }
|
|
32
|
+
|
|
33
|
+
context 'the file is under the current working directory' do
|
|
34
|
+
let(:file) { File.expand_path('spec/spec_helper.rb') }
|
|
35
|
+
|
|
36
|
+
it 'prints as relative path' do
|
|
37
|
+
expect(output.string).to include('== spec/spec_helper.rb ==')
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context 'the file is outside of the current working directory' do
|
|
42
|
+
let(:file) do
|
|
43
|
+
tempfile = Tempfile.new('')
|
|
44
|
+
tempfile.close
|
|
45
|
+
File.expand_path(tempfile.path)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'prints as absolute path' do
|
|
49
|
+
expect(output.string).to include("== #{file} ==")
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context 'when the offence is not corrected' do
|
|
54
|
+
let(:corrected) { false }
|
|
55
|
+
|
|
56
|
+
it 'prints message as-is' do
|
|
57
|
+
expect(output.string)
|
|
58
|
+
.to include(': This is a message.')
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context 'when the offence is automatically corrected' do
|
|
63
|
+
let(:corrected) { true }
|
|
64
|
+
|
|
65
|
+
it 'prints [Corrected] along with message' do
|
|
66
|
+
expect(output.string)
|
|
67
|
+
.to include(': [Corrected] This is a message.')
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe '#report_summary' do
|
|
73
|
+
context 'when no files inspected' do
|
|
74
|
+
it 'handles pluralization correctly' do
|
|
75
|
+
formatter.report_summary(0, 0, 0)
|
|
76
|
+
expect(output.string).to eq(
|
|
77
|
+
"\n0 files inspected, no offences detected\n")
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context 'when a file inspected and no offences detected' do
|
|
82
|
+
it 'handles pluralization correctly' do
|
|
83
|
+
formatter.report_summary(1, 0, 0)
|
|
84
|
+
expect(output.string).to eq(
|
|
85
|
+
"\n1 file inspected, no offences detected\n")
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context 'when a offence detected' do
|
|
90
|
+
it 'handles pluralization correctly' do
|
|
91
|
+
formatter.report_summary(1, 1, 0)
|
|
92
|
+
expect(output.string).to eq(
|
|
93
|
+
"\n1 file inspected, 1 offence detected\n")
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
context 'when 2 offences detected' do
|
|
98
|
+
it 'handles pluralization correctly' do
|
|
99
|
+
formatter.report_summary(2, 2, 0)
|
|
100
|
+
expect(output.string).to eq(
|
|
101
|
+
"\n2 files inspected, 2 offences detected\n")
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
context 'when an offence is corrected' do
|
|
106
|
+
it 'prints about correction' do
|
|
107
|
+
formatter.report_summary(1, 1, 1)
|
|
108
|
+
expect(output.string).to eq(
|
|
109
|
+
"\n1 file inspected, 1 offence detected, 1 offence corrected\n")
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
context 'when 2 offences are corrected' do
|
|
114
|
+
it 'handles pluralization correctly' do
|
|
115
|
+
formatter.report_summary(1, 1, 2)
|
|
116
|
+
expect(output.string).to eq(
|
|
117
|
+
"\n1 file inspected, 1 offence detected, 2 offences corrected\n")
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Rubocop::Options, :isolated_environment do
|
|
6
|
+
include FileHelper
|
|
7
|
+
|
|
8
|
+
subject(:options) { described_class.new }
|
|
9
|
+
|
|
10
|
+
before(:each) do
|
|
11
|
+
$stdout = StringIO.new
|
|
12
|
+
$stderr = StringIO.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
after(:each) do
|
|
16
|
+
$stdout = STDOUT
|
|
17
|
+
$stderr = STDERR
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def abs(path)
|
|
21
|
+
File.expand_path(path)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe 'option' do
|
|
25
|
+
describe '-h/--help' do
|
|
26
|
+
it 'exits cleanly' do
|
|
27
|
+
expect { options.parse ['-h'] }.to exit_with_code(0)
|
|
28
|
+
expect { options.parse ['--help'] }.to exit_with_code(0)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'shows help text' do
|
|
32
|
+
begin
|
|
33
|
+
options.parse(['--help'])
|
|
34
|
+
rescue SystemExit # rubocop:disable HandleExceptions
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
expected_help = <<-END
|
|
38
|
+
Usage: rubocop [options] [file1, file2, ...]
|
|
39
|
+
--only COP Run just one cop.
|
|
40
|
+
-c, --config FILE Specify configuration file.
|
|
41
|
+
--auto-gen-config Generate a configuration file acting as a
|
|
42
|
+
TODO list.
|
|
43
|
+
-f, --format FORMATTER Choose an output formatter. This option
|
|
44
|
+
can be specified multiple times to enable
|
|
45
|
+
multiple formatters at the same time.
|
|
46
|
+
[p]rogress (default)
|
|
47
|
+
[s]imple
|
|
48
|
+
[c]lang
|
|
49
|
+
[e]macs
|
|
50
|
+
[j]son
|
|
51
|
+
[f]iles
|
|
52
|
+
[o]ffences
|
|
53
|
+
custom formatter class name
|
|
54
|
+
-o, --out FILE Write output to a file instead of STDOUT.
|
|
55
|
+
This option applies to the previously
|
|
56
|
+
specified --format, or the default format
|
|
57
|
+
if no format is specified.
|
|
58
|
+
-r, --require FILE Require Ruby file.
|
|
59
|
+
--show-cops [cop1,cop2,...] Shows the given cops, or all cops by
|
|
60
|
+
default, and their configurations for the
|
|
61
|
+
current directory.
|
|
62
|
+
-d, --debug Display debug info.
|
|
63
|
+
-D, --display-cop-names Display cop names in offence messages.
|
|
64
|
+
-R, --rails Run extra Rails cops.
|
|
65
|
+
-l, --lint Run only lint cops.
|
|
66
|
+
-a, --auto-correct Auto-correct offences.
|
|
67
|
+
-n, --no-color Disable color output.
|
|
68
|
+
-v, --version Display version.
|
|
69
|
+
-V, --verbose-version Display verbose version.
|
|
70
|
+
END
|
|
71
|
+
|
|
72
|
+
expect($stdout.string).to eq(expected_help)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'lists all builtin formatters' do
|
|
76
|
+
begin
|
|
77
|
+
options.parse(['--help'])
|
|
78
|
+
rescue SystemExit # rubocop:disable HandleExceptions
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
option_sections = $stdout.string.lines.slice_before(/^\s*-/)
|
|
82
|
+
|
|
83
|
+
format_section = option_sections.find do |lines|
|
|
84
|
+
lines.first =~ /^\s*-f/
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
formatter_keys = format_section.reduce([]) do |keys, line|
|
|
88
|
+
match = line.match(/^[ ]{39}(\[[a-z\]]+)/)
|
|
89
|
+
next keys unless match
|
|
90
|
+
keys << match.captures.first.gsub(/\[|\]/, '')
|
|
91
|
+
end.sort
|
|
92
|
+
|
|
93
|
+
expected_formatter_keys =
|
|
94
|
+
Rubocop::Formatter::FormatterSet::BUILTIN_FORMATTERS_FOR_KEYS
|
|
95
|
+
.keys.sort
|
|
96
|
+
|
|
97
|
+
expect(formatter_keys).to eq(expected_formatter_keys)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe '--only' do
|
|
102
|
+
it 'exits with error if an incorrect cop name is passed' do
|
|
103
|
+
expect { options.parse(%w(--only 123)) }
|
|
104
|
+
.to raise_error(ArgumentError, /Unrecognized cop name: 123./)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe '--require' do
|
|
109
|
+
let(:required_file_path) { './path/to/required_file.rb' }
|
|
110
|
+
|
|
111
|
+
before do
|
|
112
|
+
create_file('example.rb', '# encoding: utf-8')
|
|
113
|
+
|
|
114
|
+
create_file(required_file_path, [
|
|
115
|
+
'# encoding: utf-8',
|
|
116
|
+
"puts 'Hello from required file!'"
|
|
117
|
+
])
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'requires the passed path' do
|
|
121
|
+
options.parse(['--require', required_file_path, 'example.rb'])
|
|
122
|
+
expect($stdout.string).to start_with('Hello from required file!')
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
unless Rubocop::Version::STRING.start_with?('0')
|
|
128
|
+
describe '-e/--emacs option' do
|
|
129
|
+
it 'is dropped in RuboCop 1.0.0' do
|
|
130
|
+
# This spec can be removed once the option is dropped.
|
|
131
|
+
expect { options.parse(['--emacs']) }
|
|
132
|
+
.to raise_error(OptionParser::InvalidOption)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
describe '-s/--silent option' do
|
|
137
|
+
it 'raises error in RuboCop 1.0.0' do
|
|
138
|
+
# This spec can be removed
|
|
139
|
+
# once Options#ignore_dropped_options is removed.
|
|
140
|
+
expect { options.parse(['--silent']) }
|
|
141
|
+
.to raise_error(OptionParser::InvalidOption)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|