golint 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/golint.gemspec +1 -1
- data/lib/golint.rb +16 -4
- data/lib/golint/version.rb +1 -1
- data/test/golint_test.rb +35 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99aeb7a1e0d2754c3fddd1cb0b47d031f500d59b
|
4
|
+
data.tar.gz: 8a0c9f63aa71e0467e1830a025c777d62bb765da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7e55ec17dc9b33e113efd3a0274170303b2dea3c6651443970a3d24b309693e494ccddf08aed357bd01f56da18947fc2b5089e6d78bba5e36a8db10b6b1dd45
|
7
|
+
data.tar.gz: 5983ac1ec23f485bfcf03df8e7d590af83ce580d4a2125934e85962507dd1a0002b6613d2dcc2ae73aa2cad7835fa2500ea8daca4934dac6369b90f29961cb08
|
data/golint.gemspec
CHANGED
data/lib/golint.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "golint/version"
|
2
2
|
require "tempfile"
|
3
3
|
require "base64"
|
4
|
+
require 'open3'
|
4
5
|
|
5
6
|
module Golint
|
6
7
|
class Match < Struct.new(:line, :comment)
|
@@ -15,15 +16,26 @@ module Golint
|
|
15
16
|
file.write(content)
|
16
17
|
file.close
|
17
18
|
|
18
|
-
|
19
|
+
stdin, stdout, stderr, wait_thr = Open3.popen3('golint', file.path)
|
19
20
|
|
20
|
-
|
21
|
+
out = stdout.read
|
22
|
+
err = stderr.read
|
21
23
|
|
24
|
+
if err.size > 0
|
25
|
+
parse_matches(file.path, err)
|
26
|
+
elsif out.size > 0
|
27
|
+
parse_matches(file.path, out)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_matches(path, body)
|
32
|
+
pattern = "#{path}:"
|
22
33
|
matches = []
|
23
|
-
|
34
|
+
body.each_line do |line|
|
24
35
|
line = line.sub(pattern, "").sub("\n", "")
|
36
|
+
|
25
37
|
res = line.match(REGEXP)
|
26
|
-
matches << Match.new(res[1], res[3].strip)
|
38
|
+
matches << Match.new(res[1].to_i, res[3].strip)
|
27
39
|
end
|
28
40
|
|
29
41
|
matches
|
data/lib/golint/version.rb
CHANGED
data/test/golint_test.rb
CHANGED
@@ -1,8 +1,41 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class TestGolint < MiniTest::Unit::TestCase
|
4
|
-
def
|
4
|
+
def test_server
|
5
5
|
file = File.open('test/fixtures/server.go')
|
6
|
-
|
6
|
+
results = Golint.lint(file.read)
|
7
|
+
|
8
|
+
assert_equal results.size, 11
|
9
|
+
|
10
|
+
assert_equal results[0].line, 30
|
11
|
+
assert_equal results[0].comment, "don't use underscores in Go names; var item_id should be itemID"
|
12
|
+
assert_equal results[1].line, 32
|
13
|
+
assert_equal results[1].comment, "don't use underscores in Go names; var some_item should be someItem"
|
14
|
+
assert_equal results[2].line, 69
|
15
|
+
assert_equal results[2].comment, "don't use underscores in Go names; var revision_file should be revisionFile"
|
16
|
+
assert_equal results[3].line, 83
|
17
|
+
assert_equal results[3].comment, "don't use underscores in Go names; var category_id should be categoryID"
|
18
|
+
assert_equal results[4].line, 84
|
19
|
+
assert_equal results[4].comment, "don't use underscores in Go names; var aspect_filters should be aspectFilters"
|
20
|
+
assert_equal results[5].line, 87
|
21
|
+
assert_equal results[5].comment, "don't use underscores in Go names; var per_page should be perPage"
|
22
|
+
assert_equal results[6].line, 92
|
23
|
+
assert_equal results[6].comment, "don't use underscores in Go names; var page_num should be pageNum"
|
24
|
+
assert_equal results[7].line, 97
|
25
|
+
assert_equal results[7].comment, "don't use underscores in Go names; var search_result should be searchResult"
|
26
|
+
assert_equal results[8].line, 118
|
27
|
+
assert_equal results[8].comment, "don't use underscores in Go names; var secret_useragent should be secretUseragent"
|
28
|
+
assert_equal results[9].line, 122
|
29
|
+
assert_equal results[9].comment, "don't use ALL_CAPS in Go names; use CamelCase"
|
30
|
+
assert_equal results[10].line, 122
|
31
|
+
assert_equal results[10].comment, "exported const ROUTE_PREFIX should have comment (or a comment on this block) or be unexported"
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_one_line
|
35
|
+
results = Golint.lint('item_id := vars["item_id"]')
|
36
|
+
|
37
|
+
assert_equal results.size, 1
|
38
|
+
assert_equal results[0].line, 1
|
39
|
+
assert_equal results[0].comment, "expected 'package', found 'IDENT' item_id"
|
7
40
|
end
|
8
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: golint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kir Shatrov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Ruby wrapper for golint utility
|