codeclimate 0.71.1 → 0.71.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/engines.yml +4 -0
- data/lib/cc/cli.rb +0 -1
- metadata +3 -4
- data/lib/cc/cli/test.rb +0 -263
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee1d2c780390e753d24ab05cd46657350a0df23f
|
4
|
+
data.tar.gz: 86cee97fe5f73bedd95e246696b9f170c9a77d99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 221ff9dfc9d20188dbee5aa2717633830d50f8153b38df3c0d04bcae70e2388d3f8ad0f1e8bafc7f3ff26d028221bbc187262788ee8219dd94f65ade8a29f2c5
|
7
|
+
data.tar.gz: 8dcdfa59cc65cedef1ef89ae77e3dc8893fdcd959e22c8703661d0a9e41f530ee231c419e57135ad8617453603ab259bff087c6bbb7f8c706862d100d3a8e130
|
data/config/engines.yml
CHANGED
@@ -209,6 +209,10 @@ stylelint:
|
|
209
209
|
beta: codeclimate/codeclimate-stylelint:beta
|
210
210
|
stable: codeclimate/codeclimate-stylelint
|
211
211
|
description: A mighty, modern CSS linter.
|
212
|
+
swiftlint:
|
213
|
+
channels:
|
214
|
+
stable: codeclimate/codeclimate-swiftlint
|
215
|
+
description: A tool to enforce Swift style and conventions.
|
212
216
|
tailor:
|
213
217
|
channels:
|
214
218
|
stable: codeclimate/codeclimate-tailor
|
data/lib/cc/cli.rb
CHANGED
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.71.
|
4
|
+
version: 0.71.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code Climate
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02
|
11
|
+
date: 2018-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -225,7 +225,6 @@ files:
|
|
225
225
|
- lib/cc/cli/output.rb
|
226
226
|
- lib/cc/cli/prepare.rb
|
227
227
|
- lib/cc/cli/runner.rb
|
228
|
-
- lib/cc/cli/test.rb
|
229
228
|
- lib/cc/cli/validate_config.rb
|
230
229
|
- lib/cc/cli/version.rb
|
231
230
|
- lib/cc/cli/version_checker.rb
|
@@ -272,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
272
271
|
version: '0'
|
273
272
|
requirements: []
|
274
273
|
rubyforge_project:
|
275
|
-
rubygems_version: 2.
|
274
|
+
rubygems_version: 2.6.14
|
276
275
|
signing_key:
|
277
276
|
specification_version: 4
|
278
277
|
summary: Code Climate CLI
|
data/lib/cc/cli/test.rb
DELETED
@@ -1,263 +0,0 @@
|
|
1
|
-
require "tmpdir"
|
2
|
-
|
3
|
-
module CC
|
4
|
-
module CLI
|
5
|
-
class Marker
|
6
|
-
def self.from_text(engine_name, test_file, line_number, text)
|
7
|
-
marker = Marker.new(line_number, text)
|
8
|
-
attrs = attrs_from_marker(text.sub(/^.*\[issue\] ?/, ""))
|
9
|
-
|
10
|
-
marker.issue = attrs.merge(
|
11
|
-
"engine_name" => engine_name,
|
12
|
-
"location" => {
|
13
|
-
"path" => test_file,
|
14
|
-
"lines" => {
|
15
|
-
"begin" => line_number + 1,
|
16
|
-
"end" => line_number + 1,
|
17
|
-
},
|
18
|
-
},
|
19
|
-
)
|
20
|
-
|
21
|
-
if marker.issue["category"]
|
22
|
-
marker.issue["categories"] = Array.wrap(marker.issue["category"])
|
23
|
-
marker.issue.delete("category")
|
24
|
-
end
|
25
|
-
|
26
|
-
marker
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.attrs_from_marker(text)
|
30
|
-
if text.blank?
|
31
|
-
{}
|
32
|
-
else
|
33
|
-
matches = text.scan(/([a-z\._-]+)=(?:(")((?:\\.|[^"])*)"|([^\s]*))/).map(&:compact)
|
34
|
-
|
35
|
-
key_values = matches.map do |match|
|
36
|
-
munge_match(match)
|
37
|
-
end
|
38
|
-
|
39
|
-
Hash[key_values]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.munge_match(match)
|
44
|
-
if match.size == 3 # Quoted
|
45
|
-
key, _, value = match
|
46
|
-
value = '"' + value + '"'
|
47
|
-
else
|
48
|
-
key, value = match
|
49
|
-
end
|
50
|
-
|
51
|
-
[key, munge_value(value)]
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.munge_value(value)
|
55
|
-
JSON.load(value)
|
56
|
-
rescue JSON::ParserError
|
57
|
-
value
|
58
|
-
end
|
59
|
-
|
60
|
-
attr_reader :line, :line_text
|
61
|
-
attr_accessor :issue
|
62
|
-
|
63
|
-
def initialize(line, line_text)
|
64
|
-
@line = line
|
65
|
-
@line_text = line_text
|
66
|
-
@issue = issue
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
class Test < Command
|
71
|
-
ARGUMENT_LIST = "<engine_name>".freeze
|
72
|
-
SHORT_HELP = "Test an engine.".freeze
|
73
|
-
HELP = "Validate that an engine is behaving correctly.\n" \
|
74
|
-
"\n"\
|
75
|
-
" <engine_name> Engine to test".freeze
|
76
|
-
|
77
|
-
def run
|
78
|
-
@engine_name = @args.first
|
79
|
-
|
80
|
-
if @engine_name.blank?
|
81
|
-
fatal "Usage: codeclimate test #{rainbow.wrap("engine_name").underline}"
|
82
|
-
end
|
83
|
-
|
84
|
-
test_engine
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_engine
|
88
|
-
within_tempdir do
|
89
|
-
prepare_working_dir
|
90
|
-
unpack_tests
|
91
|
-
run_tests
|
92
|
-
end
|
93
|
-
ensure
|
94
|
-
remove_null_container
|
95
|
-
end
|
96
|
-
|
97
|
-
def within_tempdir(&block)
|
98
|
-
Dir.mktmpdir { |tmp| Dir.chdir(tmp, &block) }
|
99
|
-
end
|
100
|
-
|
101
|
-
def unpack_tests
|
102
|
-
test_paths.each do |test_path|
|
103
|
-
unpack(test_path)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def run_tests
|
108
|
-
Dir["*"].each do |file|
|
109
|
-
next unless File.directory?(file)
|
110
|
-
process_directory(file)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def process_directory(test_directory)
|
115
|
-
markers = markers_in(test_directory)
|
116
|
-
|
117
|
-
actual_issues = issues_in(test_directory)
|
118
|
-
compare_issues(actual_issues, markers)
|
119
|
-
end
|
120
|
-
|
121
|
-
def compare_issues(actual_issues, markers)
|
122
|
-
markers.each do |marker|
|
123
|
-
validate_issue(marker, actual_issues)
|
124
|
-
end
|
125
|
-
|
126
|
-
validate_unexpected_issues(actual_issues)
|
127
|
-
end
|
128
|
-
|
129
|
-
def validate_issue(marker, actual_issues)
|
130
|
-
if (index = locate_match(actual_issues, marker))
|
131
|
-
announce_pass(marker)
|
132
|
-
actual_issues.delete_at(index)
|
133
|
-
else
|
134
|
-
announce_fail(marker, actual_issues)
|
135
|
-
fatal "Expected issue not found."
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def locate_match(actual_issues, marker)
|
140
|
-
actual_issues.each_with_index do |actual, index|
|
141
|
-
if fuzzy_match(marker.issue, actual)
|
142
|
-
return index
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
nil
|
147
|
-
end
|
148
|
-
|
149
|
-
def announce_pass(marker)
|
150
|
-
say format("PASS %3d: %s", marker.line, marker.line_text)
|
151
|
-
end
|
152
|
-
|
153
|
-
def announce_fail(marker, actual_issues)
|
154
|
-
say colorize(format("FAIL %3d: %s", marker.line, marker.line_text), :red)
|
155
|
-
say colorize("Expected:", :yellow)
|
156
|
-
say colorize(JSON.pretty_generate(marker.issue), :yellow)
|
157
|
-
say "\n"
|
158
|
-
say colorize("Actual:", :yellow)
|
159
|
-
say colorize(JSON.pretty_generate(actual_issues), :yellow)
|
160
|
-
end
|
161
|
-
|
162
|
-
def validate_unexpected_issues(actual_issues)
|
163
|
-
if actual_issues.any?
|
164
|
-
say colorize("Actuals not empty after matching.", :red)
|
165
|
-
say "\n"
|
166
|
-
say colorize("#{actual_issues.size} remaining:", :yellow)
|
167
|
-
say colorize(JSON.pretty_generate(actual_issues), :yellow)
|
168
|
-
fatal "Unexpected issue found."
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
def fuzzy_match(expected, actual)
|
173
|
-
expected.all? do |key, value|
|
174
|
-
actual[key] == value
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def issues_in(test_directory)
|
179
|
-
issue_docs = capture_stdout do
|
180
|
-
codeclimate_analyze(test_directory)
|
181
|
-
end
|
182
|
-
|
183
|
-
JSON.parse(issue_docs)
|
184
|
-
end
|
185
|
-
|
186
|
-
def codeclimate_analyze(relative_path)
|
187
|
-
codeclimate_path = File.expand_path(File.join(File.dirname(__FILE__), "../../../bin/codeclimate"))
|
188
|
-
|
189
|
-
system(
|
190
|
-
codeclimate_path, "analyze",
|
191
|
-
"--engine", @engine_name,
|
192
|
-
"-f", "json",
|
193
|
-
relative_path
|
194
|
-
)
|
195
|
-
end
|
196
|
-
|
197
|
-
def prepare_working_dir
|
198
|
-
`git init`
|
199
|
-
|
200
|
-
File.open(".codeclimate.yml", "w") do |config|
|
201
|
-
config.write("engines:\n #{@engine_name}:\n enabled: true")
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
def markers_in(test_directory)
|
206
|
-
[].tap do |markers|
|
207
|
-
Dir[File.join(test_directory, "**/*")].each do |file|
|
208
|
-
next unless File.file?(file)
|
209
|
-
lines = File.readlines(file)
|
210
|
-
|
211
|
-
lines.each_with_index do |line, index|
|
212
|
-
if line =~ /\[issue\].*/
|
213
|
-
markers << Marker.from_text(@engine_name, file, index + 1, line)
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
def unpack(path)
|
221
|
-
system("docker cp #{null_container_id}:#{path} .")
|
222
|
-
end
|
223
|
-
|
224
|
-
def null_container_id
|
225
|
-
# docker cp only works with containers, not images so
|
226
|
-
# workaround it by creating a throwaway container
|
227
|
-
@null_container_id = `docker run -d #{engine_image} false`.chomp
|
228
|
-
end
|
229
|
-
|
230
|
-
def remove_null_container
|
231
|
-
`docker rm -f #{null_container_id}` if null_container_id
|
232
|
-
end
|
233
|
-
|
234
|
-
def test_paths
|
235
|
-
Array.wrap(engine_spec["test_paths"])
|
236
|
-
end
|
237
|
-
|
238
|
-
def engine_spec
|
239
|
-
@engine_spec ||= JSON.parse(`docker run --rm #{engine_image} cat /engine.json`)
|
240
|
-
end
|
241
|
-
|
242
|
-
def engine_image
|
243
|
-
engine_registry[@engine_name]["channels"]["stable"]
|
244
|
-
end
|
245
|
-
|
246
|
-
# Stolen from ActiveSupport (where it was deprecated)
|
247
|
-
def capture_stdout
|
248
|
-
captured_stream = Tempfile.new("stdout")
|
249
|
-
origin_stream = $stdout.dup
|
250
|
-
$stdout.reopen(captured_stream)
|
251
|
-
|
252
|
-
yield
|
253
|
-
|
254
|
-
$stdout.rewind
|
255
|
-
return captured_stream.read
|
256
|
-
ensure
|
257
|
-
captured_stream.close
|
258
|
-
captured_stream.unlink
|
259
|
-
$stdout.reopen(origin_stream)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
263
|
-
end
|