From b9d391802ac263299830a08f4e39dd8155ca378c Mon Sep 17 00:00:00 2001 From: ydah Date: Tue, 4 Jun 2024 02:03:47 +0900 Subject: [PATCH] Support `AutoCorrect: contextual` option for LSP Fix: https://github.com/rubocop/rubocop-rspec/issues/1883 --- CHANGELOG.md | 1 + config/default.yml | 22 ++++++++++++--- docs/modules/ROOT/pages/cops_rspec.adoc | 36 ++++++++++++------------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fb385765..2bc0475f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Remove `RSpec/FilePath` cop. ([@ydah]) - Add new `RSpec/ExpectInLet` cop. ([@yasu551]) - Remove `RSpec/Capybara/FeatureMethods` cop. If you are using this cop, change it to use `RSpec/Dialect`. ([@ydah]) +- Support `AutoCorrect: contextual` option for LSP. ([@ydah]) ## 2.29.2 (2024-05-02) diff --git a/config/default.yml b/config/default.yml index da29a180a..36a07ef4f 100644 --- a/config/default.yml +++ b/config/default.yml @@ -147,7 +147,9 @@ RSpec/Be: RSpec/BeEmpty: Description: Prefer using `be_empty` when checking for an empty array. Enabled: pending + AutoCorrect: contextual VersionAdded: '2.20' + VersionChanged: "<>" Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeEmpty RSpec/BeEq: @@ -311,15 +313,18 @@ RSpec/DuplicatedMetadata: RSpec/EmptyExampleGroup: Description: Checks if an example group does not include any tests. Enabled: true + AutoCorrect: contextual SafeAutoCorrect: false VersionAdded: '1.7' - VersionChanged: '2.13' + VersionChanged: "<>" Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyExampleGroup RSpec/EmptyHook: Description: Checks for empty before and after hooks. Enabled: true + AutoCorrect: contextual VersionAdded: '1.39' + VersionChanged: "<>" Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyHook RSpec/EmptyLineAfterExample: @@ -363,7 +368,9 @@ RSpec/EmptyLineAfterSubject: RSpec/EmptyMetadata: Description: Avoid empty metadata hash. Enabled: pending + AutoCorrect: contextual VersionAdded: '2.24' + VersionChanged: "<>" Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyMetadata RSpec/EmptyOutput: @@ -462,8 +469,9 @@ RSpec/ExpectOutput: RSpec/Focus: Description: Checks if examples are focused. Enabled: true + AutoCorrect: contextual VersionAdded: '1.5' - VersionChanged: '2.1' + VersionChanged: "<>" Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Focus RSpec/HookArgument: @@ -481,7 +489,9 @@ RSpec/HookArgument: RSpec/HooksBeforeExamples: Description: Checks for before/around/after hooks that come after an example. Enabled: true + AutoCorrect: contextual VersionAdded: '1.29' + VersionChanged: "<>" Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/HooksBeforeExamples RSpec/IdenticalEqualityAssertion: @@ -587,8 +597,9 @@ RSpec/LeakyConstantDeclaration: RSpec/LetBeforeExamples: Description: Checks for `let` definitions that come after an example. Enabled: true + AutoCorrect: contextual VersionAdded: '1.16' - VersionChanged: '1.22' + VersionChanged: "<>" Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/LetBeforeExamples RSpec/LetSetup: @@ -838,14 +849,17 @@ RSpec/ReturnFromStub: RSpec/ScatteredLet: Description: Checks for let scattered across the example group. Enabled: true + AutoCorrect: contextual VersionAdded: '1.14' - VersionChanged: '1.39' + VersionChanged: "<>" Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ScatteredLet RSpec/ScatteredSetup: Description: Checks for setup scattered across multiple hooks in an example group. Enabled: true + AutoCorrect: contextual VersionAdded: '1.10' + VersionChanged: "<>" Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/ScatteredSetup RSpec/SharedContext: diff --git a/docs/modules/ROOT/pages/cops_rspec.adoc b/docs/modules/ROOT/pages/cops_rspec.adoc index b7f3696c3..46320617d 100644 --- a/docs/modules/ROOT/pages/cops_rspec.adoc +++ b/docs/modules/ROOT/pages/cops_rspec.adoc @@ -199,9 +199,9 @@ expect(foo).to be(true) | Pending | Yes -| Always +| Command-line only | 2.20 -| - +| <> |=== Prefer using `be_empty` when checking for an empty array. @@ -1153,9 +1153,9 @@ describe 'Something', :a | Enabled | Yes -| Always (Unsafe) +| Command-line only (Unsafe) | 1.7 -| 2.13 +| <> |=== Checks if an example group does not include any tests. @@ -1207,9 +1207,9 @@ end | Enabled | Yes -| Always +| Command-line only | 1.39 -| - +| <> |=== Checks for empty before and after hooks. @@ -1510,9 +1510,9 @@ let(:foo) { bar } | Pending | Yes -| Always +| Command-line only | 2.24 -| - +| <> |=== Avoid empty metadata hash. @@ -2127,9 +2127,9 @@ expect { my_app.print_report }.to output('Hello World').to_stdout | Enabled | Yes -| Always +| Command-line only | 1.5 -| 2.1 +| <> |=== Checks if examples are focused. @@ -2289,9 +2289,9 @@ end | Enabled | Yes -| Always +| Command-line only | 1.29 -| - +| <> |=== Checks for before/around/after hooks that come after an example. @@ -3044,9 +3044,9 @@ end | Enabled | Yes -| Always +| Command-line only | 1.16 -| 1.22 +| <> |=== Checks for `let` definitions that come after an example. @@ -5000,9 +5000,9 @@ allow(Foo).to receive(:bar).and_return(bar.baz) | Enabled | Yes -| Always +| Command-line only | 1.14 -| 1.39 +| <> |=== Checks for let scattered across the example group. @@ -5043,9 +5043,9 @@ end | Enabled | Yes -| Always +| Command-line only | 1.10 -| - +| <> |=== Checks for setup scattered across multiple hooks in an example group.