rubocop-yayoi 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +19 -0
  3. data/README.md +2 -0
  4. data/lib/rubocop/cop/cop.rb +15 -0
  5. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  6. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +1 -1
  7. data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
  8. data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +1 -1
  9. data/lib/rubocop/cop/layout/indentation_consistency.rb +1 -1
  10. data/lib/rubocop/cop/layout/indentation_width.rb +3 -2
  11. data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
  12. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +10 -3
  13. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +19 -7
  14. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
  15. data/lib/rubocop/cop/lint/unused_method_argument.rb +0 -2
  16. data/lib/rubocop/cop/lint/useless_access_modifier.rb +47 -1
  17. data/lib/rubocop/cop/lint/useless_assignment.rb +8 -1
  18. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
  19. data/lib/rubocop/cop/metrics/line_length.rb +1 -1
  20. data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
  21. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +24 -3
  22. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +13 -2
  23. data/lib/rubocop/cop/mixin/method_complexity.rb +32 -0
  24. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +8 -1
  25. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +9 -2
  26. data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
  27. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
  28. data/lib/rubocop/cop/naming/variable_name.rb +1 -1
  29. data/lib/rubocop/cop/style/and_or.rb +2 -1
  30. data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
  31. data/lib/rubocop/cop/style/colon_method_call.rb +1 -1
  32. data/lib/rubocop/cop/style/comment_annotation.rb +28 -3
  33. data/lib/rubocop/cop/style/def_with_parentheses.rb +1 -1
  34. data/lib/rubocop/cop/style/documentation.rb +12 -1
  35. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  36. data/lib/rubocop/cop/style/empty_method.rb +6 -2
  37. data/lib/rubocop/cop/style/mutable_constant.rb +1 -1
  38. data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
  39. data/lib/rubocop/cop/style/redundant_return.rb +11 -2
  40. data/lib/rubocop/cop/style/symbol_array.rb +21 -0
  41. data/lib/rubocop/cop/style/unneeded_condition.rb +10 -2
  42. data/lib/rubocop/cop/style/unneeded_interpolation.rb +1 -1
  43. data/lib/rubocop/cop/style/word_array.rb +11 -2
  44. data/lib/rubocop/yayoi/version.rb +1 -1
  45. data/lib/rubocop-yayoi.rb +4 -0
  46. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd646f6d502dcae26a3ee043a4a9f379b5f818ed513c7b12816b81b58c092a1d
4
- data.tar.gz: 3e2e3ca11118f2a7a1d411762f08f6388f787bdeac29ec099fc0d8b210f82f16
3
+ metadata.gz: c8b1eb1be46ec7f4b73fbe7bceae1a6eb190f77e8603f7df5ba08018bdc14baf
4
+ data.tar.gz: a2dbade19948eacf246522e3dd3f1d8c3883e22097a674d527208529e041029d
5
5
  SHA512:
6
- metadata.gz: 689e52d24e000cfd8b2239c91dc260b185cdafcf0861a250258c81f76bc4dfc2f4b90af58ffeb16c28a2cc171608542ac999c841f8a87e9b24e4dcc4aa4b6d55
7
- data.tar.gz: 5d061b0091edde9c16815a2c93d6661f4f71e5842eefb052e3fb01a58e2dfb5ac928b0a91d7464fc55b94eb87771d24f0bcb622a4f08ea18e247c4a36364234a
6
+ metadata.gz: 9c34b3346bb085e5a2c81779ec51dd815a0df5518534a981ce77ed012cca4dcc06feb9e21126ff241df1a50c8e0b6fc2766fddaf73af3fd60c712ef54a90bb94
7
+ data.tar.gz: 77486cb28980de30d35c1f05113710a4e9849f54dd4814c259fdba8474360a1812609271bfe6539f331e73a3431b3da461b87f35cb91473908a4b36e07a9ba9b
data/.rubocop.yml CHANGED
@@ -7,6 +7,25 @@ AllCops:
7
7
  - 'spec/fixtures/**/*'
8
8
  - 'tmp/**/*'
9
9
 
10
+ # Offense count: 77
11
+ Metrics/AbcSize:
12
+ Max: 17
13
+
14
+ # Offense count: 52
15
+ # Configuration parameters: CountComments.
16
+ Metrics/ClassLength:
17
+ Max: 181
18
+
19
+ # Offense count: 222
20
+ # Configuration parameters: CountComments, ExcludedMethods.
21
+ Metrics/MethodLength:
22
+ Max: 14
23
+
24
+ # Offense count: 5
25
+ # Configuration parameters: CountComments.
26
+ Metrics/ModuleLength:
27
+ Max: 141
28
+
10
29
  Naming/FileName:
11
30
  Exclude:
12
31
  - lib/rubocop-yayoi.rb
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Rubocop::Yayoi
2
2
 
3
+ [![Build Status](https://travis-ci.org/YutaGoto/rubocop-yayoi.svg?branch=master)](https://travis-ci.org/YutaGoto/rubocop-yayoi)
4
+
3
5
  `ζ*'ヮ')ζ<うっうー!`
4
6
 
5
7
  このgemは [rubocop](https://github.com/rubocop-hq/rubocop) 実行後に表示されるテキストがアイドルマスター 765プロ所属の高槻やよい風に指摘してくれるgemです!
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ class Cop
6
+ def message(_node = nil)
7
+ if self.class.const_defined?(:YAYOI_MSG)
8
+ self.class::YAYOI_MSG
9
+ else
10
+ self.class::MSG
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -5,7 +5,7 @@ module RuboCop
5
5
  module Layout
6
6
  class DefEndAlignment < Cop
7
7
  include EndKeywordAlignment
8
- MSG = "ζ*'ヮ')ζ<うっうー! %d, %dにある`end`が%d, %dにある`%s`とずれていますよー!".freeze
8
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!%d, %dにある`end`が%d, %dにある`%s`とずれていますよー!".freeze
9
9
  end
10
10
  end
11
11
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Layout
6
6
  class EmptyLineBetweenDefs < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!メソッドとメソッドの間には空行をいれましょうねー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!メソッドとメソッドの間には空行をいれましょうねー!".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Layout
6
6
  class EmptyLines < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!余分な改行がありますよー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!余分な改行がありますよー!".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Layout
6
6
  class EmptyLinesAroundMethodBody < Cop
7
- KIND = 'メソッド'.freeze
7
+ YAYOI_KIND = 'メソッド'.freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Layout
6
6
  class IndentationConsistency < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!矛盾しているインデントの場所がありますよー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!矛盾しているインデントの場所がありますよー!".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,8 +4,9 @@ module RuboCop
4
4
  module Cop
5
5
  module Layout
6
6
  class IndentationWidth < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!%<configured_indentation_width>dスペースを使いましょうねー" \
8
- '(%<indentation>dはだめですよー)'.freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!" \
8
+ '%<configured_indentation_width>dスペースを使いましょうねー' \
9
+ '(%<indentation>dはだめですよー)'.freeze
9
10
  end
10
11
  end
11
12
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Layout
6
6
  class InitialIndentation < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!ファイルの最初の行はインデントをいれないでくださいねー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!ファイルの最初の行はインデントをいれないでくださいねー!".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,9 +4,16 @@ module RuboCop
4
4
  module Cop
5
5
  module Lint
6
6
  class AmbiguousBlockAssociation < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!" \
8
- 'ブロックが`%<method>s`メソッドの呼び出しにちゃんと関連連れられているかわからないですー。' \
9
- 'ちゃんと`%<param>s`にカッコを使いましょうねー!'.freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!" \
8
+ 'ブロックが`%<method>s`メソッドの呼び出しにちゃんと関連連れられているかわからないですー。' \
9
+ 'ちゃんと`%<param>s`にカッコを使いましょうねー!'.freeze
10
+
11
+ def message(send_node)
12
+ block_param = send_node.last_argument
13
+
14
+ format(YAYOI_MSG, param: block_param.source,
15
+ method: block_param.send_node.source)
16
+ end
10
17
  end
11
18
  end
12
19
  end
@@ -4,13 +4,25 @@ module RuboCop
4
4
  module Cop
5
5
  module Lint
6
6
  class IneffectiveAccessModifier < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!%<line>d行目にある`%<modifier>s`は" \
8
- 'シングルトンメソッドの%<modifier>sを作りませんよー!' \
9
- '代わりに%<alternative>s'.freeze
10
- ALTERNATIVE_PRIVATE = '`private_class_method`か`private`を' \
11
- '`class << self`ブロックの内部に置きましょー!'.freeze
12
- ALTERNATIVE_PROTECTED = '`protected`を' \
13
- '`class << self`ブロックの内部に置きましょー!'.freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!%<line>d行目にある`%<modifier>s`は" \
8
+ 'シングルトンメソッドの%<modifier>sを作りませんよー!' \
9
+ '代わりに%<alternative>s'.freeze
10
+ YAYOI_ALTERNATIVE_PRIVATE = '`private_class_method`か`private`を' \
11
+ '`class << self`ブロックの内部に置きましょー!'.freeze
12
+ YAYOI_ALTERNATIVE_PROTECTED = '`protected`を' \
13
+ '`class << self`ブロックの内部に置きましょー!'.freeze
14
+
15
+ def format_message(modifier)
16
+ visibility = modifier.method_name
17
+ alternative = if visibility == :private
18
+ YAYOI_ALTERNATIVE_PRIVATE
19
+ else
20
+ YAYOI_ALTERNATIVE_PROTECTED
21
+ end
22
+ format(YAYOI_MSG, modifier: visibility,
23
+ line: modifier.location.expression.line,
24
+ alternative: alternative)
25
+ end
14
26
  end
15
27
  end
16
28
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Lint
6
6
  class UnreachableCode < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!処理されないコードがありますよー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!処理されないコードがありますよー!".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,6 @@ module RuboCop
4
4
  module Cop
5
5
  module Lint
6
6
  class UnusedMethodArgument < Cop
7
- # rubocop:disable Metrics/MethodLength
8
7
  def message(variable)
9
8
  message = String.new(
10
9
  "ζ*'ヮ')ζ<うっうー!使っていない引数がありますよー `#{variable.name}`!"
@@ -24,7 +23,6 @@ module RuboCop
24
23
 
25
24
  message
26
25
  end
27
- # rubocop:enable Metrics/MethodLength
28
26
  end
29
27
  end
30
28
  end
@@ -4,7 +4,53 @@ module RuboCop
4
4
  module Cop
5
5
  module Lint
6
6
  class UselessAccessModifier < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!`%<current>s`は意味がないですよー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!`%<current>s`は意味がないですよー!".freeze
8
+
9
+ def check_node(node)
10
+ return if node.nil?
11
+
12
+ if node.begin_type?
13
+ check_scope(node)
14
+ elsif node.send_type? && node.bare_access_modifier?
15
+ add_offense(
16
+ node,
17
+ message: format(YAYOI_MSG, current: node.method_name)
18
+ )
19
+ end
20
+ end
21
+
22
+ def check_scope(node)
23
+ cur_vis, unused = check_child_nodes(node, nil, :public)
24
+
25
+ return unless unused
26
+
27
+ add_offense(unused, message: format(YAYOI_MSG, current: cur_vis))
28
+ end
29
+
30
+ def check_send_node(node, cur_vis, unused)
31
+ if node.bare_access_modifier?
32
+ check_new_visibility(node, unused, node.method_name, cur_vis)
33
+ elsif node.method_name == :private_class_method && !node.arguments?
34
+ add_offense(
35
+ node,
36
+ message: format(YAYOI_MSG, current: node.method_name)
37
+ )
38
+ [cur_vis, unused]
39
+ end
40
+ end
41
+
42
+ def check_new_visibility(node, unused, new_vis, cur_vis)
43
+ if new_vis == cur_vis
44
+ add_offense(node, message: format(YAYOI_MSG, current: cur_vis))
45
+ else
46
+ if unused
47
+ add_offense(unused, message: format(YAYOI_MSG, current: cur_vis))
48
+ end
49
+ unused = node
50
+ end
51
+
52
+ [new_vis, unused]
53
+ end
8
54
  end
9
55
  end
10
56
  end
@@ -4,7 +4,14 @@ module RuboCop
4
4
  module Cop
5
5
  module Lint
6
6
  class UselessAssignment < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!使っていない変数がありますよー! - `%<variable>s`.".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!使っていない変数がありますよー! - `%<variable>s`.".freeze
8
+
9
+ def message_for_useless_assignment(assignment)
10
+ variable = assignment.variable
11
+
12
+ format(YAYOI_MSG, variable: variable.name) +
13
+ message_specification(assignment, variable).to_s
14
+ end
8
15
  end
9
16
  end
10
17
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Metrics
6
6
  class CyclomaticComplexity < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!%<method>sの循環的複雑度がとても高いですよー!" \
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!%<method>sの循環的複雑度がとても高いですよー!" \
8
8
  '[%<complexity>d/%<max>d]'.freeze
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Metrics
6
6
  class LineLength < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!一行の長さがとても長いですよー! [%<length>d/%<max>d]".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!一行の長さがとても長いですよー! [%<length>d/%<max>d]".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Metrics
6
6
  class PerceivedComplexity < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!%<method>sの複雑度がとても高いですよー!" \
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!%<method>sの複雑度がとても高いですよー!" \
8
8
  '[%<complexity>d/%<max>d]'.freeze
9
9
  end
10
10
  end
@@ -4,9 +4,30 @@ module RuboCop
4
4
  module Cop
5
5
  module Layout
6
6
  module EmptyLinesAroundBody
7
- MSG_EXTRA = "ζ*'ヮ')ζ<うっうー!%<kind>sに空行が見つかりましたよー!".freeze
8
- MSG_MISSING = "ζ*'ヮ')ζ<うっうー!%<kind>sのまわりに空行がないですよー!".freeze
9
- MSG_DEFERRED = "ζ*'ヮ')ζ<うっうー!%<type>sの前に空行がないですよー!".freeze
7
+ YAYOI_MSG_EXTRA = "ζ*'ヮ')ζ<うっうー!%<kind>sに空行が見つかりましたよー!".freeze
8
+ YAYOI_MSG_MISSING = "ζ*'ヮ')ζ<うっうー!%<kind>sのまわりに空行がないですよー!".freeze
9
+ YAYOI_MSG_DEFERRED = "ζ*'ヮ')ζ<うっうー!%<type>sの前に空行がないですよー!".freeze
10
+
11
+ def check_source(style, line_no, desc)
12
+ case style
13
+ when :no_empty_lines
14
+ check_line(style, line_no, message(YAYOI_MSG_EXTRA, desc), &:empty?)
15
+ when :empty_lines
16
+ check_line(style, line_no, message(YAYOI_MSG_MISSING, desc)) do |l|
17
+ !l.empty?
18
+ end
19
+ end
20
+ end
21
+
22
+ def deferred_message(node)
23
+ format(YAYOI_MSG_DEFERRED, type: node.type)
24
+ end
25
+
26
+ def message(type, desc)
27
+ kind = self.class::KIND
28
+ kind = self.class::YAYOI_KIND if kind.blank?
29
+ format(type, kind: kind, location: desc)
30
+ end
10
31
  end
11
32
  end
12
33
  end
@@ -3,8 +3,19 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module EndKeywordAlignment
6
- MSG = "ζ*'ヮ')ζ<うっうー! %<end_line>d, %<end_col>dにある`end`が" \
7
- '%<align_line>d, %<align_col>dにある`%<source>s`とずれていますよー!'.freeze
6
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー! %<end_line>d, %<end_col>dにある`end`が" \
7
+ '%<align_line>d, %<align_col>d' \
8
+ 'にある`%<source>s`とずれていますよー!'.freeze
9
+
10
+ def add_offense_for_misalignment(node, align_with)
11
+ end_loc = node.loc.end
12
+ msg = format(YAYOI_MSG, end_line: end_loc.line,
13
+ end_col: end_loc.column,
14
+ source: align_with.source,
15
+ align_line: align_with.line,
16
+ align_col: align_with.column)
17
+ add_offense(node, location: end_loc, message: msg)
18
+ end
8
19
  end
9
20
  end
10
21
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module MethodComplexity
6
+ def class_msg
7
+ msg = self.class::MSG
8
+ msg = self.class::YAYOI_MSG if msg.blank?
9
+ msg
10
+ end
11
+
12
+ def check_complexity(node, method_name)
13
+ # Accepts empty methods always.
14
+ return unless node.body
15
+
16
+ max = cop_config['Max']
17
+ complexity = complexity(node.body)
18
+
19
+ return unless complexity > max
20
+
21
+ msg = format(class_msg,
22
+ method: method_name,
23
+ complexity: complexity,
24
+ max: max)
25
+
26
+ add_offense(node, message: msg) do
27
+ self.max = complexity.ceil
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -3,7 +3,14 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module SpaceAfterPunctuation
6
- MSG = "ζ*'ヮ')ζ<うっうー!%<token>sの後ろにスペースがないですよー!".freeze
6
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!%<token>sの後ろにスペースがないですよー!".freeze
7
+
8
+ def investigate(processed_source)
9
+ each_missing_space(processed_source.tokens) do |token|
10
+ add_offense(token, location: token.pos,
11
+ message: format(YAYOI_MSG, token: kind(token)))
12
+ end
13
+ end
7
14
  end
8
15
  end
9
16
  end
@@ -3,8 +3,8 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module UncommunicativeName
6
- LENGTH_MSG = "ζ*'ヮ')ζ<うっうー!" \
7
- '%<name_type>sの長さは最低でも%<min>s文字以上にしましょうねー!'.freeze
6
+ YAYOI_LENGTH_YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!" \
7
+ '%<name_type>sの長さは最低でも%<min>s文字以上にしましょうねー!'.freeze
8
8
 
9
9
  def name_type(node)
10
10
  @name_type ||= begin
@@ -14,6 +14,13 @@ module RuboCop
14
14
  end
15
15
  end
16
16
  end
17
+
18
+ def length_offense(node, range)
19
+ add_offense(node, location: range,
20
+ message: format(YAYOI_LENGTH_YAYOI_MSG,
21
+ name_type: name_type(node).capitalize,
22
+ min: min_length))
23
+ end
17
24
  end
18
25
  end
19
26
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Naming
6
6
  class AsciiIdentifiers < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!識別子にはラテン文字だけを使いましょうねー".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!識別子にはラテン文字だけを使いましょうねー".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Naming
6
6
  class ClassAndModuleCamelCase < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!モデル名やモジュール名にはCamelCaseを使いましょうねー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!モデル名やモジュール名にはCamelCaseを使いましょうねー!".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Naming
6
6
  class VariableName < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!変数名は%<style>sを使いましょうねー".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!変数名は%<style>sを使いましょうねー".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,8 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class AndOr < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!`%<current>s` じゃなくて `%<prefer>s` をつかいましょうねー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!" \
8
+ '`%<current>s` じゃなくて `%<prefer>s` をつかいましょうねー!'.freeze
8
9
  end
9
10
  end
10
11
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class AsciiComments < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!コメントにはラテン文字だけを使いましょうねー".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!コメントにはラテン文字だけを使いましょうねー".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class ColonMethodCall < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!メソッドを呼ぶのに`::`を使ってはいけません!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!メソッドを呼ぶのに`::`を使ってはいけません!".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,9 +4,34 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class CommentAnnotation < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!`%<keyword>s`のような注釈は全部大きい文字にして" \
8
- 'コロン、スペースのあとにコメントを書きましょうねー!'.freeze
9
- MISSING_NOTE = "ζ*'ヮ')ζ<うっうー!`%<keyword>s`があるけども、肝心のコメントがないですよー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!`%<keyword>s`のような注釈は全部大きい文字にして" \
8
+ 'コロン、スペースのあとにコメントを書きましょうねー!'.freeze
9
+ YAYOI_MISSING_NOTE = "ζ*'ヮ')ζ<うっうー!" \
10
+ '`%<keyword>s`があるけども、肝心のコメントがないですよー!'.freeze
11
+
12
+ def investigate(processed_source)
13
+ processed_source.comments.each_with_index do |comment, index|
14
+ next unless first_comment_line?(processed_source.comments, index) ||
15
+ inline_comment?(comment)
16
+
17
+ margin, first_word, colon, space, note = split_comment(comment)
18
+ next unless annotation?(comment) &&
19
+ !correct_annotation?(first_word, colon, space, note)
20
+
21
+ length = concat_length(first_word, colon, space)
22
+ add_offense(
23
+ comment,
24
+ location: annotation_range(comment, margin, length),
25
+ message: format(message(note), keyword: first_word)
26
+ )
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def message(note)
33
+ note ? YAYOI_MSG : YAYOI_MISSING_NOTE
34
+ end
10
35
  end
11
36
  end
12
37
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class DefWithParentheses < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!メソッドに引数がないときは、`()`を省略しましょうねー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!メソッドに引数がないときは、`()`を省略しましょうねー!".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,18 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class Documentation < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!%<type>sのドキュメントのコメントを書きましょうねー".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!%<type>sのドキュメントのコメントを書きましょうねー".freeze
8
+
9
+ def check(node, body, type)
10
+ return if namespace?(body)
11
+ return if documentation_comment?(node) || nodoc_comment?(node)
12
+ return if compact_namespace?(node) &&
13
+ nodoc_comment?(outer_module(node).first)
14
+
15
+ add_offense(node,
16
+ location: :keyword,
17
+ message: format(YAYOI_MSG, type: type))
18
+ end
8
19
  end
9
20
  end
10
21
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class DoubleNegation < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!二重否定を使わないようにしましょうねー! (`!!`)".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!二重否定を使わないようにしましょうねー! (`!!`)".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,9 +4,13 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class EmptyMethod < Cop
7
- MSG_COMPACT = "ζ*'ヮ')ζ<うっうー!なにも書いてないメソッドは1行で書きましょうねー!".freeze
8
- MSG_EXPANDED = "ζ*'ヮ')ζ<うっうー!なにも書いてないメソッドは1行で書かないで、" \
7
+ YAYOI_MSG_COMPACT = "ζ*'ヮ')ζ<うっうー!なにも書いてないメソッドは1行で書きましょうねー!".freeze
8
+ YAYOI_MSG_EXPANDED = "ζ*'ヮ')ζ<うっうー!なにも書いてないメソッドは1行で書かないで、" \
9
9
  '`end`を次の行に書きましょうねー!'.freeze
10
+
11
+ def message(_node)
12
+ compact_style? ? YAYOI_MSG_COMPACT : YAYOI_MSG_EXPANDED
13
+ end
10
14
  end
11
15
  end
12
16
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class MutableConstant < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!書き換え可能な定数を`.freeze`で更新できないようにしましょうねー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!書き換え可能な定数を`.freeze`で更新できないようにしましょうねー!".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class NumericLiterals < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!3桁区切りにアンダースコア(_)を使いましょうねー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!3桁区切りにアンダースコア(_)を使いましょうねー!".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,8 +4,17 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class RedundantReturn < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!冗長な`return`がありますよー!".freeze
8
- MULTI_RETURN_MSG = "ζ*'ヮ')ζ<うっうー!複数の値を返すときは配列を使いましょうねー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!冗長な`return`がありますよー!".freeze
8
+ YAYOI_MULTI_RETURN_YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!" \
9
+ '複数の値を返すときは配列を使いましょうねー!'.freeze
10
+
11
+ def message(node)
12
+ if !allow_multiple_return_values? && node.children.size > 1
13
+ "#{YAYOI_MSG} #{YAYOI_MULTI_RETURN_YAYOI_MSG}"
14
+ else
15
+ YAYOI_MSG
16
+ end
17
+ end
9
18
  end
10
19
  end
11
20
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ class SymbolArray < Cop
7
+ PERCENT_YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!" \
8
+ 'シンボルだけだけの配列には`%w`か`%W`を使いましょうねー!'.freeze
9
+ ARRAY_YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!配列には`[]`を使いましょうねー!".freeze
10
+
11
+ def message(_node)
12
+ if style == :percent
13
+ PERCENT_YAYOI_MSG
14
+ else
15
+ ARRAY_YAYOI_MSG
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -4,8 +4,16 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class UnneededCondition < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!ダブルパイプ(`||`)を使いましょうねー!".freeze
8
- UNNEEDED_CONDITION = "ζ*'ヮ')ζ<うっうー!いらない条件がありますよー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!ダブルパイプ(`||`)を使いましょうねー!".freeze
8
+ YAYOI_UNNEEDED_CONDITION = "ζ*'ヮ')ζ<うっうー!いらない条件がありますよー!".freeze
9
+
10
+ def message(node)
11
+ if node.modifier_form? || !node.else_branch
12
+ YAYOI_UNNEEDED_CONDITION
13
+ else
14
+ YAYOI_MSG
15
+ end
16
+ end
9
17
  end
10
18
  end
11
19
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class UnneededInterpolation < Cop
7
- MSG = "ζ*'ヮ')ζ<うっうー!文字列の式展開よりも`to_s`を使いましょうねー!".freeze
7
+ YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!文字列の式展開よりも`to_s`を使いましょうねー!".freeze
8
8
  end
9
9
  end
10
10
  end
@@ -4,8 +4,17 @@ module RuboCop
4
4
  module Cop
5
5
  module Style
6
6
  class WordArray < Cop
7
- PERCENT_MSG = "ζ*'ヮ')ζ<うっうー!文字列だけだけの配列には`%w`か`%W`を使いましょうねー!".freeze
8
- ARRAY_MSG = "ζ*'')ζ<うっうー!配列には`[]`を使いましょうねー!".freeze
7
+ PERCENT_YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!" \
8
+ '文字列だけだけの配列には`%w`か`%W`を使いましょうねー!'.freeze
9
+ ARRAY_YAYOI_MSG = "ζ*'ヮ')ζ<うっうー!配列には`[]`を使いましょうねー!".freeze
10
+
11
+ def message(_node)
12
+ if style == :percent
13
+ PERCENT_YAYOI_MSG
14
+ else
15
+ ARRAY_YAYOI_MSG
16
+ end
17
+ end
9
18
  end
10
19
  end
11
20
  end
@@ -1,5 +1,5 @@
1
1
  module Rubocop
2
2
  module Yayoi
3
- VERSION = '0.0.2'.freeze
3
+ VERSION = '0.1.0'.freeze
4
4
  end
5
5
  end
data/lib/rubocop-yayoi.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'rubocop'
2
2
 
3
+ require_relative 'rubocop/cop/cop'
4
+
3
5
  require_relative 'rubocop/formatter/progress_formatter'
4
6
  require_relative 'rubocop/formatter/simple_text_formatter'
5
7
 
@@ -22,6 +24,7 @@ require_relative 'rubocop/cop/lint/useless_assignment'
22
24
 
23
25
  require_relative 'rubocop/cop/mixin/empty_lines_around_body'
24
26
  require_relative 'rubocop/cop/mixin/end_keyword_alignment'
27
+ require_relative 'rubocop/cop/mixin/method_complexity'
25
28
  require_relative 'rubocop/cop/mixin/space_after_punctuation'
26
29
  require_relative 'rubocop/cop/mixin/uncommunicative_name'
27
30
 
@@ -46,6 +49,7 @@ require_relative 'rubocop/cop/style/mutable_constant'
46
49
  require_relative 'rubocop/cop/style/numeric_literals'
47
50
  require_relative 'rubocop/cop/style/redundant_return'
48
51
  require_relative 'rubocop/cop/style/string_literals'
52
+ require_relative 'rubocop/cop/style/symbol_array'
49
53
  require_relative 'rubocop/cop/style/unneeded_condition'
50
54
  require_relative 'rubocop/cop/style/unneeded_interpolation'
51
55
  require_relative 'rubocop/cop/style/word_array'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-yayoi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - YutaGoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-06 00:00:00.000000000 Z
11
+ date: 2019-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -72,6 +72,7 @@ files:
72
72
  - bin/setup
73
73
  - lib/rubocop-yayoi.rb
74
74
  - lib/rubocop/cop/.DS_Store
75
+ - lib/rubocop/cop/cop.rb
75
76
  - lib/rubocop/cop/layout/def_end_alignment.rb
76
77
  - lib/rubocop/cop/layout/empty_line_between_defs.rb
77
78
  - lib/rubocop/cop/layout/empty_lines.rb
@@ -94,6 +95,7 @@ files:
94
95
  - lib/rubocop/cop/mixin/.DS_Store
95
96
  - lib/rubocop/cop/mixin/empty_lines_around_body.rb
96
97
  - lib/rubocop/cop/mixin/end_keyword_alignment.rb
98
+ - lib/rubocop/cop/mixin/method_complexity.rb
97
99
  - lib/rubocop/cop/mixin/space_after_punctuation.rb
98
100
  - lib/rubocop/cop/mixin/uncommunicative_name.rb
99
101
  - lib/rubocop/cop/naming/ascii_identifiers.rb
@@ -113,6 +115,7 @@ files:
113
115
  - lib/rubocop/cop/style/numeric_literals.rb
114
116
  - lib/rubocop/cop/style/redundant_return.rb
115
117
  - lib/rubocop/cop/style/string_literals.rb
118
+ - lib/rubocop/cop/style/symbol_array.rb
116
119
  - lib/rubocop/cop/style/unneeded_condition.rb
117
120
  - lib/rubocop/cop/style/unneeded_interpolation.rb
118
121
  - lib/rubocop/cop/style/word_array.rb