rubocop-openhab-scripting 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 955f29cdd76ba5e7858aaa48cc1ceb9b303a4f517927bce3a1192649f058959e
4
+ data.tar.gz: a5f2b10777e796688fde4c4d2e97d37c8d2da10fd299a08bb6093f2e65748826
5
+ SHA512:
6
+ metadata.gz: 1eda9a0893cd037dc92d8789bc4c077be92a36b655e50f1af85ee62efa2ed2b81d8e00a8e5bbc069a430a089f7a8155c31648d5288ce047dc4c6c547a8585c00
7
+ data.tar.gz: 9af9e6189c68c27ad52b9bdcec5e896080ddeed5591708afca0c8e5b19395a269c900dd20faf9fa96a830542ce67f51b3505f9a8cb902648d572aed4d0654fe5
@@ -0,0 +1,8 @@
1
+ OpenHAB:
2
+ Enabled: true
3
+ Include:
4
+ - '**/ruby/personal/**/*.rb'
5
+
6
+ OpenHAB/StatePredicate:
7
+ Description: 'When comparing against named states and commands, prefer predicate methods.'
8
+ Enabled: true
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module OpenHAB
6
+ # When comparing against named states and commands, prefer predicate methods.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # Switch == ON
11
+ #
12
+ # # bad
13
+ # event.command == UP
14
+ #
15
+ # # good
16
+ # Switch.on?
17
+ #
18
+ # # good
19
+ # event.command.up?
20
+ #
21
+ class StatePredicate < Base
22
+ MSG = "Use `%<predicate>s?` instead of `== %<constant>s`."
23
+
24
+ METHODS = %i[
25
+ REFRESH
26
+ OPEN
27
+ CLOSED
28
+ ON
29
+ OFF
30
+ INCREASE
31
+ DECREASE
32
+ UP
33
+ DOWN
34
+ STOP
35
+ MOVE
36
+ PLAYING
37
+ PAUSED
38
+ REWINDING
39
+ FASTFORWARDING
40
+ PLAY
41
+ PAUSE
42
+ REWIND
43
+ FASTFORWARD
44
+ NEXT
45
+ PREVIOUS
46
+ ].to_set.freeze
47
+ def_node_matcher :bad_comparison?, <<~PATTERN
48
+ (send _ :== (const nil? $METHODS))
49
+ PATTERN
50
+
51
+ def message(constant)
52
+ format(MSG, predicate: constant.downcase, constant: constant)
53
+ end
54
+
55
+ def on_send(node)
56
+ bad_comparison?(node) { |constant| add_offense(node, message: message(constant)) }
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "openhab/state_predicate"
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
4
+ # See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md
5
+ module RuboCop
6
+ module OpenHAB
7
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
8
+ # bit of our configuration.
9
+ module Inject
10
+ def self.defaults!
11
+ path = CONFIG_DEFAULT.to_s
12
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
13
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
14
+ puts "configuration from #{path}" if ConfigLoader.debug?
15
+ config = ConfigLoader.merge_with_default(config, path)
16
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module OpenHAB
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "openhab/version"
4
+
5
+ module RuboCop
6
+ module OpenHAB
7
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
8
+ CONFIG_DEFAULT = PROJECT_ROOT.join("config", "default.yml").freeze
9
+ CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
10
+
11
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ require_relative "rubocop/openhab"
6
+ require_relative "rubocop/openhab/version"
7
+ require_relative "rubocop/openhab/inject"
8
+
9
+ RuboCop::OpenHAB::Inject.defaults!
10
+
11
+ require_relative "rubocop/cop/openhab_cops"
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-openhab-scripting
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Cody Cutrer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.21'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.21'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.4'
97
+ description:
98
+ email:
99
+ - cody@cutrer.us
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - config/default.yml
105
+ - lib/rubocop-openhab.rb
106
+ - lib/rubocop/cop/openhab/state_predicate.rb
107
+ - lib/rubocop/cop/openhab_cops.rb
108
+ - lib/rubocop/openhab.rb
109
+ - lib/rubocop/openhab/inject.rb
110
+ - lib/rubocop/openhab/version.rb
111
+ homepage: https://github.com/ccutrer/rubocop-openhab-scripting
112
+ licenses:
113
+ - MIT
114
+ metadata:
115
+ allowed_push_host: https://rubygems.org
116
+ homepage_uri: https://github.com/ccutrer/rubocop-openhab-scripting
117
+ source_code_uri: https://github.com/ccutrer/rubocop-openhab-scripting
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: 2.5.0
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubygems_version: 3.2.27
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: RuboCop cops for openhab-scripting rules
137
+ test_files: []