Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create automatic documentation based on the cop's descriptions #51

Merged
merged 12 commits into from
Aug 4, 2023
Merged
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Metrics/BlockLength:
- 'spec/**/*.rb'
- '*.gemspec'

Metrics/MethodLength:
Exclude:
- 'Rakefile'
- '**/*.rake'
- 'spec/**/*.rb'
- '*.gemspec'

Metrics/ClassLength:
Exclude:
- 'tasks/**/*.rb'
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ gem 'pry'
gem 'rake'
gem 'rspec'
gem 'rubocop'
gem 'yard'
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ GEM
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
unicode-display_width (2.4.2)
yard (0.9.34)

PLATFORMS
-darwin-22
Expand All @@ -69,6 +70,7 @@ DEPENDENCIES
rspec
rubocop
rubocop-solidus!
yard

BUNDLED WITH
2.3.26
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ require:

After this simply use the `rubocop` command to start linting.

## Documentation

You can read about each cop supplied by RuboCop Solidus in [the docs](docs/cops.md).

## Creating new cops

To create a new cop, run the following command:
Expand Down
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ require 'rspec/core/rake_task'

Dir['tasks/**/*.rake'].each { |t| load t }

task default: %i[spec rubocop]
task default: %i[
spec
rubocop
generate_cops_documentation
documentation_syntax_check
]

RuboCop::RakeTask.new

Expand Down
19 changes: 19 additions & 0 deletions docs/cops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Available cops

In the following section you find all available cops:

<!-- START_COP_LIST -->
#### Department [Solidus](cops_solidus.md)

* [Solidus/ClassEvalDecorator](cops_solidus.md#solidusclassevaldecorator)
* [Solidus/ReimbursementHookDeprecated](cops_solidus.md#solidusreimbursementhookdeprecated)
* [Solidus/SpreeCalculatorFreeShippingDeprecated](cops_solidus.md#solidusspreecalculatorfreeshippingdeprecated)
* [Solidus/SpreeCalculatorPercentPerItemDeprecated](cops_solidus.md#solidusspreecalculatorpercentperitemdeprecated)
* [Solidus/SpreeCalculatorPriceSackDeprecated](cops_solidus.md#solidusspreecalculatorpricesackdeprecated)
* [Solidus/SpreeDefaultCreditCardDeprecated](cops_solidus.md#solidusspreedefaultcreditcarddeprecated)
* [Solidus/SpreeGatewayBogusDeprecated](cops_solidus.md#solidusspreegatewaybogusdeprecated)
* [Solidus/SpreeIconDeprecated](cops_solidus.md#solidusspreeicondeprecated)
* [Solidus/SpreeRefundCallPerform](cops_solidus.md#solidusspreerefundcallperform)
* [Solidus/SpreeTDeprecated](cops_solidus.md#solidusspreetdeprecated)

<!-- END_COP_LIST -->
276 changes: 276 additions & 0 deletions docs/cops_solidus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
# Solidus

## Solidus/ClassEvalDecorator

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged | Required Solidus Version
--- | --- | --- | --- | --- | ---
Enabled | Yes | No | 0.1.0 | - | -

Solidus suggests a decorator module instead of `class_eval` when overriding some features.
This cop finds any `class_eval` and asks to use a decorator module instead.
More info: https://guides.solidus.io/customization/customizing-the-core.

### Examples

```ruby
# bad
SpreeClass.class_eval do
# your code here
end

# good
module Spree
module SpreeClassDecorator
# your code here
end

Spree::SpreeClass.prepend self
end
```

### References

* [https://github.com/solidusio/rubocop-solidus/issues/21](https://github.com/solidusio/rubocop-solidus/issues/21)

## Solidus/ReimbursementHookDeprecated

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged | Required Solidus Version
--- | --- | --- | --- | --- | ---
Enabled | Yes | No | 0.1.0 | - | 2.11

This cop finds reimbursement_success_hooks and reimbursement_failed_hooks calls and
asks to remove them and subscribe to reimbursement_reimbursed event instead.

### Examples

```ruby
# bad
reimbursement_success_hooks.each { |h| h.call self }
reimbursement_failed_hooks.each { |h| h.call self }

# good
```
```ruby
# bad
reimbursement_success_hooks.any?
reimbursement_failed_hooks.any?

# good
```

### References

* [https://github.com/solidusio/rubocop-solidus/issues/27](https://github.com/solidusio/rubocop-solidus/issues/27)

## Solidus/SpreeCalculatorFreeShippingDeprecated

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged | Required Solidus Version
--- | --- | --- | --- | --- | ---
Enabled | Yes | No | 0.1.0 | - | -

This cop finds Spree::Calculator::FreeShipping calls.
This cop is needed as they have been deprecated in future version.

### Examples

```ruby
# bad
Spree::Calculator::FreeShipping

# good
```

### References

* [https://github.com/solidusio/rubocop-solidus/issues/29](https://github.com/solidusio/rubocop-solidus/issues/29)

## Solidus/SpreeCalculatorPercentPerItemDeprecated

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged | Required Solidus Version
--- | --- | --- | --- | --- | ---
Enabled | Yes | Yes | 0.1.0 | - | -

This cop finds Spree::Calculator::PercentPerItem calls.
This cop is needed as they have been deprecated in future version.

### Examples

```ruby
# bad
Spree::Calculator::PercentPerItem

# good
Spree::Calculator::PercentOnLineItem
```

### References

* [https://github.com/solidusio/rubocop-solidus/issues/29](https://github.com/solidusio/rubocop-solidus/issues/29)

## Solidus/SpreeCalculatorPriceSackDeprecated

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged | Required Solidus Version
--- | --- | --- | --- | --- | ---
Enabled | Yes | No | 0.1.0 | - | -

This cop finds Spree::Calculator::PriceSack calls.
This cop is needed as they have been deprecated in future version.

### Examples

```ruby
# bad
Spree::Calculator::PriceSack

# good
```

### References

* [https://github.com/solidusio/rubocop-solidus/issues/29](https://github.com/solidusio/rubocop-solidus/issues/29)

## Solidus/SpreeDefaultCreditCardDeprecated

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged | Required Solidus Version
--- | --- | --- | --- | --- | ---
Enabled | Yes | Yes | 0.1.0 | - | 2.2

This cop finds user.default_credit_card suggest using user.wallet.default_wallet_payment_source.

### Examples

```ruby
# bad
user.default_credit_card

# good
user.wallet.default_wallet_payment_source
```

### References

* [https://github.com/solidusio/rubocop-solidus/issues/33](https://github.com/solidusio/rubocop-solidus/issues/33)

## Solidus/SpreeGatewayBogusDeprecated

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged | Required Solidus Version
--- | --- | --- | --- | --- | ---
Enabled | Yes | Yes | 0.1.0 | - | 2.1

This cop finds Spree::Gateway::Bogus calls and replaces them with the Spree::PaymentMethod::BogusCreditCard.
This cop is needed as the Spree::Gateway::Bogus has been deprecated in future version.

### Examples

```ruby
# bad
Spree::Gateway::Bogus.new
Spree::Gateway::Bogus.create
Spree::Gateway::Bogus.create!

# good
Spree::PaymentMethod::BogusCreditCard.new
Spree::PaymentMethod::BogusCreditCard.create
Spree::PaymentMethod::BogusCreditCard.create!
```

### References

* [https://github.com/solidusio/rubocop-solidus/issues/26](https://github.com/solidusio/rubocop-solidus/issues/26)

## Solidus/SpreeIconDeprecated

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged | Required Solidus Version
--- | --- | --- | --- | --- | ---
Enabled | Yes | Yes | 0.1.0 | - | 2.3

This cop finds icon helper calls and suggest using solidus_icon.

### Examples

```ruby
# bad
helper.icon('example')

# good
helper.solidus_icon('example')
```

### References

* [https://github.com/solidusio/rubocop-solidus/issues/32](https://github.com/solidusio/rubocop-solidus/issues/32)

## Solidus/SpreeRefundCallPerform

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged | Required Solidus Version
--- | --- | --- | --- | --- | ---
Enabled | Yes | No | 0.1.0 | - | 2.11

This cop finds Spree::Refund.create(your: attributes) calls and
replaces them with the Spree::Refund.create(your: attributes, perform_after_create: false).perform! call.

### Examples

```ruby
# bad
Spree::Refund.create(your: attributes)

# good
Spree::Refund.create(your: attributes, perform_after_create: false).perform!
```

### References

* [https://github.com/solidusio/rubocop-solidus/issues/28](https://github.com/solidusio/rubocop-solidus/issues/28)

## Solidus/SpreeTDeprecated

Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged | Required Solidus Version
--- | --- | --- | --- | --- | ---
Enabled | Yes | Yes | 0.1.0 | - | -

This cop finds Spree.t method calls and replaces them with the I18n,t method call.
This cop is needed as the Spree.t version has been deprecated in future version.

### Examples

```ruby
# Without any parameters

# bad
Spree.t(:bar)

# good
I18n.t(:bar, scope: :spree)
```
```ruby
# With the scope parameter

# bad
Spree.t(:bar, scope: [:city])

# good
I18n.t(:bar, scope: [:spree, :city])
```
```ruby
# With the scope and other parameters

# bad
Spree.t(:bar, scope: [:city], email: email)

# good
I18n.t(:bar, scope: [:spree, :city], email: email)
```
```ruby
# With the scope parameter as a string

# bad
Spree.t('bar', scope: 'admin.city')

# good
I18n.t('bar', scope: 'spree.admin.city')
```

### References

* [https://github.com/solidusio/rubocop-solidus/issues/22](https://github.com/solidusio/rubocop-solidus/issues/22)
4 changes: 4 additions & 0 deletions lib/rubocop/cop/mixin/target_solidus_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def minimum_solidus_version(version)
def targeted_solidus_version?(version)
Gem::Version.new(@minimum_solidus_version) <= Gem::Version.new(version)
end

def required_minimum_solidus_version
@minimum_solidus_version
end
end

# This method overrides the one in RuboCop::Cop::Base.
Expand Down
Loading