rubocop-cable_ready 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2917b152ca55dac54178332b058c19488c338d586aa15e67b77061e474281011
4
- data.tar.gz: 7411b6898d713a078fc49f7c8273e51fa351013a3888701e4f3a7f98a1d7af10
3
+ metadata.gz: 8d53a99f06039b50d0b41b94062a4eef19834fca34b749af1a9503e7acbef8ed
4
+ data.tar.gz: ecb21ade65d6d3c38a2d81d25355078c8c5a05d6442e8ca2bd9b13c1fb94b75f
5
5
  SHA512:
6
- metadata.gz: 2fa42e00a308bb687d7fa06d9647b4a7740fb598b8d328e190f35210188e7d487f1284e1a022c2d5864c9730d139503500212495265ccab00dde53c118b9a1e0
7
- data.tar.gz: 354c79132f70afeb1eeb85243f341d0025bcb2bf6ee8e0226ba4566941a67fed748972e9b5cb1eb7c90a769ad501f260bff4e2aac9838e2d99d23402e41ed96b
6
+ metadata.gz: 26ec37c74856e9c4d84830f13aaaf04973ab82d6e5a01caf011546bcf09a4f2bc8daa7a0e73833572abdfcdb438454fb9695a5cfaa40a8b3c9051f92ad478cf7
7
+ data.tar.gz: 488feee9dba724d37c8ecc0542bbf266ce610d9ad18d11ee67e7d3c7edd3b22c29b2e3850bf258bf78979856b65a985e055732a9fa9e0cf811bd6cb16a2b2e37
@@ -5,14 +5,20 @@ on: [push, pull_request]
5
5
  jobs:
6
6
  build:
7
7
  runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby-version: [2.6, 2.7, '3.0', 3.1, 3.2]
8
11
  steps:
9
12
  - uses: actions/checkout@v2
10
13
 
11
- - name: Set up Ruby
14
+ - name: Set up Ruby ${{ matrix.ruby-version }}
12
15
  uses: ruby/setup-ruby@v1
13
16
  with:
14
- ruby-version: 3.0.1
17
+ ruby-version: ${{ matrix.ruby-version }}
15
18
  bundler-cache: true
16
19
 
20
+ - name: Lint
21
+ run: bundle exec rubocop
22
+
17
23
  - name: Run tests
18
- run: bundle exec rake
24
+ run: bundle exec rspec spec
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *~
data/.rubocop.yml CHANGED
@@ -20,3 +20,7 @@ Layout/LineLength:
20
20
  Naming/FileName:
21
21
  Exclude:
22
22
  - lib/rubocop-cable_ready.rb
23
+
24
+ Metrics/BlockLength:
25
+ Exclude:
26
+ - spec/**/*.rb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,3 @@
1
- ## [Unreleased]
1
+ ## Changelog
2
2
 
3
- ## [0.1.0] - 2021-06-28
4
-
5
- - Initial release
3
+ Please see [GitHub](https://github.com/marcoroth/rubocop-cable_ready/releases) for detailed changelogs.
data/Gemfile.lock CHANGED
@@ -9,6 +9,7 @@ GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
11
  ast (2.4.2)
12
+ diff-lcs (1.4.4)
12
13
  minitest (5.14.4)
13
14
  parallel (1.20.1)
14
15
  parser (3.0.1.1)
@@ -17,6 +18,19 @@ GEM
17
18
  rake (13.0.3)
18
19
  regexp_parser (2.1.1)
19
20
  rexml (3.2.5)
21
+ rspec (3.10.0)
22
+ rspec-core (~> 3.10.0)
23
+ rspec-expectations (~> 3.10.0)
24
+ rspec-mocks (~> 3.10.0)
25
+ rspec-core (3.10.1)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-expectations (3.10.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-mocks (3.10.2)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-support (3.10.2)
20
34
  rubocop (1.17.0)
21
35
  parallel (~> 1.10)
22
36
  parser (>= 3.0.0.0)
@@ -32,12 +46,14 @@ GEM
32
46
  unicode-display_width (2.0.0)
33
47
 
34
48
  PLATFORMS
49
+ arm64-darwin-21
35
50
  x86_64-darwin-19
36
51
  x86_64-linux
37
52
 
38
53
  DEPENDENCIES
39
54
  minitest (~> 5.0)
40
55
  rake (~> 13.0)
56
+ rspec
41
57
  rubocop (~> 1.7)
42
58
  rubocop-cable_ready!
43
59
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Rubocop::CableReady
1
+ # RuboCop::CableReady
2
2
 
3
3
  CableReady-specific analysis for your projects, as an extension to [RuboCop](https://github.com/rubocop/rubocop).
4
4
 
@@ -58,6 +58,100 @@ RuboCop::RakeTask.new do |task|
58
58
  end
59
59
  ```
60
60
 
61
+ ## Cops
62
+
63
+ #### `CableReady/ApplicationRecordEnableUpdates`
64
+
65
+ | Enabled by default | Supports autocorrection | Include | Version Added | Version Changed |
66
+ | --- | --- | --- | --- | --- |
67
+ | true | No | `app/models/**/*.rb` | 0.2.0 | 0.2.0 |
68
+
69
+ The `enable_cable_ready_updates` class method shouldn't be called in `ApplicationRecord`. Instead call `enable_cable_ready_updates` in every model you want to track and broadcast updates.
70
+
71
+
72
+ ##### Examples
73
+
74
+ ```ruby
75
+ # bad
76
+
77
+ class ApplicationRecord < ActiveRecord::Base
78
+ include CableReady::Updatable
79
+
80
+ enable_cable_ready_updates on: :update
81
+ end
82
+
83
+
84
+ # good
85
+
86
+ class Post < ApplicationRecord
87
+ include CableReady::Updatable
88
+
89
+ enable_cable_ready_updates on: :update
90
+ end
91
+
92
+
93
+ # good
94
+
95
+ class ApplicationRecord < ActiveRecord::Base
96
+ include CableReady::Updatable
97
+ end
98
+
99
+ class Post < ApplicationRecord
100
+ enable_cable_ready_updates on: :update
101
+ end
102
+ ```
103
+
104
+ ----
105
+
106
+ #### `CableReady/BroadcasterControllerAction`
107
+
108
+ | Enabled by default | Supports autocorrection | Include | Version Added | Version Changed |
109
+ | --- | --- | --- | --- | --- |
110
+ | false | No | `app/controllers/**/*.rb` | 0.2.0 | 0.2.0 |
111
+
112
+ It's discouraged to broadcast CableReady broadcasts from Controller actions.
113
+
114
+ ##### Examples
115
+
116
+ ```ruby
117
+ # bad
118
+
119
+ def create
120
+ cable_ready[UserChannel]
121
+ .append(selector: "...", html: "...")
122
+ .broadcast
123
+ end
124
+
125
+
126
+ # good
127
+
128
+ def create
129
+ end
130
+ ```
131
+
132
+ ----
133
+
134
+ #### `CableReady/UnusedCableReadyCall`
135
+
136
+ | Enabled by default | Supports autocorrection | Include | Version Added | Version Changed |
137
+ | --- | --- | --- | --- | --- |
138
+ | true | No | `app/**/*.rb` | 0.1.0 | 0.1.0 |
139
+
140
+ The `cable_ready` method shouldn't be called without being followed by an operation.
141
+
142
+ ##### Examples
143
+
144
+ ```ruby
145
+ # bad
146
+
147
+ cable_ready
148
+
149
+
150
+ # good
151
+
152
+ cable_ready.inner_html(...)
153
+ ```
154
+
61
155
  ## Development
62
156
 
63
157
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -74,4 +168,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
74
168
 
75
169
  ## Code of Conduct
76
170
 
77
- Everyone interacting in the Rubocop::CableReady project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/marcoroth/rubocop-cable_ready/blob/master/CODE_OF_CONDUCT.md).
171
+ Everyone interacting in the RuboCop::CableReady project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/marcoroth/rubocop-cable_ready/blob/master/CODE_OF_CONDUCT.md).
data/bin/console CHANGED
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "bundler/setup"
5
+ require "rubocop"
5
6
  require "rubocop/cable_ready"
6
7
 
7
8
  # You can add fixtures and/or initialization code here to make experimenting
data/config/default.yml CHANGED
@@ -1,5 +1,15 @@
1
1
  ---
2
- CableReady:
2
+ CableReady/ApplicationRecordEnableUpdates:
3
+ Enabled: true
4
+ Include:
5
+ - "app/models/**/*.rb"
6
+
7
+ CableReady/BroadcasterControllerAction:
8
+ Enabled: false
9
+ Include:
10
+ - "app/controllers/**/*.rb"
11
+
12
+ CableReady/UnusedCableReadyCall:
3
13
  Enabled: true
4
14
  Include:
5
15
  - "**/*.rb"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Rubocop
3
+ module RuboCop
4
4
  module CableReady
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Rubocop
3
+ module RuboCop
4
4
  module CableReady
5
5
  end
6
6
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module CableReady
6
+ class ApplicationRecordEnableUpdates < Base
7
+ MSG = "%<method_name>s should not be switched on globally"
8
+
9
+ def_node_search :active_record_base_class?, <<~PATTERN
10
+ (const (const nil? :ActiveRecord) :Base)
11
+ PATTERN
12
+
13
+ def_node_matcher :is_application_record?, <<~PATTERN
14
+ (const nil? :ApplicationRecord)
15
+ PATTERN
16
+
17
+ def on_send(node)
18
+ receiver_node, _method_name, *_arg_nodes = *node.parent.parent
19
+
20
+ return unless %i[enable_updates enable_cable_ready_updates].include?(node.method_name)
21
+
22
+ return unless is_application_record?(receiver_node)
23
+
24
+ return unless node.ancestors.any? { |ancestor| active_record_base_class?(ancestor) }
25
+
26
+ message = format(MSG, method_name: node.method_name)
27
+ add_offense(node, message: message)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module CableReady
6
+ class BroadcasterControllerAction < Base
7
+ MSG = "CableReady::Broadcaster should not be used in a Rails controller action"
8
+
9
+ def_node_search :action_controller_base_class?, <<~PATTERN
10
+ (const (const nil? :ActionController) :Base)
11
+ PATTERN
12
+
13
+ def on_send(node)
14
+ return if node.method_name != :include
15
+
16
+ return unless node.ancestors.any? { |ancestor| action_controller_base_class?(ancestor) }
17
+
18
+ add_offense(node)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "cable_ready/application_record_enable_updates"
4
+ require_relative "cable_ready/broadcaster_controller_action"
3
5
  require_relative "cable_ready/unused_cable_ready_call"
@@ -4,7 +4,7 @@ require_relative "lib/rubocop/cable_ready/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "rubocop-cable_ready"
7
- spec.version = Rubocop::CableReady::VERSION
7
+ spec.version = RuboCop::CableReady::VERSION
8
8
  spec.authors = ["Marco Roth"]
9
9
  spec.email = ["marco.roth@hey.com"]
10
10
 
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_runtime_dependency "rubocop-ast", ">= 1.1.0"
32
32
 
33
33
  spec.add_development_dependency "rake"
34
+ spec.add_development_dependency "rspec"
34
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-cable_ready
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Roth
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-28 00:00:00.000000000 Z
11
+ date: 2023-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '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: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Code style checking for CableReady
56
70
  email:
57
71
  - marco.roth@hey.com
@@ -76,7 +90,9 @@ files:
76
90
  - lib/rubocop/cable_ready.rb
77
91
  - lib/rubocop/cable_ready/inject.rb
78
92
  - lib/rubocop/cable_ready/version.rb
93
+ - lib/rubocop/cop/cable_ready/application_record_enable_updates.rb
79
94
  - lib/rubocop/cop/cable_ready/base.rb
95
+ - lib/rubocop/cop/cable_ready/broadcaster_controller_action.rb
80
96
  - lib/rubocop/cop/cable_ready/unused_cable_ready_call.rb
81
97
  - lib/rubocop/cop/cable_ready_cops.rb
82
98
  - rubocop-cable_ready.gemspec
@@ -102,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
118
  - !ruby/object:Gem::Version
103
119
  version: '0'
104
120
  requirements: []
105
- rubygems_version: 3.2.15
121
+ rubygems_version: 3.4.1
106
122
  signing_key:
107
123
  specification_version: 4
108
124
  summary: Code style checking for CableReady