rubocop-sketchup 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,14 +12,14 @@ module RuboCop
12
12
  MSG = "Avoid relying on internal logic of Dynamic Components.".freeze
13
13
 
14
14
  def on_gvar(node)
15
- check(node)
15
+ check_global(node)
16
16
  end
17
17
 
18
18
  def on_gvasgn(node)
19
- check(node)
19
+ check_global(node)
20
20
  end
21
21
 
22
- def check(node)
22
+ def check_global(node)
23
23
  global_var, = *node
24
24
  return unless dc_global_var?(global_var)
25
25
  add_offense(node, location: :name, severity: :error)
@@ -45,9 +45,7 @@ module RuboCop
45
45
 
46
46
 
47
47
  def_node_search :force_encoding, <<-PATTERN
48
- (send
49
- (_ $_)
50
- :force_encoding ...)
48
+ (send ({lvar ivar cvar} $_) :force_encoding ...)
51
49
  PATTERN
52
50
 
53
51
  def on_assign(node)
@@ -61,7 +59,6 @@ module RuboCop
61
59
  add_offense(node)
62
60
  end
63
61
 
64
- # TODO: Review this list of aliases.
65
62
  alias on_lvasgn on_assign
66
63
  alias on_masgn on_assign
67
64
  alias on_casgn on_assign
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module SketchupSuggestions
6
+ # Some of the shipped extensions in SketchUp monkey-patch the API
7
+ # namespace. This is an unfortunate no-no that was done a long time ago
8
+ # before the extension best-practices were established. These functions
9
+ # might change or be removed at any time. They will also not work when
10
+ # the extensions are disabled. Avoid using these methods.
11
+ class MonkeyPatchedApi < Cop
12
+
13
+ include SketchUp::DynamicComponentMethods
14
+
15
+ def on_send(node)
16
+ # Only check instance methods.
17
+ return if node.receiver && node.receiver.const_type?
18
+
19
+ name = node.method_name
20
+
21
+ dc_method = DC_METHODS.find { |m| m[:name] == name }
22
+ return unless dc_method
23
+
24
+ if dc_method.key?(:variables)
25
+ return unless node.receiver && node.receiver.variable?
26
+ receiver_name = node.receiver.children.first
27
+ # Account for instance and class variables.
28
+ receiver_name = receiver_name.to_s.tr('@', '').to_sym
29
+ return unless dc_method[:variables].include?(receiver_name)
30
+ end
31
+
32
+ path = dc_method[:path]
33
+ message = "#{path}##{name} is not part of the official API. "\
34
+ "It's a monkey-patched addition by Dynamic Components."
35
+ add_offense(node, severity: :error, message: message)
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+ end
@@ -5,6 +5,8 @@ module RuboCop
5
5
  module SketchupSuggestions
6
6
  class OperationName < Cop
7
7
 
8
+ include RangeHelp
9
+
8
10
  MSG = 'Operation name should be a short capitalized description.'.freeze
9
11
  MSG_MAX = "Operation names should not be short and concise. [%d/%d]".freeze
10
12
 
@@ -25,9 +25,30 @@ module RuboCop
25
25
  )
26
26
  PATTERN
27
27
 
28
+
29
+ def_node_matcher :sketchup_extension_new, <<-PATTERN
30
+ (send
31
+ (const nil? :SketchupExtension) :new
32
+ _
33
+ (str $_))
34
+ PATTERN
35
+
36
+ def_node_matcher :sketchup_extension_new?, <<-PATTERN
37
+ (send
38
+ (const nil? :SketchupExtension) :new
39
+ _
40
+ (str _))
41
+ PATTERN
42
+
43
+
28
44
  def on_send(node)
29
- return unless sketchup_require?(node)
30
- filename = sketchup_require(node)
45
+ if sketchup_require?(node)
46
+ filename = sketchup_require(node)
47
+ elsif sketchup_extension_new?(node)
48
+ filename = sketchup_extension_new(node)
49
+ else
50
+ return
51
+ end
31
52
  add_offense(node, location: :expression) unless valid_filename?(filename)
32
53
  end
33
54
 
@@ -36,6 +57,7 @@ module RuboCop
36
57
  def valid_filename?(filename)
37
58
  File.extname(filename).empty?
38
59
  end
60
+
39
61
  end
40
62
  end
41
63
  end
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module SketchUp
3
- VERSION = '0.2.1'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  # NOTE: Remember to update the README.md instructions on how to install
27
27
  # compatible RuboCop version.
28
- spec.add_dependency 'rubocop', '~> 0.52.0'
28
+ spec.add_dependency 'rubocop', '~> 0.54.0'
29
29
  spec.add_development_dependency 'bundler', '~> 1.13'
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-sketchup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trimble Inc, SketchUp Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-05 00:00:00.000000000 Z
11
+ date: 2018-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.52.0
19
+ version: 0.54.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.52.0
26
+ version: 0.54.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,6 +50,7 @@ files:
50
50
  - lib/rubocop/sketchup.rb
51
51
  - lib/rubocop/sketchup/config.rb
52
52
  - lib/rubocop/sketchup/dc_globals.rb
53
+ - lib/rubocop/sketchup/dc_methods.rb
53
54
  - lib/rubocop/sketchup/deprecations/add_separator_to_menu.rb
54
55
  - lib/rubocop/sketchup/deprecations/operation_next_transparent.rb
55
56
  - lib/rubocop/sketchup/deprecations/require_all.rb
@@ -57,6 +58,7 @@ files:
57
58
  - lib/rubocop/sketchup/deprecations/show_ruby_panel.rb
58
59
  - lib/rubocop/sketchup/deprecations/sketchup_set.rb
59
60
  - lib/rubocop/sketchup/extension_project.rb
61
+ - lib/rubocop/sketchup/features.rb
60
62
  - lib/rubocop/sketchup/formatter/extension_review.rb
61
63
  - lib/rubocop/sketchup/inject.rb
62
64
  - lib/rubocop/sketchup/namespace.rb
@@ -71,19 +73,24 @@ files:
71
73
  - lib/rubocop/sketchup/requirements/extension_namespace.rb
72
74
  - lib/rubocop/sketchup/requirements/file_structure.rb
73
75
  - lib/rubocop/sketchup/requirements/global_constants.rb
76
+ - lib/rubocop/sketchup/requirements/global_include.rb
74
77
  - lib/rubocop/sketchup/requirements/global_methods.rb
75
78
  - lib/rubocop/sketchup/requirements/global_variables.rb
76
79
  - lib/rubocop/sketchup/requirements/language_handler_globals.rb
77
80
  - lib/rubocop/sketchup/requirements/load_path.rb
78
81
  - lib/rubocop/sketchup/requirements/minimal_registration.rb
82
+ - lib/rubocop/sketchup/requirements/observers_start_operation.rb
79
83
  - lib/rubocop/sketchup/requirements/register_extension.rb
80
84
  - lib/rubocop/sketchup/requirements/ruby_core_namespace.rb
81
85
  - lib/rubocop/sketchup/requirements/ruby_stdlib_namespace.rb
82
86
  - lib/rubocop/sketchup/requirements/shipped_extensions_namespace.rb
83
87
  - lib/rubocop/sketchup/requirements/sketchup_extension.rb
88
+ - lib/rubocop/sketchup/sketchup_version.rb
89
+ - lib/rubocop/sketchup/suggestions/compatibility.rb
84
90
  - lib/rubocop/sketchup/suggestions/dc_internals.rb
85
91
  - lib/rubocop/sketchup/suggestions/file_encoding.rb
86
92
  - lib/rubocop/sketchup/suggestions/model_entities.rb
93
+ - lib/rubocop/sketchup/suggestions/monkey_patched_api.rb
87
94
  - lib/rubocop/sketchup/suggestions/operation_name.rb
88
95
  - lib/rubocop/sketchup/suggestions/sketchup_find_support_file.rb
89
96
  - lib/rubocop/sketchup/suggestions/sketchup_require.rb