rubocop-sorted_methods_by_call 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9a05a73b134e3c92389b69552df981d71c730623059376b90029f1875bdf6945
4
+ data.tar.gz: cf522e97fabcf31eafb02ddf9b52980d9c681adc6f04bc297729dfe1f9f53af7
5
+ SHA512:
6
+ metadata.gz: 2f5e49e6eefca4dcce2a4de646afae45292170f2389672fcc6a17120ac6d16d22e50e81fafaaf0c8e008300da816d1d886f4d43e5180ebe5c40b267d6a36e064
7
+ data.tar.gz: 7a0dc929281d31759bdef79d990d61427bc277421ae096df8f49662a04fd74fcae98b6f785912308d360ce35d9ac4a1a26947208c167265da00d0f240bd66f81
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ plugins:
4
+ - rubocop-rake
5
+ - rubocop-rspec
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 3.4
9
+ NewCops: enable
10
+
11
+ Layout/LineLength:
12
+ Max: 120
13
+
14
+ Naming/FileName:
15
+ Exclude:
16
+ - 'lib/rubocop-sorted_methods_by_call.rb'
17
+
18
+ Style/WhileUntilDo:
19
+ Enabled: false
20
+
21
+ Style/RedundantFetchBlock:
22
+ Enabled: false
23
+
24
+ Naming/MethodParameterName:
25
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,59 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2025-11-05 21:07:30 UTC using RuboCop version 1.81.7.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 7
10
+ # Configuration parameters: EnforcedStyle, AllowedGems.
11
+ # SupportedStyles: Gemfile, gems.rb, gemspec
12
+ Gemspec/DevelopmentDependencies:
13
+ Exclude:
14
+ - 'rubocop-sorted_methods_by_call.gemspec'
15
+
16
+ # Offense count: 1
17
+ # Configuration parameters: Severity.
18
+ Gemspec/RequiredRubyVersion:
19
+ Exclude:
20
+ - 'rubocop-sorted_methods_by_call.gemspec'
21
+
22
+ # Offense count: 4
23
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
24
+ Metrics/AbcSize:
25
+ Max: 61
26
+
27
+ # Offense count: 1
28
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
29
+ # AllowedMethods: refine
30
+ Metrics/BlockLength:
31
+ Max: 43
32
+
33
+ # Offense count: 5
34
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
35
+ Metrics/CyclomaticComplexity:
36
+ Max: 20
37
+
38
+ # Offense count: 7
39
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
40
+ Metrics/MethodLength:
41
+ Max: 58
42
+
43
+ # Offense count: 4
44
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
45
+ Metrics/PerceivedComplexity:
46
+ Max: 22
47
+
48
+ # Offense count: 11
49
+ # Configuration parameters: CountAsOne.
50
+ RSpec/ExampleLength:
51
+ Max: 26
52
+
53
+ # Offense count: 2
54
+ # This cop supports safe autocorrection (--autocorrect).
55
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
56
+ # SupportedStyles: single_quotes, double_quotes
57
+ Style/StringLiterals:
58
+ Exclude:
59
+ - 'spec/rubocop/cop/sorted_methods_by_call/waterfall_spec.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.7
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in rubocop-sorted_methods_by_call.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,92 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubocop-sorted_methods_by_call (1.0.0)
5
+ lint_roller
6
+ rubocop (>= 1.72.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.3)
12
+ diff-lcs (1.5.0)
13
+ fasterer (0.11.0)
14
+ ruby_parser (>= 3.19.1)
15
+ json (2.15.2)
16
+ language_server-protocol (3.17.0.5)
17
+ lint_roller (1.1.0)
18
+ parallel (1.27.0)
19
+ parser (3.3.10.0)
20
+ ast (~> 2.4.1)
21
+ racc
22
+ prism (1.6.0)
23
+ racc (1.8.1)
24
+ rainbow (3.1.1)
25
+ rake (13.0.6)
26
+ regexp_parser (2.11.3)
27
+ rspec (3.12.0)
28
+ rspec-core (~> 3.12.0)
29
+ rspec-expectations (~> 3.12.0)
30
+ rspec-mocks (~> 3.12.0)
31
+ rspec-core (3.12.0)
32
+ rspec-support (~> 3.12.0)
33
+ rspec-expectations (3.12.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.12.0)
36
+ rspec-mocks (3.12.0)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.12.0)
39
+ rspec-support (3.12.0)
40
+ rubocop (1.81.7)
41
+ json (~> 2.3)
42
+ language_server-protocol (~> 3.17.0.2)
43
+ lint_roller (~> 1.1.0)
44
+ parallel (~> 1.10)
45
+ parser (>= 3.3.0.2)
46
+ rainbow (>= 2.2.2, < 4.0)
47
+ regexp_parser (>= 2.9.3, < 3.0)
48
+ rubocop-ast (>= 1.47.1, < 2.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 2.4.0, < 4.0)
51
+ rubocop-ast (1.47.1)
52
+ parser (>= 3.3.7.2)
53
+ prism (~> 1.4)
54
+ rubocop-performance (1.26.0)
55
+ lint_roller (~> 1.1)
56
+ rubocop (>= 1.75.0, < 2.0)
57
+ rubocop-ast (>= 1.44.0, < 2.0)
58
+ rubocop-rake (0.7.1)
59
+ lint_roller (~> 1.1)
60
+ rubocop (>= 1.72.1)
61
+ rubocop-rspec (3.7.0)
62
+ lint_roller (~> 1.1)
63
+ rubocop (~> 1.72, >= 1.72.1)
64
+ ruby-progressbar (1.13.0)
65
+ ruby_parser (3.21.1)
66
+ racc (~> 1.5)
67
+ sexp_processor (~> 4.16)
68
+ sexp_processor (4.17.4)
69
+ unicode-display_width (3.2.0)
70
+ unicode-emoji (~> 4.1)
71
+ unicode-emoji (4.1.0)
72
+ webrick (1.7.0)
73
+ yard (0.9.28)
74
+ webrick (~> 1.7.0)
75
+
76
+ PLATFORMS
77
+ arm64-darwin-24
78
+ arm64-darwin-25
79
+ x86_64-linux
80
+
81
+ DEPENDENCIES
82
+ fasterer
83
+ rake (>= 13.0)
84
+ rspec (>= 3.0)
85
+ rubocop-performance
86
+ rubocop-rake
87
+ rubocop-rspec
88
+ rubocop-sorted_methods_by_call!
89
+ yard
90
+
91
+ BUNDLED WITH
92
+ 2.3.25
data/LICENSE.txt ADDED
@@ -0,0 +1,11 @@
1
+ Copyright 2022 unurgunite
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,222 @@
1
+ # RuboCop::SortedMethodsByCall
2
+
3
+ ![Repobeats](https://repobeats.axiom.co/api/embed/7926fec94bffd7fcaa69700fb9464ed96cf69083.svg "Repobeats analytics image")
4
+ [![CI](https://github.com/unurgunite/rubocop-sorted_methods_by_call/actions/workflows/ci.yml/badge.svg)](https://github.com/unurgunite/rubocop-sorted_methods_by_call/actions)
5
+ [![Gem Version](https://badge.fury.io/rb/rubocop-sorted_methods_by_call.svg)](https://rubygems.org/gems/rubocop-sorted_methods_by_call)
6
+
7
+ * [RuboCop::SortedMethodsByCall](#rubocopsortedmethodsbycall)
8
+ * [Features](#features)
9
+ * [Installation](#installation)
10
+ * [Configuration](#configuration)
11
+ * [Basic Setup](#basic-setup)
12
+ * [Configuration Options](#configuration-options)
13
+ * [Usage Examples](#usage-examples)
14
+ * [Good Code (waterfall order)](#good-code-waterfall-order)
15
+ * [Bad Code (violates waterfall order)](#bad-code-violates-waterfall-order)
16
+ * [Autocorrection](#autocorrection)
17
+ * [Testing](#testing)
18
+ * [Development](#development)
19
+ * [Available Commands](#available-commands)
20
+ * [Release Process](#release-process)
21
+ * [Requirements](#requirements)
22
+ * [Contributing](#contributing)
23
+ * [License](#license)
24
+ * [Code of Conduct](#code-of-conduct)
25
+
26
+ **Enforces "waterfall" method ordering**: define methods *after* any method that calls them within the same scope.
27
+
28
+ ## Features
29
+
30
+ - **Waterfall ordering enforcement**: Caller methods must be defined before their callees
31
+ - **Smart visibility handling**: Respects `private`/`protected`/`public` sections
32
+ - **Safe mutual recursion**: Handles recursive method calls gracefully
33
+ - **Autocorrection support**: Automatically reorders methods (opt-in with `-A`)
34
+ - **Full RuboCop integration**: Works seamlessly with modern RuboCop plugin system
35
+ - **Comprehensive scope support**: Classes, modules, singleton classes, and top-level
36
+
37
+ ## Installation
38
+
39
+ Add this line to your application's Gemfile:
40
+
41
+ ```ruby
42
+ gem 'rubocop-sorted_methods_by_call'
43
+ ```
44
+
45
+ And then execute:
46
+
47
+ ```bash
48
+ bundle install
49
+ ```
50
+
51
+ Or install it yourself:
52
+
53
+ ```bash
54
+ gem install rubocop-sorted_methods_by_call
55
+ ```
56
+
57
+ ## Configuration
58
+
59
+ ### Basic Setup
60
+
61
+ Add to your `.rubocop.yml`:
62
+
63
+ ```yaml
64
+ plugins:
65
+ - rubocop-sorted_methods_by_call
66
+
67
+ SortedMethodsByCall/Waterfall:
68
+ Enabled: true
69
+ ```
70
+
71
+ ### Configuration Options
72
+
73
+ ```yaml
74
+ SortedMethodsByCall/Waterfall:
75
+ Enabled: true
76
+ SafeAutoCorrect: false # Autocorrection requires -A flag
77
+ AllowedRecursion: true # Allow mutual recursion (default: true)
78
+ ```
79
+
80
+ ## Usage Examples
81
+
82
+ ### Good Code (waterfall order)
83
+
84
+ ```ruby
85
+
86
+ class Service
87
+ def call
88
+ do_smth
89
+ end
90
+
91
+ private
92
+
93
+ def do_smth
94
+ well
95
+ end
96
+
97
+ def well
98
+ 123
99
+ end
100
+ end
101
+ ```
102
+
103
+ ### Bad Code (violates waterfall order)
104
+
105
+ ```ruby
106
+
107
+ class Service
108
+ def call
109
+ do_smth
110
+ end
111
+
112
+ private
113
+
114
+ def well # ❌ Offense: Define #well after its caller #do_smth
115
+ 123
116
+ end
117
+
118
+ def do_smth
119
+ well
120
+ end
121
+ end
122
+ ```
123
+
124
+ ### Autocorrection
125
+
126
+ Run with unsafe autocorrection to automatically fix violations:
127
+
128
+ ```bash
129
+ bundle exec rubocop -A
130
+ ```
131
+
132
+ This will reorder the methods while preserving comments and visibility modifiers:
133
+
134
+ ```ruby
135
+
136
+ class Service
137
+ def call
138
+ do_smth
139
+ end
140
+
141
+ private
142
+
143
+ def do_smth
144
+ well
145
+ end
146
+
147
+ def well
148
+ 123
149
+ end
150
+ end
151
+ ```
152
+
153
+ ## Testing
154
+
155
+ Run the test suite:
156
+
157
+ ```bash
158
+ bundle exec rspec
159
+ ```
160
+
161
+ Run RuboCop on the gem itself:
162
+
163
+ ```bash
164
+ bundle exec rubocop
165
+ bundle exec rubocop --config .rubocop.test.yml lib/ -A
166
+ ```
167
+
168
+ ## Development
169
+
170
+ After checking out the repo, run:
171
+
172
+ ```bash
173
+ bin/setup
174
+ ```
175
+
176
+ This will install dependencies and start an interactive console.
177
+
178
+ ### Available Commands
179
+
180
+ - `bin/console` - Interactive development console
181
+ - `bin/setup` - Install dependencies and build gem
182
+ - `bundle exec rake` - Run tests and linting
183
+
184
+ ### Release Process
185
+
186
+ 1. Update version in `lib/rubocop/sorted_methods_by_call/version.rb`
187
+ 2. Create and push a git tag: `git tag v0.1.0 && git push origin v0.1.0`
188
+ 3. GitHub Actions will automatically:
189
+ - Build the gem
190
+ - Publish to RubyGems.org
191
+ - Create a GitHub release
192
+
193
+ ## Requirements
194
+
195
+ - **Ruby**: >= 2.7
196
+ - **RuboCop**: >= 1.72.0 (required for plugin system)
197
+
198
+ ## Contributing
199
+
200
+ Bug reports and pull requests are welcome! Please follow these guidelines:
201
+
202
+ 1. Fork the repository
203
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
204
+ 3. Commit your changes (`git commit -am 'Add amazing feature'`)
205
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
206
+ 5. Open a pull request
207
+
208
+ Please ensure your code passes all tests and follows the existing style.
209
+
210
+ ## License
211
+
212
+ The gem is available as open source under the terms of
213
+ the [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause).
214
+
215
+ ## Code of Conduct
216
+
217
+ Everyone interacting with this project is expected to follow the [Code of Conduct](CODE_OF_CONDUCT.md).
218
+
219
+ ---
220
+
221
+ > **Note**: This gem is now stable and ready for production use! The "waterfall" ordering pattern helps create more
222
+ > readable code by ensuring that methods are defined in the order they're conceptually needed.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ require 'rubocop/rake_task'
8
+ RuboCop::RakeTask.new
9
+
10
+ task default: %i[spec rubocop]
@@ -0,0 +1,7 @@
1
+ # Default configuration for rubocop-sorted_methods_by_call
2
+ SortedMethodsByCall/Waterfall:
3
+ Description: "Enforces waterfall ordering: define methods after the methods that call them."
4
+ Enabled: false
5
+ VersionAdded: "1.0.0"
6
+ SafeAutoCorrect: false
7
+ AllowedRecursion: true
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'rubocop-sorted_methods_by_call'