danger-swift_lint 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: 67150ac476e6024bd8efa9521efd77b6dc4b7925
4
+ data.tar.gz: cc79df9605f1e37721a4ded5982cf9318e986ef7
5
+ SHA512:
6
+ metadata.gz: 5187ef32e2c6f78ea9de668a92ba21630044b906e1b0caaf663fd3b70e61952e765a5505ffb4e17a202eb6e2b27a98e22a3b9a96629bbf3f97b8ac83166362c4
7
+ data.tar.gz: 82ab49ad4d08088442b20e42afe7f3892755fa120c2bbbb79e30a073e0666d6a0c879388f09e80db6325628e8b84bd6b20b42df5b3928beee2f6547d69f7ab42
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ .ruby-version
47
+ .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ cache:
3
+ directories:
4
+ - bundle
5
+
6
+ rvm:
7
+ - 2.0
8
+ - 2.1.3
9
+ - 2.3.1
10
+
11
+ script:
12
+ - bundle exec rake spec
13
+ - bundle exec danger plugins lint
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-swiftlint.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'mocha'
8
+ gem 'bacon'
9
+ gem 'mocha-on-bacon'
10
+ gem 'prettybacon'
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Adam Yanalunas
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,56 @@
1
+
2
+
3
+ ### swiftlint
4
+
5
+ Surface your SwiftLint JSON report in pull requests.
6
+ If no report exists, one will be created using the existing SwiftLint install.
7
+ Results are displayed in a markdown table.
8
+
9
+ <blockquote>Run report
10
+ <pre>
11
+ # Runs SwiftLint if necessary and processes the report using the default settings
12
+ swiftlint.report</pre>
13
+ </blockquote>
14
+
15
+ <blockquote>Run a report with a specific report file
16
+ <pre>
17
+ # Assumes your path starts in the present directory
18
+ swiftlint.report 'path/to/report.json'</pre>
19
+ </blockquote>
20
+
21
+ <blockquote>Run a report, ignoring warnings
22
+ <pre>
23
+ swiftlint.enabled_types = [:error]
24
+ swiftlint.report</pre>
25
+ </blockquote>
26
+
27
+ <blockquote>Run a report, defining custom warning emoji
28
+ <pre>
29
+ swiftlint.issue_emoji[:warning] = '❓'
30
+ swiftlint.report</pre>
31
+ </blockquote>
32
+
33
+
34
+
35
+ #### Attributes
36
+
37
+ `enabled_types` - Allows you to set which issue types are displayed.
38
+ Defaults to `[:warning", :error]`
39
+
40
+ `issue_emoji` - Allows configuration of which emoji is shown for an issue type.
41
+ Defaults to `{:warning: '⚠', :error: '❌'}`
42
+
43
+
44
+
45
+
46
+ #### Methods
47
+
48
+ `report` - Lint an existing report or have one generated. Will fail if `swiftlint` is not installed.
49
+ Generates a `markdown` list of warnings and errors from the JSON report, linking to each issue's line in the PR.
50
+ Does nothing when there are no valid issues to raise.
51
+
52
+ `swiftlint_installed?` - Determine if swiftlint is currently installed in the system paths.
53
+
54
+
55
+
56
+
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module Pod
4
+ class TemplateConfigurator
5
+
6
+ attr_reader :plugin_command
7
+ attr_reader :plugin_file
8
+ attr_reader :plugin_name
9
+
10
+ def initialize(plugin_name)
11
+ unless plugin_name
12
+ puts "Please specify a plugin name on the command line."
13
+ exit
14
+ end
15
+
16
+ @plugin_command = plugin_name.split('-').last
17
+ @plugin_file = plugin_name.dup
18
+ @plugin_name = plugin_name
19
+ end
20
+
21
+ def run
22
+ unless plugin_name =~ /cocoapods-.+/
23
+ puts "Plugin name needs to be of the form 'cocoapods-*'."
24
+ exit
25
+ end
26
+
27
+ puts "Configuring #{plugin_name}"
28
+ print_info
29
+ clean_template_files
30
+ replace_variables_in_files
31
+ rename_template_files
32
+ reinitialize_git_repo
33
+ end
34
+
35
+ #----------------------------------------#
36
+
37
+ def print_info
38
+ puts "user name:#{user_name}"
39
+ puts "user email:#{user_email}"
40
+ puts "year:#{year}"
41
+ end
42
+
43
+ def clean_template_files
44
+ `rm -rf configure`
45
+ `rm -rf README.md`
46
+ `rm -rf LICENSE`
47
+ end
48
+
49
+ def replace_variables_in_files
50
+ file_names = [
51
+ 'PLUGIN_LICENSE.txt',
52
+ 'PLUGIN_README.md',
53
+ 'Gemfile',
54
+ 'PLUGIN.gemspec.template',
55
+ 'lib/PLUGIN.rb',
56
+ 'lib/PLUGIN/gem_version.rb',
57
+ 'lib/cocoapods_plugin.rb',
58
+ 'lib/PLUGIN/command.rb',
59
+ 'lib/PLUGIN/command/COMMAND.rb',
60
+ 'spec/command/COMMAND_spec.rb'
61
+ ]
62
+
63
+ file_names.each do |file_name|
64
+ text = File.read(file_name)
65
+ text.gsub!("${PLUGIN_CLASS}", plugin_name.split('-').last.capitalize)
66
+ text.gsub!("${PLUGIN_COMMAND}", plugin_command)
67
+ text.gsub!("${PLUGIN_MODULE}", plugin_name.split('-').map(&:capitalize).join(''))
68
+ text.gsub!("${PLUGIN_FILE}", plugin_file)
69
+ text.gsub!("${PLUGIN_NAME}", plugin_name)
70
+ text.gsub!("${USER_NAME}", user_name)
71
+ text.gsub!("${USER_EMAIL}", user_email)
72
+ text.gsub!("${YEAR}", year)
73
+ File.open(file_name, "w") { |file| file.puts text }
74
+ end
75
+ end
76
+
77
+ def rename_template_files
78
+ `mv PLUGIN_LICENSE.txt LICENSE.txt`
79
+ `mv PLUGIN_README.md README.md`
80
+ `mv PLUGIN.gemspec.template #{plugin_file}.gemspec`
81
+ `mv lib/PLUGIN.rb lib/#{plugin_file}.rb`
82
+ `mv lib/PLUGIN lib/#{plugin_file}`
83
+ `mv lib/#{plugin_file}/command/COMMAND.rb lib/#{plugin_file}/command/#{plugin_command}.rb`
84
+ `mv spec/command/COMMAND_spec.rb spec/command/#{plugin_command}_spec.rb`
85
+ end
86
+
87
+ def reinitialize_git_repo
88
+ `rm -rf .git`
89
+ `git init`
90
+ `git add -A`
91
+ `git commit -m "Initial commit"`
92
+ end
93
+
94
+ #----------------------------------------#
95
+
96
+ def user_name
97
+ (ENV['GIT_COMMITTER_NAME'] || `git config user.name`).strip
98
+ end
99
+
100
+ def user_email
101
+ (ENV['GIT_COMMITTER_EMAIL'] || `git config user.email`).strip
102
+ end
103
+
104
+ def year
105
+ Time.now.year.to_s
106
+ end
107
+
108
+ #----------------------------------------#
109
+ end
110
+ end
111
+
112
+ #-----------------------------------------------------------------------------#
113
+
114
+ # TODO: Handle description
115
+ # TODO: Handle usage
116
+ # TODO: Handle GitHub URL
117
+
118
+ plugin_name = ARGV.shift
119
+ Pod::TemplateConfigurator.new(plugin_name).run
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-swift_lint'
8
+ spec.version = DangerSwiftLint::VERSION
9
+ spec.authors = ['Adam Yanalunas']
10
+ spec.email = ['adam@yanalunas.com']
11
+ spec.description = 'A Danger plugin for displaying SwiftLint issues in your pull request'
12
+ spec.summary = 'A Danger plugin for displaying SwiftLint issues in your pull request'
13
+ spec.homepage = 'https://github.com/adamyanalunas/danger-swiftlint'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'danger'
21
+
22
+ # Let's you test your plugin via the linter
23
+ spec.add_development_dependency "yard", '~> 0.8'
24
+
25
+ # General ruby development
26
+ spec.add_development_dependency 'bundler', '~> 1.3'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+
29
+ # Testing support
30
+ spec.add_development_dependency 'rspec', '~> 3.4'
31
+
32
+ # Makes testing easy via `bundle exec guard`
33
+ spec.add_development_dependency 'guard', '~> 2.14'
34
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
35
+
36
+ # If you want to work on older builds of ruby
37
+ spec.add_development_dependency 'listen', '3.0.7'
38
+
39
+ # This gives you the chance to run a REPL inside your test
40
+ # via
41
+ # binding.pry
42
+ # This will stop test execution and let you inspect the results
43
+ spec.add_development_dependency 'pry'
44
+ end
@@ -0,0 +1,148 @@
1
+ require 'json'
2
+
3
+ module Danger
4
+ # Surface your SwiftLint JSON report in pull requests.
5
+ # If no report exists, one will be created using the existing SwiftLint install.
6
+ # Results are displayed in a markdown table.
7
+ #
8
+ # @example Run report
9
+ #
10
+ # # Runs SwiftLint if necessary and processes the report using the default settings
11
+ # swiftlint.report
12
+ #
13
+ # @example Run a report with a specific report file
14
+ #
15
+ # # Assumes your path starts in the present directory
16
+ # swiftlint.report 'path/to/report.json'
17
+ #
18
+ # @example Run a report, ignoring warnings
19
+ #
20
+ # swiftlint.enabled_types = [:error]
21
+ # swiftlint.report
22
+ #
23
+ # @example Run a report, defining custom warning emoji
24
+ #
25
+ # swiftlint.issue_emoji[:warning] = '❓'
26
+ # swiftlint.report
27
+ #
28
+ # @tags lint, linting, swift, ios, macos, xcode
29
+ #
30
+ class DangerSwiftLint < Plugin
31
+ # Allows you to set which issue types are displayed.
32
+ # Defaults to `[:warning", :error]`
33
+ #
34
+ # @return [Array<Symbol>]
35
+ attr_accessor :enabled_types
36
+
37
+ # Allows configuration of which emoji is shown for an issue type.
38
+ # Defaults to `{:warning: '⚠', :error: '❌'}`
39
+ #
40
+ # @return [Hash<Symbol, String>]
41
+ attr_accessor :issue_emoji
42
+
43
+ def initialize dangerfile
44
+ super(dangerfile)
45
+
46
+ @enabled_types = [:warning, :error]
47
+ @issue_emoji = {warning: '⚠', error: '❌'}
48
+ end
49
+
50
+ # Lint an existing report or have one generated. Will fail if `swiftlint` is not installed.
51
+ # Generates a `markdown` list of warnings and errors from the JSON report, linking to each issue's line in the PR.
52
+ # Does nothing when there are no valid issues to raise.
53
+ #
54
+ # @param [String] file
55
+ # A full system path to an existing SwiftLint JSON report.
56
+ # If nil, swiftlint will be run to generate the report.
57
+ # @return [void]
58
+ #
59
+ def report(file = nil)
60
+ # Check that swiftlint is in the user's PATH
61
+ # raise "swiftlint is not in the user's PATH, or it failed to install" unless swiftlint_installed?
62
+ unless swiftlint_installed?
63
+ fail "swiftlint is not in the user's PATH, or it failed to install"
64
+ return
65
+ end
66
+
67
+ # Create a report file if none is provided
68
+ file = generate_report if file == nil
69
+
70
+ # Gather JSON from the report to process
71
+ report_json = get_report_json file
72
+
73
+ # No need to create a report if there are no issues
74
+ return if report_json.length == 0
75
+
76
+ # Assumes this is being run in the root of the repo, using PWD to find the relative path of repo files
77
+ commit_path = path_for_commit
78
+ issues = ''
79
+ report_json.each do |entry|
80
+ type = entry['severity'].downcase.to_sym
81
+ next unless enabled_types.include? type
82
+
83
+ line = entry['line']
84
+ report_filename = entry['file']
85
+ repo_file_path = repo_path report_filename
86
+ issue_path = issue_path commit_path, repo_file_path, line
87
+ reason = entry['reason']
88
+
89
+ issues << "| #{issue_emoji[type]} | [#{repo_file_path} (line #{line})](#{issue_path}) | #{reason} |\n"
90
+ end
91
+
92
+ show_report issues
93
+ end
94
+
95
+ # Determine if swiftlint is currently installed in the system paths.
96
+ # @return [Bool]
97
+ def swiftlint_installed?
98
+ `which swiftlint`.strip.empty? == false
99
+ end
100
+
101
+ private
102
+ def generate_report
103
+ filename = 'swiftlint_report.json'
104
+ `swiftlint lint --quiet --reporter json > ./#{filename}`
105
+ filename
106
+ end
107
+
108
+ def get_report_json file
109
+ JSON.parse File.read(file, encoding:'utf-8')
110
+ end
111
+
112
+ def issue_path commit_path, repo_file_path, line
113
+ check_scm_support
114
+
115
+ commit_path + repo_file_path + "#L#{line}"
116
+ end
117
+
118
+ def path_for_commit
119
+ check_scm_support
120
+
121
+ # Get some metadata about the local setup
122
+ host = 'https://' + env.request_source.host
123
+ repo_slug = env.ci_source.repo_slug
124
+
125
+ host + '/' + repo_slug + '/' + 'tree' + '/' + env.request_source.pr_json[:head][:sha]
126
+ end
127
+
128
+ def repo_path report_path, root = Dir.pwd
129
+ report_path[report_path.index(root) + root.length, report_path.length]
130
+ end
131
+
132
+ def show_report issues
133
+ return if issues.empty?
134
+
135
+ header = "### SwiftLint found issues\n\n"
136
+ header << "| Severity | File | Message |\n"
137
+ header << "|----------|------|---------|\n"
138
+
139
+ markdown header + issues
140
+ end
141
+
142
+ def check_scm_support
143
+ unless defined? @dangerfile.github
144
+ raise 'This plugin only supports Github. Would love PRs to support more! https://github.com/adamyanalunas/danger-swiftlint/'
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,3 @@
1
+ module DangerSwiftLint
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,115 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe DangerSwiftLint do
5
+ it 'is a plugin' do
6
+ expect(Danger::DangerSwiftLint < Danger::Plugin).to be_truthy
7
+ end
8
+
9
+ describe 'with Dangerfile' do
10
+ before do
11
+ @dangerfile = testing_dangerfile
12
+ @swiftlint = @dangerfile.swift_lint
13
+ @report_file = Dir.pwd + '/spec/fixtures/report_fixture.json'
14
+ @report_json = JSON.parse File.read(@report_file, encoding:'utf-8')
15
+
16
+ @swiftlint.env.request_source.pr_json = { head: { ref: 'my_fake_branch', sha: '123abc' } }
17
+ end
18
+
19
+ describe 'report' do
20
+ before do
21
+ allow(@swiftlint).to receive(:swiftlint_installed?).and_return(true)
22
+ allow(@swiftlint).to receive(:get_report_json).and_return(@report_json)
23
+ allow(Dir).to receive(:pwd).and_return('/Users/user/development')
24
+ end
25
+
26
+ it 'should raise when swiftlint not installed' do
27
+ allow(@swiftlint).to receive(:swiftlint_installed?).and_return(false)
28
+ @swiftlint.report
29
+ expect(@swiftlint.status_report[:errors]).to eq(["swiftlint is not in the user's PATH, or it failed to install"])
30
+ end
31
+
32
+ it 'should run swiftlint when no report is provided' do
33
+ expect(@swiftlint).to receive(:`).with('swiftlint lint --quiet --reporter json > ./swiftlint_report.json').and_return(@report_file)
34
+ @swiftlint.report
35
+ end
36
+
37
+ it 'should create a heading on the first line' do
38
+ @swiftlint.report @report_file
39
+
40
+ output = @swiftlint.status_report[:markdowns].first.message.split "\n"
41
+
42
+ expect(output[0]).to eq('### SwiftLint found issues')
43
+ expect(output[1]).to eq('')
44
+ end
45
+
46
+ it 'should create a markdown table under the heading' do
47
+ @swiftlint.report @report_file
48
+
49
+ output = @swiftlint.status_report[:markdowns].first.message.split "\n"
50
+
51
+ expect(output[2]).to eq('| Severity | File | Message |')
52
+ expect(output[3]).to eq('|----------|------|---------|')
53
+ end
54
+
55
+ it 'should contain entries and links to all issues from report' do
56
+ @swiftlint.report @report_file
57
+
58
+ output = @swiftlint.status_report[:markdowns].first.message.split "\n"
59
+ issues = output.drop(4)
60
+
61
+ expect(issues[0]).to eq("| ⚠ | [/adamyanalunas/danger-swiftlint/Controllers/Controller.swift (line 37)](https://github.com/adamyanalunas/danger-swiftlint/tree/123abc/adamyanalunas/danger-swiftlint/Controllers/Controller.swift#L37) | Limit vertical whitespace to a single empty line. Currently 2. |")
62
+ expect(issues[1]).to eq("| ❌ | [/adamyanalunas/danger-swiftlint/Controllers/Controller.swift (line 39)](https://github.com/adamyanalunas/danger-swiftlint/tree/123abc/adamyanalunas/danger-swiftlint/Controllers/Controller.swift#L39) | Enum element name should start with a lowercase character: 'Bar' |")
63
+ expect(issues[2]).to eq("| ⚠ | [/adamyanalunas/danger-swiftlint/Controllers/Controller.swift (line 438)](https://github.com/adamyanalunas/danger-swiftlint/tree/123abc/adamyanalunas/danger-swiftlint/Controllers/Controller.swift#L438) | File should contain 400 lines or less: currently contains 438 |")
64
+ end
65
+
66
+ it 'should only process errors when configured as such' do
67
+ @swiftlint.enabled_types = [:error]
68
+ @swiftlint.report @report_file
69
+
70
+ output = @swiftlint.status_report[:markdowns].first.message.split "\n"
71
+ issues = output.drop(4)
72
+
73
+ expect(issues.length).to eq(1)
74
+ expect(issues[0]).to eq("| ❌ | [/adamyanalunas/danger-swiftlint/Controllers/Controller.swift (line 39)](https://github.com/adamyanalunas/danger-swiftlint/tree/123abc/adamyanalunas/danger-swiftlint/Controllers/Controller.swift#L39) | Enum element name should start with a lowercase character: 'Bar' |")
75
+ end
76
+
77
+ it 'should only process warnings when configured as such' do
78
+ @swiftlint.enabled_types = [:warning]
79
+ @swiftlint.report @report_file
80
+
81
+ output = @swiftlint.status_report[:markdowns].first.message.split "\n"
82
+ issues = output.drop(4)
83
+
84
+ expect(issues.length).to eq(2)
85
+ expect(issues[0]).to eq("| ⚠ | [/adamyanalunas/danger-swiftlint/Controllers/Controller.swift (line 37)](https://github.com/adamyanalunas/danger-swiftlint/tree/123abc/adamyanalunas/danger-swiftlint/Controllers/Controller.swift#L37) | Limit vertical whitespace to a single empty line. Currently 2. |")
86
+ expect(issues[1]).to eq("| ⚠ | [/adamyanalunas/danger-swiftlint/Controllers/Controller.swift (line 438)](https://github.com/adamyanalunas/danger-swiftlint/tree/123abc/adamyanalunas/danger-swiftlint/Controllers/Controller.swift#L438) | File should contain 400 lines or less: currently contains 438 |")
87
+ end
88
+
89
+ it 'should show custom emojis' do
90
+ @swiftlint.issue_emoji = {warning: '❓', error: '🛑'}
91
+ @swiftlint.report @report_file
92
+
93
+ output = @swiftlint.status_report[:markdowns].first.message.split "\n"
94
+ issues = output.drop(4)
95
+
96
+ expect(issues[0]).to include("| ❓ |")
97
+ expect(issues[1]).to include("| 🛑 |")
98
+ expect(issues[2]).to include("| ❓ |")
99
+ end
100
+ end
101
+
102
+ describe 'swiftlint_installed?' do
103
+ it 'should handle swiftlint not being installed' do
104
+ allow(@swiftlint).to receive(:`).with('which swiftlint').and_return('')
105
+ expect(@swiftlint.swiftlint_installed?).to be_falsy
106
+ end
107
+
108
+ it 'should handle swiftlint being installed' do
109
+ allow(@swiftlint).to receive(:`).with('which swiftlint').and_return('/usr/local/bin/swiftlint')
110
+ expect(@swiftlint.swiftlint_installed?).to be_truthy
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,29 @@
1
+ [
2
+ {
3
+ "rule_id" : "vertical_whitespace",
4
+ "reason" : "Limit vertical whitespace to a single empty line. Currently 2.",
5
+ "character" : null,
6
+ "file" : "\/Users\/user\/development\/adamyanalunas\/danger-swiftlint\/Controllers\/Controller.swift",
7
+ "severity" : "Warning",
8
+ "type" : "Vertical Whitespace",
9
+ "line" : 37
10
+ },
11
+ {
12
+ "rule_id" : "identifier_name",
13
+ "reason" : "Enum element name should start with a lowercase character: 'Bar'",
14
+ "character" : 10,
15
+ "file" : "\/Users\/user\/development\/adamyanalunas\/danger-swiftlint\/Controllers\/Controller.swift",
16
+ "severity" : "Error",
17
+ "type" : "Identifier Name",
18
+ "line" : 39
19
+ },
20
+ {
21
+ "rule_id" : "file_length",
22
+ "reason" : "File should contain 400 lines or less: currently contains 438",
23
+ "character" : null,
24
+ "file" : "\/Users\/user\/development\/adamyanalunas\/danger-swiftlint\/Controllers\/Controller.swift",
25
+ "severity" : "Warning",
26
+ "type" : "File Line Length",
27
+ "line" : 438
28
+ }
29
+ ]
@@ -0,0 +1,65 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $:.unshift((ROOT + 'lib').to_s)
4
+ $:.unshift((ROOT + 'spec').to_s)
5
+
6
+ require 'bundler/setup'
7
+ require 'pry'
8
+
9
+ require 'rspec'
10
+ require 'danger'
11
+
12
+ # Use coloured output, it's the best.
13
+ RSpec.configure do |config|
14
+ config.filter_gems_from_backtrace "bundler"
15
+ config.color = true
16
+ config.tty = true
17
+
18
+ # config.include Danger::Support::CIHelper, use: :ci_helper
19
+ end
20
+
21
+ require 'danger_plugin'
22
+
23
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
24
+ # If you are expanding these files, see if it's already been done ^.
25
+
26
+ # A silent version of the user interface,
27
+ # it comes with an extra function `.string` which will
28
+ # strip all ANSI colours from the string.
29
+
30
+ # rubocop:disable Lint/NestedMethodDefinition
31
+ def testing_ui
32
+ @output = StringIO.new
33
+ def @output.winsize
34
+ [20, 9999]
35
+ end
36
+
37
+ cork = Cork::Board.new(out: @output)
38
+ def cork.string
39
+ out.string.gsub(/\e\[([;\d]+)?m/, "")
40
+ end
41
+ cork
42
+ end
43
+ # rubocop:enable Lint/NestedMethodDefinition
44
+
45
+ # Example environment (ENV) that would come from
46
+ # running a PR on TravisCI
47
+ def testing_env
48
+ {
49
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
50
+ 'TRAVIS_PULL_REQUEST' => '800',
51
+ 'TRAVIS_REPO_SLUG' => 'adamyanalunas/danger-swiftlint',
52
+ 'TRAVIS_PULL_REQUEST' => '1',
53
+ 'TRAVIS_PULL_REQUEST_BRANCH' => 'pr_branch',
54
+ 'TRAVIS_PULL_REQUEST_SHA' => '7d0c0f7434bca40ed12a78bd735209c3e5a2e289',
55
+ 'TRAVIS_COMMIT' => '7d0c0f7434bca40ed12a78bd735209c3e5a2e289',
56
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
57
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
58
+ }
59
+ end
60
+
61
+ # A stubbed out Dangerfile for use in tests
62
+ def testing_dangerfile
63
+ env = Danger::EnvironmentManager.new(testing_env)
64
+ Danger::Dangerfile.new(env, testing_ui)
65
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-swift_lint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adam Yanalunas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
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: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.14'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.14'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: listen
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 3.0.7
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 3.0.7
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: A Danger plugin for displaying SwiftLint issues in your pull request
140
+ email:
141
+ - adam@yanalunas.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".travis.yml"
148
+ - Gemfile
149
+ - LICENSE
150
+ - README.md
151
+ - Rakefile
152
+ - configure
153
+ - danger-swiftlint.gemspec
154
+ - lib/danger_plugin.rb
155
+ - lib/version.rb
156
+ - spec/danger_plugin_spec.rb
157
+ - spec/fixtures/report_fixture.json
158
+ - spec/spec_helper.rb
159
+ homepage: https://github.com/adamyanalunas/danger-swiftlint
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.2.2
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: A Danger plugin for displaying SwiftLint issues in your pull request
183
+ test_files:
184
+ - spec/danger_plugin_spec.rb
185
+ - spec/fixtures/report_fixture.json
186
+ - spec/spec_helper.rb