tailor 1.1.5 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +23 -23
- data/History.rdoc +14 -0
- data/README.rdoc +42 -2
- data/Rakefile +7 -0
- data/features/continuous_integration.feature +28 -0
- data/lib/tailor/cli.rb +17 -4
- data/lib/tailor/cli/options.rb +6 -0
- data/lib/tailor/configuration.rb +19 -3
- data/lib/tailor/configuration/style.rb +7 -0
- data/lib/tailor/critic.rb +4 -2
- data/lib/tailor/formatters/yaml.rb +51 -0
- data/lib/tailor/lexer.rb +6 -4
- data/lib/tailor/rake_task.rb +44 -6
- data/lib/tailor/reporter.rb +9 -3
- data/lib/tailor/rulers/allow_invalid_ruby_ruler.rb +3 -3
- data/lib/tailor/rulers/indentation_spaces_ruler.rb +24 -6
- data/lib/tailor/rulers/indentation_spaces_ruler/indentation_manager.rb +2 -2
- data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +9 -6
- data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +1 -1
- data/lib/tailor/version.rb +1 -1
- data/spec/functional/configuration_spec.rb +37 -0
- data/spec/functional/horizontal_spacing/braces_spec.rb +113 -113
- data/spec/functional/horizontal_spacing/brackets_spec.rb +39 -39
- data/spec/functional/horizontal_spacing/comma_spacing_spec.rb +27 -27
- data/spec/functional/horizontal_spacing/hard_tabs_spec.rb +42 -42
- data/spec/functional/horizontal_spacing/long_lines_spec.rb +16 -16
- data/spec/functional/horizontal_spacing/parens_spec.rb +48 -48
- data/spec/functional/horizontal_spacing/trailing_whitespace_spec.rb +23 -23
- data/spec/functional/horizontal_spacing_spec.rb +11 -11
- data/spec/functional/indentation_spacing/bad_indentation_spec.rb +212 -215
- data/spec/functional/indentation_spacing_spec.rb +8 -7
- data/spec/functional/naming/camel_case_methods_spec.rb +16 -16
- data/spec/functional/naming/screaming_snake_case_classes_spec.rb +30 -30
- data/spec/functional/naming_spec.rb +5 -4
- data/spec/functional/rake_task_spec.rb +56 -10
- data/spec/functional/vertical_spacing/class_length_spec.rb +16 -16
- data/spec/functional/vertical_spacing/method_length_spec.rb +16 -16
- data/spec/functional/vertical_spacing_spec.rb +5 -4
- data/spec/support/bad_indentation_cases.rb +35 -35
- data/spec/support/good_indentation_cases.rb +108 -108
- data/spec/support/horizontal_spacing_cases.rb +37 -37
- data/spec/support/naming_cases.rb +6 -6
- data/spec/support/vertical_spacing_cases.rb +4 -4
- data/spec/unit/tailor/cli_spec.rb +34 -12
- data/spec/unit/tailor/configuration_spec.rb +18 -0
- data/spec/unit/tailor/formatters/yaml_spec.rb +75 -0
- data/spec/unit/tailor/reporter_spec.rb +23 -4
- data/spec/unit/tailor/rulers/indentation_spaces_ruler_spec.rb +12 -10
- data/spec/unit/tailor/version_spec.rb +3 -2
- metadata +35 -63
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f695173027042af6a56e7cada6e1b408a9b5ce5a
|
4
|
+
data.tar.gz: 516aaac032622983b31d33148f14240b1be63d1b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98bd7768f8d97ffdeead10bbff2010c25236873499eb2eb62f0ecf6a94b1c0b921ad3e088e722752cbbd7c965c6b54b05e23bb5e01e1cb3bf9eea60eb30efecc
|
7
|
+
data.tar.gz: da3a3b39e51d1542cc86d975b209352d883e3b1569300f46f1387b569426cd945393ba0b7aa789ba2785e46efd1e53f69fc6f62772728f24dc96ca55bc6218e9
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,54 +1,54 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tailor (1.
|
4
|
+
tailor (1.2.0)
|
5
5
|
log_switch (>= 0.3.0)
|
6
6
|
term-ansicolor (>= 1.0.5)
|
7
7
|
text-table (>= 1.2.2)
|
8
8
|
|
9
9
|
GEM
|
10
|
-
remote:
|
10
|
+
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
12
|
aruba (0.5.1)
|
13
13
|
childprocess (~> 0.3.6)
|
14
14
|
cucumber (>= 1.1.1)
|
15
15
|
rspec-expectations (>= 2.7.0)
|
16
|
-
builder (3.
|
17
|
-
childprocess (0.3.
|
18
|
-
ffi (~> 1.0, >= 1.0.
|
19
|
-
cucumber (1.2.
|
16
|
+
builder (3.2.0)
|
17
|
+
childprocess (0.3.9)
|
18
|
+
ffi (~> 1.0, >= 1.0.11)
|
19
|
+
cucumber (1.2.2)
|
20
20
|
builder (>= 2.1.2)
|
21
21
|
diff-lcs (>= 1.1.3)
|
22
|
-
gherkin (~> 2.11.
|
23
|
-
|
24
|
-
diff-lcs (1.1
|
22
|
+
gherkin (~> 2.11.6)
|
23
|
+
multi_json (~> 1.3)
|
24
|
+
diff-lcs (1.2.1)
|
25
25
|
fakefs (0.4.2)
|
26
|
-
ffi (1.
|
27
|
-
ffi (1.
|
26
|
+
ffi (1.4.0)
|
27
|
+
ffi (1.4.0-java)
|
28
28
|
gherkin (2.11.6)
|
29
29
|
json (>= 1.7.6)
|
30
30
|
gherkin (2.11.6-java)
|
31
31
|
json (>= 1.7.6)
|
32
|
-
json (1.7.
|
33
|
-
json (1.7.
|
32
|
+
json (1.7.7)
|
33
|
+
json (1.7.7-java)
|
34
34
|
log_switch (0.4.0)
|
35
|
-
multi_json (1.
|
35
|
+
multi_json (1.6.1)
|
36
36
|
rake (10.0.3)
|
37
|
-
rspec (2.
|
38
|
-
rspec-core (~> 2.
|
39
|
-
rspec-expectations (~> 2.
|
40
|
-
rspec-mocks (~> 2.
|
41
|
-
rspec-core (2.
|
42
|
-
rspec-expectations (2.
|
43
|
-
diff-lcs (
|
44
|
-
rspec-mocks (2.
|
37
|
+
rspec (2.13.0)
|
38
|
+
rspec-core (~> 2.13.0)
|
39
|
+
rspec-expectations (~> 2.13.0)
|
40
|
+
rspec-mocks (~> 2.13.0)
|
41
|
+
rspec-core (2.13.0)
|
42
|
+
rspec-expectations (2.13.0)
|
43
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
44
|
+
rspec-mocks (2.13.0)
|
45
45
|
simplecov (0.7.1)
|
46
46
|
multi_json (~> 1.0)
|
47
47
|
simplecov-html (~> 0.7.1)
|
48
48
|
simplecov-html (0.7.1)
|
49
49
|
term-ansicolor (1.0.7)
|
50
50
|
text-table (1.2.2)
|
51
|
-
yard (0.8.
|
51
|
+
yard (0.8.5.2)
|
52
52
|
|
53
53
|
PLATFORMS
|
54
54
|
java
|
data/History.rdoc
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
=== 1.2.0 2013-03-06
|
2
|
+
|
3
|
+
* gh-119[https://github.com/turboladen/tailor/issues/119]
|
4
|
+
* AllowInvalidRubyRuler now uses Gem.ruby to use the ruby that tailor was
|
5
|
+
run with.
|
6
|
+
* gh-130[https://github.com/turboladen/tailor/issues/130]
|
7
|
+
* AllowInvalidRubyRuler now handles file names with spaces in them.
|
8
|
+
* gh-131[https://github.com/turboladen/tailor/issues/131]
|
9
|
+
* Added YAML output formatter. Thanks @leandronsp!
|
10
|
+
* gh-133[https://github.com/turboladen/tailor/issues/133]
|
11
|
+
* Added support for Ruby 2.0.0-p0. ...which is actually just accounting for
|
12
|
+
a {fix to Ripper}[https://bugs.ruby-lang.org/issues/6211] that finally got
|
13
|
+
merged in to a Ruby release.
|
14
|
+
|
1
15
|
=== 1.1.5 2013-01-30
|
2
16
|
|
3
17
|
* gh-127[https://github.com/turboladen/tailor/issues/127]
|
data/README.rdoc
CHANGED
@@ -93,11 +93,16 @@ Check only files ending in .rb under the 'test' directory:
|
|
93
93
|
Check defaults (lib/**/*.rb):
|
94
94
|
|
95
95
|
$ tailor
|
96
|
-
|
96
|
+
|
97
|
+
Printing the results in a output file (if using a formatter that accepts output files, like 'yaml'):
|
98
|
+
|
99
|
+
$ tailor path/to/check --output-file=my-results.yaml
|
100
|
+
$ tailor --output-file=my-results-from-defaults.yaml
|
101
|
+
|
97
102
|
Use defaults via a Rake task (if you have a .tailor file, it'll use those settings):
|
98
103
|
|
99
104
|
require 'tailor/rake_task'
|
100
|
-
|
105
|
+
|
101
106
|
Tailor::RakeTask.new
|
102
107
|
|
103
108
|
==== On style...
|
@@ -270,6 +275,21 @@ level to +:off+:
|
|
270
275
|
end
|
271
276
|
|
272
277
|
|
278
|
+
===== Formatters
|
279
|
+
|
280
|
+
By default Tailor uses the text formatter, printing the results on console. Tailor
|
281
|
+
also provides a YAML formatter, that accepts an output file if using the option
|
282
|
+
--output-file=*.yaml
|
283
|
+
|
284
|
+
# .tailor
|
285
|
+
Tailor.config do |config|
|
286
|
+
config.formatters 'text', 'yaml'
|
287
|
+
|
288
|
+
# just one
|
289
|
+
config.formatters 'text'
|
290
|
+
end
|
291
|
+
|
292
|
+
|
273
293
|
=== Define A Custom Ruler
|
274
294
|
|
275
295
|
While tailor provides a number of Rulers for checking style, it also provides a
|
@@ -343,10 +363,30 @@ add infomation about your ruler to your config file. If you created a Ruler:
|
|
343
363
|
|
344
364
|
Next time you run tailor, your Ruler will get initialized and used.
|
345
365
|
|
366
|
+
=== Using the lib
|
367
|
+
|
368
|
+
Sometimes you could use tailor as a lib, getting the results as a hash
|
369
|
+
and manipulate them according your domain.
|
370
|
+
|
371
|
+
require 'tailor/cli'
|
372
|
+
|
373
|
+
# only results from a specific path
|
374
|
+
tailor = Tailor::CLI.new %w(app/controllers)
|
375
|
+
tailor.result # result should be a hash {"filename" => [problems]}
|
376
|
+
|
377
|
+
# using other file config (hiding path, it'll use from default config)
|
378
|
+
Tailor::CLI.new %w(--config-file=.other-config)
|
379
|
+
Tailor::CLI.new [] # uses file set from .tailor file config
|
380
|
+
|
381
|
+
# printing the results in a output file
|
382
|
+
tailor = Tailor::CLI.new %w(--output-file=results.yaml)
|
383
|
+
tailor.execute!
|
384
|
+
|
346
385
|
== REQUIREMENTS:
|
347
386
|
|
348
387
|
* Rubies (tested)
|
349
388
|
* 1.9.3
|
389
|
+
* 2.0.0
|
350
390
|
* Gems
|
351
391
|
* log_switch
|
352
392
|
* term-ansicolor
|
data/Rakefile
CHANGED
@@ -3,6 +3,13 @@ require 'cucumber'
|
|
3
3
|
require 'cucumber/rake/task'
|
4
4
|
require 'rspec/core/rake_task'
|
5
5
|
require 'yard'
|
6
|
+
require_relative 'lib/tailor/rake_task'
|
7
|
+
|
8
|
+
|
9
|
+
Tailor::RakeTask.new do |task|
|
10
|
+
task.formatters = %w[yaml]
|
11
|
+
task.tailor_opts = %w[--output-file=output.yml]
|
12
|
+
end
|
6
13
|
|
7
14
|
|
8
15
|
#------------------------------------------------------------------------------
|
@@ -92,6 +92,34 @@ Feature: Continuous Integration
|
|
92
92
|
And the output should not match /SystemExit/
|
93
93
|
And the exit status should be 1
|
94
94
|
|
95
|
+
Scenario: Rake task, override config file
|
96
|
+
Given a file named "errors.rb" with:
|
97
|
+
"""
|
98
|
+
puts 'hi'
|
99
|
+
|
100
|
+
|
101
|
+
"""
|
102
|
+
And my configuration file ".tailor" looks like:
|
103
|
+
"""
|
104
|
+
Tailor.config do |config|
|
105
|
+
config.file_set 'errors.rb' do |style|
|
106
|
+
style.trailing_newlines 0, level: :error
|
107
|
+
end
|
108
|
+
end
|
109
|
+
"""
|
110
|
+
And a file named "Rakefile" with:
|
111
|
+
"""
|
112
|
+
require 'tailor/rake_task'
|
113
|
+
|
114
|
+
Tailor::RakeTask.new do |task|
|
115
|
+
task.file_set 'errors.rb' do |style|
|
116
|
+
style.trailing_newlines 2, level: :error
|
117
|
+
end
|
118
|
+
end
|
119
|
+
"""
|
120
|
+
When I successfully run `rake tailor`
|
121
|
+
Then the output should match /errors\.rb\s+|\s+0/
|
122
|
+
|
95
123
|
Scenario: Rake task, missing config file
|
96
124
|
Given a file named "errors.rb" with:
|
97
125
|
"""
|
data/lib/tailor/cli.rb
CHANGED
@@ -4,6 +4,7 @@ require_relative 'cli/options'
|
|
4
4
|
require_relative 'logger'
|
5
5
|
require_relative 'reporter'
|
6
6
|
|
7
|
+
|
7
8
|
class Tailor
|
8
9
|
|
9
10
|
# The Command-Line Interface worker. Execution from the command line
|
@@ -11,16 +12,19 @@ class Tailor
|
|
11
12
|
class CLI
|
12
13
|
include LogSwitch::Mixin
|
13
14
|
|
15
|
+
# @return [Tailor::Configuration]
|
16
|
+
attr_reader :configuration
|
17
|
+
|
14
18
|
# The main method of execution from the command line.
|
19
|
+
#
|
20
|
+
# @param [Array] args Arguments from the command-line.
|
15
21
|
def self.run(args)
|
16
22
|
new(args).execute!
|
17
23
|
end
|
18
24
|
|
19
25
|
# @param [Array] args Arguments from the command-line.
|
20
26
|
def initialize(args)
|
21
|
-
Tailor::Logger.log = false
|
22
27
|
options = Options.parse!(args)
|
23
|
-
|
24
28
|
@configuration = Configuration.new(args, options)
|
25
29
|
@configuration.load!
|
26
30
|
|
@@ -43,9 +47,18 @@ class Tailor
|
|
43
47
|
@reporter.file_report(problems_for_file, label)
|
44
48
|
end
|
45
49
|
|
46
|
-
@reporter.summary_report(@critic.problems)
|
47
|
-
|
50
|
+
@reporter.summary_report(@critic.problems, output_file: @configuration.output_file)
|
48
51
|
@critic.problem_count(:error) > 0
|
49
52
|
end
|
53
|
+
|
54
|
+
# Critiques all file sets, then returns the problems found as a result.
|
55
|
+
#
|
56
|
+
# @return [Hash{String => Array}] The list of problems, where the keys are
|
57
|
+
# the file names in which the problems were found, and the values are the
|
58
|
+
# respective lists of problems for each file.
|
59
|
+
def result
|
60
|
+
@critic.critique(@configuration.file_sets)
|
61
|
+
@critic.problems
|
62
|
+
end
|
50
63
|
end
|
51
64
|
end
|
data/lib/tailor/cli/options.rb
CHANGED
@@ -14,6 +14,7 @@ class Tailor
|
|
14
14
|
def self.parse!(args)
|
15
15
|
options = OpenStruct.new
|
16
16
|
options.config_file = ''
|
17
|
+
options.output_file = ''
|
17
18
|
options.formatters = []
|
18
19
|
options.show_config = false
|
19
20
|
options.style = {}
|
@@ -33,6 +34,11 @@ class Tailor
|
|
33
34
|
options.config_file = config
|
34
35
|
end
|
35
36
|
|
37
|
+
opt.on('-o', '--output-file FILE',
|
38
|
+
"Print result in a output file if using the proper formatter.") do |output|
|
39
|
+
options.output_file = output
|
40
|
+
end
|
41
|
+
|
36
42
|
opt.on('--create-config', 'Create a new .tailor file') do
|
37
43
|
if create_config
|
38
44
|
msg = "Your new tailor config file was created at "
|
data/lib/tailor/configuration.rb
CHANGED
@@ -28,17 +28,24 @@ class Tailor
|
|
28
28
|
new
|
29
29
|
end
|
30
30
|
|
31
|
+
# @return [Hash]
|
31
32
|
attr_reader :file_sets
|
33
|
+
|
34
|
+
# @return [Array]
|
32
35
|
attr_reader :formatters
|
33
36
|
|
37
|
+
# @return [String]
|
38
|
+
attr_reader :output_file
|
39
|
+
|
34
40
|
# @param [Array] runtime_file_list
|
35
41
|
# @param [OpenStruct] options
|
36
42
|
# @option options [String] config_file
|
37
43
|
# @option options [Array] formatters
|
38
44
|
# @option options [Hash] style
|
39
45
|
def initialize(runtime_file_list=nil, options=nil)
|
40
|
-
@formatters = [
|
46
|
+
@formatters = %w[text]
|
41
47
|
@file_sets = {}
|
48
|
+
@output_file = ''
|
42
49
|
@runtime_file_list = runtime_file_list
|
43
50
|
log "Got runtime file list: #{@runtime_file_list}"
|
44
51
|
|
@@ -65,6 +72,7 @@ class Tailor
|
|
65
72
|
@file_sets = { default: FileSet.new(@runtime_file_list) }
|
66
73
|
end
|
67
74
|
|
75
|
+
get_output_file_from_cli_opts
|
68
76
|
get_formatters_from_cli_opts
|
69
77
|
get_file_sets_from_cli_opts
|
70
78
|
get_style_from_cli_opts
|
@@ -118,7 +126,7 @@ class Tailor
|
|
118
126
|
@file_sets[label].update_file_list(file_set[:file_list])
|
119
127
|
@file_sets[label].update_style(file_set[:style])
|
120
128
|
else
|
121
|
-
log "Creating new label
|
129
|
+
log "Creating new label: #{label}"
|
122
130
|
@file_sets[label] =
|
123
131
|
FileSet.new(file_set[:file_list], file_set[:style])
|
124
132
|
end
|
@@ -162,10 +170,17 @@ class Tailor
|
|
162
170
|
end
|
163
171
|
end
|
164
172
|
|
173
|
+
def get_output_file_from_cli_opts
|
174
|
+
unless @options.nil? || @options.output_file.empty? || @options.output_file.nil?
|
175
|
+
@output_file = @options.output_file
|
176
|
+
log "@output_file is now: '#{@output_file}'"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
165
180
|
def get_formatters_from_cli_opts
|
166
181
|
unless @options.nil? || @options.formatters.empty? || @options.formatters.nil?
|
167
182
|
@formatters = @options.formatters
|
168
|
-
log "@formatters is now #{@formatters}"
|
183
|
+
log "@formatters is now: '#{@formatters}'"
|
169
184
|
end
|
170
185
|
end
|
171
186
|
|
@@ -207,6 +222,7 @@ class Tailor
|
|
207
222
|
table.head = [{ value: 'Configuration', colspan: 2, align: :center }]
|
208
223
|
table.rows << :separator
|
209
224
|
table.rows << ['Formatters', @formatters]
|
225
|
+
table.rows << ['Output File', @output_file]
|
210
226
|
|
211
227
|
@file_sets.each do |label, file_set|
|
212
228
|
table.rows << :separator
|
data/lib/tailor/critic.rb
CHANGED
@@ -10,7 +10,7 @@ class Tailor
|
|
10
10
|
# files. It handles initializing the Ruler objects it needs based on the
|
11
11
|
# configuration given to it.
|
12
12
|
class Critic
|
13
|
-
include
|
13
|
+
include LogSwitch::Mixin
|
14
14
|
include Tailor::Rulers
|
15
15
|
|
16
16
|
# The instance method that starts the process of looking for problems in
|
@@ -41,7 +41,9 @@ class Tailor
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
# @return [Hash]
|
44
|
+
# @return [Hash{String => Array}] The list of problems, where the keys are
|
45
|
+
# the file names in which the problems were found, and the values are the
|
46
|
+
# respective lists of problems for each file.
|
45
47
|
def problems
|
46
48
|
@problems ||= {}
|
47
49
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'yaml'
|
3
|
+
require_relative '../formatter'
|
4
|
+
|
5
|
+
class Tailor
|
6
|
+
module Formatters
|
7
|
+
class Yaml < Tailor::Formatter
|
8
|
+
attr_reader :accepts_output_file
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@accepts_output_file = true
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
# Prints the report on all of the files that just got checked.
|
16
|
+
#
|
17
|
+
# @param [Hash] report Values are filenames; keys are problems for each
|
18
|
+
# of those files.
|
19
|
+
def summary_report(report)
|
20
|
+
build_hash(report).to_yaml
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# @param [Hash] report The list of problems found by Tailor::CLI.
|
26
|
+
# @return [Hash] The Hash of problems to be converted to YAML.
|
27
|
+
def build_hash(report)
|
28
|
+
report.reject! { |_, v| v.empty? }
|
29
|
+
|
30
|
+
report.inject({}) do |result, problem_set|
|
31
|
+
file_name = problem_set.first
|
32
|
+
problems = problem_set.last
|
33
|
+
|
34
|
+
problems.each do |problem|
|
35
|
+
result[file_name] ||= []
|
36
|
+
|
37
|
+
result[file_name] << {
|
38
|
+
type: problem[:type],
|
39
|
+
line: problem[:line],
|
40
|
+
column: problem[:column],
|
41
|
+
message: problem[:message],
|
42
|
+
level: problem[:level]
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
result
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|