rubocop-sensei 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/Gemfile.lock +25 -21
- data/LICENSE.txt +13 -0
- data/README.md +64 -9
- data/config/default.yml +10 -0
- data/demo.gif +0 -0
- data/lib/rubocop/cop/lecture/explain_numbered_parameters.rb +34 -0
- data/lib/rubocop/cop/lecture/explain_pattern_match_case_in.rb +46 -0
- data/lib/rubocop/cop/lecture/explain_symbol_to_proc.rb +1 -1
- data/lib/rubocop/cop/sensei_cops.rb +2 -0
- data/lib/rubocop/sensei/version.rb +1 -1
- data/rubocop-sensei.gemspec +1 -1
- data/sample/.rubocop.yml +8 -0
- data/sample/Gemfile +6 -0
- data/sample/Gemfile.lock +41 -0
- data/sample/target.rb +4 -0
- metadata +11 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5479d9e29fc19485cd4debdeb0f6441dc444003ed7f2472227abd0e4cd95680d
|
4
|
+
data.tar.gz: 524580de696dc8e3c808f683c92414f083b108c06e1e5a8ae393e12d5bca6a6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed56878a610c3dcfd5457d1ed94303dc002dfcc95fdd699ed34ec16a732f666b87496f27ad316386550865f362f17dfb9248cf0ac72b8e4e66ce47e303555897
|
7
|
+
data.tar.gz: 379348550eb3a117028c506a435410d707feeee23c3150827afb98ba240ae78cff9146d36be98a1eebe8d3badc54da5c1ea98f376dfa70214970eee0ff00695f
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rubocop-sensei (0.1.
|
4
|
+
rubocop-sensei (0.1.5)
|
5
5
|
rubocop
|
6
6
|
typeprof
|
7
7
|
|
@@ -9,52 +9,56 @@ GEM
|
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
11
|
ast (2.4.2)
|
12
|
-
debug (1.
|
12
|
+
debug (1.8.0)
|
13
13
|
irb (>= 1.5.0)
|
14
14
|
reline (>= 0.3.1)
|
15
15
|
diff-lcs (1.5.0)
|
16
16
|
io-console (0.6.0)
|
17
|
-
irb (1.
|
18
|
-
reline (>= 0.3.
|
17
|
+
irb (1.7.3)
|
18
|
+
reline (>= 0.3.6)
|
19
19
|
json (2.6.3)
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
language_server-protocol (3.17.0.3)
|
21
|
+
minitest (5.18.1)
|
22
|
+
parallel (1.23.0)
|
23
|
+
parser (3.2.2.3)
|
23
24
|
ast (~> 2.4.1)
|
25
|
+
racc
|
26
|
+
racc (1.7.1)
|
24
27
|
rainbow (3.1.1)
|
25
28
|
rake (13.0.6)
|
26
|
-
rbs (
|
27
|
-
regexp_parser (2.
|
28
|
-
reline (0.3.
|
29
|
+
rbs (3.1.0)
|
30
|
+
regexp_parser (2.8.1)
|
31
|
+
reline (0.3.6)
|
29
32
|
io-console (~> 0.5)
|
30
33
|
rexml (3.2.5)
|
31
34
|
rspec (3.12.0)
|
32
35
|
rspec-core (~> 3.12.0)
|
33
36
|
rspec-expectations (~> 3.12.0)
|
34
37
|
rspec-mocks (~> 3.12.0)
|
35
|
-
rspec-core (3.12.
|
38
|
+
rspec-core (3.12.2)
|
36
39
|
rspec-support (~> 3.12.0)
|
37
|
-
rspec-expectations (3.12.
|
40
|
+
rspec-expectations (3.12.3)
|
38
41
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
42
|
rspec-support (~> 3.12.0)
|
40
|
-
rspec-mocks (3.12.
|
43
|
+
rspec-mocks (3.12.6)
|
41
44
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
45
|
rspec-support (~> 3.12.0)
|
43
|
-
rspec-support (3.12.
|
44
|
-
rubocop (1.
|
46
|
+
rspec-support (3.12.1)
|
47
|
+
rubocop (1.54.2)
|
45
48
|
json (~> 2.3)
|
49
|
+
language_server-protocol (>= 3.17.0)
|
46
50
|
parallel (~> 1.10)
|
47
|
-
parser (>= 3.2.
|
51
|
+
parser (>= 3.2.2.3)
|
48
52
|
rainbow (>= 2.2.2, < 4.0)
|
49
53
|
regexp_parser (>= 1.8, < 3.0)
|
50
54
|
rexml (>= 3.2.5, < 4.0)
|
51
|
-
rubocop-ast (>= 1.
|
55
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
52
56
|
ruby-progressbar (~> 1.7)
|
53
57
|
unicode-display_width (>= 2.4.0, < 3.0)
|
54
|
-
rubocop-ast (1.
|
55
|
-
parser (>= 3.
|
56
|
-
ruby-progressbar (1.
|
57
|
-
typeprof (0.21.
|
58
|
+
rubocop-ast (1.29.0)
|
59
|
+
parser (>= 3.2.1.0)
|
60
|
+
ruby-progressbar (1.13.0)
|
61
|
+
typeprof (0.21.7)
|
58
62
|
rbs (>= 1.8.1)
|
59
63
|
unicode-display_width (2.4.2)
|
60
64
|
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2023 Kuniaki Igarashi
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# RuboSensei
|
2
2
|
|
3
3
|
- RuboSensei は書いたRuby/Railsコードに対して、より良い書き方を教えてくれるツールです
|
4
|
-
- RuboCop
|
4
|
+
- RuboCop Gem の仕組みをつかっています
|
5
5
|
- rubocopコマンドで良い書き方のアドバイスが表示されます
|
6
|
-
-
|
6
|
+
- RuboCop に標準で入っているLSPをつかうとエディタ上で書いたコードのそばに表示できます
|
7
7
|
|
8
8
|
![demo](demo.gif)
|
9
9
|
|
10
|
-
#
|
10
|
+
# つかい方
|
11
|
+
|
12
|
+
## インストール
|
11
13
|
|
12
14
|
- Gemfile に以下を追加します。
|
13
15
|
|
@@ -31,13 +33,15 @@ Lecture:
|
|
31
33
|
Enabled: true
|
32
34
|
```
|
33
35
|
|
36
|
+
## rubocopコマンドからつかう
|
37
|
+
|
34
38
|
- rubocop コマンドを実行します
|
35
39
|
- $ bundle exec rubocop
|
36
40
|
|
37
41
|
- rubocop コマンドに `--autocorrect` オプションを渡すと、対応している項目は自動修正も行います
|
38
42
|
- $ bundle exec rubocop --autocorrect
|
39
43
|
|
40
|
-
|
44
|
+
- 実行結果例
|
41
45
|
|
42
46
|
```
|
43
47
|
app/models/book.rb:12:5: C: Lecture/PreferMap: このeachメソッドはmapメソッドで置き換えられるかもしれません。
|
@@ -46,10 +50,23 @@ app/models/book.rb:12:5: C: Lecture/PreferMap: このeachメソッドはmapメ
|
|
46
50
|
^^^^^^^^^^^^^^^^^
|
47
51
|
```
|
48
52
|
|
49
|
-
|
53
|
+
## VSCode で書いているコード上にアドバイスする
|
54
|
+
|
55
|
+
- VSCode で書いているコード上でリアルタイムにアドバイスを表示できます
|
56
|
+
- RuboCopに標準で入っているLSP機能と、VSCode拡張 vscode-rubocop をつかいます
|
57
|
+
- VSCode拡張 vscode-rubocop をVSCodeへインストールして有効にします
|
58
|
+
- https://marketplace.visualstudio.com/items?itemName=rubocop.vscode-rubocop
|
59
|
+
- rubocopコマンドが実行可能になっていれば、自動でRuboCopを実行して結果を表示します
|
60
|
+
- 手動でLSPを起動するコマンドを実行する必要はありません
|
61
|
+
|
62
|
+
# .rubocop.yml の書き方例
|
63
|
+
|
64
|
+
- RuboSenseiのアドバイスはLectureカテゴリとしてまとめられています
|
50
65
|
|
51
|
-
|
52
|
-
|
66
|
+
## プロジェクトの.rubocop.ymlがないとき
|
67
|
+
|
68
|
+
- たとえば次のような内容で作成します
|
69
|
+
- RuboCopデフォルトの検査のうちStyle, LintカテゴリだけをONにして、RuboSenseiのアドバイス(Lectureカテゴリ)をONにするときの.rubocop.ymlの例
|
53
70
|
|
54
71
|
```
|
55
72
|
AllCops:
|
@@ -69,7 +86,7 @@ Lecture:
|
|
69
86
|
Enabled: true
|
70
87
|
```
|
71
88
|
|
72
|
-
- RuboCopデフォルトの検査をオフにしてRuboSensei
|
89
|
+
- RuboCopデフォルトの検査をオフにしてRuboSenseiのアドバイス(Lectureカテゴリ)をONにするときの.rubocop.ymlの例
|
73
90
|
|
74
91
|
```yaml
|
75
92
|
AllCops:
|
@@ -85,6 +102,44 @@ Lecture/ReplaceElsif:
|
|
85
102
|
Enabled: true
|
86
103
|
```
|
87
104
|
|
105
|
+
## プロジェクトの.rubocop.ymlがあるとき
|
106
|
+
|
107
|
+
- require設定に rubocop-sensei を追加します
|
108
|
+
|
109
|
+
```yaml
|
110
|
+
require:
|
111
|
+
- rubocop-sensei
|
112
|
+
```
|
113
|
+
|
114
|
+
- カテゴリ設定に Lecture を有効にする設定を追加します
|
115
|
+
|
116
|
+
```yaml
|
117
|
+
Lecture:
|
118
|
+
Enabled: true
|
119
|
+
```
|
120
|
+
|
121
|
+
## アドバイスを非表示にするとき
|
122
|
+
|
123
|
+
- RuboSenseiのアドバイス表示時に書かれている名前を指定してEnabled: false設定を追記します
|
124
|
+
|
125
|
+
```yaml
|
126
|
+
Lecture:
|
127
|
+
Enabled: true
|
128
|
+
|
129
|
+
Lecture/ReplaceElsif:
|
130
|
+
Enabled: false
|
131
|
+
```
|
132
|
+
|
133
|
+
- 全アドバイスをオフにするときはLectureカテゴリをEnabled: falseにします
|
134
|
+
- または、Lectureカテゴリの設定を削除します
|
135
|
+
|
136
|
+
```yaml
|
137
|
+
Lecture:
|
138
|
+
Enabled: false
|
139
|
+
```
|
140
|
+
|
88
141
|
# License
|
89
142
|
|
90
|
-
|
143
|
+
- Apache License Version 2.0
|
144
|
+
- https://www.apache.org/licenses/LICENSE-2.0
|
145
|
+
- (RuboSensei v0.1.4 まではMITライセンス)
|
data/config/default.yml
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
Lecture/ExplainPatternMatchCaseIn:
|
2
|
+
Description: 'Explain pattern match case in'
|
3
|
+
Enabled: true
|
4
|
+
VersionAdded: '0.1.5'
|
5
|
+
|
6
|
+
Lecture/ExplainNumberedParameters:
|
7
|
+
Description: 'Explain numbered parameters'
|
8
|
+
Enabled: true
|
9
|
+
VersionAdded: '0.1.5'
|
10
|
+
|
1
11
|
Lecture/ExplainSymbolToProc :
|
2
12
|
Description: 'Explain receiver.method(&:method)'
|
3
13
|
Enabled: true
|
data/demo.gif
CHANGED
Binary file
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lecture
|
6
|
+
# foo.bar{ _1.baz } は foo.bar{|x| x.baz } と同じです。
|
7
|
+
# _1と書くことで、||で囲まれたブロック変数を書かずに短く書けます。
|
8
|
+
# ナンバーパラメータと呼ばれます。
|
9
|
+
# _1, _2, _3, ... と複数書くこともできます。
|
10
|
+
# foo.bar{ [_1,_2] } は foo.bar{|x,y| [x,y] }と同じです。
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# # good
|
14
|
+
# foo.bar{ _1.baz }
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# foo.bar{|x| x.baz }
|
18
|
+
#
|
19
|
+
class ExplainNumberedParameters < Base
|
20
|
+
MSG = <<~STRING
|
21
|
+
foo.bar{ _1.baz } は foo.bar{|x| x.baz } と同じです。
|
22
|
+
_1と書くことで、||で囲まれたブロック変数を書かずに短く書けます。
|
23
|
+
ナンバーパラメータと呼ばれます。
|
24
|
+
_1, _2, _3, ... と複数書くこともできます。
|
25
|
+
foo.bar{ [_1,_2] } は foo.bar{|x,y| [x,y] }と同じです。
|
26
|
+
STRING
|
27
|
+
|
28
|
+
def on_numblock(node)
|
29
|
+
add_offense(node)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lecture
|
6
|
+
# case in はパターンマッチ構文です。次のようにつかいます。
|
7
|
+
# case [1,2,3]
|
8
|
+
# in [x,2,3]
|
9
|
+
# end
|
10
|
+
# p x #=> 1
|
11
|
+
# caseにつづけて書いた式(この例では [1,2,3] )を実行して、結果とマッチするものをin節に書いたパターン群から探します。
|
12
|
+
# in節には変数入りのパターンを書くことができ、caseにつづけて書いた式の結果とパターンとを対応させ、それぞれの変数に代入します。
|
13
|
+
#
|
14
|
+
# 便利なケースは、深いハッシュや配列にマッチさせるときや、複数の変数に代入するときです。
|
15
|
+
# case { a: [1,2,3], b: { c: 10 }}
|
16
|
+
# in { a: [x,2,3], b: { c: y }}
|
17
|
+
# end
|
18
|
+
# p x #=> 1
|
19
|
+
# p y #=> 10
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# # good
|
23
|
+
# case [1,2,3]
|
24
|
+
# in [x,2,3]
|
25
|
+
# in [x,5,6]
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
class ExplainPatternMatchCaseIn < Base
|
29
|
+
MSG = <<~STRING
|
30
|
+
case in はパターンマッチ構文です。次のようにつかいます。
|
31
|
+
case [1,2,3]
|
32
|
+
in [x,2,3]
|
33
|
+
end
|
34
|
+
p x #=> 1
|
35
|
+
caseにつづけて書いた式(例では [1,2,3] )を実行して、結果とマッチするものをin節に書いたパターン群から探します。
|
36
|
+
in節には変数入りのパターンを書くことができ、caseにつづけて書いた式の結果とパターンとを対応させ、それぞれの変数に代入します。
|
37
|
+
STRING
|
38
|
+
|
39
|
+
# 1行inでは呼ばれないことを確認済み
|
40
|
+
def on_case_match(node)
|
41
|
+
add_offense(node)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'lecture/explain_numbered_parameters'
|
4
|
+
require_relative 'lecture/explain_pattern_match_case_in'
|
3
5
|
require_relative 'lecture/prefer_symbol_to_proc'
|
4
6
|
require_relative 'lecture/explain_symbol_to_proc'
|
5
7
|
require_relative 'lecture/prefer_map'
|
data/rubocop-sensei.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.summary = "Rubocop Sensei"
|
12
12
|
spec.description = "."
|
13
13
|
spec.homepage = "https://github.com/igaiga/rubocop-sensei"
|
14
|
-
spec.required_ruby_version = ">=
|
14
|
+
spec.required_ruby_version = ">= 3.0.0"
|
15
15
|
|
16
16
|
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
17
17
|
|
data/sample/.rubocop.yml
ADDED
data/sample/Gemfile
ADDED
data/sample/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ast (2.4.2)
|
5
|
+
json (2.6.3)
|
6
|
+
parallel (1.23.0)
|
7
|
+
parser (3.2.2.1)
|
8
|
+
ast (~> 2.4.1)
|
9
|
+
rainbow (3.1.1)
|
10
|
+
rbs (3.0.4)
|
11
|
+
regexp_parser (2.8.0)
|
12
|
+
rexml (3.2.5)
|
13
|
+
rubocop (1.50.2)
|
14
|
+
json (~> 2.3)
|
15
|
+
parallel (~> 1.10)
|
16
|
+
parser (>= 3.2.0.0)
|
17
|
+
rainbow (>= 2.2.2, < 4.0)
|
18
|
+
regexp_parser (>= 1.8, < 3.0)
|
19
|
+
rexml (>= 3.2.5, < 4.0)
|
20
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
21
|
+
ruby-progressbar (~> 1.7)
|
22
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
23
|
+
rubocop-ast (1.28.0)
|
24
|
+
parser (>= 3.2.1.0)
|
25
|
+
rubocop-sensei (0.1.4)
|
26
|
+
rubocop
|
27
|
+
typeprof
|
28
|
+
ruby-progressbar (1.13.0)
|
29
|
+
typeprof (0.21.7)
|
30
|
+
rbs (>= 1.8.1)
|
31
|
+
unicode-display_width (2.4.2)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
arm64-darwin-22
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
rubocop
|
38
|
+
rubocop-sensei
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
2.4.10
|
data/sample/target.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-sensei
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuniaki Igarashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -50,11 +50,14 @@ files:
|
|
50
50
|
- Gemfile
|
51
51
|
- Gemfile.lock
|
52
52
|
- 'LICENSE '
|
53
|
+
- LICENSE.txt
|
53
54
|
- README.md
|
54
55
|
- Rakefile
|
55
56
|
- config/default.yml
|
56
57
|
- demo.gif
|
57
58
|
- lib/rubocop-sensei.rb
|
59
|
+
- lib/rubocop/cop/lecture/explain_numbered_parameters.rb
|
60
|
+
- lib/rubocop/cop/lecture/explain_pattern_match_case_in.rb
|
58
61
|
- lib/rubocop/cop/lecture/explain_symbol_to_proc.rb
|
59
62
|
- lib/rubocop/cop/lecture/prefer_map.rb
|
60
63
|
- lib/rubocop/cop/lecture/prefer_symbol_to_proc.rb
|
@@ -65,6 +68,10 @@ files:
|
|
65
68
|
- lib/rubocop/sensei/inject.rb
|
66
69
|
- lib/rubocop/sensei/version.rb
|
67
70
|
- rubocop-sensei.gemspec
|
71
|
+
- sample/.rubocop.yml
|
72
|
+
- sample/Gemfile
|
73
|
+
- sample/Gemfile.lock
|
74
|
+
- sample/target.rb
|
68
75
|
- sig/rubocop/sensei.rbs
|
69
76
|
homepage: https://github.com/igaiga/rubocop-sensei
|
70
77
|
licenses: []
|
@@ -79,14 +86,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
86
|
requirements:
|
80
87
|
- - ">="
|
81
88
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
89
|
+
version: 3.0.0
|
83
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
91
|
requirements:
|
85
92
|
- - ">="
|
86
93
|
- !ruby/object:Gem::Version
|
87
94
|
version: '0'
|
88
95
|
requirements: []
|
89
|
-
rubygems_version: 3.4.
|
96
|
+
rubygems_version: 3.4.16
|
90
97
|
signing_key:
|
91
98
|
specification_version: 4
|
92
99
|
summary: Rubocop Sensei
|