ccru 0.1.5 → 0.1.7
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/ccru/javascript_linter.rb +63 -1
- data/lib/ccru/javascript_linter_runner.rb +5 -2
- data/lib/ccru/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 20d17debc362218e7bd68e57cff217704df4ac263885c7f467fa4a682b318517
|
|
4
|
+
data.tar.gz: f356b6682d584a9af3a55274674fe5c65d6ddeab7d39faee12fb6f5073cf1f13
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eb00a13f5188ad77e6565f9ce3cb28ce431595043a244f4e42d00a67caf581988332696c29f08315a6abd96e60e7c19517e7d498f2bf6f2d77ca6b4e8bc75f90
|
|
7
|
+
data.tar.gz: ea3a1c071a6c0563c1ba469a75cc294143843ea2692df4833d7715af42231c10011deb3be8e4fda63e56da4cba7f45f9d756b7efd8d3e82c6188e8c263412611
|
data/Gemfile.lock
CHANGED
|
@@ -173,6 +173,20 @@ module Ccru
|
|
|
173
173
|
@offenses
|
|
174
174
|
end
|
|
175
175
|
|
|
176
|
+
def lint_filtered(content, changed_lines)
|
|
177
|
+
@current_code = content.lines
|
|
178
|
+
|
|
179
|
+
changed_lines.each do |line_number|
|
|
180
|
+
line_content = content.lines[line_number - 1]
|
|
181
|
+
next unless line_content
|
|
182
|
+
|
|
183
|
+
check_js_conventions_for_line(line_content, line_number)
|
|
184
|
+
check_line_trailing_whitespace(line_content, line_number)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
@offenses
|
|
188
|
+
end
|
|
189
|
+
|
|
176
190
|
def check_js_conventions(content)
|
|
177
191
|
@current_code = content.lines
|
|
178
192
|
|
|
@@ -187,13 +201,21 @@ module Ccru
|
|
|
187
201
|
end
|
|
188
202
|
end
|
|
189
203
|
|
|
204
|
+
def check_js_conventions_for_line(line_content, line_number)
|
|
205
|
+
return if line_content.strip.empty?
|
|
206
|
+
return if commment?(line_content, line_number)
|
|
207
|
+
|
|
208
|
+
check_line_conventions(line_content, line_number)
|
|
209
|
+
end
|
|
210
|
+
|
|
190
211
|
# rubocop:disable Metrics
|
|
191
212
|
def check_line_conventions(line_content, line_number)
|
|
192
213
|
ES6_VIOLATIONS.merge(CODE_QUALITY_RULES).each do |rule_name, rule|
|
|
193
214
|
next if line_content.match(rule[:pattern]).nil?
|
|
194
215
|
next if rule_name == :missing_semicolon && no_need_semicolon?(line_content)
|
|
195
216
|
next if rule_name == :unused_variables && used_variable?(line_content, line_number)
|
|
196
|
-
next if rule_name == :loose_equality && line_content.include?("!==")
|
|
217
|
+
next if rule_name == :loose_equality && (line_content.include?("===") || line_content.include?("!=="))
|
|
218
|
+
next if rule_name == :loose_inequality && line_content.include?("!==")
|
|
197
219
|
|
|
198
220
|
add_offense(rule_name, rule, line_content, line_number)
|
|
199
221
|
break
|
|
@@ -253,8 +275,48 @@ module Ccru
|
|
|
253
275
|
# but JS ASI will handle it, I consider it unnecessary
|
|
254
276
|
return true if line.match(/^(return|break|continue|throw)\b/)
|
|
255
277
|
|
|
278
|
+
# Object/array literal properties and elements don't need semicolons
|
|
279
|
+
return true if in_object_or_array_literal?(line_content)
|
|
280
|
+
|
|
256
281
|
false
|
|
257
282
|
end
|
|
283
|
+
|
|
284
|
+
def in_object_or_array_literal?(line_content)
|
|
285
|
+
return false unless @current_code
|
|
286
|
+
|
|
287
|
+
line_number = @current_code.index(line_content) + 1
|
|
288
|
+
return false unless line_number
|
|
289
|
+
|
|
290
|
+
# Check if we're inside an object or array literal
|
|
291
|
+
brace_count = 0
|
|
292
|
+
bracket_count = 0
|
|
293
|
+
in_object = false
|
|
294
|
+
in_array = false
|
|
295
|
+
|
|
296
|
+
@current_code.each_with_index do |code_line, index|
|
|
297
|
+
break if index >= line_number
|
|
298
|
+
|
|
299
|
+
# Check for braces and brackets
|
|
300
|
+
code_line.each_char do |char|
|
|
301
|
+
case char
|
|
302
|
+
when "{"
|
|
303
|
+
brace_count += 1
|
|
304
|
+
in_object = true if brace_count == 1
|
|
305
|
+
when "}"
|
|
306
|
+
brace_count -= 1
|
|
307
|
+
in_object = false if brace_count.zero?
|
|
308
|
+
when "["
|
|
309
|
+
bracket_count += 1
|
|
310
|
+
in_array = true if bracket_count == 1
|
|
311
|
+
when "]"
|
|
312
|
+
bracket_count -= 1
|
|
313
|
+
in_array = false if bracket_count.zero?
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
in_object || in_array
|
|
319
|
+
end
|
|
258
320
|
# rubocop:enable Metrics
|
|
259
321
|
|
|
260
322
|
def commment?(line_content, line_number)
|
|
@@ -25,8 +25,11 @@ module Ccru
|
|
|
25
25
|
return 0 unless content && meta[:lines].any?
|
|
26
26
|
|
|
27
27
|
linter = JavaScriptLinter.new
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
offenses = linter.lint_filtered(content, meta[:lines])
|
|
29
|
+
return 0 if offenses.empty?
|
|
30
|
+
|
|
31
|
+
print_offenses(path, offenses)
|
|
32
|
+
1
|
|
30
33
|
end
|
|
31
34
|
end
|
|
32
35
|
end
|
data/lib/ccru/version.rb
CHANGED