rubocop-sensei 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +12 -12
- data/config/default.yml +8 -3
- data/lib/rubocop/cop/{style → lecture}/replace_elsif.rb +5 -2
- data/lib/rubocop/cop/lecture/unless_else.rb +30 -0
- data/lib/rubocop/cop/sensei_cops.rb +2 -1
- data/lib/rubocop/sensei/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4417b210dffcd34adf72e0699d8f8fb835da4adf6495800f61b4d20337ef1789
|
4
|
+
data.tar.gz: 0e52dde379f1e0f6d1bef9e6e294c8504dc07862522712edcd2162ff0170ecc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ce15e09a41f442788be5ef73bb6612d1c2716a2860f2d1fa71b1cb8788d6ee0861039e49bdb69436a0ef1010fa0d73a8fd88ae426930795059b89c50084ebf4
|
7
|
+
data.tar.gz: d9cf4aab057cc1af99cb732702eb6deda38ae9c6b4763b599ab36e836ae75a5ed86266990c68adfb7b093328f81d49db74c3a5752016369c9c1d550f1f902f7c
|
data/Gemfile.lock
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rubocop-sensei (0.1.
|
4
|
+
rubocop-sensei (0.1.3)
|
5
5
|
rubocop
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
ast (2.4.2)
|
11
|
-
debug (1.7.
|
11
|
+
debug (1.7.1)
|
12
12
|
irb (>= 1.5.0)
|
13
13
|
reline (>= 0.3.1)
|
14
14
|
diff-lcs (1.5.0)
|
15
|
-
io-console (0.
|
16
|
-
irb (1.6.
|
15
|
+
io-console (0.6.0)
|
16
|
+
irb (1.6.2)
|
17
17
|
reline (>= 0.3.0)
|
18
18
|
json (2.6.3)
|
19
|
-
minitest (5.
|
19
|
+
minitest (5.17.0)
|
20
20
|
parallel (1.22.1)
|
21
|
-
parser (3.
|
21
|
+
parser (3.2.0.0)
|
22
22
|
ast (~> 2.4.1)
|
23
23
|
rainbow (3.1.1)
|
24
24
|
rake (13.0.6)
|
25
25
|
regexp_parser (2.6.1)
|
26
|
-
reline (0.3.
|
26
|
+
reline (0.3.2)
|
27
27
|
io-console (~> 0.5)
|
28
28
|
rexml (3.2.5)
|
29
29
|
rspec (3.12.0)
|
@@ -32,27 +32,27 @@ GEM
|
|
32
32
|
rspec-mocks (~> 3.12.0)
|
33
33
|
rspec-core (3.12.0)
|
34
34
|
rspec-support (~> 3.12.0)
|
35
|
-
rspec-expectations (3.12.
|
35
|
+
rspec-expectations (3.12.1)
|
36
36
|
diff-lcs (>= 1.2.0, < 2.0)
|
37
37
|
rspec-support (~> 3.12.0)
|
38
|
-
rspec-mocks (3.12.
|
38
|
+
rspec-mocks (3.12.1)
|
39
39
|
diff-lcs (>= 1.2.0, < 2.0)
|
40
40
|
rspec-support (~> 3.12.0)
|
41
41
|
rspec-support (3.12.0)
|
42
|
-
rubocop (1.
|
42
|
+
rubocop (1.42.0)
|
43
43
|
json (~> 2.3)
|
44
44
|
parallel (~> 1.10)
|
45
45
|
parser (>= 3.1.2.1)
|
46
46
|
rainbow (>= 2.2.2, < 4.0)
|
47
47
|
regexp_parser (>= 1.8, < 3.0)
|
48
48
|
rexml (>= 3.2.5, < 4.0)
|
49
|
-
rubocop-ast (>= 1.
|
49
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
50
50
|
ruby-progressbar (~> 1.7)
|
51
51
|
unicode-display_width (>= 1.4.0, < 3.0)
|
52
52
|
rubocop-ast (1.24.1)
|
53
53
|
parser (>= 3.1.1.0)
|
54
54
|
ruby-progressbar (1.11.0)
|
55
|
-
unicode-display_width (2.
|
55
|
+
unicode-display_width (2.4.2)
|
56
56
|
|
57
57
|
PLATFORMS
|
58
58
|
arm64-darwin-21
|
data/config/default.yml
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
|
2
|
-
Description:
|
1
|
+
Lecture/ReplaceElsif:
|
2
|
+
Description: "`elsif` can be replaced with `case`"
|
3
3
|
Enabled: true
|
4
|
-
VersionAdded:
|
4
|
+
VersionAdded: "0.1.0"
|
5
|
+
|
6
|
+
Lecture/UnlessElse:
|
7
|
+
Description: "Do not use `unless` with `else`. Rewrite these with the positive case first."
|
8
|
+
Enabled: true
|
9
|
+
VersionAdded: "0.1.3"
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
|
-
module
|
5
|
+
module Lecture
|
6
6
|
# `elsif`は`case`で書き換え可能です。
|
7
7
|
# N個の分岐から1つ選ぶ「N者択一」のときはcaseをつかうと読みやすくなります。
|
8
8
|
#
|
@@ -65,7 +65,10 @@ module RuboCop
|
|
65
65
|
return unless node.elsif?
|
66
66
|
|
67
67
|
add_offense(node) do |corrector|
|
68
|
-
|
68
|
+
# if => case when
|
69
|
+
replacing_string = "case" + "\n" +
|
70
|
+
" " * node.parent.source_range.column + "when"
|
71
|
+
corrector.replace(node.parent.loc.keyword, replacing_string)
|
69
72
|
corrector.replace(node.loc.keyword, "when") # elsif => when
|
70
73
|
end
|
71
74
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Lecture
|
6
|
+
class UnlessElse < ::RuboCop::Cop::Style::UnlessElse
|
7
|
+
MSG = <<~STRING
|
8
|
+
`unless` `else` は避けた方が良いです。
|
9
|
+
`if` をつかって書き直すと読みやすくなります。
|
10
|
+
|
11
|
+
unless x == 1
|
12
|
+
puts "foo"
|
13
|
+
else
|
14
|
+
puts "bar"
|
15
|
+
end
|
16
|
+
|
17
|
+
ifをつかって書き直した例です。
|
18
|
+
|
19
|
+
if x == 1
|
20
|
+
puts "bar"
|
21
|
+
else
|
22
|
+
puts "foo"
|
23
|
+
end
|
24
|
+
|
25
|
+
このCopは RuboCop gem Style/UnlessElse と同じ内容です。
|
26
|
+
STRING
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuniaki Igarashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -40,8 +40,9 @@ files:
|
|
40
40
|
- Rakefile
|
41
41
|
- config/default.yml
|
42
42
|
- lib/rubocop-sensei.rb
|
43
|
+
- lib/rubocop/cop/lecture/replace_elsif.rb
|
44
|
+
- lib/rubocop/cop/lecture/unless_else.rb
|
43
45
|
- lib/rubocop/cop/sensei_cops.rb
|
44
|
-
- lib/rubocop/cop/style/replace_elsif.rb
|
45
46
|
- lib/rubocop/sensei.rb
|
46
47
|
- lib/rubocop/sensei/inject.rb
|
47
48
|
- lib/rubocop/sensei/version.rb
|