cane 1.2.0 → 1.3.0

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.
data/HISTORY.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Cane History
2
2
 
3
+ ## 1.3.0 - 20 April 2012 (c166dfa0)
4
+
5
+ * Remove dependency on tailor. Fewer styles checks are performed, but the three
6
+ remaining are the only ones I've found useful.
7
+
3
8
  ## 1.2.0 - 31 March 2012 (adce51b9)
4
9
 
5
10
  * Gracefully handle files with invalid syntax (#1)
@@ -27,7 +27,6 @@ Gem::Specification.new do |gem|
27
27
  gem.executables << "cane"
28
28
  gem.version = Cane::VERSION
29
29
  gem.has_rdoc = false
30
- gem.add_dependency 'tailor'
31
30
  gem.add_development_dependency 'rspec', '~> 2.0'
32
31
  gem.add_development_dependency 'rake'
33
32
  gem.add_development_dependency 'simplecov'
@@ -1,97 +1,44 @@
1
- require 'tailor'
2
-
3
1
  require 'cane/style_violation'
4
2
 
5
3
  module Cane
6
4
 
7
- # Creates violations for files that do not meet style conventions. This uses
8
- # the `tailor` gem, configured to exclude some of its less reliable checks
9
- # (mostly spacing around punctuation).
5
+ # Creates violations for files that do not meet style conventions. Only
6
+ # highly obvious, probable, and non-controversial checks are performed here.
7
+ # It is not the goal of the tool to provide an extensive style report, but
8
+ # only to prevent studid mistakes.
10
9
  class StyleCheck < Struct.new(:opts)
11
10
  def violations
12
- Dir[opts.fetch(:files)].map do |file_name|
13
- find_violations_in_file(file_name)
11
+ file_list.map do |file_path|
12
+ map_lines(file_path) do |line, line_number|
13
+ violations_for_line(line.chomp).map do |message|
14
+ StyleViolation.new(file_path, line_number + 1, message)
15
+ end
16
+ end
14
17
  end.flatten
15
18
  end
16
19
 
17
20
  protected
18
21
 
19
- def find_violations_in_file(file_name)
20
- source = File.open(file_name, 'r:utf-8')
21
- file_path = Pathname.new(file_name)
22
-
23
- source.each_line.map.with_index do |source_line, line_number|
24
- violations_for_line(file_path, source_line, line_number)
22
+ def violations_for_line(line)
23
+ result = []
24
+ if line.length > measure
25
+ result << "Line is >%i characters (%i)" % [measure, line.length]
25
26
  end
27
+ result << "Line contains trailing whitespace" if line =~ /\s$/
28
+ result << "Line contains hard tabs" if line =~ /\t/
29
+ result
26
30
  end
27
31
 
28
- def violations_for_line(file_path, source_line, line_number)
29
- FileLine.new(source_line, opts).problems.map do |message|
30
- StyleViolation.new(file_path, line_number + 1, message)
31
- end
32
- end
33
- end
34
-
35
- # The `tailor` gem was not designed to be used as a library, so interfacing
36
- # with it is a bit of a mess. This wrapper is attempt to confine that mess to
37
- # a single point in the code.
38
- class FileLine < Tailor::FileLine
39
- attr_accessor :opts
40
-
41
- def initialize(source_line, opts)
42
- self.opts = opts
43
-
44
- super(source_line, nil, nil)
45
- end
46
-
47
- def find_problems
48
- # This is weird. These methods actually have side-effects! We capture
49
- # the effects my monkey-patching #print_problem below.
50
- spacing_problems
51
- method_line? && camel_case_method?
52
- class_line? && snake_case_class?
53
- too_long?
54
- end
55
-
56
- def print_problem(message)
57
- @problems << message.gsub(/\[.+\]\s+/, '')
32
+ def file_list
33
+ Dir[opts.fetch(:files)]
58
34
  end
59
35
 
60
- def problems
61
- @problems = []
62
- find_problems
63
- @problems
64
- end
65
-
66
- # A copy of the parent method that only uses a small subset of the spacing
67
- # checks we actually want (the others are too buggy or controversial).
68
- def spacing_problems
69
- spacing_conditions.each_pair do |condition, values|
70
- unless self.scan(values.first).empty?
71
- print_problem values[1]
72
- end
73
- end
74
- end
75
-
76
- def spacing_conditions
77
- SPACING_CONDITIONS.select {|k, _|
78
- [:hard_tabbed, :trailing_whitespace].include?(k)
79
- }
80
- end
81
-
82
- # Copy of parent method using a configurable line length.
83
- def too_long?
84
- length = self.chomp.length
85
- if length > line_length_max
86
- print_problem "Line is >#{line_length_max} characters (#{length})"
87
- return true
88
- end
89
-
90
- false
36
+ def measure
37
+ opts.fetch(:measure)
91
38
  end
92
39
 
93
- def line_length_max
94
- opts.fetch(:measure)
40
+ def map_lines(file_path, &block)
41
+ File.open(file_path).each_line.map.with_index(&block)
95
42
  end
96
43
  end
97
44
 
@@ -1,3 +1,3 @@
1
1
  module Cane
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cane
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-31 00:00:00.000000000 Z
12
+ date: 2012-04-21 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: tailor
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: rspec
32
16
  requirement: !ruby/object:Gem::Requirement
@@ -130,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
114
  version: '0'
131
115
  requirements: []
132
116
  rubyforge_project:
133
- rubygems_version: 1.8.18
117
+ rubygems_version: 1.8.23
134
118
  signing_key:
135
119
  specification_version: 3
136
120
  summary: Fails your build if code quality thresholds are not met. Provides complexity