codeclimate 0.69.0 → 0.70.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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/bin/prep-release +1 -1
  3. data/config/engines.yml +32 -323
  4. data/lib/cc/analyzer.rb +5 -4
  5. data/lib/cc/analyzer/bridge.rb +106 -0
  6. data/lib/cc/analyzer/composite_container_listener.rb +4 -8
  7. data/lib/cc/analyzer/container.rb +44 -41
  8. data/lib/cc/analyzer/container/result.rb +74 -0
  9. data/lib/cc/analyzer/container_listener.rb +2 -7
  10. data/lib/cc/analyzer/engine.rb +53 -45
  11. data/lib/cc/analyzer/engine_output.rb +40 -10
  12. data/lib/cc/analyzer/formatters/formatter.rb +2 -0
  13. data/lib/cc/analyzer/formatters/html_formatter.rb +4 -0
  14. data/lib/cc/analyzer/formatters/json_formatter.rb +1 -0
  15. data/lib/cc/analyzer/formatters/plain_text_formatter.rb +8 -1
  16. data/lib/cc/analyzer/issue.rb +4 -2
  17. data/lib/cc/analyzer/issue_validations/relative_path_validation.rb +6 -2
  18. data/lib/cc/analyzer/issue_validator.rb +3 -32
  19. data/lib/cc/analyzer/logging_container_listener.rb +9 -7
  20. data/lib/cc/analyzer/measurement.rb +22 -0
  21. data/lib/cc/analyzer/measurement_validations.rb +16 -0
  22. data/lib/cc/analyzer/measurement_validations/name_validation.rb +23 -0
  23. data/lib/cc/analyzer/measurement_validations/type_validation.rb +15 -0
  24. data/lib/cc/analyzer/measurement_validations/validation.rb +27 -0
  25. data/lib/cc/analyzer/measurement_validations/value_validation.rb +21 -0
  26. data/lib/cc/analyzer/measurement_validator.rb +11 -0
  27. data/lib/cc/analyzer/raising_container_listener.rb +18 -18
  28. data/lib/cc/analyzer/statsd_container_listener.rb +22 -22
  29. data/lib/cc/analyzer/validator.rb +38 -0
  30. data/lib/cc/cli.rb +12 -12
  31. data/lib/cc/cli/analyze.rb +42 -60
  32. data/lib/cc/cli/analyze/engine_failure.rb +11 -0
  33. data/lib/cc/cli/command.rb +0 -10
  34. data/lib/cc/cli/engines.rb +0 -3
  35. data/lib/cc/cli/engines/engine_command.rb +2 -34
  36. data/lib/cc/cli/engines/install.rb +11 -17
  37. data/lib/cc/cli/engines/list.rb +5 -3
  38. data/lib/cc/cli/prepare.rb +5 -11
  39. data/lib/cc/cli/runner.rb +1 -2
  40. data/lib/cc/cli/test.rb +0 -1
  41. data/lib/cc/cli/validate_config.rb +49 -63
  42. data/lib/cc/cli/version_checker.rb +3 -3
  43. data/lib/cc/config.rb +70 -0
  44. data/lib/cc/config/checks_adapter.rb +40 -0
  45. data/lib/cc/config/default_adapter.rb +52 -0
  46. data/lib/cc/config/engine.rb +41 -0
  47. data/lib/cc/config/engine_set.rb +47 -0
  48. data/lib/cc/config/json_adapter.rb +17 -0
  49. data/lib/cc/config/prepare.rb +92 -0
  50. data/lib/cc/config/validation/check_validator.rb +34 -0
  51. data/lib/cc/config/validation/engine_validator.rb +89 -0
  52. data/lib/cc/config/validation/fetch_validator.rb +78 -0
  53. data/lib/cc/config/validation/file_validator.rb +112 -0
  54. data/lib/cc/config/validation/hash_validations.rb +52 -0
  55. data/lib/cc/config/validation/json.rb +31 -0
  56. data/lib/cc/config/validation/prepare_validator.rb +40 -0
  57. data/lib/cc/config/validation/yaml.rb +66 -0
  58. data/lib/cc/config/yaml_adapter.rb +73 -0
  59. data/lib/cc/engine_registry.rb +74 -0
  60. data/lib/cc/workspace/path_tree/dir_node.rb +1 -1
  61. metadata +36 -55
  62. data/bin/codeclimate-init +0 -6
  63. data/config/coffeelint/coffeelint.json +0 -129
  64. data/config/csslint/.csslintrc +0 -2
  65. data/config/eslint/.eslintignore +0 -1
  66. data/config/eslint/.eslintrc.yml +0 -277
  67. data/config/rubocop/.rubocop.yml +0 -1156
  68. data/lib/cc/analyzer/config.rb +0 -86
  69. data/lib/cc/analyzer/engine_registry.rb +0 -36
  70. data/lib/cc/analyzer/engines_config_builder.rb +0 -97
  71. data/lib/cc/analyzer/engines_runner.rb +0 -64
  72. data/lib/cc/cli/config.rb +0 -44
  73. data/lib/cc/cli/config_generator.rb +0 -108
  74. data/lib/cc/cli/engines/disable.rb +0 -38
  75. data/lib/cc/cli/engines/enable.rb +0 -41
  76. data/lib/cc/cli/engines/remove.rb +0 -35
  77. data/lib/cc/cli/init.rb +0 -117
  78. data/lib/cc/cli/prepare/quality.rb +0 -64
  79. data/lib/cc/cli/upgrade_config_generator.rb +0 -42
@@ -0,0 +1,31 @@
1
+ module CC
2
+ class Config
3
+ module Validation
4
+ class JSON < FileValidator
5
+ private
6
+
7
+ def validate
8
+ @data = ::JSON.parse(File.read(path))
9
+
10
+ return unless validate_hash_data
11
+
12
+ validate_version
13
+ validate_prepare
14
+ validate_engines("plugins")
15
+ validate_checks
16
+ validate_exclude_pattern("exclude_patterns")
17
+
18
+ warn_unrecognized_keys(%w[prepare plugins exclude_patterns version])
19
+ rescue ::JSON::ParserError => ex
20
+ errors << "Unable to parse: #{ex.message}"
21
+ end
22
+
23
+ def validate_version
24
+ unless data.key?("version")
25
+ warnings << %(missing 'version' key. Please add `"version": "2"`)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,40 @@
1
+ module CC
2
+ class Config
3
+ module Validation
4
+ class PrepareValidator
5
+ include HashValidations
6
+
7
+ attr_reader :errors, :warnings
8
+
9
+ def initialize(data)
10
+ @data = data
11
+
12
+ @errors = []
13
+ @warnings = []
14
+
15
+ validate
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :data
21
+
22
+ def validate
23
+ return unless validate_key_type("fetch", Array)
24
+
25
+ data.fetch("fetch", []).each do |fetch_data|
26
+ validator = FetchValidator.new(fetch_data)
27
+ validator.errors.each do |msg|
28
+ errors << msg
29
+ end
30
+ validator.warnings.each do |msg|
31
+ warnings << msg
32
+ end
33
+ end
34
+
35
+ warn_unrecognized_keys(%w[fetch])
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,66 @@
1
+ module CC
2
+ class Config
3
+ module Validation
4
+ class YAML < FileValidator
5
+ private
6
+
7
+ def validate
8
+ @data = ::YAML.safe_load(File.read(path))
9
+
10
+ return unless validate_hash_data
11
+
12
+ validate_version
13
+ validate_prepare
14
+
15
+ validate_one_of(%w[engines plugins])
16
+ validate_one_of(%w[exclude_paths exclude_patterns])
17
+
18
+ validate_engines("engines", legacy: true)
19
+ validate_engines("plugins")
20
+
21
+ validate_checks
22
+
23
+ validate_exclude_pattern("exclude_patterns")
24
+ validate_exclude_pattern("exclude_paths", legacy: true)
25
+
26
+ deprecated_key_warnings
27
+ warn_unrecognized_keys(%w[prepare engines plugins ratings languages exclude_paths exclude_patterns version])
28
+ rescue Psych::SyntaxError => ex
29
+ errors << "Unable to parse: #{ex.message}"
30
+ end
31
+
32
+ def validate_version
33
+ if !data.key?("version") && (data.key?("plugins") || data.key?("exclude_patterns"))
34
+ warnings << %(missing 'version' key. Please add `version: "2"`)
35
+ end
36
+ end
37
+
38
+ def validate_one_of(keys)
39
+ num = keys.map { |k| data.key?(k) }.select(&:present?).count
40
+ if num > 1
41
+ wrapped_keys = keys.map { |k| "'#{k}'" }
42
+ errors << "only use one of #{wrapped_keys.join(", ")}"
43
+ end
44
+ end
45
+
46
+ def deprecated_key_warnings
47
+ deprecate_key("engines", "plugins")
48
+ deprecate_key("exclude_paths", "exclude_patterns")
49
+ deprecate_key("languages")
50
+ deprecate_key("ratings")
51
+ end
52
+
53
+ def deprecate_key(key, new_key = nil)
54
+ if data.key?(key)
55
+ warnings <<
56
+ if new_key.nil?
57
+ "'#{key}' has been deprecated, and will not be used"
58
+ else
59
+ "'#{key}' has been deprecated, please use '#{new_key}' instead"
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,73 @@
1
+ module CC
2
+ class Config
3
+ class YAMLAdapter
4
+ DEFAULT_PATH = ".codeclimate.yml".freeze
5
+
6
+ attr_reader :config
7
+
8
+ def self.load(path = DEFAULT_PATH)
9
+ new(::YAML.safe_load(File.read(path)))
10
+ end
11
+
12
+ def initialize(yaml = {})
13
+ @config = yaml || {}
14
+
15
+ upconvert_legacy_yaml!
16
+ end
17
+
18
+ private
19
+
20
+ def coerce_engine(data)
21
+ if [true, false].include?(data)
22
+ { "enabled" => data }
23
+ elsif data.is_a?(Hash)
24
+ data
25
+ else
26
+ {}
27
+ end
28
+ end
29
+
30
+ # Many of our plugins still expect:
31
+ #
32
+ # { config: PATH }
33
+ #
34
+ # But we document, and hope to eventually move to:
35
+ #
36
+ # { config: { file: PATH } }
37
+ #
38
+ # We need to munge from the latter to the former when/if we encounter it
39
+ def convert_to_legacy_file_config(config)
40
+ if config.is_a?(Hash) && config.keys.one? && config.key?("file")
41
+ config["file"]
42
+ else
43
+ config
44
+ end
45
+ end
46
+
47
+ def upconvert_legacy_yaml!
48
+ config.delete("ratings")
49
+
50
+ if config.key?("engines")
51
+ config["plugins"] ||= config.delete("engines")
52
+ end
53
+
54
+ plugins = config.fetch("plugins", {})
55
+ plugins.each do |engine, data|
56
+ plugins[engine] = coerce_engine(data)
57
+ if plugins.fetch(engine)["exclude_paths"]
58
+ plugins.fetch(engine)["exclude_patterns"] ||= Array(plugins.fetch(engine).delete("exclude_paths"))
59
+ end
60
+ if plugins.fetch(engine)["config"]
61
+ plugins.fetch(engine)["config"] = convert_to_legacy_file_config(
62
+ plugins.fetch(engine).fetch("config"),
63
+ )
64
+ end
65
+ end
66
+
67
+ if config.key?("exclude_paths")
68
+ config["exclude_patterns"] ||= Array(config.delete("exclude_paths"))
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,74 @@
1
+ module CC
2
+ class EngineRegistry
3
+ include Enumerable
4
+
5
+ DEFAULT_MEMORY_LIMIT = 1_024_000_000
6
+ DEFAULT_COMMAND = nil
7
+ DEFAULT_MANIFEST_PATH = File.expand_path("../../../config/engines.yml", __FILE__)
8
+
9
+ EngineDetails = Struct.new(:image, :command, :description, :memory)
10
+ EngineDetailsNotFoundError = Class.new(StandardError)
11
+
12
+ def initialize(path = DEFAULT_MANIFEST_PATH, prefix = "")
13
+ @yaml = YAML.safe_load(File.read(path))
14
+ @prefix = prefix
15
+ end
16
+
17
+ def each
18
+ yaml.each do |name, metadata|
19
+ engine = Config::Engine.new(
20
+ name,
21
+ channel: metadata.fetch("channels").keys.first,
22
+ )
23
+ engine_details = fetch_engine_details(engine)
24
+
25
+ yield(engine, engine_details)
26
+ end
27
+ end
28
+
29
+ def fetch_engine_details(engine, development: false)
30
+ if development
31
+ EngineDetails.new("codeclimate/codeclimate-#{engine.name}", nil, "")
32
+ else
33
+ metadata = yaml.fetch(engine.name)
34
+ channels = metadata.fetch("channels")
35
+
36
+ EngineDetails.new(
37
+ [prefix, channels.fetch(engine.channel)].join,
38
+ metadata.fetch("command", DEFAULT_COMMAND),
39
+ metadata.fetch("description", "(No description available)"),
40
+ memory_limit(metadata["minimum_memory_limit"]),
41
+ )
42
+ end
43
+ rescue KeyError
44
+ raise EngineDetailsNotFoundError, not_found_message(engine, channels)
45
+ end
46
+
47
+ private
48
+
49
+ attr_reader :yaml, :prefix
50
+
51
+ def memory_limit(minimum_memory_limit)
52
+ [
53
+ minimum_memory_limit.to_i,
54
+ default_memory_limit.to_i,
55
+ ].max
56
+ end
57
+
58
+ def default_memory_limit
59
+ ENV["ENGINE_MEMORY_LIMIT_BYTES"] || DEFAULT_MEMORY_LIMIT
60
+ end
61
+
62
+ def not_found_message(engine, available_channels)
63
+ if available_channels
64
+ # Known engine, unknown channel
65
+ "Channel #{engine.channel} not found" \
66
+ " for #{engine.name}," \
67
+ " available channels: #{available_channels.keys.inspect}"
68
+ else
69
+ # Unknown engine
70
+ "No engine named #{engine.name} found"
71
+ end
72
+ end
73
+ end
74
+ end
@@ -42,7 +42,7 @@ module CC
42
42
  children[entry.basename.to_s.dup.freeze] ||= PathTree.node_for_pathname(entry)
43
43
  children[entry.basename.to_s.dup.freeze].add(*tail)
44
44
  else
45
- CLI.debug("Couldn't include because part of path doesn't exist.", path: File.join(root_path, head))
45
+ Analyzer.logger.debug("Couldn't include because part of path doesn't exist: #{File.join(root_path, head)}")
46
46
  end
47
47
  end
48
48
 
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.69.0
4
+ version: 0.70.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: 2017-11-09 00:00:00.000000000 Z
11
+ date: 2017-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.1
19
+ version: 5.1.3
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.1'
22
+ version: '5.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 4.2.1
29
+ version: 5.1.3
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.1'
32
+ version: '5.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: tty-spinner
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,20 +44,6 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: 0.1.0
47
- - !ruby/object:Gem::Dependency
48
- name: codeclimate-yaml
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: 0.13.0
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: 0.13.0
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: highline
63
49
  requirement: !ruby/object:Gem::Requirement
@@ -160,51 +146,28 @@ dependencies:
160
146
  - - "~>"
161
147
  - !ruby/object:Gem::Version
162
148
  version: '2.3'
163
- - !ruby/object:Gem::Dependency
164
- name: safe_yaml
165
- requirement: !ruby/object:Gem::Requirement
166
- requirements:
167
- - - "~>"
168
- - !ruby/object:Gem::Version
169
- version: '1.0'
170
- type: :runtime
171
- prerelease: false
172
- version_requirements: !ruby/object:Gem::Requirement
173
- requirements:
174
- - - "~>"
175
- - !ruby/object:Gem::Version
176
- version: '1.0'
177
149
  description: Code Climate command line tool
178
150
  email: hello@codeclimate.com
179
- executables:
180
- - codeclimate-init
151
+ executables: []
181
152
  extensions: []
182
153
  extra_rdoc_files: []
183
154
  files:
184
155
  - bin/check
185
156
  - bin/codeclimate
186
- - bin/codeclimate-init
187
157
  - bin/prep-release
188
158
  - bin/release
189
159
  - bin/validate-release
190
- - config/coffeelint/coffeelint.json
191
- - config/csslint/.csslintrc
192
160
  - config/engines.yml
193
- - config/eslint/.eslintignore
194
- - config/eslint/.eslintrc.yml
195
- - config/rubocop/.rubocop.yml
196
161
  - lib/cc/analyzer.rb
162
+ - lib/cc/analyzer/bridge.rb
197
163
  - lib/cc/analyzer/composite_container_listener.rb
198
- - lib/cc/analyzer/config.rb
199
164
  - lib/cc/analyzer/container.rb
165
+ - lib/cc/analyzer/container/result.rb
200
166
  - lib/cc/analyzer/container_listener.rb
201
167
  - lib/cc/analyzer/engine.rb
202
168
  - lib/cc/analyzer/engine_output.rb
203
169
  - lib/cc/analyzer/engine_output_filter.rb
204
170
  - lib/cc/analyzer/engine_output_overrider.rb
205
- - lib/cc/analyzer/engine_registry.rb
206
- - lib/cc/analyzer/engines_config_builder.rb
207
- - lib/cc/analyzer/engines_runner.rb
208
171
  - lib/cc/analyzer/filesystem.rb
209
172
  - lib/cc/analyzer/formatters.rb
210
173
  - lib/cc/analyzer/formatters/formatter.rb
@@ -231,39 +194,57 @@ files:
231
194
  - lib/cc/analyzer/issue_validator.rb
232
195
  - lib/cc/analyzer/location_description.rb
233
196
  - lib/cc/analyzer/logging_container_listener.rb
197
+ - lib/cc/analyzer/measurement.rb
198
+ - lib/cc/analyzer/measurement_validations.rb
199
+ - lib/cc/analyzer/measurement_validations/name_validation.rb
200
+ - lib/cc/analyzer/measurement_validations/type_validation.rb
201
+ - lib/cc/analyzer/measurement_validations/validation.rb
202
+ - lib/cc/analyzer/measurement_validations/value_validation.rb
203
+ - lib/cc/analyzer/measurement_validator.rb
234
204
  - lib/cc/analyzer/mounted_path.rb
235
205
  - lib/cc/analyzer/raising_container_listener.rb
236
206
  - lib/cc/analyzer/source_buffer.rb
237
207
  - lib/cc/analyzer/source_extractor.rb
238
208
  - lib/cc/analyzer/source_fingerprint.rb
239
209
  - lib/cc/analyzer/statsd_container_listener.rb
210
+ - lib/cc/analyzer/validator.rb
240
211
  - lib/cc/cli.rb
241
212
  - lib/cc/cli/analyze.rb
213
+ - lib/cc/cli/analyze/engine_failure.rb
242
214
  - lib/cc/cli/command.rb
243
- - lib/cc/cli/config.rb
244
- - lib/cc/cli/config_generator.rb
245
215
  - lib/cc/cli/console.rb
246
216
  - lib/cc/cli/engines.rb
247
- - lib/cc/cli/engines/disable.rb
248
- - lib/cc/cli/engines/enable.rb
249
217
  - lib/cc/cli/engines/engine_command.rb
250
218
  - lib/cc/cli/engines/install.rb
251
219
  - lib/cc/cli/engines/list.rb
252
- - lib/cc/cli/engines/remove.rb
253
220
  - lib/cc/cli/file_store.rb
254
221
  - lib/cc/cli/global_cache.rb
255
222
  - lib/cc/cli/global_config.rb
256
223
  - lib/cc/cli/help.rb
257
- - lib/cc/cli/init.rb
258
224
  - lib/cc/cli/output.rb
259
225
  - lib/cc/cli/prepare.rb
260
- - lib/cc/cli/prepare/quality.rb
261
226
  - lib/cc/cli/runner.rb
262
227
  - lib/cc/cli/test.rb
263
- - lib/cc/cli/upgrade_config_generator.rb
264
228
  - lib/cc/cli/validate_config.rb
265
229
  - lib/cc/cli/version.rb
266
230
  - lib/cc/cli/version_checker.rb
231
+ - lib/cc/config.rb
232
+ - lib/cc/config/checks_adapter.rb
233
+ - lib/cc/config/default_adapter.rb
234
+ - lib/cc/config/engine.rb
235
+ - lib/cc/config/engine_set.rb
236
+ - lib/cc/config/json_adapter.rb
237
+ - lib/cc/config/prepare.rb
238
+ - lib/cc/config/validation/check_validator.rb
239
+ - lib/cc/config/validation/engine_validator.rb
240
+ - lib/cc/config/validation/fetch_validator.rb
241
+ - lib/cc/config/validation/file_validator.rb
242
+ - lib/cc/config/validation/hash_validations.rb
243
+ - lib/cc/config/validation/json.rb
244
+ - lib/cc/config/validation/prepare_validator.rb
245
+ - lib/cc/config/validation/yaml.rb
246
+ - lib/cc/config/yaml_adapter.rb
247
+ - lib/cc/engine_registry.rb
267
248
  - lib/cc/resolv.rb
268
249
  - lib/cc/workspace.rb
269
250
  - lib/cc/workspace/exclusion.rb
@@ -290,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
290
271
  version: '0'
291
272
  requirements: []
292
273
  rubyforge_project:
293
- rubygems_version: 2.6.13
274
+ rubygems_version: 2.4.5
294
275
  signing_key:
295
276
  specification_version: 4
296
277
  summary: Code Climate CLI