pronto-golang 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd44117d6f62bc383eee9e2bc20067d620a4bd76
4
- data.tar.gz: b46b34cdb4cc5ab13d8e800bb8c748c075bb7fe1
3
+ metadata.gz: 44322a5abe5e297a8aca4dcbcaf6cadcc281aece
4
+ data.tar.gz: 5e3a4285833911a46405d0ca87b52f4328917374
5
5
  SHA512:
6
- metadata.gz: f4fbe3cef82de8eaa8e831f6bb60b629a89ec0e1c9eef99483c9be9c131b266e18a96df1b679c0fb9c2f4461a23a714cc7a55624042d36b22fa27542069c4cd3
7
- data.tar.gz: 09aa51442577934e76e8912c6b66433d1d6866a29001cd649179508188df9da525964b0aea3f706d01e26ce10900f5c97c50245b5c47341a7d073a47d953d166
6
+ metadata.gz: cc3dc687d363a3a91ca82ab729aa548f8dcae82ab2999e7c239355674eaaf3661bf40ac67979e0dd099a59d25be3cd6d1e78a7106bb154ffda91cefa9c79b23c
7
+ data.tar.gz: 2338419e929ff992ce3751d8fb546704d219e23b2e00dc8a5034de2200591d9bded52c60fe28b56d91345149ad64bbe11f4582580b9e7cad5856b82eb0eba1e2
data/README.md CHANGED
@@ -8,26 +8,26 @@ Pronto runner for [Golang](https://golang.org) tools
8
8
 
9
9
  | Tool | Install |
10
10
  |----------|----------|
11
- | golint | go get -u golang.org/x/lint/golint |
12
- | gosimple | go get -u honnef.co/go/tools/cmd/gosimple |
13
- | go vet | - |
14
- | unused | go get -u honnef.co/go/tools/cmd/unused |
15
- | unparam | go get -u mvdan.cc/unparam |
16
11
  | errcheck | go get -u github.com/kisielk/errcheck |
12
+ | go vet | - |
13
+ | golint | go get -u golang.org/x/lint/golint |
14
+ | staticcheck | go get -u honnef.co/go/tools/cmd/staticcheck |
17
15
 
18
- ## Enabling only certain tools
16
+ ## Configuring tools
19
17
 
20
- In order to only enable certain tools for execution it is possible to provide a `.golangtools.yml` file in the directory of execution.
18
+ In order to configure certain tools for execution it is possible to provide a `.golangtools.yml` file in the directory of execution, any parent directory or `$HOME`.
21
19
 
22
20
  It looks as follows:
23
21
  ```yaml
24
- enabled_tools:
25
- - errcheck
26
- - gosimple
27
- # ...
22
+ tools:
23
+ <tool base command>:
24
+ enabled: true
25
+ parameters: './...'
28
26
  ```
29
27
 
30
- If the `enabled_tools` is available only the tools in the list will be executed. Note that the tool in question should match the value returned by `base_command`.
28
+ If a tool is not listed here, it will automatically be enabled with the parameters `./...`.
29
+ In order to specifically disable a tool, it has to be listed and `enabled` has to be set to `false`.
30
+ If either of the keys is not provided the default will be assumed.
31
31
 
32
32
  ## Implementing additional tools
33
33
 
@@ -37,11 +37,14 @@ It is expected that it reponds to the following methods:
37
37
 
38
38
  | Method | Description |
39
39
  |--------|-------------|
40
+ | `initialize` | Configuration hash from the `.golangtools.yml` config |
40
41
  | `command(file_path)` | Executes the command and receives the file_path to allow checking only the current file |
41
- | `base_command` | Returns the name/basic command that will be invoked. Is also used for enabling and disabling it via `.golangtools.yml` |
42
- | `installed?` | Returns true if the tool can be found, e.g. through `which #{base_command}` |
42
+ | `self.base_command` | Returns the name/basic command that will be invoked. Is also used for enabling and disabling it via `.golangtools.yml` |
43
+ | `available?` | Returns true if the tool can be found, e.g. through `which #{base_command}` |
43
44
  | `parse_line(line)` | Receives the line returned from the tool for parsing. Returns `absolute_path`, `line_number`, `level`, `message text` |
44
45
 
46
+ It is possible to inherit from `Pronto::GolangTools::Base`, in which case only `self.base_command` and `parse_line` need to be implemented.
47
+
45
48
  ## License
46
49
 
47
50
  [MIT](LICENSE)
data/lib/pronto/golang.rb CHANGED
@@ -3,10 +3,13 @@ require 'pronto'
3
3
  require 'yaml'
4
4
  require 'shellwords'
5
5
 
6
+ require_relative './golang/file_finder'
6
7
  require_relative './golang/tools'
7
8
 
8
9
  module Pronto
9
10
  class Golang < Runner
11
+ include ::Pronto::GolangSupport::FileFinder
12
+
10
13
  CONFIG_FILE = '.golangtools.yml'
11
14
  GOLANG_FILE_EXTENSIONS = ['.go'].freeze
12
15
 
@@ -75,12 +78,13 @@ module Pronto
75
78
  config = dotconfig
76
79
 
77
80
  @tools = GolangTools.constants.sort.map do |constant|
78
- tool = Object.const_get("Pronto::GolangTools::#{constant}").new
81
+ next if constant.to_s == 'Base'
82
+
83
+ tool_class = Object.const_get("Pronto::GolangTools::#{constant}")
79
84
 
80
- if tool.installed? &&
81
- (!config.key?('enabled_tools') ||
82
- config['enabled_tools'].include?(tool.base_command))
85
+ tool = tool_class.new(config.fetch('tools').fetch(tool_class.base_command))
83
86
 
87
+ if tool.available?
84
88
  tool
85
89
  else
86
90
  nil
@@ -92,11 +96,17 @@ module Pronto
92
96
  end
93
97
 
94
98
  def dotconfig
95
- if File.exist?(CONFIG_FILE)
96
- return YAML.load_file(CONFIG_FILE)
99
+ file = find_file_upwards(CONFIG_FILE, Dir.pwd, use_home: true)
100
+
101
+ base = {
102
+ 'tools' => {}
103
+ }
104
+
105
+ if file
106
+ return base.merge(YAML.load_file(file))
97
107
  end
98
108
 
99
- return {}
109
+ return base
100
110
  end
101
111
 
102
112
  def go_file?(path)
@@ -0,0 +1,46 @@
1
+ require 'pathname'
2
+
3
+ module Pronto
4
+ module GolangSupport
5
+ module FileFinder
6
+ def self.root_level=(level)
7
+ @root_level = level
8
+ end
9
+
10
+ def self.root_level?(path)
11
+ @root_level == path.to_s
12
+ end
13
+
14
+ def find_file_upwards(filename, start_dir, use_home: false)
15
+ traverse_files_upwards(filename, start_dir, use_home) do |file|
16
+ # minimize iteration for performance
17
+ return file if file
18
+ end
19
+ end
20
+
21
+ def find_files_upwards(filename, start_dir, use_home: false)
22
+ files = []
23
+ traverse_files_upwards(filename, start_dir, use_home) do |file|
24
+ files << file
25
+ end
26
+ files
27
+ end
28
+
29
+ private
30
+
31
+ def traverse_files_upwards(filename, start_dir, use_home)
32
+ Pathname.new(start_dir).expand_path.ascend do |dir|
33
+ break if FileFinder.root_level?(dir)
34
+
35
+ file = dir + filename
36
+ yield(file.to_s) if file.exist?
37
+ end
38
+
39
+ return unless use_home && ENV.key?('HOME')
40
+
41
+ file = File.join(Dir.home, filename)
42
+ yield(file) if File.exist?(file)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -3,9 +3,9 @@ module Pronto
3
3
  end
4
4
  end
5
5
 
6
+ require_relative './tools/base'
7
+
6
8
  require_relative './tools/errcheck'
7
9
  require_relative './tools/golint'
8
- require_relative './tools/gosimple'
9
10
  require_relative './tools/govet'
10
- require_relative './tools/unparam'
11
- require_relative './tools/unused'
11
+ require_relative './tools/staticcheck'
@@ -0,0 +1,43 @@
1
+ module Pronto
2
+ module GolangTools
3
+ class Base
4
+ def self.base_command
5
+ raise 'base_command needs to be overwritten in inheritance'
6
+ end
7
+
8
+ def base_command
9
+ self.class.base_command
10
+ end
11
+
12
+ def initialize(config)
13
+ @config = config
14
+ end
15
+
16
+ def command(file_path)
17
+ "#{base_command} #{parameters}"
18
+ end
19
+
20
+ def parameters
21
+ @config.fetch('parameters', './...') # Default to './...' if the key is not configured
22
+ end
23
+
24
+ def available?
25
+ installed? && enabled?
26
+ end
27
+
28
+ def installed?
29
+ `which #{base_command}` != ""
30
+ end
31
+
32
+ def enabled?
33
+ @config.fetch('enabled', true) # Default to true if the key is not configured
34
+ end
35
+
36
+ def parse_line(line)
37
+ file_path, line_number, _, message = line.split(':')
38
+
39
+ return file_path, line_number, :warning, message.to_s.strip
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,18 +1,10 @@
1
1
  module Pronto
2
2
  module GolangTools
3
- class Errcheck
4
- def command(file_path)
5
- "#{base_command} ./..."
6
- end
7
-
8
- def base_command
3
+ class Errcheck < Base
4
+ def self.base_command
9
5
  'errcheck'
10
6
  end
11
7
 
12
- def installed?
13
- `which #{base_command}` != ""
14
- end
15
-
16
8
  def parse_line(line)
17
9
  file_path, line_number, _, _ = line.split(':')
18
10
 
@@ -1,18 +1,10 @@
1
1
  module Pronto
2
2
  module GolangTools
3
- class Golint
4
- def command(file_path)
5
- "#{base_command} ./..."
6
- end
7
-
8
- def base_command
3
+ class Golint < Base
4
+ def self.base_command
9
5
  'golint'
10
6
  end
11
7
 
12
- def installed?
13
- `which #{base_command}` != ""
14
- end
15
-
16
8
  def parse_line(line)
17
9
  file_path, line_number, _, message = line.split(':')
18
10
 
@@ -1,16 +1,12 @@
1
1
  module Pronto
2
2
  module GolangTools
3
- class Govet
4
- def command(file_path)
5
- "#{base_command} ./..."
6
- end
7
-
8
- def base_command
3
+ class Govet < Base
4
+ def self.base_command
9
5
  'go vet'
10
6
  end
11
7
 
12
- def installed?
13
- true
8
+ def available?
9
+ enabled?
14
10
  end
15
11
 
16
12
  def parse_line(line)
@@ -1,16 +1,8 @@
1
1
  module Pronto
2
2
  module GolangTools
3
- class Unused
4
- def command(file_path)
5
- "#{base_command} ./..."
6
- end
7
-
8
- def base_command
9
- 'unused'
10
- end
11
-
12
- def installed?
13
- `which #{base_command}` != ""
3
+ class Staticcheck < Base
4
+ def self.base_command
5
+ 'staticcheck'
14
6
  end
15
7
 
16
8
  def parse_line(line)
@@ -1,5 +1,5 @@
1
1
  module Pronto
2
2
  module GolangVersion
3
- VERSION = '0.0.6'.freeze
3
+ VERSION = '0.0.7'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pronto-golang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schoknecht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-20 00:00:00.000000000 Z
11
+ date: 2019-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pronto
@@ -63,13 +63,13 @@ files:
63
63
  - LICENSE
64
64
  - README.md
65
65
  - lib/pronto/golang.rb
66
+ - lib/pronto/golang/file_finder.rb
66
67
  - lib/pronto/golang/tools.rb
68
+ - lib/pronto/golang/tools/base.rb
67
69
  - lib/pronto/golang/tools/errcheck.rb
68
70
  - lib/pronto/golang/tools/golint.rb
69
- - lib/pronto/golang/tools/gosimple.rb
70
71
  - lib/pronto/golang/tools/govet.rb
71
- - lib/pronto/golang/tools/unparam.rb
72
- - lib/pronto/golang/tools/unused.rb
72
+ - lib/pronto/golang/tools/staticcheck.rb
73
73
  - lib/pronto/golang/version.rb
74
74
  homepage: https://github.com/Barzahlen/pronto-golang
75
75
  licenses:
@@ -1,23 +0,0 @@
1
- module Pronto
2
- module GolangTools
3
- class Gosimple
4
- def command(file_path)
5
- "#{base_command} ./..."
6
- end
7
-
8
- def base_command
9
- 'gosimple'
10
- end
11
-
12
- def installed?
13
- `which #{base_command}` != ""
14
- end
15
-
16
- def parse_line(line)
17
- file_path, line_number, _, message = line.split(':')
18
-
19
- return file_path, line_number, :warning, message.to_s.strip
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- module Pronto
2
- module GolangTools
3
- class Unparam
4
- def command(file_path)
5
- "#{base_command} ./..."
6
- end
7
-
8
- def base_command
9
- 'unparam'
10
- end
11
-
12
- def installed?
13
- `which #{base_command}` != ""
14
- end
15
-
16
- def parse_line(line)
17
- file_path, line_number, _, message = line.split(':')
18
-
19
- return file_path, line_number, :warning, message.to_s.strip
20
- end
21
- end
22
- end
23
- end