rubocop-sane 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rubocop/cop/sane/empty_line_before_comment.rb +15 -10
- data/lib/rubocop/sane/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9bdd1696e7b903bed1518dd449a1187a1551d877a5a479e7d53c4a04be014039
|
|
4
|
+
data.tar.gz: ef30ea5fc869a96828e02253e41437bad4906f99f713c1b5919c58c9a7c27e80
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9b108fd043e227b5d78526ac3f3a6b21b1e36701958ee2f9fc4537b98779bb380680cbd7d400282fba3a3f8b51dac4066033f299312bc3402df4f41fa49d54e2
|
|
7
|
+
data.tar.gz: c87f908957513184b4c36e1b0f0ad1f2204a50f98525ab800c9d3313b0b1a00a22f12d93d22f704c9c6e36f30e84f6a3f9fd51fd353ece856d4aedd383ae68c8
|
|
@@ -48,6 +48,7 @@ module RuboCop
|
|
|
48
48
|
private
|
|
49
49
|
|
|
50
50
|
def check_comment(comment)
|
|
51
|
+
return if rubocop_directive?(comment)
|
|
51
52
|
return if inline_comment?(comment)
|
|
52
53
|
return if first_line?(comment)
|
|
53
54
|
return if preceded_by_empty_line?(comment)
|
|
@@ -64,6 +65,10 @@ module RuboCop
|
|
|
64
65
|
end
|
|
65
66
|
end
|
|
66
67
|
|
|
68
|
+
def rubocop_directive?(comment)
|
|
69
|
+
comment.text.match?(/\A#\s*rubocop:(enable|disable|todo)\b/)
|
|
70
|
+
end
|
|
71
|
+
|
|
67
72
|
def inline_comment?(comment)
|
|
68
73
|
# Check if there's code before the comment on the same line
|
|
69
74
|
comment_line = processed_source.lines[comment.loc.line - 1]
|
|
@@ -106,26 +111,26 @@ module RuboCop
|
|
|
106
111
|
def block_start_pattern?(line)
|
|
107
112
|
stripped = line.strip
|
|
108
113
|
|
|
109
|
-
# Class, module, method definitions
|
|
110
|
-
return true if stripped.match?(/\A(class|module
|
|
114
|
+
# Class, module, method definitions (including decorated methods like `memoize def`)
|
|
115
|
+
return true if stripped.match?(/\A(class|module)\s/) || stripped.match?(/\bdef\s/)
|
|
111
116
|
|
|
112
117
|
# Control structures
|
|
113
|
-
return true if stripped.match?(/\A(if|unless|case|while|until|for|begin)\
|
|
114
|
-
return true if stripped == "begin"
|
|
118
|
+
return true if stripped.match?(/\A(if|unless|case|while|until|for|begin)\b/)
|
|
115
119
|
|
|
116
120
|
# Block openers (do or {)
|
|
117
|
-
return true if
|
|
118
|
-
return true if stripped.match?(/do\s*\|[^|]*\|\s*\z/)
|
|
119
|
-
return true if stripped.end_with?("{")
|
|
120
|
-
return true if stripped.match?(/\{\s*\|[^|]*\|\s*\z/)
|
|
121
|
+
return true if block_opener?(stripped)
|
|
121
122
|
|
|
122
123
|
# Rescue/ensure/else/elsif/when inside blocks
|
|
123
124
|
return true if stripped.match?(/\A(rescue|ensure|else|elsif|when)\b/)
|
|
124
125
|
|
|
125
126
|
# Private/protected/public access modifiers
|
|
126
|
-
|
|
127
|
+
stripped.match?(/\A(private|protected|public)\s*\z/)
|
|
128
|
+
end
|
|
127
129
|
|
|
128
|
-
|
|
130
|
+
def block_opener?(line)
|
|
131
|
+
line.end_with?(" do", " do |", "\tdo", "{", "[") ||
|
|
132
|
+
line.match?(/do\s*\|[^|]*\|\s*\z/) ||
|
|
133
|
+
line.match?(/\{\s*\|[^|]*\|\s*\z/)
|
|
129
134
|
end
|
|
130
135
|
end
|
|
131
136
|
end
|
data/lib/rubocop/sane/version.rb
CHANGED