codeclimate 0.2.12 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cbb3a16763441f73ecd126b74ac0cd7e086315f
4
- data.tar.gz: 17dd70c727bb8ad8496e65aabcdf3fd6d0ba2254
3
+ metadata.gz: ae822f93038f3d619b712789705ffae7c208c4c4
4
+ data.tar.gz: b0e1790279fb9722a45a1d732aaeb742c6c31103
5
5
  SHA512:
6
- metadata.gz: 4ff9002f80834f1bccfa64838fbd88730b9f4246f03bbe24a3b7603caeb1cb551075b70fb64c02de968875ace8fd959444004d0865614ba8ca53308e13b8dcb0
7
- data.tar.gz: ad2cf0955f53a1b2c2085bada281958735a8afaef4865abc6e262702215a96374e7ff5cb99798c9671afaa6df4bb4c8171d5e9e3e203561491c43e4d9787e327
6
+ metadata.gz: 7211c83e5b25b001e3ffe13e9cbc10d75a4261807d02fb9778cf2bb443738073eefb5171797654634b8553cbfa77483ae687720109444d0d8d6b7101980e5711
7
+ data.tar.gz: b292451406d827dd80bc3429e474c869a452fe1e4f48c9bee7efe2007a88a2adab5dcc41991f40f5fd85239611672711185ad0604cf6ba5d0717d41798109643
@@ -12,7 +12,7 @@ module CC
12
12
  }.freeze
13
13
 
14
14
  def self.resolve(name)
15
- FORMATTERS[name.to_sym].new or raise InvalidFormatterError, "'#{name}' is not a valid formatter. Valid options are: #{FORMATTERS.keys.join(", ")}"
15
+ FORMATTERS[name.to_sym].new(ENV['FILESYSTEM_DIR']) or raise InvalidFormatterError, "'#{name}' is not a valid formatter. Valid options are: #{FORMATTERS.keys.join(", ")}"
16
16
  end
17
17
  end
18
18
  end
@@ -2,7 +2,8 @@ module CC
2
2
  module Analyzer
3
3
  module Formatters
4
4
  class Formatter
5
- def initialize(output = $stdout)
5
+ def initialize(filesystem, output = $stdout)
6
+ @filesystem = filesystem
6
7
  @output = output
7
8
  end
8
9
 
@@ -3,7 +3,8 @@ module CC
3
3
  module Formatters
4
4
  class JSONFormatter < Formatter
5
5
 
6
- def initialize
6
+ def initialize(filesystem)
7
+ @filesystem = filesystem
7
8
  @has_begun = false
8
9
  end
9
10
 
@@ -35,7 +35,8 @@ module CC
35
35
 
36
36
  IssueSorter.new(file_issues).by_location.each do |issue|
37
37
  if location = issue["location"]
38
- print(colorize(LocationDescription.new(location, ": "), :cyan))
38
+ source_buffer = @filesystem.source_buffer_for(location["path"])
39
+ print(colorize(LocationDescription.new(source_buffer, location, ": "), :cyan))
39
40
  end
40
41
 
41
42
  print(issue["description"])
@@ -1,26 +1,23 @@
1
1
  module CC
2
2
  module Analyzer
3
3
  class LocationDescription
4
- def initialize(location, suffix = "")
4
+ def initialize(source_buffer, location, suffix = "")
5
+ @source_buffer = source_buffer
5
6
  @location = location
6
7
  @suffix = suffix
7
8
  end
8
9
 
9
10
  def to_s
10
- str = ""
11
11
  if location["lines"]
12
- str << render_lines
13
- elsif positions = location["positions"]
14
- str << render_position(positions["begin"])
15
-
16
- if positions["end"]
17
- str << "-"
18
- str << render_position(positions["end"])
19
- end
12
+ begin_line = location["lines"]["begin"]
13
+ end_line = location["lines"]["end"]
14
+ elsif location["positions"]
15
+ begin_line = position_to_line(location["positions"]["begin"])
16
+ end_line = position_to_line(location["positions"]["end"])
20
17
  end
21
18
 
19
+ str = render_lines(begin_line, end_line)
22
20
  str << suffix unless str.blank?
23
-
24
21
  str
25
22
  end
26
23
 
@@ -28,23 +25,20 @@ module CC
28
25
 
29
26
  attr_reader :location, :suffix
30
27
 
31
- def render_lines
32
- str = location["lines"]["begin"].to_s
33
- str << "-#{location["lines"]["end"]}" if location["lines"]["end"]
34
- str
28
+ def render_lines(begin_line, end_line)
29
+ if end_line == begin_line
30
+ begin_line.to_s
31
+ else
32
+ "#{begin_line}-#{end_line}"
33
+ end
35
34
  end
36
35
 
37
- def render_position(position)
38
- str = ""
39
-
36
+ def position_to_line(position)
40
37
  if position["line"]
41
- str << position["line"].to_s
42
- str << ":#{position["column"]}" if position["column"]
43
- elsif position["offset"]
44
- str << position["offset"].to_s
38
+ position["line"]
39
+ else
40
+ @source_buffer.decompose_position(position["offset"]).first
45
41
  end
46
-
47
- str
48
42
  end
49
43
  end
50
44
  end
@@ -43,7 +43,7 @@ module CC
43
43
  end
44
44
 
45
45
  def formatter
46
- @formatter ||= Formatters::PlainTextFormatter.new
46
+ @formatter ||= Formatters::PlainTextFormatter.new(filesystem)
47
47
  end
48
48
 
49
49
  def source_dir
data/lib/cc/cli/init.rb CHANGED
@@ -11,6 +11,7 @@ module CC
11
11
  else
12
12
  create_codeclimate_yaml
13
13
  say "Config file .codeclimate.yml successfully generated.\nEdit and then try running 'validate-config' to check configuration."
14
+ create_default_configs
14
15
  end
15
16
  end
16
17
 
@@ -33,6 +34,27 @@ module CC
33
34
  filesystem.write_path(CODECLIMATE_YAML, config.to_yaml)
34
35
  end
35
36
 
37
+ def create_default_configs
38
+ available_configs.each do |config_path|
39
+ file_name = File.basename(config_path)
40
+ if filesystem.exist?(file_name)
41
+ say "Skipping generating #{file_name} file (already exists)."
42
+ else
43
+ filesystem.write_path(file_name, File.read(config_path))
44
+ say "Config file #{file_name} successfully generated."
45
+ end
46
+ end
47
+ end
48
+
49
+ def available_configs
50
+ all_paths = eligible_engines.flat_map do |engine_name, _|
51
+ engine_directory = File.expand_path("../../../../config/#{engine_name}", __FILE__)
52
+ Dir.glob("#{engine_directory}/*", File::FNM_DOTMATCH)
53
+ end
54
+
55
+ all_paths.reject { |path| ['.', '..'].include?(File.basename(path)) }
56
+ end
57
+
36
58
  def exclude_paths(paths)
37
59
  expanded_paths = []
38
60
  paths.each do |dir|
@@ -52,7 +74,7 @@ module CC
52
74
  end
53
75
 
54
76
  def eligible_engines
55
- engine_registry.list.each_with_object({}) do |(engine_name, config), result|
77
+ @eligible_engines ||= engine_registry.list.each_with_object({}) do |(engine_name, config), result|
56
78
  if engine_eligible?(config)
57
79
  result[engine_name] = config
58
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeclimate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code Climate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-23 00:00:00.000000000 Z
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport