pronto-tailor 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: 3016c7adf2aec03799eaf3c7f5cf0c8cee79fb5d
4
+ data.tar.gz: 883db0b1061b64ec9194f95b592a456c2ffa46ea
5
+ SHA512:
6
+ metadata.gz: e649bdde771592ccc59178b0ef28e0fe263cc6af5e576212f6df1689406a293fdb3abea7d48d262a3c7a89c19d9f9780b68e38b593673d3b18ad6a1706704b23
7
+ data.tar.gz: 7d5a8802c7cbff8bf9d0b3f30ec8a33f0f63dfe733c831bb522c99761552c23ebfcf2ea020fd267119e5e613a6e99b53a1e4f9e182863271c758e0ff6c703582
@@ -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-tailor.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,20 @@
1
+ ![](https://travis-ci.org/ajanauskas/pronto-tailor.svg?branch=master)
2
+
3
+ # Pronto::Tailor
4
+
5
+ Pronto runner for [Tailor](https://github.com/sleekbyte/tailor), Swift static analyser and lint tool.
6
+
7
+ Tailor is needed to be installed for this runner to work.
8
+
9
+ # Configuring runner
10
+
11
+ Runner can be configured by passing additional ENV variables e.g.
12
+
13
+ `PRONTO_TAILOR_EXCEPT_RULE=trailing-whitespace pronto run --index`
14
+
15
+ Availables ENV variables are:
16
+
17
+ * `PRONTO_TAILOR_EXCEPT_RULE` - for specifying `--except` tailor parameter
18
+ * `PRONTO_TAILOR_CONFIG_FILE` - for specifying `--config` tailor parameter
19
+ * `PRONTO_TAILOR_TAILOR_PATH` - for specifying `tailor` executable path. By default `tailor` is used
20
+
@@ -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/tailor"
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,42 @@
1
+ require 'pronto'
2
+ require 'pronto/tailor/version'
3
+ require 'pronto/tailor/wrapper'
4
+
5
+ module Pronto
6
+ class TailorRunner < Runner
7
+ def initialize
8
+ end
9
+
10
+ def run(patches, _)
11
+ return [] unless patches
12
+ patches.select { |p| p.additions > 0 }
13
+ .select { |p| swift_file?(p.new_file_full_path) }
14
+ .map { |p| inspect(p) }
15
+ .flatten
16
+ .compact
17
+ end
18
+
19
+ private
20
+
21
+ def inspect(patch)
22
+ offences = Tailor::Wrapper.new(patch).lint
23
+ messages = []
24
+ offences.each do |offence|
25
+ messages += patch
26
+ .added_lines
27
+ .select { |line| line.new_lineno == offence['line'] }
28
+ .map { |line| new_message(offence, line) }
29
+ end
30
+ messages.compact
31
+ end
32
+
33
+ def new_message(offence, line)
34
+ path = line.patch.delta.new_file[:path]
35
+ Message.new(path, line, offence['level'].to_sym, offence['message'])
36
+ end
37
+
38
+ def swift_file?(path)
39
+ %w(.swift).include?(File.extname(path))
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,39 @@
1
+ module Pronto
2
+ module Tailor
3
+ CONFIGURATION_PREFIX = 'PRONTO_TAILOR_'.freeze
4
+ TAILOR_RUNNER = CONFIGURATION_PREFIX + 'TAILOR_PATH'
5
+ EXCEPT_RULE = CONFIGURATION_PREFIX + 'EXCEPT_RULE'
6
+ CONFIG_FILE = CONFIGURATION_PREFIX + 'CONFIG_FILE'
7
+
8
+ class Configuration
9
+ attr_reader :params
10
+
11
+ def initialize(params)
12
+ @params = params
13
+ end
14
+
15
+ def command_line_for_file(file)
16
+ params = [
17
+ except_rule,
18
+ config_file
19
+ ].compact.join(' ')
20
+
21
+ "#{runner} \"#{file}\" #{params}"
22
+ end
23
+
24
+ private
25
+
26
+ def runner
27
+ params[TAILOR_RUNNER] || 'tailor'
28
+ end
29
+
30
+ def except_rule
31
+ "--except=#{params[EXCEPT_RULE]}" if params[EXCEPT_RULE]
32
+ end
33
+
34
+ def config_file
35
+ "--config=#{params[CONFIG_FILE]}" if params[CONFIG_FILE]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ module Pronto
2
+ module Tailor
3
+ class OutputParser
4
+ attr_reader :output, :file
5
+
6
+ def initialize(file, output)
7
+ @file = file
8
+ @output = output
9
+ end
10
+
11
+ def parse
12
+ output.lines.map do |line|
13
+ next unless line.start_with?(file)
14
+ line_parts = line.split(':')
15
+ offence_in_line = line_parts[1]
16
+ if line_parts[2].to_i == 0
17
+ offence_level = line_parts[2].strip
18
+ else
19
+ offence_level = line_parts[3].strip
20
+ end
21
+ offence_rule = line[/\[.*?\]/].gsub('[', '').gsub(']', '')
22
+ index_of_offence_rule = line.index(offence_rule)
23
+ offence_message = line[index_of_offence_rule + offence_rule.size + 2..line.size]
24
+ {
25
+ 'line' => offence_in_line.to_i,
26
+ 'level' => offence_level,
27
+ 'rule' => offence_rule,
28
+ 'message' => offence_message
29
+ }
30
+ end.compact
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Pronto
2
+ module Tailor
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ require 'open3'
2
+ require_relative 'configuration'
3
+ require_relative 'output_parser'
4
+
5
+ module Pronto
6
+ module Tailor
7
+ class Wrapper
8
+ attr_reader :patch
9
+
10
+ def initialize(patch)
11
+ @patch = patch
12
+ end
13
+
14
+ def lint
15
+ return [] if patch.nil?
16
+ configuration = Configuration.new(ENV)
17
+ path = patch.new_file_full_path.to_s
18
+ stdout, stderr, _status = Open3.capture3(configuration.command_line_for_file(path))
19
+ puts "WARN: pronto-tailor: #{stderr}" if stderr && stderr.size > 0
20
+ return [] if stdout.nil? || stdout.size == 0
21
+ OutputParser.new(path, stdout).parse
22
+ rescue => e
23
+ puts "ERROR: pronto-tailor failed to process a diff: #{e}"
24
+ []
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pronto/tailor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pronto-tailor"
8
+ spec.version = Pronto::Tailor::VERSION
9
+ spec.authors = ["Andrius Janauskas"]
10
+ spec.email = ["andrius.janauskas@gmail.com"]
11
+ spec.homepage = 'https://github.com/ajanauskas/pronto-tailor'
12
+
13
+ spec.summary = 'Pronto runner for Tailor, swift code analyzer'
14
+ spec.description = <<-EOF
15
+ A pronto runner for Tailor - Swift code analyzer. Pronto runs analysis quickly by checking only
16
+ the relevant changes. Created to be used on pull requests, but suited for other scenarios as well. Perfect
17
+ if you want to find out quickly if branch introduces changes that conform to
18
+ your styleguide, are DRY, don't introduce security holes and more.
19
+ EOF
20
+ spec.license = 'MIT'
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.10'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_runtime_dependency 'pronto', '~> 0.5.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.3'
31
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pronto-tailor
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: 2015-12-19 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: pronto
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.5.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.5.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ description: |2
70
+ A pronto runner for Tailor - 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. Perfect
72
+ if you want to find out quickly if branch introduces changes that conform to
73
+ your styleguide, are DRY, don't introduce security holes and more.
74
+ email:
75
+ - andrius.janauskas@gmail.com
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".gitignore"
81
+ - ".rspec"
82
+ - ".travis.yml"
83
+ - CODE_OF_CONDUCT.md
84
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - lib/pronto/tailor.rb
91
+ - lib/pronto/tailor/configuration.rb
92
+ - lib/pronto/tailor/output_parser.rb
93
+ - lib/pronto/tailor/version.rb
94
+ - lib/pronto/tailor/wrapper.rb
95
+ - pronto-tailor.gemspec
96
+ homepage: https://github.com/ajanauskas/pronto-tailor
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.5
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Pronto runner for Tailor, swift code analyzer
120
+ test_files: []