pronto-luacheck 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f557b842b04ee546cda9616268baa85ae162477d
4
+ data.tar.gz: f59e7e134448ed7f1aaa8b7ba8844044feabcfaa
5
+ SHA512:
6
+ metadata.gz: 9f87c41dc6e54b1ea2588fd9ef8b9d293811c586d83f627ace51d6fc881724bd5e61556ef7ff500c88b2843b63996ba8a8ddad27e34d28b853198862c0baaeb4
7
+ data.tar.gz: 6707bc5e670317684f06029947fb538bbf9cb13a1122f8d54e3033f24f374daca2e031d033f23f246dd49e3a0a52b1eb093c489053818c59a739c7636572ccf9
@@ -0,0 +1,18 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .ruby-version
12
+ .*~
13
+ *~
14
+
15
+ *.gem
16
+ examples/
17
+ .pryrc
18
+ vendor/
@@ -0,0 +1,5 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.8
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pronto-luacheck.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Seiichi KONDO
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # Pronto::Luacheck
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/pronto-luacheck.svg)](http://badge.fury.io/rb/pronto-luacheck)
4
+ [![Build Status](https://travis-ci.org/seikichi/pronto-luacheck.svg?branch=master)](https://travis-ci.org/seikichi/pronto-luacheck)
5
+ [![Coverage Status](https://coveralls.io/repos/seikichi/pronto-luacheck/badge.svg?branch=master&service=github)](https://coveralls.io/github/seikichi/pronto-luacheck?branch=master)
6
+
7
+ [Pronto](https://github.com/mmozuras/pronto) runner for [Luacheck](https://github.com/mpeterv/luacheck).
8
+
9
+ `luacheck` is needed to be installed for this runner to work.
10
+
11
+ ## Configuration
12
+
13
+ Configuring Luacheck via `.luacheckrc` will work just fine with `pronto-luacheck`.
14
+
15
+ You can explicitly specify location of Luacheck runner by passing `PRONTO_LUACHECK_PATH` env variable e.g:
16
+
17
+ ```bash
18
+ PRONTO_LUACHECK_PATH=/usr/very/hidden/bin/luacheck pronto run --index
19
+ ```
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'pronto-luacheck'
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install pronto-luacheck
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bundle` to install dependencies. Then, run `rake test` to run the tests.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`.
42
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
43
+ which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/seikichi/pronto-luacheck.
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,16 @@
1
+ # coding: UTF-8
2
+
3
+ require 'rake/testtask'
4
+ require 'bundler/gem_tasks'
5
+ require 'rubocop/rake_task'
6
+
7
+ task default: [:test]
8
+
9
+ Rake::TestTask.new do |t|
10
+ t.libs << 'test'
11
+ t.ruby_opts = ['-r./test/helper']
12
+ t.test_files = Dir['test/**/test_*.rb']
13
+ t.verbose = true
14
+ end
15
+
16
+ RuboCop::RakeTask.new
@@ -0,0 +1,2 @@
1
+ require_relative 'luacheck/version'
2
+ require_relative 'luacheck_runner'
@@ -0,0 +1,5 @@
1
+ module Pronto
2
+ module Luacheck
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,63 @@
1
+ require 'open3'
2
+ require 'rexml/document'
3
+
4
+ module Pronto
5
+ module Luacheck
6
+ class Wrapper
7
+ def initialize
8
+ @luacheck_path = ENV['PRONTO_LUACHECK_PATH'] || 'luacheck'
9
+ end
10
+
11
+ def run(filepath)
12
+ stdout, stderr, = run_luacheck(filepath)
13
+ puts "WARN: pronto-luacheck: #{stderr}" if stderr && !stderr.empty?
14
+ return [] if stdout.nil? || stdout == 0
15
+ parse_output(stdout)
16
+ end
17
+
18
+ private
19
+
20
+ def parse_output(output)
21
+ doc = REXML::Document.new(output)
22
+
23
+ result = []
24
+ REXML::XPath.match(doc, '//testcase').each do |testcase|
25
+ file = testcase.attributes['classname']
26
+ next if testcase.elements.size != 1
27
+
28
+ failure = testcase.elements.first
29
+ md = failure.attributes['message'].
30
+ match(/\A#{Regexp.escape(file)}:(?<line>\d+):(?<column>\d+):\s+(?<message>.*)\z/)
31
+ next unless md
32
+
33
+ result << {
34
+ file: file,
35
+ line: md[:line].to_i,
36
+ column: md[:column].to_i,
37
+ level: level(failure),
38
+ message: md[:message],
39
+ rule: rule(failure)
40
+ }
41
+ end
42
+
43
+ result
44
+ end
45
+
46
+ def run_luacheck(path)
47
+ Open3.capture3("#{@luacheck_path.shellescape} --formatter=JUnit #{path.shellescape}")
48
+ end
49
+
50
+ def rule(failure)
51
+ type = failure.attributes['type']
52
+ type[1..-1]
53
+ end
54
+
55
+ def level(failure)
56
+ type = failure.attributes['type']
57
+ return :warning if type.start_with?('W')
58
+ return :error if type.start_with?('E')
59
+ :info
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,48 @@
1
+ require 'pronto'
2
+
3
+ require_relative 'luacheck/wrapper'
4
+
5
+ module Pronto
6
+ class LuacheckRunner < Runner
7
+ def initialize(_, __ = nil)
8
+ super
9
+
10
+ @inspector = ::Pronto::Luacheck::Wrapper.new
11
+ end
12
+
13
+ def run
14
+ return [] unless @patches
15
+
16
+ @patches.select { |patch| valid_patch?(patch) }
17
+ .map { |patch| inspect(patch) }
18
+ .flatten
19
+ .compact
20
+ end
21
+
22
+ private
23
+
24
+ def valid_patch?(patch)
25
+ return false if patch.additions < 1
26
+
27
+ lua_file?(patch)
28
+ end
29
+
30
+ def lua_file?(patch)
31
+ patch.new_file_full_path.to_s.end_with?('.lua')
32
+ end
33
+
34
+ def inspect(patch)
35
+ offences = @inspector.run(patch.new_file_full_path.to_s)
36
+ offences.map do |offence|
37
+ patch.added_lines
38
+ .select { |line| line.new_lineno == offence[:line] }
39
+ .map { |line| new_message(offence, line) }
40
+ end
41
+ end
42
+
43
+ def new_message(offence, line)
44
+ path = line.patch.delta.new_file[:path]
45
+ Message.new(path, line, offence[:level], offence[:message], nil, self.class)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pronto/luacheck/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'pronto-luacheck'
8
+ spec.version = Pronto::Luacheck::VERSION
9
+ spec.authors = ['Seiichi KONDO']
10
+ spec.email = ['seikichi@kmc.gr.jp']
11
+
12
+ spec.summary = 'Pronto runner for Luacheck'
13
+ spec.description = <<-EOF
14
+ A pronto runner for Luacheck - Lua code analyzer.
15
+ Pronto runs analysis quickly by checking only the relevant changes.
16
+ Created to be used on pull requests, but suited for other scenarios as well.
17
+ EOF
18
+ spec.homepage = 'https://github.com/seikichi/pronto-luacheck'
19
+ spec.license = 'MIT'
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
24
+ spec.bindir = 'exe'
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ['lib']
27
+
28
+ spec.add_runtime_dependency('pronto', '~> 0.6.0')
29
+ spec.add_development_dependency 'bundler', '~> 1.11'
30
+ spec.add_development_dependency 'coveralls'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rubocop', '~> 0.40'
33
+ spec.add_development_dependency 'simplecov', '~> 0.10.0'
34
+ spec.add_development_dependency 'test-unit', '~> 3.0'
35
+ spec.add_development_dependency 'test-unit-rr', '~> 1.0'
36
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pronto-luacheck
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Seiichi KONDO
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-15 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.6.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.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: coveralls
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.40'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.40'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.10.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.10.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: test-unit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: test-unit-rr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.0'
125
+ description: |2
126
+ A pronto runner for Luacheck - Lua code analyzer.
127
+ Pronto runs analysis quickly by checking only the relevant changes.
128
+ Created to be used on pull requests, but suited for other scenarios as well.
129
+ email:
130
+ - seikichi@kmc.gr.jp
131
+ executables: []
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - ".gitignore"
136
+ - ".rubocop.yml"
137
+ - ".travis.yml"
138
+ - Gemfile
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - lib/pronto/luacheck.rb
143
+ - lib/pronto/luacheck/version.rb
144
+ - lib/pronto/luacheck/wrapper.rb
145
+ - lib/pronto/luacheck_runner.rb
146
+ - pronto-luacheck.gemspec
147
+ homepage: https://github.com/seikichi/pronto-luacheck
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.2.5
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Pronto runner for Luacheck
171
+ test_files: []