pronto-shellcheck 0.1.1
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 +7 -0
- data/README.md +17 -0
- data/lib/pronto/shellcheck.rb +1 -0
- data/lib/pronto/shellcheck_runner.rb +92 -0
- data/lib/pronto/shellcheck_version.rb +5 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 54767b522c275952880779ffb3a042961d0da8be
|
4
|
+
data.tar.gz: e3dfaf7c4e057e8d11c40b33bba9d921fb18c203
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bd904cc1747db48028a388759a437c9d93ea4e306ac12a071a14ce8eec92a306d83ebb2e29476a00dd9a15120b09730b4827b518570a4e8c11b5031dbc4f5dc4
|
7
|
+
data.tar.gz: c641c4743fbf08fd56c2945147be17ff142345b2dae1ee483032a9cb1ce4d728fd554a40a20000dbb5880c3ea81832c76e5d32c5e846bc3276b0fd4fea416ac0
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Pronto runner for ShellCheck
|
2
|
+
|
3
|
+
[](https://codeclimate.com/github/pclalv/pronto-shellcheck)
|
4
|
+
[](https://travis-ci.org/pclalv/pronto-shellcheck)
|
5
|
+
|
6
|
+
|
7
|
+
Pronto runner for [ShellCheck](https://www.shellcheck.net). [What is Pronto?](https://github.com/mmozuras/pronto)
|
8
|
+
|
9
|
+
## Prerequisites
|
10
|
+
|
11
|
+
You'll need to install [shellcheck by yourself](https://github.com/koalaman/shellcheck#installing). If `shellcheck` is in your `PATH`, everything will simply work.
|
12
|
+
|
13
|
+
## Configuration
|
14
|
+
|
15
|
+
Pass any options you would pass to `shellcheck` with the [`SHELLCHECK_OPTS` environment variable](shellcheck_opts) to `pronto run`; e.g., `SHELLCHECK_OPTS='-x' pronto run`.
|
16
|
+
|
17
|
+
[shellcheck_opts]: [https://github.com/koalaman/shellcheck/wiki/Integration#allow-passing-through-or-configuring-the-environment-variable-shellcheck_opts]
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'shellcheck_runner'
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'pronto'
|
2
|
+
require 'shellwords'
|
3
|
+
|
4
|
+
module Pronto
|
5
|
+
class ShellCheckRunner < Runner
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
EXTENSION = /^\..*sh$/
|
9
|
+
SHEBANG = %r{^#!/.*sh}
|
10
|
+
SHELLCHECK_PRONTO_LEVELS = {
|
11
|
+
'style' => :info,
|
12
|
+
'info' => :info,
|
13
|
+
'error' => :error,
|
14
|
+
'warning' => :warning
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
def_delegator self, :shellcheckable?
|
18
|
+
|
19
|
+
def run
|
20
|
+
return [] if !@patches || @patches.count.zero?
|
21
|
+
|
22
|
+
@patches
|
23
|
+
.select { |patch| patch.additions > 0 && shellcheckable?(patch.new_file_full_path) }
|
24
|
+
.reduce([]) { |results, patch| results.concat(inspect(patch)) }
|
25
|
+
end
|
26
|
+
|
27
|
+
class << self
|
28
|
+
def shellcheckable?(path)
|
29
|
+
path_has_extension?(path) || file_has_shebang?(path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def path_has_extension?(path)
|
33
|
+
!(EXTENSION =~ path.extname).nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
def file_has_shebang?(path)
|
37
|
+
shebang = File.readlines(path).first
|
38
|
+
!(SHEBANG =~ shebang).nil?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private :shellcheckable?
|
43
|
+
private
|
44
|
+
|
45
|
+
def repo_path
|
46
|
+
@repo_path ||= @patches.first.repo.path
|
47
|
+
end
|
48
|
+
|
49
|
+
def inspect(patch)
|
50
|
+
offences = run_shellcheck(patch).reject do |offence|
|
51
|
+
if offence['code'] == 1071
|
52
|
+
$stderr.puts "Skipped #{offence['file']}"
|
53
|
+
$stderr.puts "Reason: #{offence['message']} (SC#{offence['code']})"
|
54
|
+
true
|
55
|
+
else
|
56
|
+
false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
offences
|
61
|
+
.reduce([]) do |messages, offence|
|
62
|
+
messages.concat(
|
63
|
+
patch
|
64
|
+
.added_lines
|
65
|
+
.select { |line| line.new_lineno == offence['line'] }
|
66
|
+
.map { |line| new_message(offence, line) }
|
67
|
+
)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def new_message(offence, line)
|
72
|
+
path = line.patch.delta.new_file[:path]
|
73
|
+
level = SHELLCHECK_PRONTO_LEVELS[offence['level']]
|
74
|
+
message = "SC#{offence['code']}: #{offence['message']}"
|
75
|
+
|
76
|
+
Message.new(path, line, level, message, nil, self.class)
|
77
|
+
end
|
78
|
+
|
79
|
+
def run_shellcheck(patch)
|
80
|
+
Dir.chdir(repo_path) do
|
81
|
+
escaped_file_path = Shellwords.escape(patch.new_file_full_path.to_s)
|
82
|
+
JSON.parse(
|
83
|
+
`shellcheck #{shellcheck_opts} -f json #{escaped_file_path}`
|
84
|
+
)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def shellcheck_opts
|
89
|
+
ENV['SHELLCHECK_OPTS']
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pronto-shellcheck
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Alvarez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pronto
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.7.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '11.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '11.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files:
|
74
|
+
- README.md
|
75
|
+
files:
|
76
|
+
- README.md
|
77
|
+
- lib/pronto/shellcheck.rb
|
78
|
+
- lib/pronto/shellcheck_runner.rb
|
79
|
+
- lib/pronto/shellcheck_version.rb
|
80
|
+
homepage:
|
81
|
+
licenses: []
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 2.0.0
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements:
|
98
|
+
- shellcheck (in PATH)
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.5.1
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Pronto runner for ShellCheck
|
104
|
+
test_files: []
|