rubocop-rails_config 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +9 -0
- data/README.md +47 -0
- data/config/rails.yml +176 -0
- data/lib/custom_cops/refute_not.rb +71 -0
- data/lib/custom_cops.rb +3 -0
- data/lib/generators/rubocop_rails_config/install_generator.rb +35 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4c7fc5420b16ed5c2e8d2730cb44da84adc1adf0fdef0455405aff08fb71bd27
|
4
|
+
data.tar.gz: 366f39cdde5bd424680be024494543e9ea94a97eed728cb5b06a723af9c819c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b5f2615ad66e6d8873eca0b0e3c2050be31e535b8ffa54825feb3e58d5b0c31cb73437bf46e2fa4afc5b74f11d1acce4ca3658dc63835ed75cf36c432218711
|
7
|
+
data.tar.gz: 18e8ad7c9c1aea31fff3e39e826425f8e01dbf60cba3d0f77280c1468582efe9aa0d9884a46a5ef75f0886edaba33e77db02f385b1b6b421e4c8528f213008ea
|
data/LICENSE
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Toshimaru Enomoto
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# rubocop-rails_config
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.com/toshimaru/rubocop-rails_config.svg?branch=master)](https://travis-ci.com/toshimaru/rubocop-rails_config)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/rubocop-rails_config.svg)](https://badge.fury.io/rb/rubocop-rails_config)
|
5
|
+
|
6
|
+
RuboCop configuration which has the same code style checking as official Ruby on Rails.
|
7
|
+
|
8
|
+
[Official RoR Rubocop Configuration](https://github.com/rails/rails/blob/master/.rubocop.yml)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's `Gemfile`:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem "rubocop-rails_config"
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Add this line to your application's `.rubocop.yml`, or just run `rails generate rubocop_rails:install`:
|
21
|
+
|
22
|
+
```yml
|
23
|
+
inherit_gem:
|
24
|
+
rubocop-rails_config:
|
25
|
+
- config/rails.yml
|
26
|
+
```
|
27
|
+
|
28
|
+
## Customization
|
29
|
+
|
30
|
+
If you'd like to customize the rubocop setting, you can override it.
|
31
|
+
|
32
|
+
For example, if you want to change `TargetRubyVersion`, you can do it like:
|
33
|
+
|
34
|
+
```yml
|
35
|
+
inherit_gem:
|
36
|
+
rubocop-rails_config:
|
37
|
+
- config/rails.yml
|
38
|
+
|
39
|
+
AllCops:
|
40
|
+
TargetRubyVersion: 2.3
|
41
|
+
```
|
42
|
+
|
43
|
+
This overrides `config/rails.yml` setting with `TargetRubyVersion: 2.3`.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/config/rails.yml
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
require: custom_cops
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.2
|
5
|
+
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
|
6
|
+
# to ignore them, so only the ones explicitly set in this file are enabled.
|
7
|
+
DisabledByDefault: true
|
8
|
+
Exclude:
|
9
|
+
- '**/templates/**/*'
|
10
|
+
- '**/vendor/**/*'
|
11
|
+
- '**/vendor/**/.*'
|
12
|
+
- '**/node_modules/**/*'
|
13
|
+
- 'actionpack/lib/action_dispatch/journey/parser.rb'
|
14
|
+
|
15
|
+
# Prefer assert_not_x over refute_x
|
16
|
+
CustomCops/RefuteNot:
|
17
|
+
Include:
|
18
|
+
- '**/test/**/*'
|
19
|
+
|
20
|
+
# Prefer &&/|| over and/or.
|
21
|
+
Style/AndOr:
|
22
|
+
Enabled: true
|
23
|
+
|
24
|
+
# Do not use braces for hash literals when they are the last argument of a
|
25
|
+
# method call.
|
26
|
+
Style/BracesAroundHashParameters:
|
27
|
+
Enabled: true
|
28
|
+
EnforcedStyle: context_dependent
|
29
|
+
|
30
|
+
# Align `when` with `case`.
|
31
|
+
Layout/CaseIndentation:
|
32
|
+
Enabled: true
|
33
|
+
|
34
|
+
# Align comments with method definitions.
|
35
|
+
Layout/CommentIndentation:
|
36
|
+
Enabled: true
|
37
|
+
|
38
|
+
Layout/ElseAlignment:
|
39
|
+
Enabled: true
|
40
|
+
|
41
|
+
# Align `end` with the matching keyword or starting expression except for
|
42
|
+
# assignments, where it should be aligned with the LHS.
|
43
|
+
Layout/EndAlignment:
|
44
|
+
Enabled: true
|
45
|
+
EnforcedStyleAlignWith: variable
|
46
|
+
AutoCorrect: true
|
47
|
+
|
48
|
+
Layout/EmptyLineAfterMagicComment:
|
49
|
+
Enabled: true
|
50
|
+
|
51
|
+
# In a regular class definition, no empty lines around the body.
|
52
|
+
Layout/EmptyLinesAroundClassBody:
|
53
|
+
Enabled: true
|
54
|
+
|
55
|
+
# In a regular method definition, no empty lines around the body.
|
56
|
+
Layout/EmptyLinesAroundMethodBody:
|
57
|
+
Enabled: true
|
58
|
+
|
59
|
+
# In a regular module definition, no empty lines around the body.
|
60
|
+
Layout/EmptyLinesAroundModuleBody:
|
61
|
+
Enabled: true
|
62
|
+
|
63
|
+
Layout/FirstParameterIndentation:
|
64
|
+
Enabled: true
|
65
|
+
|
66
|
+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
|
67
|
+
Style/HashSyntax:
|
68
|
+
Enabled: true
|
69
|
+
|
70
|
+
# Method definitions after `private` or `protected` isolated calls need one
|
71
|
+
# extra level of indentation.
|
72
|
+
Layout/IndentationConsistency:
|
73
|
+
Enabled: true
|
74
|
+
EnforcedStyle: rails
|
75
|
+
|
76
|
+
# Two spaces, no tabs (for indentation).
|
77
|
+
Layout/IndentationWidth:
|
78
|
+
Enabled: true
|
79
|
+
|
80
|
+
Layout/LeadingCommentSpace:
|
81
|
+
Enabled: true
|
82
|
+
|
83
|
+
Layout/SpaceAfterColon:
|
84
|
+
Enabled: true
|
85
|
+
|
86
|
+
Layout/SpaceAfterComma:
|
87
|
+
Enabled: true
|
88
|
+
|
89
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
90
|
+
Enabled: true
|
91
|
+
|
92
|
+
Layout/SpaceAroundKeyword:
|
93
|
+
Enabled: true
|
94
|
+
|
95
|
+
Layout/SpaceAroundOperators:
|
96
|
+
Enabled: true
|
97
|
+
|
98
|
+
Layout/SpaceBeforeComma:
|
99
|
+
Enabled: true
|
100
|
+
|
101
|
+
Layout/SpaceBeforeFirstArg:
|
102
|
+
Enabled: true
|
103
|
+
|
104
|
+
Style/DefWithParentheses:
|
105
|
+
Enabled: true
|
106
|
+
|
107
|
+
# Defining a method with parameters needs parentheses.
|
108
|
+
Style/MethodDefParentheses:
|
109
|
+
Enabled: true
|
110
|
+
|
111
|
+
Style/FrozenStringLiteralComment:
|
112
|
+
Enabled: true
|
113
|
+
EnforcedStyle: always
|
114
|
+
Exclude:
|
115
|
+
- 'actionview/test/**/*.builder'
|
116
|
+
- 'actionview/test/**/*.ruby'
|
117
|
+
- 'actionpack/test/**/*.builder'
|
118
|
+
- 'actionpack/test/**/*.ruby'
|
119
|
+
- 'activestorage/db/migrate/**/*.rb'
|
120
|
+
- 'db/migrate/**/*.rb'
|
121
|
+
- 'db/*.rb'
|
122
|
+
|
123
|
+
# Use `foo {}` not `foo{}`.
|
124
|
+
Layout/SpaceBeforeBlockBraces:
|
125
|
+
Enabled: true
|
126
|
+
|
127
|
+
# Use `foo { bar }` not `foo {bar}`.
|
128
|
+
Layout/SpaceInsideBlockBraces:
|
129
|
+
Enabled: true
|
130
|
+
|
131
|
+
# Use `{ a: 1 }` not `{a:1}`.
|
132
|
+
Layout/SpaceInsideHashLiteralBraces:
|
133
|
+
Enabled: true
|
134
|
+
|
135
|
+
Layout/SpaceInsideParens:
|
136
|
+
Enabled: true
|
137
|
+
|
138
|
+
# Check quotes usage according to lint rule below.
|
139
|
+
Style/StringLiterals:
|
140
|
+
Enabled: true
|
141
|
+
EnforcedStyle: double_quotes
|
142
|
+
|
143
|
+
# Detect hard tabs, no hard tabs.
|
144
|
+
Layout/Tab:
|
145
|
+
Enabled: true
|
146
|
+
|
147
|
+
# Blank lines should not have any spaces.
|
148
|
+
Layout/TrailingBlankLines:
|
149
|
+
Enabled: true
|
150
|
+
|
151
|
+
# No trailing whitespace.
|
152
|
+
Layout/TrailingWhitespace:
|
153
|
+
Enabled: true
|
154
|
+
|
155
|
+
# Use quotes for string literals when they are enough.
|
156
|
+
Style/UnneededPercentQ:
|
157
|
+
Enabled: true
|
158
|
+
|
159
|
+
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
|
160
|
+
Lint/RequireParentheses:
|
161
|
+
Enabled: true
|
162
|
+
|
163
|
+
Lint/StringConversionInInterpolation:
|
164
|
+
Enabled: true
|
165
|
+
|
166
|
+
Style/RedundantReturn:
|
167
|
+
Enabled: true
|
168
|
+
AllowMultipleReturnValues: true
|
169
|
+
|
170
|
+
Style/Semicolon:
|
171
|
+
Enabled: true
|
172
|
+
AllowAsExpressionSeparator: true
|
173
|
+
|
174
|
+
# Prefer Foo.method over Foo::method
|
175
|
+
Style/ColonMethodCall:
|
176
|
+
Enabled: true
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CustomCops
|
4
|
+
# Enforces the use of `#assert_not` methods over `#refute` methods.
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# # bad
|
8
|
+
# refute false
|
9
|
+
# refute_empty [1, 2, 3]
|
10
|
+
# refute_equal true, false
|
11
|
+
#
|
12
|
+
# # good
|
13
|
+
# assert_not false
|
14
|
+
# assert_not_empty [1, 2, 3]
|
15
|
+
# assert_not_equal true, false
|
16
|
+
#
|
17
|
+
class RefuteNot < RuboCop::Cop::Cop
|
18
|
+
MSG = "Prefer `%<assert_method>s` over `%<refute_method>s`"
|
19
|
+
|
20
|
+
CORRECTIONS = {
|
21
|
+
refute: "assert_not",
|
22
|
+
refute_empty: "assert_not_empty",
|
23
|
+
refute_equal: "assert_not_equal",
|
24
|
+
refute_in_delta: "assert_not_in_delta",
|
25
|
+
refute_in_epsilon: "assert_not_in_epsilon",
|
26
|
+
refute_includes: "assert_not_includes",
|
27
|
+
refute_instance_of: "assert_not_instance_of",
|
28
|
+
refute_kind_of: "assert_not_kind_of",
|
29
|
+
refute_nil: "assert_not_nil",
|
30
|
+
refute_operator: "assert_not_operator",
|
31
|
+
refute_predicate: "assert_not_predicate",
|
32
|
+
refute_respond_to: "assert_not_respond_to",
|
33
|
+
refute_same: "assert_not_same",
|
34
|
+
refute_match: "assert_no_match"
|
35
|
+
}.freeze
|
36
|
+
|
37
|
+
OFFENSIVE_METHODS = CORRECTIONS.keys.freeze
|
38
|
+
|
39
|
+
def_node_matcher :offensive?, "(send nil? #offensive_method? ...)"
|
40
|
+
|
41
|
+
def on_send(node)
|
42
|
+
return unless offensive?(node)
|
43
|
+
|
44
|
+
message = offense_message(node.method_name)
|
45
|
+
add_offense(node, location: :selector, message: message)
|
46
|
+
end
|
47
|
+
|
48
|
+
def autocorrect(node)
|
49
|
+
->(corrector) do
|
50
|
+
corrector.replace(
|
51
|
+
node.loc.selector,
|
52
|
+
CORRECTIONS[node.method_name]
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def offensive_method?(method_name)
|
60
|
+
OFFENSIVE_METHODS.include?(method_name)
|
61
|
+
end
|
62
|
+
|
63
|
+
def offense_message(method_name)
|
64
|
+
format(
|
65
|
+
MSG,
|
66
|
+
refute_method: method_name,
|
67
|
+
assert_method: CORRECTIONS[method_name]
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/lib/custom_cops.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators/base"
|
4
|
+
require "active_support/core_ext/string"
|
5
|
+
|
6
|
+
module RubocopRailsConfig
|
7
|
+
module Generators
|
8
|
+
class InstallGenerator < Rails::Generators::Base
|
9
|
+
desc "Creates a .rubocop.yml config file that inherits from the official Ruby on Rails .rubocop.yml."
|
10
|
+
|
11
|
+
def create_config_file
|
12
|
+
file_method = config_file_exists? ? :prepend : :create
|
13
|
+
send :"#{file_method}_file", config_file_path, config_file_content
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def config_file_exists?
|
19
|
+
File.exist?(config_file_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def config_file_path
|
23
|
+
".rubocop.yml"
|
24
|
+
end
|
25
|
+
|
26
|
+
def config_file_content
|
27
|
+
<<-EOS.strip_heredoc
|
28
|
+
inherit_gem:
|
29
|
+
rubocop-rails_config:
|
30
|
+
- config/rails.yml
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-rails_config
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Toshimaru
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.53'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.53'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: RuboCop configuration which has the same code style checking as official
|
84
|
+
Ruby on Rails
|
85
|
+
email: me@toshimaru.net
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- config/rails.yml
|
93
|
+
- lib/custom_cops.rb
|
94
|
+
- lib/custom_cops/refute_not.rb
|
95
|
+
- lib/generators/rubocop_rails_config/install_generator.rb
|
96
|
+
homepage: https://github.com/toshimaru/rubocop-rails_config
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 2.2.2
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.7.3
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: RuboCop configuration which has the same code style checking as official
|
120
|
+
Ruby on Rails
|
121
|
+
test_files: []
|