rubocop-openproject 0.2.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b7762dbbe159ef129537b0da6ca121fde8f6417a92ae9d55acff9af82002456
4
- data.tar.gz: f1193f7c4cf3b908b52a29649927a6e73a5f39376a79e69e0c0540461600ed01
3
+ metadata.gz: 9cfe3bab3bbbc3032190c71f7e824eb2d451f854248d076aca30db79723f346b
4
+ data.tar.gz: b265782c32033cd8315f9a0b3bef3cb4cf7c0bdcf01d3fb85de59559fa9a9935
5
5
  SHA512:
6
- metadata.gz: 8d78e20f34afc1d1ac0ffcafa68a1a0953e49b7952d62e0ced2f78866500c43708294f5131796e0e2583c0aa0eab031fdfe818f063184313ef5747642ffcca21
7
- data.tar.gz: 0d590796e0332ab1679f46062f967d4ab0bee76a97f7f7dc85617dc1186e60437e08071c4c1b6e6981a17fd2262e834fcd9294eb53c1751f9c31d81f1d85a5ff
6
+ metadata.gz: cde9e717e29db386ab61514b4533f0861956fe2aefe5eeadc9b5baf0c12fb4fa3851f565c0cab2ca9919ed652c27623a45ef1f41ed9c6f2f9bce81fcf2f9aff7
7
+ data.tar.gz: 690ebd432e8719ba28f5bd2e146304883626dde1cdd8fab45a6dc518cf16401615c3cdab7382c258db7cc166b40baac9e512c915a26a59aafe5fbb0897d74d22
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] - 2026-03-27
4
+
5
+ - Add NoNotImplementedError cop
6
+
7
+ ## [0.3.0] - 2025-07-11
8
+
9
+ - Remove redundant NoDoEndBlockWithRSpecCapybaraMatcherInExpect cop
10
+
3
11
  ## [0.2.0] - 2024-10-18
4
12
 
5
13
  - Add `OpenProject/NoSleepInFeatureSpecs` cop to check that `sleep` calls in
data/README.md CHANGED
@@ -26,6 +26,15 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
26
26
 
27
27
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
28
 
29
+ ## Releasing
30
+
31
+ 1. Update the version in `lib/rubocop/open_project/version.rb`
32
+ 2. Update the changelog in `CHANGELOG.md`
33
+ 3. Run `bundle install` to update `Gemfile.lock`
34
+ 4. Run `rake` to check everything is fine and fix any issues
35
+ 5. Commit your changes (`git commit -am 'Prepare release X.Y.Z'`)
36
+ 6. Run `bundle exec rake release`
37
+
29
38
  ## Contributing
30
39
 
31
40
  Bug reports and pull requests are welcome on GitHub at https://github.com/opf/rubocop-openproject.
data/config/default.yml CHANGED
@@ -8,6 +8,11 @@ OpenProject/NoDoEndBlockWithRSpecCapybaraMatcherInExpect:
8
8
  Enabled: true
9
9
  VersionAdded: '0.1.0'
10
10
 
11
+ OpenProject/NoNotImplementedError:
12
+ Description: 'Do not raise `NotImplementedError` to signal an unimplemented abstract method.'
13
+ Enabled: true
14
+ VersionAdded: '0.4.0'
15
+
11
16
  OpenProject/NoSleepInFeatureSpecs:
12
17
  Description: 'Avoid using `sleep` greater than 1 second in feature specs.'
13
18
  Enabled: true
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module OpenProject
6
+ # Warns against using a `NotImplementedError` exception when a method
7
+ # should be implemented by a subclass or including module. Ruby's
8
+ # `NotImplementedError` is reserved for platform-specific missing
9
+ # features (e.g., methods depending on `fsync` or `fork`), not for
10
+ # abstract method patterns.
11
+ #
12
+ # @example
13
+ # # bad
14
+ # raise NotImplementedError
15
+ #
16
+ # # bad
17
+ # raise NotImplementedError, "Subclasses must implement #foo"
18
+ #
19
+ # # bad
20
+ # raise NotImplementedError.new("Subclasses must implement #foo")
21
+ #
22
+ # # bad
23
+ # fail NotImplementedError
24
+ #
25
+ # # good
26
+ # raise NotYetImplementedError
27
+ #
28
+ # # good
29
+ # raise SubclassResponsibilityError, "#{self.class} must implement #foo"
30
+ #
31
+ class NoNotImplementedError < Base
32
+ MSG = "Do not raise `NotImplementedError` to signal an unimplemented abstract method. " \
33
+ "Ruby's `NotImplementedError` is reserved for platform-specific missing features. " \
34
+ "Raise a descriptive custom error class instead."
35
+
36
+ RESTRICT_ON_SEND = %i[raise fail].freeze
37
+
38
+ def_node_matcher :raises_not_implemented_error?, <<~PATTERN
39
+ {
40
+ (send nil? {:raise :fail} (const nil? :NotImplementedError) ...)
41
+ (send nil? {:raise :fail} (send (const nil? :NotImplementedError) :new ...) ...)
42
+ }
43
+ PATTERN
44
+
45
+ def on_send(node)
46
+ return unless raises_not_implemented_error?(node)
47
+
48
+ add_offense(node)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "open_project/add_preview_for_view_component"
4
- require_relative "open_project/no_do_end_block_with_rspec_capybara_matcher_in_expect"
4
+ require_relative "open_project/no_not_implemented_error"
5
5
  require_relative "open_project/use_service_result_factory_methods"
6
6
  require_relative "open_project/no_sleep_in_feature_specs"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module OpenProject
5
- VERSION = "0.2.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-openproject
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenProject GmbH
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2024-10-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rubocop
@@ -39,7 +39,7 @@ files:
39
39
  - config/default.yml
40
40
  - lib/rubocop-openproject.rb
41
41
  - lib/rubocop/cop/open_project/add_preview_for_view_component.rb
42
- - lib/rubocop/cop/open_project/no_do_end_block_with_rspec_capybara_matcher_in_expect.rb
42
+ - lib/rubocop/cop/open_project/no_not_implemented_error.rb
43
43
  - lib/rubocop/cop/open_project/no_sleep_in_feature_specs.rb
44
44
  - lib/rubocop/cop/open_project/use_service_result_factory_methods.rb
45
45
  - lib/rubocop/cop/open_project_cops.rb
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubygems_version: 3.6.0.dev
71
+ rubygems_version: 3.6.9
72
72
  specification_version: 4
73
73
  summary: RuboCop cops for OpenProject
74
74
  test_files: []
@@ -1,89 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module OpenProject
6
- # As +do .. end+ block has less precedence than method call, a +do .. end+
7
- # block at the end of a rspec matcher will be an argument to the +to+ method,
8
- # which is not handled by Capybara matchers (teamcapybara/capybara/#2616).
9
- #
10
- # @example
11
- #
12
- # # bad
13
- # expect(page).to have_selector("input") do |input|
14
- # input.value == "hello world"
15
- # end
16
- #
17
- # # good
18
- # expect(page).to have_selector("input") { |input| input.value == "hello world" }
19
- #
20
- # # good
21
- # expect(page).to have_selector("input", value: "hello world")
22
- #
23
- # # good
24
- # match_input_with_hello_world = have_selector("input") do |input|
25
- # input.value == "hello world"
26
- # end
27
- # expect(page).to match_input_with_hello_world
28
- #
29
- # # good
30
- # expect(foo).to have_received(:bar) do |arg|
31
- # arg == :baz
32
- # end
33
- #
34
- class NoDoEndBlockWithRSpecCapybaraMatcherInExpect < Base
35
- CAPYBARA_MATCHER_METHODS = %w[selector css xpath text title current_path link button
36
- field checked_field unchecked_field select table
37
- sibling ancestor].flat_map do |matcher_type|
38
- ["have_#{matcher_type}", "have_no_#{matcher_type}"]
39
- end
40
-
41
- MSG = "The `do .. end` block is associated with `to` and not with Capybara matcher `%<matcher_method>s`."
42
-
43
- def_node_matcher :expect_to_with_block?, <<~PATTERN
44
- # ruby-parse output
45
- (block
46
- (send
47
- (send nil? :expect ...)
48
- :to
49
- ...
50
- )
51
- ...
52
- )
53
- PATTERN
54
-
55
- def_node_matcher :rspec_matcher, <<~PATTERN
56
- (send
57
- (send nil? :expect...)
58
- :to
59
- (:send nil? $_matcher_method ...)
60
- )
61
- PATTERN
62
-
63
- def on_block(node)
64
- return unless expect_to_with_block?(node)
65
- return unless capybara_matcher?(node)
66
-
67
- add_offense(offense_range(node), message: offense_message(node))
68
- end
69
-
70
- private
71
-
72
- def capybara_matcher?(node)
73
- matcher_name = node.send_node.arguments.first.method_name.to_s
74
- CAPYBARA_MATCHER_METHODS.include?(matcher_name)
75
- end
76
-
77
- def offense_range(node)
78
- node.send_node.loc.selector.join(node.loc.end)
79
- end
80
-
81
- def offense_message(node)
82
- rspec_matcher(node.send_node) do |matcher_method|
83
- format(MSG, matcher_method:)
84
- end
85
- end
86
- end
87
- end
88
- end
89
- end