codegrade 0.0.1 → 0.0.2
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/bin/codegrade +2 -2
- data/lib/codegrade/commit.rb +6 -3
- data/lib/codegrade/formatter.rb +1 -1
- data/lib/codegrade/grader/commit_message.rb +113 -99
- data/lib/codegrade/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5db65c0710cb981a6a70470a77af6483a0003067
|
4
|
+
data.tar.gz: fa8eb37af5f94816e754f3d114c993b72fc9152b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed5a8224328dc6347e910839b9b93ad444dfa5add89fdb0d8ee3c5eecc324e627415ca8e95c4277b6c426045373bf1081f8f1fe9238fdba483367bc6c7bd202b
|
7
|
+
data.tar.gz: b4722a0199d9084dcaca7695113061cd116edc40dda13b2e13a3eccb5059c40349bd9ef8fa733a58ee96508e008595cc9b116d4854001bd3102da370d9796dfc
|
data/bin/codegrade
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
2
|
|
4
3
|
$LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
|
5
4
|
|
6
5
|
require 'codegrade'
|
7
6
|
|
8
|
-
|
7
|
+
commit = Codegrade::Commit.new('.', ARGV[0])
|
8
|
+
offenses = Codegrade::Grader::Grader.new(commit).grade
|
9
9
|
Codegrade::Formatter.new(offenses).print
|
data/lib/codegrade/commit.rb
CHANGED
@@ -32,9 +32,12 @@ module Codegrade
|
|
32
32
|
def parse_git_tree(tree, path)
|
33
33
|
files = []
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
return [] if commit.parents.size > 1
|
36
|
+
|
37
|
+
diff = commit.parents[0].diff(commit)
|
38
|
+
|
39
|
+
diff.deltas.each do |delta|
|
40
|
+
files.push(delta.new_file[:path])
|
38
41
|
end
|
39
42
|
|
40
43
|
files
|
data/lib/codegrade/formatter.rb
CHANGED
@@ -13,7 +13,7 @@ module Codegrade
|
|
13
13
|
puts
|
14
14
|
|
15
15
|
offenses.each do |offense|
|
16
|
-
file = offense.file.gsub(working_directory, '')
|
16
|
+
file = offense.file.gsub(working_directory, '') unless offense.file.nil?
|
17
17
|
puts "- #{file}:#{offense.line_number}:#{offense.column_number}"
|
18
18
|
end
|
19
19
|
|
@@ -20,199 +20,213 @@ module Codegrade
|
|
20
20
|
|
21
21
|
def parse_commit_message
|
22
22
|
lines = @message.split("\n")
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
state = {
|
24
|
+
:paragraph => [],
|
25
|
+
:paragraph_start => 1,
|
26
|
+
:inside_punctation => false }
|
26
27
|
|
27
28
|
lines.each_with_index do |line, index|
|
28
|
-
paragraph << line
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
if inside_punctation
|
73
|
-
if paragraph_line > 1
|
74
|
-
check_punctation_leading_whitespace(line, line_number)
|
75
|
-
end
|
76
|
-
else
|
77
|
-
if ! blank_line
|
78
|
-
check_line_leading_whitespace(line, line_number)
|
79
|
-
end
|
29
|
+
state[:paragraph] << line
|
30
|
+
|
31
|
+
state.merge!(
|
32
|
+
:line => line,
|
33
|
+
:index => index,
|
34
|
+
:line_number => index + 1,
|
35
|
+
:blank_line => blank?(line),
|
36
|
+
:title_line => index == 0,
|
37
|
+
:start_of_punctation => line.start_with?('* '),
|
38
|
+
:was_in_punctation => state[:inside_punctation])
|
39
|
+
|
40
|
+
state[:end_of_paragraph] = !state[:title_line] &&
|
41
|
+
state[:paragraph].any? &&
|
42
|
+
(index == lines.length - 1 || blank?(lines[index + 1])) &&
|
43
|
+
!blank?(state[:paragraph].last)
|
44
|
+
|
45
|
+
state[:inside_punctation] = state[:inside_punctation] ||
|
46
|
+
state[:start_of_punctation]
|
47
|
+
|
48
|
+
check_title_leading_lowercase(state)
|
49
|
+
check_title_too_long(state)
|
50
|
+
check_title_trailing_dot(state)
|
51
|
+
check_title_multiple_lines(state)
|
52
|
+
|
53
|
+
check_line_trailing_whitespace(state)
|
54
|
+
check_line_too_long(state)
|
55
|
+
check_line_leading_whitespace(state)
|
56
|
+
check_redundant_empty_line(state)
|
57
|
+
|
58
|
+
check_punctation_leading_whitespace(state)
|
59
|
+
check_punctation_leading_lowercase(state)
|
60
|
+
check_punctation_trailing_dot(state)
|
61
|
+
check_punctation_no_separating_line(state)
|
62
|
+
|
63
|
+
check_paragraph_leading_lowercase(state)
|
64
|
+
check_paragraph_no_trailing_dot(state)
|
65
|
+
|
66
|
+
if state[:blank_line]
|
67
|
+
state.merge!(
|
68
|
+
:paragraph => [],
|
69
|
+
:paragraph_start => state[:line_number] + 1,
|
70
|
+
:inside_punctation => false)
|
80
71
|
end
|
81
72
|
end
|
82
73
|
end
|
83
74
|
|
84
|
-
def check_title_leading_lowercase(
|
85
|
-
if line[0].downcase == line[0]
|
75
|
+
def check_title_leading_lowercase(state)
|
76
|
+
if state[:title_line] && state[:line][0].downcase == state[:line][0]
|
86
77
|
add_offense(
|
87
78
|
:category => 'title_leading_lowercase',
|
88
|
-
:line_number => line_number,
|
79
|
+
:line_number => state[:line_number],
|
89
80
|
:column_number => 1)
|
90
81
|
end
|
91
82
|
end
|
92
83
|
|
93
|
-
def check_title_too_long(
|
94
|
-
if line.length > 50
|
84
|
+
def check_title_too_long(state)
|
85
|
+
if state[:title_line] && state[:line].length > 50
|
95
86
|
add_offense(
|
96
87
|
:category => 'title_too_long',
|
97
|
-
:line_number => line_number,
|
88
|
+
:line_number => state[:line_number],
|
98
89
|
:column_number => 51)
|
99
90
|
end
|
100
91
|
end
|
101
92
|
|
102
|
-
def check_title_trailing_dot(
|
103
|
-
if (m = line.match(/\.\s*$/))
|
93
|
+
def check_title_trailing_dot(state)
|
94
|
+
if state[:title_line] && (m = state[:line].match(/\.\s*$/))
|
104
95
|
add_offense(
|
105
96
|
:category => 'title_trailing_dot',
|
106
|
-
:line_number => line_number,
|
97
|
+
:line_number => state[:line_number],
|
107
98
|
:column_number => m.begin(0))
|
108
99
|
end
|
109
100
|
end
|
110
101
|
|
111
|
-
def check_title_multiple_lines(
|
112
|
-
if
|
102
|
+
def check_title_multiple_lines(state)
|
103
|
+
return if state[:blank_line]
|
104
|
+
|
105
|
+
if state[:line_number] == 2
|
113
106
|
add_offense(
|
114
107
|
:category => 'title_multiple_lines',
|
115
|
-
:line_number => line_number)
|
108
|
+
:line_number => state[:line_number])
|
116
109
|
end
|
117
110
|
end
|
118
111
|
|
119
|
-
def check_redundant_empty_line(
|
120
|
-
|
112
|
+
def check_redundant_empty_line(state)
|
113
|
+
return unless state[:blank_line]
|
114
|
+
|
115
|
+
if state[:paragraph].select { |line| !blank?(line) }.empty?
|
121
116
|
add_offense(
|
122
117
|
:category => 'redundant_empty_line',
|
123
|
-
:line_number => line_number)
|
118
|
+
:line_number => state[:line_number])
|
124
119
|
end
|
125
120
|
end
|
126
121
|
|
127
|
-
def check_line_trailing_whitespace(
|
128
|
-
if
|
122
|
+
def check_line_trailing_whitespace(state)
|
123
|
+
return if state[:blank_line]
|
124
|
+
|
125
|
+
if (m = state[:line].match(/\s+$/))
|
129
126
|
add_offense(
|
130
127
|
:category => 'line_trailing_whitespace',
|
131
|
-
:line_number => line_number,
|
128
|
+
:line_number => state[:line_number],
|
132
129
|
:column_number => m.begin(0) + 1)
|
133
130
|
end
|
134
131
|
end
|
135
132
|
|
136
|
-
def check_line_leading_whitespace(
|
137
|
-
if
|
133
|
+
def check_line_leading_whitespace(state)
|
134
|
+
if !state[:inside_punctation] &&
|
135
|
+
!state[:blank_line] &&
|
136
|
+
(m = state[:line].match(/^\s+/))
|
138
137
|
add_offense(
|
139
138
|
:category => 'line_leading_whitespace',
|
140
|
-
:line_number => line_number,
|
139
|
+
:line_number => state[:line_number],
|
141
140
|
:column_number => m.end(0))
|
142
141
|
end
|
143
142
|
end
|
144
143
|
|
145
|
-
def check_line_too_long(
|
146
|
-
if
|
144
|
+
def check_line_too_long(state)
|
145
|
+
return if state[:blank_line] || state[:title_line]
|
146
|
+
|
147
|
+
if state[:line].length > 70
|
147
148
|
add_offense(
|
148
149
|
:category => 'line_too_long',
|
149
|
-
:line_number => line_number,
|
150
|
+
:line_number => state[:line_number],
|
150
151
|
:column_number => 71)
|
151
152
|
end
|
152
153
|
end
|
153
154
|
|
154
|
-
def check_paragraph_leading_lowercase(
|
155
|
-
|
155
|
+
def check_paragraph_leading_lowercase(state)
|
156
|
+
return unless state[:end_of_paragraph] && !state[:inside_punctation]
|
157
|
+
|
158
|
+
line = strip(state[:paragraph].first)
|
156
159
|
|
157
160
|
if line[0].downcase == line[0] &&
|
158
161
|
!link?(line.split[0])
|
159
162
|
add_offense(
|
160
163
|
:category => 'paragraph_leading_lowercase',
|
161
|
-
:line_number => paragraph_start,
|
164
|
+
:line_number => state[:paragraph_start],
|
162
165
|
:column_number => 1)
|
163
166
|
end
|
164
167
|
end
|
165
168
|
|
166
|
-
def check_paragraph_no_trailing_dot(
|
167
|
-
|
169
|
+
def check_paragraph_no_trailing_dot(state)
|
170
|
+
return unless state[:end_of_paragraph] && !state[:inside_punctation]
|
171
|
+
|
172
|
+
line = strip(state[:paragraph].last)
|
168
173
|
|
169
174
|
if line[-1] != '.' &&
|
170
175
|
!link?(line.split[-1])
|
171
176
|
add_offense(
|
172
177
|
:category => 'paragraph_no_trailing_dot',
|
173
|
-
:line_number => paragraph_start +
|
174
|
-
|
178
|
+
:line_number => state[:paragraph_start] +
|
179
|
+
state[:paragraph].length - 1,
|
180
|
+
:column_number => state[:paragraph].last.length)
|
175
181
|
end
|
176
182
|
end
|
177
183
|
|
178
|
-
def check_punctation_no_separating_line(
|
179
|
-
if
|
184
|
+
def check_punctation_no_separating_line(state)
|
185
|
+
if state[:start_of_punctation] && state[:was_in_punctation]
|
180
186
|
add_offense(
|
181
187
|
:category => 'punctation_no_separating_line',
|
182
|
-
:line_number => line_number)
|
188
|
+
:line_number => state[:line_number])
|
183
189
|
end
|
184
190
|
end
|
185
191
|
|
186
|
-
def check_punctation_leading_whitespace(
|
187
|
-
if
|
192
|
+
def check_punctation_leading_whitespace(state)
|
193
|
+
if state[:inside_punctation] &&
|
194
|
+
!state[:blank_line] &&
|
195
|
+
state[:paragraph].length > 1 &&
|
196
|
+
(m = state[:line].match(/^\s*/)) && m.end(0) != 2
|
188
197
|
add_offense(
|
189
198
|
:category => 'punctation_leading_whitespace',
|
190
|
-
:line_number => line_number,
|
199
|
+
:line_number => state[:line_number],
|
191
200
|
:column_number => m.end(0))
|
192
201
|
end
|
193
202
|
end
|
194
203
|
|
195
|
-
def check_punctation_leading_lowercase(
|
196
|
-
|
204
|
+
def check_punctation_leading_lowercase(state)
|
205
|
+
return unless state[:end_of_paragraph] && state[:inside_punctation]
|
206
|
+
|
207
|
+
line = strip(state[:paragraph].first)
|
197
208
|
|
198
209
|
if line[2].downcase == line[2] &&
|
199
210
|
!link?(line.split[0])
|
200
211
|
add_offense(
|
201
212
|
:category => 'punctation_leading_lowercase',
|
202
|
-
:line_number => paragraph_start,
|
213
|
+
:line_number => state[:paragraph_start],
|
203
214
|
:column_number => 3)
|
204
215
|
end
|
205
216
|
end
|
206
217
|
|
207
|
-
def check_punctation_trailing_dot(
|
208
|
-
|
218
|
+
def check_punctation_trailing_dot(state)
|
219
|
+
return unless state[:end_of_paragraph] && state[:inside_punctation]
|
220
|
+
|
221
|
+
line = strip(state[:paragraph].last)
|
209
222
|
|
210
223
|
if line[-1] == '.' &&
|
211
224
|
!link?(line.split[-1])
|
212
225
|
add_offense(
|
213
226
|
:category => 'punctation_trailing_dot',
|
214
|
-
:line_number => paragraph_start +
|
215
|
-
|
227
|
+
:line_number => state[:paragraph_start] +
|
228
|
+
state[:paragraph].length - 1,
|
229
|
+
:column_number => state[:paragraph].last.length)
|
216
230
|
end
|
217
231
|
end
|
218
232
|
|
data/lib/codegrade/version.rb
CHANGED