rubocop-rspec-extra 0.2.0 → 0.3.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: 15b0c1d5b0b7c30874b0c8f567006e6ae733d4ad096eaa885b9397feed61de69
4
- data.tar.gz: 47e774fa8976ee7a0d8f3b348224d2ccb95bc529334880aa1bd6a71f02e941a2
3
+ metadata.gz: d885353b04e17a9ba6e002a3aeaa1d58726f13d9134edfdbfb5adac37d72d312
4
+ data.tar.gz: 0720cb32f2ce81e26e687870cccd9fc6174e10340f077f50bdbc89661278ae45
5
5
  SHA512:
6
- metadata.gz: 53973d3db669c54dcdcee88596381906a407d33d63eec4c1536c361f118b59de9a3f8bc90a4984462cd6507af0c9bb080cfd59de20724341c6e3fff7969a2609
7
- data.tar.gz: ed2a3474c9676133f943bab5170cc0f0b20a1f5b5f06e8d6f6ba60e8aea78b721838e8df9ff2e8a4d85bc06902489e543e50d2a46d886421727d347fff2bb04a
6
+ metadata.gz: cfd41a33039afbd015fb9ee731ddb16055ecc42e29f844dfba12b307595dd9f06ab1f7d317e8e204ed39932d23b8a679eb3458d0da97e55274909d9e2b3407b8
7
+ data.tar.gz: e178ee6def16d08d667df04bd4fd4514fdc69d110d00dc825f213e5f797deacd8b6078f8b125d7a441643eef32ee5dbfd5a803f6bbc6735ae3d548fa98172751
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
- require:
4
- - rubocop/cop/internal_affairs
3
+ plugins:
4
+ - rubocop-internal_affairs
5
5
  - rubocop-performance
6
6
  - rubocop-rake
7
7
  - rubocop-rspec
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Master (Unreleased)
4
4
 
5
+ ## 0.3.0 (2025-03-19)
6
+
7
+ - Pluginfy RuboCop RSpec Extra. ([@ydah])
8
+ - Add `RSpec/Extra/FlatExamples` cop. ([@ydah])
9
+
5
10
  ## 0.2.0 (2024-03-01)
6
11
 
7
12
  - Fix an error for `RSpec/Extra/RestrictBlockTag`. ([@ydah])
data/Gemfile CHANGED
@@ -9,5 +9,5 @@ gem "rake"
9
9
  gem "rspec", "~> 3.11"
10
10
  gem "rubocop-performance", "~> 1.7"
11
11
  gem "rubocop-rake", "~> 0.6"
12
- gem "rubocop-rspec", "~> 2.18"
12
+ gem "rubocop-rspec", "~> 3.0"
13
13
  gem "yard"
data/README.md CHANGED
@@ -28,13 +28,13 @@ ways to do this:
28
28
  Put this into your `.rubocop.yml`.
29
29
 
30
30
  ```yaml
31
- require: rubocop-rspec-extra
31
+ plugins: rubocop-rspec-extra
32
32
  ```
33
33
 
34
34
  Alternatively, use the following array notation when specifying multiple extensions.
35
35
 
36
36
  ```yaml
37
- require:
37
+ plugins:
38
38
  - rubocop-rspec
39
39
  - rubocop-rspec-extra
40
40
  ```
@@ -42,17 +42,20 @@ require:
42
42
  Now you can run `rubocop` and it will automatically load the RuboCop RSpec Extra
43
43
  cops together with the standard cops.
44
44
 
45
+ > [!NOTE]
46
+ > The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
47
+
45
48
  ### Command line
46
49
 
47
50
  ```bash
48
- rubocop --require rubocop-rspec-extra
51
+ rubocop --plugins rubocop-rspec-extra
49
52
  ```
50
53
 
51
54
  ### Rake task
52
55
 
53
56
  ```ruby
54
57
  RuboCop::RakeTask.new do |task|
55
- task.requires << 'rubocop-rspec-extra'
58
+ task.plugins << 'rubocop-rspec-extra'
56
59
  end
57
60
  ```
58
61
 
@@ -62,7 +65,7 @@ All cops are located under
62
65
  [`lib/rubocop/cop/rspec/extra`](lib/rubocop/cop/rspec/extra), and contain
63
66
  examples/documentation.
64
67
 
65
- In your `.rubocop.yml`, you may treat the Committee cops just like any other
68
+ In your `.rubocop.yml`, you may treat the RSpec extra cops just like any other
66
69
  cop. For example:
67
70
 
68
71
  ```yaml
@@ -77,5 +80,5 @@ Checkout the [contribution guidelines](.github/CONTRIBUTING.md).
77
80
 
78
81
  ## License
79
82
 
80
- `rubocop-committee` is MIT licensed. [See the accompanying file](MIT-LICENSE.md) for
83
+ `rubocop-rspec-extra` is MIT licensed. [See the accompanying file](MIT-LICENSE.md) for
81
84
  the full text.
data/config/default.yml CHANGED
@@ -8,6 +8,11 @@ RSpec/Extra/BeEmpty:
8
8
  VersionAdded: '0.1'
9
9
  Reference: https://www.rubydoc.info/gems/rubocop-rspec-extra/RuboCop/Cop/RSpec/Extra/BeEmpty
10
10
 
11
+ RSpec/Extra/FlatExamples:
12
+ Description: 'Restrict unnecessary nesting by example groups.'
13
+ Enabled: false
14
+ VersionAdded: '0.3'
15
+
11
16
  RSpec/Extra/RestrictBlockTag:
12
17
  Description: 'Restrict to only allowed block tags.'
13
18
  Enabled: false
@@ -2,8 +2,9 @@
2
2
 
3
3
  === Department xref:cops_rspec_extra.adoc[RSpec/Extra]
4
4
 
5
- * xref:cops_rspec_extra.adoc#rspecextra/beempty[RSpec/Extra/BeEmpty]
6
- * xref:cops_rspec_extra.adoc#rspecextra/restrictblocktag[RSpec/Extra/RestrictBlockTag]
7
- * xref:cops_rspec_extra.adoc#rspecextra/restrictblocktagvalue[RSpec/Extra/RestrictBlockTagValue]
5
+ * xref:cops_rspec_extra.adoc#rspecextrabeempty[RSpec/Extra/BeEmpty]
6
+ * xref:cops_rspec_extra.adoc#rspecextraflatexamples[RSpec/Extra/FlatExamples]
7
+ * xref:cops_rspec_extra.adoc#rspecextrarestrictblocktag[RSpec/Extra/RestrictBlockTag]
8
+ * xref:cops_rspec_extra.adoc#rspecextrarestrictblocktagvalue[RSpec/Extra/RestrictBlockTagValue]
8
9
 
9
10
  // END_COP_LIST
@@ -6,20 +6,22 @@
6
6
 
7
7
  = RSpec/Extra
8
8
 
9
+ [#rspecextrabeempty]
9
10
  == RSpec/Extra/BeEmpty
10
11
 
11
12
  |===
12
13
  | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
13
14
 
14
- | Pending
15
+ | Enabled
15
16
  | Yes
16
17
  | Always
17
- | 0.2
18
+ | -
18
19
  | -
19
20
  |===
20
21
 
21
22
  Prefer using `be_empty` when checking for an empty array.
22
23
 
24
+ [#examples-rspecextrabeempty]
23
25
  === Examples
24
26
 
25
27
  [source,ruby]
@@ -38,26 +40,56 @@ expect(array).to match_array([])
38
40
  expect(array).to be_empty
39
41
  ----
40
42
 
41
- === References
43
+ [#rspecextraflatexamples]
44
+ == RSpec/Extra/FlatExamples
45
+
46
+ |===
47
+ | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
48
+
49
+ | Enabled
50
+ | Yes
51
+ | No
52
+ | -
53
+ | -
54
+ |===
55
+
56
+ Restrict unnecessary nesting by example groups.
57
+
58
+ [#examples-rspecextraflatexamples]
59
+ === Examples
60
+
61
+ [source,ruby]
62
+ ----
63
+ # bad
64
+ context 'when condition' do
65
+ it 'tests something' do
66
+ end
67
+ end
42
68
 
43
- * https://www.rubydoc.info/gems/rubocop-rspec-extra/RuboCop/Cop/RSpec/Extra/BeEmpty
69
+ # good
70
+ it 'tests something when condition' do
71
+ end
72
+ ----
44
73
 
74
+ [#rspecextrarestrictblocktag]
45
75
  == RSpec/Extra/RestrictBlockTag
46
76
 
47
77
  |===
48
78
  | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
49
79
 
50
- | Disabled
80
+ | Enabled
51
81
  | Yes
52
82
  | No
53
- | 0.2
83
+ | -
54
84
  | -
55
85
  |===
56
86
 
57
87
  Restrict to only allowed block tags.
58
88
 
89
+ [#examples-rspecextrarestrictblocktag]
59
90
  === Examples
60
91
 
92
+ [#allowtags_-__foo__-_bar__-rspecextrarestrictblocktag]
61
93
  ==== AllowTags: ['foo', 'bar']
62
94
 
63
95
  [source,ruby]
@@ -83,32 +115,25 @@ RSpec.describe 'Something' do
83
115
  end
84
116
  ----
85
117
 
86
- === Configurable attributes
87
-
88
- |===
89
- | Name | Default value | Configurable values
90
-
91
- | AllowTags
92
- | `[]`
93
- | Array
94
- |===
95
-
118
+ [#rspecextrarestrictblocktagvalue]
96
119
  == RSpec/Extra/RestrictBlockTagValue
97
120
 
98
121
  |===
99
122
  | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
100
123
 
101
- | Pending
124
+ | Enabled
102
125
  | Yes
103
126
  | No
104
- | 0.2
127
+ | -
105
128
  | -
106
129
  |===
107
130
 
108
131
  Restrict to only allowed block tag value.
109
132
 
133
+ [#examples-rspecextrarestrictblocktagvalue]
110
134
  === Examples
111
135
 
136
+ [#allowtagvalues_-_-foo_-_baz_-_-rspecextrarestrictblocktagvalue]
112
137
  ==== AllowTagValues: { foo: 'baz' }
113
138
 
114
139
  [source,ruby]
@@ -121,13 +146,3 @@ end
121
146
  RSpec.describe 'Something', foo: :baz do
122
147
  end
123
148
  ----
124
-
125
- === Configurable attributes
126
-
127
- |===
128
- | Name | Default value | Configurable values
129
-
130
- | AllowTagValues
131
- | `{}`
132
- |
133
- |===
@@ -8,13 +8,13 @@ There are some ways to do this:
8
8
  Put this into your `.rubocop.yml`:
9
9
 
10
10
  ----
11
- require: rubocop-rspec-extra
11
+ plugins: rubocop-rspec-extra
12
12
  ----
13
13
 
14
14
  or, if you are using several extensions:
15
15
 
16
16
  ----
17
- require:
17
+ plugins:
18
18
  - rubocop-rspec
19
19
  - rubocop-rspec-extra
20
20
  ----
@@ -24,7 +24,7 @@ cops together with the standard cops.
24
24
 
25
25
  [source,bash]
26
26
  ----
27
- $ rubocop --require rubocop-rspec-extra
27
+ $ rubocop --plugins rubocop-rspec-extra
28
28
  ----
29
29
 
30
30
  == Rake task
@@ -32,6 +32,8 @@ $ rubocop --require rubocop-rspec-extra
32
32
  [source,ruby]
33
33
  ----
34
34
  RuboCop::RakeTask.new do |task|
35
- task.requires << 'rubocop-rspec-extra'
35
+ task.plugins << 'rubocop-rspec-extra'
36
36
  end
37
37
  ----
38
+
39
+ NOTE: The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
@@ -57,7 +57,7 @@ module RuboCop
57
57
  )
58
58
  PATTERN
59
59
 
60
- def on_send(node)
60
+ def on_send(node) # rubocop:disable InternalAffairs/OnSendWithoutOnCSend
61
61
  expect_array_empty_true?(node.parent) do |actual, expect|
62
62
  register_offense(actual, expect)
63
63
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module RSpec
6
+ module Extra
7
+ # Restrict unnecessary nesting by example groups.
8
+ #
9
+ # @example
10
+ # # bad
11
+ # context 'when condition' do
12
+ # it 'tests something' do
13
+ # end
14
+ # end
15
+ #
16
+ # # good
17
+ # it 'tests something when condition' do
18
+ # end
19
+ #
20
+ class FlatExamples < Base
21
+ MSG = "Unnecessary nesting by example groups detected."
22
+
23
+ # @!method redundant?(node)
24
+ def_node_matcher :redundant?, <<~PATTERN
25
+ (block (send #rspec? #ExampleGroups.regular ...) _ (block (send _ #Examples.regular ...) ...))
26
+ PATTERN
27
+
28
+ def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
29
+ return unless redundant?(node)
30
+
31
+ add_offense(node)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lint_roller"
4
+
5
+ module RuboCop
6
+ module RSpec
7
+ module Extra
8
+ # A plugin that integrates RuboCop RSpec Extra with RuboCop's plugin system.
9
+ class Plugin < LintRoller::Plugin
10
+ def about
11
+ LintRoller::About.new(
12
+ name: "rubocop-rspec-extra",
13
+ version: Version::STRING,
14
+ homepage: "https://github.com/ydah/rubocop-rspec-extra",
15
+ description: "A RuboCop extension focused on enforcing RSpec. A place where no one is officially employed, but where useful cops can gather."
16
+ )
17
+ end
18
+
19
+ def supported?(context)
20
+ context.engine == :rubocop
21
+ end
22
+
23
+ def rules(_context)
24
+ project_root = Pathname.new(__dir__).join("../../../..")
25
+
26
+ LintRoller::Rules.new(type: :path, config_format: :rubocop, value: project_root.join("config", "default.yml"))
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rubocop
4
- module Rspec
4
+ module RSpec
5
5
  module Extra
6
- VERSION = "0.2.0"
6
+ VERSION = "0.3.0"
7
7
  end
8
8
  end
9
9
  end
@@ -2,22 +2,17 @@
2
2
 
3
3
  require "rubocop-rspec"
4
4
 
5
- require_relative "rubocop/rspec/extra/inject"
6
5
  require_relative "rubocop/rspec/extra/version"
7
-
6
+ require_relative "rubocop/rspec/extra/plugin"
8
7
  require_relative "rubocop/cop/rspec/extra/be_empty"
8
+ require_relative "rubocop/cop/rspec/extra/flat_examples"
9
9
  require_relative "rubocop/cop/rspec/extra/restrict_block_tag"
10
10
  require_relative "rubocop/cop/rspec/extra/restrict_block_tag_value"
11
11
 
12
- module RuboCop
12
+ module Rubocop
13
13
  module RSpec
14
+ # RuboCop RSpec Rails project namespace.
14
15
  module Extra
15
- PROJECT_ROOT = ::Pathname.new(__dir__).parent.expand_path.freeze
16
- CONFIG_DEFAULT = PROJECT_ROOT.join("config", "default.yml").freeze
17
- CONFIG = ::YAML.safe_load(CONFIG_DEFAULT.read).freeze
18
- private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
19
16
  end
20
17
  end
21
18
  end
22
-
23
- RuboCop::RSpec::Extra::Inject.defaults!
@@ -13,7 +13,7 @@ namespace :cut_release do
13
13
  def add_header_to_changelog(version)
14
14
  update_file("CHANGELOG.md") do |changelog|
15
15
  changelog.sub("## Master (Unreleased)\n\n",
16
- '\0' "## #{version} (#{Time.now.strftime("%F")})\n\n")
16
+ "\\0## #{version} (#{Time.now.strftime("%F")})\n\n")
17
17
  end
18
18
  end
19
19
 
metadata CHANGED
@@ -1,29 +1,48 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-rspec-extra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ydah
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-02-29 00:00:00.000000000 Z
10
+ date: 2025-03-18 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: lint_roller
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.1'
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: rubocop
15
28
  requirement: !ruby/object:Gem::Requirement
16
29
  requirements:
17
30
  - - ">="
18
31
  - !ruby/object:Gem::Version
19
- version: '0'
32
+ version: 1.72.1
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: '2.0'
20
36
  type: :runtime
21
37
  prerelease: false
22
38
  version_requirements: !ruby/object:Gem::Requirement
23
39
  requirements:
24
40
  - - ">="
25
41
  - !ruby/object:Gem::Version
26
- version: '0'
42
+ version: 1.72.1
43
+ - - "<"
44
+ - !ruby/object:Gem::Version
45
+ version: '2.0'
27
46
  description: |
28
47
  A RuboCop extension focused on enforcing RSpec.
29
48
  A place where no one is officially employed, but where useful cops can gather.
@@ -55,9 +74,10 @@ files:
55
74
  - docs/modules/ROOT/pages/usage.adoc
56
75
  - lib/rubocop-rspec-extra.rb
57
76
  - lib/rubocop/cop/rspec/extra/be_empty.rb
77
+ - lib/rubocop/cop/rspec/extra/flat_examples.rb
58
78
  - lib/rubocop/cop/rspec/extra/restrict_block_tag.rb
59
79
  - lib/rubocop/cop/rspec/extra/restrict_block_tag_value.rb
60
- - lib/rubocop/rspec/extra/inject.rb
80
+ - lib/rubocop/rspec/extra/plugin.rb
61
81
  - lib/rubocop/rspec/extra/version.rb
62
82
  - tasks/cops_documentation.rake
63
83
  - tasks/cut_release.rake
@@ -69,8 +89,8 @@ metadata:
69
89
  homepage_uri: https://github.com/ydah/rubocop-rspec-extra
70
90
  source_code_uri: https://github.com/ydah/rubocop-rspec-extra
71
91
  changelog_uri: https://github.com/ydah/rubocop-rspec-extra/blob/master/CHANGELOG.md
92
+ default_lint_roller_plugin: RuboCop::RSpec::Extra::Plugin
72
93
  rubygems_mfa_required: 'true'
73
- post_install_message:
74
94
  rdoc_options: []
75
95
  require_paths:
76
96
  - lib
@@ -85,8 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
105
  - !ruby/object:Gem::Version
86
106
  version: '0'
87
107
  requirements: []
88
- rubygems_version: 3.5.3
89
- signing_key:
108
+ rubygems_version: 3.7.0.dev
90
109
  specification_version: 4
91
110
  summary: A RuboCop extension focused on enforcing RSpec.
92
111
  test_files: []
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module RSpec
5
- module Extra
6
- module Inject
7
- def self.defaults!
8
- path = CONFIG_DEFAULT.to_s
9
- hash = ::RuboCop::ConfigLoader.send(:load_yaml_configuration, path)
10
- config = ::RuboCop::Config.new(hash, path).tap(&:make_excludes_absolute)
11
- puts "configuration from #{path}" if ::RuboCop::ConfigLoader.debug?
12
- config = ::RuboCop::ConfigLoader.merge_with_default(config, path)
13
- ::RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
14
- end
15
- end
16
- end
17
- end
18
- end