rubocop-munra 0.1.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 +7 -0
- data/.ruby-version +1 -0
- data/AGENTS.md +99 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +42 -0
- data/config/default.yml +27 -0
- data/docs/modules/ROOT/pages/cops.adoc +2 -0
- data/docs/modules/ROOT/pages/cops_munra.adoc +336 -0
- data/docs/usage.md +160 -0
- data/lib/rubocop/cop/munra/00_class_body_helper.rb +27 -0
- data/lib/rubocop/cop/munra/00_rspec_helpers.rb +66 -0
- data/lib/rubocop/cop/munra/00_transaction_block_mixin.rb +49 -0
- data/lib/rubocop/cop/munra/let_layout.rb +155 -0
- data/lib/rubocop/cop/munra/named_subject_layout.rb +165 -0
- data/lib/rubocop/cop/munra/no_human_attribute_name.rb +31 -0
- data/lib/rubocop/cop/munra/no_leading_dot.rb +25 -0
- data/lib/rubocop/cop/munra/no_spec_method.rb +28 -0
- data/lib/rubocop/cop/munra/no_transaction_exit.rb +42 -0
- data/lib/rubocop/cop/munra/success_error_siblings.rb +82 -0
- data/lib/rubocop/cop/munra.rb +20 -0
- data/lib/rubocop/munra/plugin.rb +39 -0
- data/lib/rubocop/munra/version.rb +14 -0
- data/lib/rubocop-munra.rb +13 -0
- data/sig/rubocop/munra.rbs +6 -0
- metadata +107 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 211baee15bec0968116998e15c534d185f9a314ea6525b77b5c8bc3cd1fbfe55
|
|
4
|
+
data.tar.gz: 5e878ca780b3c71f83203916de0b022b8515064bbf05f014d7a779dedbde8e3c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e745965b64049bdc5c816e4a15d9dfe71e4016ac48cf0823a4cd4f6777ce14695862f541f746a34195dd9f233dfcb774758d1af630f73b81251940762b2413e7
|
|
7
|
+
data.tar.gz: f2e099f19538fa6e1fb6c177973cf732dab54301fb6bbd325f52391d01cf1e257641e5edf8f4c77483cd9f91465d753637bfc289ad71fa395f1ef291863e7179
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.2.0
|
data/AGENTS.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# AGENTS.md — rubocop-munra
|
|
2
|
+
|
|
3
|
+
RuboCop plugin (department `Munra`) consumed by Rails apps through Bundler (`path:`, `git:`, or RubyGems).
|
|
4
|
+
|
|
5
|
+
Write code, comments, docs, commit messages, issues, and pull requests in English.
|
|
6
|
+
|
|
7
|
+
## Git
|
|
8
|
+
|
|
9
|
+
Treat the session as **Orca** when the working tree path contains `/orca/workspaces/` or when `ORCA=1` is set in the environment. Otherwise treat it as a local (non-Orca) session.
|
|
10
|
+
|
|
11
|
+
### Inside Orca
|
|
12
|
+
|
|
13
|
+
Stage, commit, push, and open pull requests as the issue or task requires. Use English commit messages and PR bodies. A cop PR links the issue (`Closes #N`) and describes the cop, the config keys, and how to override them. Do not leave finished work unstaged or unpushed when the card asks for a PR.
|
|
14
|
+
|
|
15
|
+
### Outside Orca
|
|
16
|
+
|
|
17
|
+
Do not stage or commit. Never run `git add`, `git restore --staged`, `git rm`, or `git commit`. Leave every change unstaged in the working tree. The user reviews the diff locally and stages and commits it.
|
|
18
|
+
|
|
19
|
+
Do not push unless the user asks.
|
|
20
|
+
|
|
21
|
+
## Ruby
|
|
22
|
+
|
|
23
|
+
Develop on Ruby 3.2.0, the oldest version this gem supports. `.ruby-version` pins rbenv to that interpreter. Before running Bundler, RuboCop, or tests, `ruby -v` must report 3.2.0.
|
|
24
|
+
|
|
25
|
+
The published gem must run on every Ruby from 3.2.0 upward. Do not use syntax or standard-library behavior added after 3.2.0. Keep `required_ruby_version` at `>= 3.2.0` in the gemspec and `TargetRubyVersion: 3.2` in `.rubocop.yml`.
|
|
26
|
+
|
|
27
|
+
## Layout
|
|
28
|
+
|
|
29
|
+
| Piece | Where |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| Cop | `lib/rubocop/cop/munra/<snake_case>.rb` |
|
|
32
|
+
| Defaults / options | `config/default.yml` (`Munra/<CopName>`) |
|
|
33
|
+
| Cop test | `test/rubocop/cop/munra/<snake_case>_test.rb` (Minitest) |
|
|
34
|
+
| Other class test | `test/` path that mirrors `lib/`, one test class per implementation class |
|
|
35
|
+
| User guide | `docs/usage.md` |
|
|
36
|
+
| Generated cop reference | `docs/modules/ROOT/pages/cops_munra.adoc` |
|
|
37
|
+
|
|
38
|
+
`lib/rubocop/cop/munra.rb` `require`s every file in `munra/` in alphabetical order. Helpers use the `00_` prefix so they load before cops. Do not edit the loader when adding a cop.
|
|
39
|
+
|
|
40
|
+
Keep `Munra/<CopName>` entries in `config/default.yml` in alphabetical order by cop name. Whenever a cop is added or removed, leave the remaining declarations sorted among themselves.
|
|
41
|
+
|
|
42
|
+
The generated `docs/modules/ROOT/pages/cops_munra.adoc` must list cops in alphabetical order by name as well. After adding or removing a cop, regenerate the reference and confirm the sections stay sorted.
|
|
43
|
+
|
|
44
|
+
## After every change
|
|
45
|
+
|
|
46
|
+
Run both, and do not finish while either fails:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
bundle exec rubocop
|
|
50
|
+
bundle exec rake test
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`rake test` starts SimpleCov. Line and branch coverage of `lib/**/*.rb` must stay at 100% for the run and for each file (`minimum_coverage` / `minimum_coverage_by_file` in `test/test_helper.rb`). Do not lower those thresholds to make a change pass. Cover the new paths instead.
|
|
54
|
+
|
|
55
|
+
`bundle exec rake` runs the test task and RuboCop.
|
|
56
|
+
|
|
57
|
+
## Tests
|
|
58
|
+
|
|
59
|
+
- Write examples with Minitest's spec DSL: `describe`, `context`, `let`, `subject`, and `it` (`test/test_helper.rb`). Do not add examples as `def test_*` methods. `context` groups a condition. `subject` is the object under test. `let` holds the other values an example needs.
|
|
60
|
+
- Do not leave a bare `it` as a sibling of a nested `describe` / `context`. Wrap that example in its own `context` (preferred) or `describe` so every `it` sits under a grouping block.
|
|
61
|
+
- Prefer `let` (and `subject`) over local variables inside `it` blocks. If a value is assigned and then used in assertions, move it to a `let` on the surrounding `describe` / `context`. Keep a local only when it cannot live in `let` (for example a path bound inside `Dir.mktmpdir`).
|
|
62
|
+
- One spec file per implementation class. A cop `Munra/NoLeadingDot` is specified in `test/rubocop/cop/munra/no_leading_dot_test.rb`. A mixin or plugin class gets its own file; do not fold several classes into one unrelated spec.
|
|
63
|
+
- Prefer unit tests that call the class directly. Build real AST with `parse_source` / `inspect_cop` (`test/test_helper.rb`) and real config objects. Also keep integration coverage for plugin loading and the default config file.
|
|
64
|
+
- Do not use mocks, stubs, or spies unless the dependency cannot be constructed in-process (network, clock, process). A small `Struct` for a LintRoller context is not a mock. Do not stub RuboCop, the file system, or the class under test.
|
|
65
|
+
- Assert the behavior of the implementation: offenses, config keys, and return values. Do not assert private call sequences.
|
|
66
|
+
- Within an `it`, keep comparable assertions in alphabetical order: constant paths by full namespace and class name, config dig keys and similar string identifiers by the key being asserted. Sort each homogeneous list among itself (for example department options together, then cop names together).
|
|
67
|
+
- Cop tests go through `inspect_cop`. Pass `cop_config` when the example depends on an override.
|
|
68
|
+
|
|
69
|
+
## Documentation
|
|
70
|
+
|
|
71
|
+
Document public classes, modules, and non-obvious methods with YARD comments in English (`@param`, `@return`, `@example` where a sample helps).
|
|
72
|
+
|
|
73
|
+
Cop classes need a prose description and `@example` blocks (`# bad` / `# good`) so RuboCop's documentation generator can render them. Domain constants (attribute names, superclasses, allowed files) belong in `config/default.yml` and are read with `cop_config`. Generic style or RSpec conventions may stay in code.
|
|
74
|
+
|
|
75
|
+
When a cop, its comment, or `config/default.yml` changes, regenerate the reference:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
bundle exec rake generate_cops_documentation
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Do not hand-edit `docs/modules/ROOT/pages/cops_munra.adoc` or `docs/modules/ROOT/pages/cops.adoc`. After `rake generate_cops_documentation`, the cop sections in `cops_munra.adoc` must remain in alphabetical order by cop name. Include the regenerated files in the same change set (commit them under Orca Git rules; leave them unstaged outside Orca). Update `docs/usage.md` when install or configuration behavior changes. The guide must keep working examples of enabling the plugin, disabling a cop, `Include` / `Exclude`, and overriding options.
|
|
82
|
+
|
|
83
|
+
## New cop
|
|
84
|
+
|
|
85
|
+
1. Implement `lib/rubocop/cop/munra/<snake_case>.rb` with class docs and examples.
|
|
86
|
+
2. Register defaults under `Munra/<CopName>` in `config/default.yml`, inserted in alphabetical order among the other cops.
|
|
87
|
+
3. Add `test/rubocop/cop/munra/<snake_case>_test.rb` using the Minitest spec DSL rules above.
|
|
88
|
+
4. Update `test/rubocop/munra/load_test.rb`: assert the new constant and the `Munra/<CopName>` config dig, both in alphabetical order among the existing asserts.
|
|
89
|
+
5. Run RuboCop, the full test suite (100% coverage), and `rake generate_cops_documentation`. Confirm `cops_munra.adoc` sections stay alphabetical.
|
|
90
|
+
6. Follow the Git rules above (commit/push/PR in Orca; leave unstaged outside Orca).
|
|
91
|
+
7. In the consuming app, set only `Include`, `Exclude`, and overrides in `.rubocop.yml`. Do not copy the cop into the app.
|
|
92
|
+
|
|
93
|
+
## GitHub
|
|
94
|
+
|
|
95
|
+
Issues, pull requests, and review comments are in English. A cop pull request links the issue (`Closes #N`) and describes the cop, the config keys, and how to override them.
|
|
96
|
+
|
|
97
|
+
## Workspace
|
|
98
|
+
|
|
99
|
+
Tasks that touch cops and a consuming app should use a multi-root workspace (app + this gem).
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
"rubocop-munra" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
+
|
|
5
|
+
* Participants will be tolerant of opposing views.
|
|
6
|
+
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
+
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
+
|
|
10
|
+
If you have any concerns about behaviour within this project, please contact us at ["ramonsantos.pe@gmail.com"](mailto:"ramonsantos.pe@gmail.com").
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ramonsantos
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# rubocop-munra
|
|
2
|
+
|
|
3
|
+
Custom RuboCop cops (department `Munra`) for Rails application conventions.
|
|
4
|
+
|
|
5
|
+
Requires Ruby 3.2.0 or newer.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
# Gemfile
|
|
11
|
+
gem 'rubocop-munra', path: '../../rubocop-munra'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
bundle install
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
In `.rubocop.yml`:
|
|
21
|
+
|
|
22
|
+
```yaml
|
|
23
|
+
plugins:
|
|
24
|
+
- rubocop-munra
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Enable or disable the department, restrict paths, and override cop options in the app. The gem keeps the defaults.
|
|
28
|
+
|
|
29
|
+
Configuration examples, `Include` / `Exclude`, and option overrides: [docs/usage.md](docs/usage.md).
|
|
30
|
+
|
|
31
|
+
Per-cop reference (generated from the cop sources): [docs/modules/ROOT/pages/cops_munra.adoc](docs/modules/ROOT/pages/cops_munra.adoc).
|
|
32
|
+
|
|
33
|
+
## Development
|
|
34
|
+
|
|
35
|
+
Development uses Ruby 3.2.0 (`.ruby-version`). The gem stays compatible with every Ruby from that version upward.
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
bundle install
|
|
39
|
+
bundle exec rubocop
|
|
40
|
+
bundle exec rake test
|
|
41
|
+
bundle exec rake generate_cops_documentation
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`rake test` requires 100% line and branch coverage of `lib/`. See [AGENTS.md](AGENTS.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
|
|
5
|
+
desc 'Run the Minitest suite with SimpleCov started before the tests'
|
|
6
|
+
task :test do
|
|
7
|
+
ruby '-Ilib:test -w test/suite.rb'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
require 'rubocop/rake_task'
|
|
11
|
+
|
|
12
|
+
RuboCop::RakeTask.new
|
|
13
|
+
|
|
14
|
+
desc 'Generate AsciiDoc cop documentation from source comments and config/default.yml'
|
|
15
|
+
task :generate_cops_documentation do
|
|
16
|
+
require 'yard'
|
|
17
|
+
require 'rubocop'
|
|
18
|
+
require 'rubocop-munra'
|
|
19
|
+
require 'rubocop/cops_documentation_generator'
|
|
20
|
+
|
|
21
|
+
munra_cop_files = Dir[File.expand_path('lib/rubocop/cop/munra/*.rb', __dir__)]
|
|
22
|
+
generator = CopsDocumentationGenerator.new(
|
|
23
|
+
departments: %w[Munra],
|
|
24
|
+
plugin_name: 'rubocop-munra'
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# `CopsDocumentationGenerator#call` only loads an existing `.yardoc` database.
|
|
28
|
+
# Parse Munra cop sources into the registry so class comments become AsciiDoc
|
|
29
|
+
# without requiring a separate `yard` run first.
|
|
30
|
+
generator.define_singleton_method(:call) do
|
|
31
|
+
YARD::Registry.load!
|
|
32
|
+
YARD.parse(munra_cop_files)
|
|
33
|
+
departments.each { |department| print_cops_of_department(department) }
|
|
34
|
+
print_table_of_contents
|
|
35
|
+
ensure
|
|
36
|
+
RuboCop::ConfigLoader.default_configuration = nil
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
generator.call
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
task default: %i[test rubocop]
|
data/config/default.yml
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
Munra:
|
|
3
|
+
Enabled: true
|
|
4
|
+
# GitHub pages for generated cop docs. Fragment is the cop name without a slash.
|
|
5
|
+
DocumentationBaseURL: https://github.com/ramonsantos/rubocop-munra/blob/main/docs/modules/ROOT/pages
|
|
6
|
+
DocumentationExtension: .adoc
|
|
7
|
+
|
|
8
|
+
Munra/LetLayout:
|
|
9
|
+
Enabled: true
|
|
10
|
+
|
|
11
|
+
Munra/NamedSubjectLayout:
|
|
12
|
+
Enabled: true
|
|
13
|
+
|
|
14
|
+
Munra/NoHumanAttributeName:
|
|
15
|
+
Enabled: true
|
|
16
|
+
|
|
17
|
+
Munra/NoLeadingDot:
|
|
18
|
+
Enabled: true
|
|
19
|
+
|
|
20
|
+
Munra/NoSpecMethod:
|
|
21
|
+
Enabled: true
|
|
22
|
+
|
|
23
|
+
Munra/NoTransactionExit:
|
|
24
|
+
Enabled: true
|
|
25
|
+
|
|
26
|
+
Munra/SuccessErrorSiblings:
|
|
27
|
+
Enabled: true
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
////
|
|
2
|
+
Do NOT edit this file by hand directly, as it is automatically generated.
|
|
3
|
+
|
|
4
|
+
Please make any necessary changes to the cop documentation within the source files themselves.
|
|
5
|
+
////
|
|
6
|
+
|
|
7
|
+
= Munra
|
|
8
|
+
|
|
9
|
+
[#munraletlayout]
|
|
10
|
+
== Munra/LetLayout
|
|
11
|
+
|
|
12
|
+
|===
|
|
13
|
+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
|
|
14
|
+
|
|
15
|
+
| Enabled
|
|
16
|
+
| Yes
|
|
17
|
+
| No
|
|
18
|
+
| -
|
|
19
|
+
| -
|
|
20
|
+
|===
|
|
21
|
+
|
|
22
|
+
Enforces blank lines and ordering for single-line versus multi-line `let` blocks.
|
|
23
|
+
|
|
24
|
+
Single-line `let` declarations stay together without blank lines between them,
|
|
25
|
+
and they come before multi-line `let` blocks. A multi-line `let` has a blank
|
|
26
|
+
line before and after it. The blank line before it is unnecessary when the
|
|
27
|
+
previous line is empty or already opens the surrounding block.
|
|
28
|
+
|
|
29
|
+
[#examples-munraletlayout]
|
|
30
|
+
=== Examples
|
|
31
|
+
|
|
32
|
+
[#single-line-lets-stay-together-munraletlayout]
|
|
33
|
+
==== Single-line lets stay together
|
|
34
|
+
|
|
35
|
+
[source,ruby]
|
|
36
|
+
----
|
|
37
|
+
# bad
|
|
38
|
+
RSpec.describe Foo do
|
|
39
|
+
let(:name) { 'Ada' }
|
|
40
|
+
|
|
41
|
+
let(:role) { 'admin' }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# good
|
|
45
|
+
RSpec.describe Foo do
|
|
46
|
+
let(:name) { 'Ada' }
|
|
47
|
+
let(:role) { 'admin' }
|
|
48
|
+
end
|
|
49
|
+
----
|
|
50
|
+
|
|
51
|
+
[#multi-line-lets-are-surrounded-by-blank-lines-munraletlayout]
|
|
52
|
+
==== Multi-line lets are surrounded by blank lines
|
|
53
|
+
|
|
54
|
+
[source,ruby]
|
|
55
|
+
----
|
|
56
|
+
# bad
|
|
57
|
+
RSpec.describe Foo do
|
|
58
|
+
let(:name) { 'Ada' }
|
|
59
|
+
let(:profile) do
|
|
60
|
+
{ role: 'admin' }
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# good
|
|
65
|
+
RSpec.describe Foo do
|
|
66
|
+
let(:name) { 'Ada' }
|
|
67
|
+
|
|
68
|
+
let(:profile) do
|
|
69
|
+
{ role: 'admin' }
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
----
|
|
74
|
+
|
|
75
|
+
[#single-line-lets-come-before-multi-line-lets-munraletlayout]
|
|
76
|
+
==== Single-line lets come before multi-line lets
|
|
77
|
+
|
|
78
|
+
[source,ruby]
|
|
79
|
+
----
|
|
80
|
+
# bad
|
|
81
|
+
RSpec.describe Foo do
|
|
82
|
+
let(:profile) do
|
|
83
|
+
{ role: 'admin' }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
let(:name) { 'Ada' }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# good
|
|
90
|
+
RSpec.describe Foo do
|
|
91
|
+
let(:name) { 'Ada' }
|
|
92
|
+
|
|
93
|
+
let(:profile) do
|
|
94
|
+
{ role: 'admin' }
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
end
|
|
98
|
+
----
|
|
99
|
+
|
|
100
|
+
[#munranamedsubjectlayout]
|
|
101
|
+
== Munra/NamedSubjectLayout
|
|
102
|
+
|
|
103
|
+
|===
|
|
104
|
+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
|
|
105
|
+
|
|
106
|
+
| Enabled
|
|
107
|
+
| Yes
|
|
108
|
+
| No
|
|
109
|
+
| -
|
|
110
|
+
| -
|
|
111
|
+
|===
|
|
112
|
+
|
|
113
|
+
Named `subject` must be the first declaration in its example group;
|
|
114
|
+
do not repeat the subject body inline inside `expect`.
|
|
115
|
+
|
|
116
|
+
[#examples-munranamedsubjectlayout]
|
|
117
|
+
=== Examples
|
|
118
|
+
|
|
119
|
+
[source,ruby]
|
|
120
|
+
----
|
|
121
|
+
# bad
|
|
122
|
+
RSpec.describe FooService do
|
|
123
|
+
let(:name) { 'x' }
|
|
124
|
+
subject(:result) { described_class.call(name:) }
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# bad
|
|
128
|
+
RSpec.describe FooService do
|
|
129
|
+
subject { described_class.call }
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# bad
|
|
133
|
+
RSpec.describe FooService do
|
|
134
|
+
subject(:result) { described_class.call(name: 'x') }
|
|
135
|
+
|
|
136
|
+
it 'works' do
|
|
137
|
+
expect(described_class.call(name: 'x')).to be(true)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# good
|
|
142
|
+
RSpec.describe FooService do
|
|
143
|
+
subject(:result) { described_class.call(name: 'x') }
|
|
144
|
+
|
|
145
|
+
it 'works' do
|
|
146
|
+
expect(result).to be(true)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
----
|
|
150
|
+
|
|
151
|
+
[#munranohumanattributename]
|
|
152
|
+
== Munra/NoHumanAttributeName
|
|
153
|
+
|
|
154
|
+
|===
|
|
155
|
+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
|
|
156
|
+
|
|
157
|
+
| Enabled
|
|
158
|
+
| Yes
|
|
159
|
+
| No
|
|
160
|
+
| -
|
|
161
|
+
| -
|
|
162
|
+
|===
|
|
163
|
+
|
|
164
|
+
Prefer `I18n.t('activerecord.attributes...')` over `human_attribute_name`.
|
|
165
|
+
|
|
166
|
+
[#examples-munranohumanattributename]
|
|
167
|
+
=== Examples
|
|
168
|
+
|
|
169
|
+
[source,ruby]
|
|
170
|
+
----
|
|
171
|
+
# bad
|
|
172
|
+
Student.human_attribute_name(:name)
|
|
173
|
+
|
|
174
|
+
# good
|
|
175
|
+
I18n.t('activerecord.attributes.student.name')
|
|
176
|
+
----
|
|
177
|
+
|
|
178
|
+
[#munranoleadingdot]
|
|
179
|
+
== Munra/NoLeadingDot
|
|
180
|
+
|
|
181
|
+
|===
|
|
182
|
+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
|
|
183
|
+
|
|
184
|
+
| Enabled
|
|
185
|
+
| Yes
|
|
186
|
+
| No
|
|
187
|
+
| -
|
|
188
|
+
| -
|
|
189
|
+
|===
|
|
190
|
+
|
|
191
|
+
Flags a method chain broken with a leading dot.
|
|
192
|
+
|
|
193
|
+
[#examples-munranoleadingdot]
|
|
194
|
+
=== Examples
|
|
195
|
+
|
|
196
|
+
[source,ruby]
|
|
197
|
+
----
|
|
198
|
+
# bad
|
|
199
|
+
user
|
|
200
|
+
.name
|
|
201
|
+
|
|
202
|
+
# good
|
|
203
|
+
user.
|
|
204
|
+
name
|
|
205
|
+
----
|
|
206
|
+
|
|
207
|
+
[#munranospecmethod]
|
|
208
|
+
== Munra/NoSpecMethod
|
|
209
|
+
|
|
210
|
+
|===
|
|
211
|
+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
|
|
212
|
+
|
|
213
|
+
| Enabled
|
|
214
|
+
| Yes
|
|
215
|
+
| No
|
|
216
|
+
| -
|
|
217
|
+
| -
|
|
218
|
+
|===
|
|
219
|
+
|
|
220
|
+
Disallows `def` in a spec.
|
|
221
|
+
|
|
222
|
+
Use `let` or a helper instead of defining a method in the spec file.
|
|
223
|
+
|
|
224
|
+
[#examples-munranospecmethod]
|
|
225
|
+
=== Examples
|
|
226
|
+
|
|
227
|
+
[source,ruby]
|
|
228
|
+
----
|
|
229
|
+
# bad
|
|
230
|
+
def helper
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
# bad
|
|
234
|
+
def self.helper
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# good
|
|
238
|
+
let(:user) { build_user }
|
|
239
|
+
----
|
|
240
|
+
|
|
241
|
+
[#munranotransactionexit]
|
|
242
|
+
== Munra/NoTransactionExit
|
|
243
|
+
|
|
244
|
+
|===
|
|
245
|
+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
|
|
246
|
+
|
|
247
|
+
| Enabled
|
|
248
|
+
| Yes
|
|
249
|
+
| No
|
|
250
|
+
| -
|
|
251
|
+
| -
|
|
252
|
+
|===
|
|
253
|
+
|
|
254
|
+
Disallows `return` and `next` inside a transaction block.
|
|
255
|
+
|
|
256
|
+
Abort the transaction with `raise ActiveRecord::Rollback` instead.
|
|
257
|
+
|
|
258
|
+
[#examples-munranotransactionexit]
|
|
259
|
+
=== Examples
|
|
260
|
+
|
|
261
|
+
[source,ruby]
|
|
262
|
+
----
|
|
263
|
+
# bad
|
|
264
|
+
ApplicationRecord.transaction do
|
|
265
|
+
return false
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
# bad
|
|
269
|
+
record.with_lock do
|
|
270
|
+
next if skip?
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
# good
|
|
274
|
+
ApplicationRecord.transaction do
|
|
275
|
+
raise ActiveRecord::Rollback
|
|
276
|
+
end
|
|
277
|
+
----
|
|
278
|
+
|
|
279
|
+
[#munrasuccesserrorsiblings]
|
|
280
|
+
== Munra/SuccessErrorSiblings
|
|
281
|
+
|
|
282
|
+
|===
|
|
283
|
+
| Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
|
|
284
|
+
|
|
285
|
+
| Enabled
|
|
286
|
+
| Yes
|
|
287
|
+
| No
|
|
288
|
+
| -
|
|
289
|
+
| -
|
|
290
|
+
|===
|
|
291
|
+
|
|
292
|
+
When a group has a `when success` or `when error` context, sibling
|
|
293
|
+
`context` blocks must use only those two names.
|
|
294
|
+
|
|
295
|
+
[#examples-munrasuccesserrorsiblings]
|
|
296
|
+
=== Examples
|
|
297
|
+
|
|
298
|
+
[source,ruby]
|
|
299
|
+
----
|
|
300
|
+
# bad
|
|
301
|
+
RSpec.describe FooService do
|
|
302
|
+
describe '.call' do
|
|
303
|
+
context 'when success' do
|
|
304
|
+
it { }
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
context 'when validation fails' do
|
|
308
|
+
it { }
|
|
309
|
+
end
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
# good
|
|
314
|
+
RSpec.describe FooService do
|
|
315
|
+
describe '.call' do
|
|
316
|
+
context 'when success' do
|
|
317
|
+
it { }
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
context 'when error' do
|
|
321
|
+
it { }
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
# good
|
|
327
|
+
RSpec.describe FooService do
|
|
328
|
+
context 'when logged in' do
|
|
329
|
+
it { }
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
context 'when logged out' do
|
|
333
|
+
it { }
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
----
|