{"id":13878793,"url":"https://github.com/shanecav84/rubocop-ordered_methods","last_synced_at":"2025-04-02T13:05:52.520Z","repository":{"id":54195616,"uuid":"171149892","full_name":"shanecav84/rubocop-ordered_methods","owner":"shanecav84","description":"Check that methods are defined alphabetically per access modifier block.","archived":false,"fork":false,"pushed_at":"2024-10-01T15:18:35.000Z","size":123,"stargazers_count":16,"open_issues_count":4,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-02T08:48:43.686Z","etag":null,"topics":["linter","rubocop","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shanecav84.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-17T17:21:41.000Z","updated_at":"2025-03-29T22:37:54.000Z","dependencies_parsed_at":"2024-01-13T20:40:04.926Z","dependency_job_id":"3c92b234-d3af-4a69-ae31-6c3b16aa33ea","html_url":"https://github.com/shanecav84/rubocop-ordered_methods","commit_stats":{"total_commits":85,"total_committers":6,"mean_commits":"14.166666666666666","dds":"0.16470588235294115","last_synced_commit":"0c5526001bc4bcf03dac46aac7f333de065766f7"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanecav84%2Frubocop-ordered_methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanecav84%2Frubocop-ordered_methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanecav84%2Frubocop-ordered_methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanecav84%2Frubocop-ordered_methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shanecav84","download_url":"https://codeload.github.com/shanecav84/rubocop-ordered_methods/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246819774,"owners_count":20839095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linter","rubocop","ruby"],"created_at":"2024-08-06T08:02:00.172Z","updated_at":"2025-04-02T13:05:52.498Z","avatar_url":"https://github.com/shanecav84.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"[![Gem Version](https://badge.fury.io/rb/rubocop-ordered_methods.svg)](https://badge.fury.io/rb/rubocop-ordered_methods)\n[![Build Status](https://github.com/shanecav84/rubocop-ordered_methods/actions/workflows/main.yml/badge.svg)](https://github.com/shanecav84/rubocop-ordered_methods/actions)\n\n# RuboCop OrderedMethods\n\nCheck that methods are defined alphabetically per access modifier block (class, \npublic, private, protected). Includes [autocorrection](#corrector).\n\n```ruby\n# bad\ndef self.b_class; end\ndef self.a_class; end\n\ndef b_public; end\ndef a_public; end\n\nprivate\n\ndef b_private; end\ndef a_private; end\n\n# good\ndef self.a_class; end\ndef self.b_class; end\n\ndef a_public; end\ndef b_public; end\n\nprivate\n\ndef a_private; end\ndef b_private; end\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rubocop-ordered_methods'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rubocop-ordered_methods\n\n## Usage\n\nYou need to tell RuboCop to load the OrderedMethods extension. There are two\nways to do this:\n\n### RuboCop configuration file\n\nPut this into your `.rubocop.yml`.\n\n```\nrequire: rubocop-ordered_methods\n```\n\nNow you can run `rubocop` and it will automatically load the RuboCop OrderedMethods\ncops together with the standard cops.\n\n### Command line\n\n```bash\nrubocop --require rubocop-ordered_methods\n```\n\n### Configurable attributes\n\nName | Default value | Configurable values\n--- | --- | ---\nEnforcedStyle | `'alphabetical'` | `'alphabetical'`\nIgnoredMethods | `['initialize']` | Array\nMethodQualifiers | `[]` | Array\nSignature | `nil` | `'sorbet'`, `nil`\n\n#### Example\n\n```\n# .rubocop.yml\nLayout/OrderedMethods:\n  EnforcedStyle: alphabetical\n  IgnoredMethods:\n    - initialize\n  MethodQualifiers:\n    - memoize\n  Signature: sorbet\n```\n\n### Corrector\n\nThe corrector will attempt to order methods based on the `EnforcedStyle`. It attempts to\ninclude surrounding comments and the qualifiers (e.g., aliases) listed in\n`::RuboCop::Cop::OrderedMethodsCorrector::QUALIFIERS`. The following (monstrous)\nsource is able to be correctly ordered:\n\n```ruby\n# Long\n# Preceding\n# Comment\n# class_b\ndef self.class_b; end\nprivate_class_method :class_b\n\ndef self.class_a; end\n# Long\n# Succeeding\n# Comment\n# class_a\npublic_class_method :class_a\n\n# Preceding comment for instance_b\ndef instance_b; end\n# Long\n# Succeeding\n# Comment\n# instance_b\nalias_method :orig_instance_b, :instance_b\nmodule_function :instance_b\nprivate :instance_b\nprotected :instance_b\npublic :instance_b\n\n# Long\n# Preceding\n# Comment\n# instance_a\ndef instance_a; end\n# Succeeding comment for instance_a\nalias :new_instance_a :instance_a\nalias_method :orig_instance_a, :instance_a\nmodule_function :instance_a\nprivate :instance_a\nprotected :instance_a\npublic :instance_a\n```\n\n#### Method qualifiers\nSome gems (like `memery`, `memoist`, etc.) provide a DSL that modifies the method (e.g. for memoization).\nThose DSL methods can be added to the `MethodQualifiers` configuration, and they will be respected.\n\nE.g. the following source can be correctly ordered:\n```ruby\ndef b; end;\nmemoize def a;end\n```\n\n#### Method signatures\n\nSupport for (Sorbet) method signatures was added to the corrector by\n[#7](https://github.com/shanecav84/rubocop-ordered_methods/pull/7).\nIt is off by default due to performance concerns (not yet benchmarked). Enable\nwith `Signature: sorbet`.\n\n#### Caveats\n\n* The corrector will warn and refuse to order a method if it were to be\n  defined before its alias\n* If there's ambiguity about which method a comment or qualifier belongs to,\n  the corrector might fail to order correctly. For example, in the following, \n  the corrector would incorrectly order the comment as a comment of `a`:\n\n  ```ruby\n  def b; end\n  # Comment b\n  def a; end\n  ```\n\n## Project status\n\nDevelopment is ongoing. There might be extended periods between releases. \nThe maintenance goal is to add features as needed and to maintain compatibility \nwith Ruby and rubocop updates.\n\n## Development\n\n### Setup\n\n```bash\nbundle install\nbundle exec rake\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at \nhttps://github.com/shanecav84/rubocop-ordered_methods. This project is intended \nto be a safe, welcoming space for collaboration, and contributors are expected \nto adhere to the [Contributor Covenant](http://contributor-covenant.org) code of\n conduct.\n\n## License\n\nThe gem is available as open source under the terms of the \n[MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the RuboCop OrderedMethods project’s codebases, issue \ntrackers, chat rooms and mailing lists is expected to follow the \n[code of conduct](https://github.com/shanecav84/rubocop-ordered_methods/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshanecav84%2Frubocop-ordered_methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshanecav84%2Frubocop-ordered_methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshanecav84%2Frubocop-ordered_methods/lists"}