pronto-swiftlint 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: 78f4143dc5191d038cf0d6596078c0bf95401682
4
+ data.tar.gz: 378bafa5022df2932bbd04a71e5fc4f8a68c884d
5
+ SHA512:
6
+ metadata.gz: 59cc87cf5a38de91b46d7d39068405d40039f3f517afcc58450dc981b238a6d80cd5db986a6e7e0ebee29b506b3893f614545468843fe61535dfe2c10ef736b5
7
+ data.tar.gz: 6039d07c89afbf8d778be20b759ad9a3fcbfb420da84d8de49b2e559c35bfcc2bd157aad146acc40bc5dcb88a233f583b1a2382b58b9d18d4c0f59a8d7361ba6
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pronto-swiftlint.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Andrius Janauskas
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,11 @@
1
+ # Pronto::Tailor
2
+
3
+ [Pronto](https://github.com/mmozuras/pronto) runner for [Swiftlint](https://github.com/realm/SwiftLint)
4
+
5
+ Swiftlint is needed to be installed for this runner to work.
6
+
7
+ # Configuring runner
8
+
9
+ You can explicitly specify location of SwiftLint runner by passing `PRONTO_SWIFTLINT_PATH` env variable e.g:
10
+
11
+ `PRONTO_SWIFTLINT_PATH=/usr/very/hidden/bin/swiftlint pronto run --index`
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pronto/swiftlint"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ require 'pronto/swiftlint/version'
2
+
3
+ require_relative 'swiftlint_runner'
4
+
@@ -0,0 +1,43 @@
1
+ require 'json'
2
+
3
+ module Pronto
4
+ module Swiftlint
5
+ class OutputParser
6
+ def parse(output)
7
+ begin
8
+ violations = JSON.parse(output)
9
+ rescue => e
10
+ puts "pronto-swiftlint ERROR: failed to parse output. Is formatter set to json? #{e}"
11
+ return []
12
+ end
13
+
14
+ result = {}
15
+ violations.each do |violation|
16
+ file = violation['file']
17
+ result[file] ||= []
18
+ result[file] << {
19
+ file: violation['file'],
20
+ line: violation['line'],
21
+ column: violation['character'],
22
+ level: parse_severity(violation['severity']),
23
+ message: violation['reason'],
24
+ rule: violation['rule_id']
25
+ }
26
+ end
27
+ result
28
+ end
29
+
30
+ private
31
+
32
+ def parse_severity(severity)
33
+ if severity == 'Warning'
34
+ :warning
35
+ elsif severity == 'Error'
36
+ :error
37
+ else
38
+ :info
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ module Pronto
2
+ module Swiftlint
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ require 'open3'
2
+ require_relative 'output_parser'
3
+
4
+ module Pronto
5
+ module Swiftlint
6
+ class Wrapper
7
+ def lint
8
+ stdout, stderr, _ = Open3.capture3(swiftlint_executable)
9
+ puts "WARN: pronto-swiftlint: #{stderr}" if stderr && stderr.size > 0
10
+ return {} if stdout.nil? || stdout == 0
11
+ OutputParser.new.parse(stdout)
12
+ end
13
+
14
+ private
15
+
16
+ def swiftlint_executable
17
+ ENV['PRONTO_SWIFTLINT_PATH'] || 'swiftlint'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ require 'pronto/swiftlint/wrapper'
2
+ require 'pronto'
3
+
4
+ module Pronto
5
+ class SwiftlintRunner < Runner
6
+ def run(patches, _)
7
+ return [] unless patches
8
+
9
+ offences = Swiftlint::Wrapper.new.lint
10
+
11
+ patches.select { |p| p.additions > 0 }
12
+ .select { |p| swift_file?(p.new_file_full_path) }
13
+ .map { |p| inspect(p, offences) }
14
+ .flatten
15
+ .compact
16
+ end
17
+
18
+ private
19
+
20
+ def inspect(patch, offences)
21
+ messages = []
22
+ offences_in_file = offences[patch.new_file_full_path.to_s]
23
+ return unless offences_in_file
24
+
25
+ offences_in_file.each do |offence|
26
+ messages += patch
27
+ .added_lines
28
+ .select { |line| line.new_lineno == offence[:line] }
29
+ .map { |line| new_message(offence, line) }
30
+ end
31
+
32
+ messages.compact
33
+ end
34
+
35
+ def new_message(offence, line)
36
+ path = line.patch.delta.new_file[:path]
37
+ Message.new(path, line, offence[:level], offence[:message])
38
+ end
39
+
40
+ def swift_file?(path)
41
+ %w(.swift).include?(File.extname(path))
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pronto/swiftlint/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'pronto-swiftlint'
8
+ spec.version = Pronto::Swiftlint::VERSION
9
+ spec.authors = ['Andrius Janauskas']
10
+ spec.email = ['andrius.janauskas@gmail.com']
11
+
12
+ spec.summary = 'Pronto runner for SwiftLint'
13
+ spec.description = <<-EOF
14
+ A pronto runner for SwiftLint - Swift code analyzer. Pronto runs analysis quickly by checking only
15
+ the relevant changes. Created to be used on pull requests, but suited for other scenarios as well.
16
+ EOF
17
+ spec.homepage = 'https://github.com/ajanauskas/pronto-swiftlint'
18
+ spec.license = 'MIT'
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.10'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.3'
28
+
29
+ spec.add_runtime_dependency 'pronto', '~> 0.5.0'
30
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pronto-swiftlint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrius Janauskas
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pronto
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.5.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.5.0
69
+ description: |2
70
+ A pronto runner for SwiftLint - Swift code analyzer. Pronto runs analysis quickly by checking only
71
+ the relevant changes. Created to be used on pull requests, but suited for other scenarios as well.
72
+ email:
73
+ - andrius.janauskas@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/pronto/swiftlint.rb
89
+ - lib/pronto/swiftlint/output_parser.rb
90
+ - lib/pronto/swiftlint/version.rb
91
+ - lib/pronto/swiftlint/wrapper.rb
92
+ - lib/pronto/swiftlint_runner.rb
93
+ - pronto-swiftlint.gemspec
94
+ homepage: https://github.com/ajanauskas/pronto-swiftlint
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.5
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Pronto runner for SwiftLint
118
+ test_files: []