RuboCop

一个基于社区 Ruby 风格指南的 Ruby 静态代码分析器和格式化器。「A Ruby static code analyzer and formatter, based on the community Ruby style guide.」

Github星跟蹤圖

RuboCop

榜样很重要。
--警官亚历克斯-J-墨菲/《机械战警》。

RuboCop 是一个 Ruby 静态代码分析器(也就是 linter)和代码格式化器。开箱即用,它可以执行社区 Ruby 风格指南 中的许多准则。除了报告代码中发现的问题,RuboCop 还能自动为你修复许多问题。

RuboCop 非常灵活,它的大部分行为都可以通过各种配置选项进行调整。

请考虑为它的持续发展提供资金支持。

安装方法

RuboCop 的安装非常标准:

$ gem install rubocop

如果你想使用 bundler 安装 RuboCop,请在你的 Gemfile 中添加一行(但将 require 选项设置为 false,因为它是一个独立的工具)。

gem 'rubocop', require: false

RuboCop 的开发速度非常快,在不同的小版本之间经常会出现向后不兼容的变化(因为我们还没有达到 1.0 版本)。为了防止 RuboCop 不需要的更新,你可能需要在你的 Gemfile 中使用一个保守的版本锁定。

gem 'rubocop', '~> 0.93.1', require: false

快速启动

只要在 Ruby 项目的文件夹中输入 rubocop,就能看到神奇的效果。

$ cd my/cool/ruby/project
$ rubocop

文档

你可以在它的 官方文档 中阅读更多关于 RuboCop 的信息。

兼容性

RuboCop 支持以下 Ruby 实现。

  • MRI 2.4+
  • JRuby 9.2+

更多细节请参见兼容性

自述章(Readme Badge)

如果你在你的项目中使用了 RuboCop,你可以在你的 readme 中加入这些徽章,让人们知道你的代码是按照社区 Ruby Style Guide 编写的。

Ruby Style Guide

开发团队

以下是 RuboCop 的核心开发人员名单。

徽标

RuboCop 的标志由 Dimiter Petrov 设计。你可以在这里找到各种格式的标志。
该标志采用知识共享署名-非商业4.0国际许可协议进行许可。

贡献者

以下是所有为 RuboCop 开发做出贡献的人的名单

我非常感谢他们每一个人!如果你想为 RuboCop 做出贡献,请花一点点时间阅读我们的贡献指南

如果你想为 RuboCop 做出贡献,请花时间阅读我们的贡献指南。

将更多的 Ruby 风格指南转化为 RuboCop警察是我们目前的首要任务。编写一个新的 RuboCop 规则是深入了解 RuboCop 的好方法!当然,错误报告和对 RuboCop 的建议也是我们的首要任务。

当然,我们也欢迎大家提出错误报告和改进建议。GitHub 上的拉取请求就更好了! :-)

变更日志

RuboCop 的更新日志请点击这里

著作权

Copyright (c) 2012-2020 Bozhidar Batsov. 详见 LICENSE.txt


(The first version translated by vz on 2020.10.15)

主要指標

概覽
名稱與所有者rubocop/rubocop
主編程語言Ruby
編程語言Ruby (語言數: 4)
平台Linux, Mac, Windows
許可證MIT License
所有者活动
創建於2012-04-21 10:09:58
推送於2025-04-22 15:37:31
最后一次提交2025-04-22 20:21:32
發布數297
最新版本名稱v1.75.3 (發布於 2025-04-22 12:03:09)
第一版名稱v0.0.0 (發布於 )
用户参与
星數12.7k
關注者數177
派生數3.1k
提交數15.1k
已啟用問題?
問題數5915
打開的問題數317
拉請求數7183
打開的拉請求數45
關閉的拉請求數703
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

Ruby Style Guide
Gem Version
CircleCI Status
Actions Status
Test Coverage
Maintainability
Discord

Role models are important.
-- Officer Alex J. Murphy / RoboCop

RuboCop is a Ruby static code analyzer (a.k.a. linter) and code formatter. Out of the box it
will enforce many of the guidelines outlined in the community Ruby Style
Guide
. Apart from reporting the problems discovered in your code,
RuboCop can also automatically fix many of them for you.

RuboCop is extremely flexible and most aspects of its behavior can be tweaked via various
configuration options.


Patreon
OpenCollective
OpenCollective
Tidelift

Working on RuboCop is often fun, but it also requires a great deal of time and energy.

Please consider financially supporting its ongoing development.

Installation

RuboCop's installation is pretty standard:

$ gem install rubocop

If you'd rather install RuboCop using bundler, add a line for it in your Gemfile (but set the require option to false, as it is a standalone tool):

gem 'rubocop', require: false

RuboCop is stable between minor versions, both in terms of API and cop configuration.
We aim to ease the maintenance of RuboCop extensions and the upgrades between RuboCop
releases. All big changes are reserved for major releases.
To prevent an unwanted RuboCop update you might want to use a conservative version lock
in your Gemfile:

gem 'rubocop', '~> 1.60', require: false

See our versioning policy for further details.

Quickstart

Just type rubocop in a Ruby project's folder and watch the magic happen.

$ cd my/cool/ruby/project
$ rubocop

You can also use this magic in your favorite editor with RuboCop's built-in LSP server.

Documentation

You can read a lot more about RuboCop in its official docs.

Compatibility

RuboCop officially supports the following runtime Ruby implementations:

  • MRI 2.7+
  • JRuby 9.4+

Targets Ruby 2.0+ code analysis.

See the compatibility documentation for further details.

Readme Badge

If you use RuboCop in your project, you can include one of these badges in your readme to let people know that your code is written following the community Ruby Style Guide.

Ruby Style Guide

Ruby Style Guide

Here are the Markdown snippets for the two badges:

[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)

[![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)

Team

Here's a list of RuboCop's core developers:

See the team page for more details.

RuboCop's logo was created by Dimiter Petrov. You can find the logo in various
formats here.

The logo is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.

Contributors

Here's a list of
all the people who have contributed to the development of RuboCop.

I'm extremely grateful to each and every one of them!

If you'd like to contribute to RuboCop, please take the time to go
through our short
contribution guidelines.

Converting more of the Ruby Style Guide into RuboCop cops is our top
priority right now. Writing a new cop is a great way to dive into RuboCop!

Of course, bug reports and suggestions for improvements are always
welcome. GitHub pull requests are even better! :-)

Funding

While RuboCop is free software and will always be, the project would benefit immensely from some funding.
Raising a monthly budget of a couple of thousand dollars would make it possible to pay people to work on
certain complex features, fund other development related stuff (e.g. hardware, conference trips) and so on.
Raising a monthly budget of over $5000 would open the possibility of someone working full-time on the project
which would speed up the pace of development significantly.

We welcome both individual and corporate sponsors! We also offer a
wide array of funding channels to account for your preferences
(although
currently Open Collective is our
preferred funding platform).

If you're working in a company that's making significant use of RuboCop we'd appreciate it if you suggest to your company
to become a RuboCop sponsor.

You can support the development of RuboCop via
GitHub Sponsors,
Patreon,
PayPal,
Open Collective
and Tidelift
.

Note: If doing a sponsorship in the form of donation is problematic for your company from an accounting standpoint, we'd recommend
the use of Tidelift, where you can get a support-like subscription instead.

Open Collective Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]






























Open Collective Sponsors

Become a sponsor and get your logo on our README on GitHub with a link to your site. [Become a sponsor]






























Changelog

RuboCop's changelog is available here.

Copyright (c) 2012-2024 Bozhidar Batsov. See LICENSE.txt for
further details.