danger-detekt-instacart 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b764046152e872ed4909383bf6ee158807244d1aef3ad6f13ab8d1d89ae50f3b
4
+ data.tar.gz: 0df1e39db6cb862cc6b00d0a1ee8b2eefc8fb2f3be2cd4010f36f7ae90cd1092
5
+ SHA512:
6
+ metadata.gz: 2948c60dc188f6ffa8b8b9d0f8cfae99baff98176171d9a8419cb965c6dad328b0b21ecbbadae2125559127dc630233a32cf55b6786be3c00611c0c5cd23a077
7
+ data.tar.gz: f568ae43cc6f1e056aa6954af029168c70b6ddd2794dea27f0944334625ee218c69672a4c84ea25b8f378091a8c5bbabd550afba27960f786956a28e9221870f
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
4
+ .yardoc
5
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,152 @@
1
+ # Defaults can be found here: https://github.com/bbatsov/rubocop/blob/master/config/default.yml
2
+
3
+ # If you don't like these settings, just delete this file :)
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.0
7
+
8
+ Style/StringLiterals:
9
+ EnforcedStyle: double_quotes
10
+ Enabled: true
11
+
12
+ # kind_of? is a good way to check a type
13
+ Style/ClassCheck:
14
+ EnforcedStyle: kind_of?
15
+
16
+ # It's better to be more explicit about the type
17
+ Style/BracesAroundHashParameters:
18
+ Enabled: false
19
+
20
+ # specs sometimes have useless assignments, which is fine
21
+ Lint/UselessAssignment:
22
+ Exclude:
23
+ - '**/spec/**/*'
24
+
25
+ # We could potentially enable the 2 below:
26
+ Layout/IndentHash:
27
+ Enabled: false
28
+
29
+ Layout/AlignHash:
30
+ Enabled: false
31
+
32
+ # HoundCI doesn't like this rule
33
+ Layout/DotPosition:
34
+ Enabled: false
35
+
36
+ # We allow !! as it's an easy way to convert ot boolean
37
+ Style/DoubleNegation:
38
+ Enabled: false
39
+
40
+ # Cop supports --auto-correct.
41
+ Lint/UnusedBlockArgument:
42
+ Enabled: false
43
+
44
+ # We want to allow class Fastlane::Class
45
+ Style/ClassAndModuleChildren:
46
+ Enabled: false
47
+
48
+ Metrics/AbcSize:
49
+ Max: 60
50
+
51
+ # The %w might be confusing for new users
52
+ Style/WordArray:
53
+ MinSize: 19
54
+
55
+ # raise and fail are both okay
56
+ Style/SignalException:
57
+ Enabled: false
58
+
59
+ # Better too much 'return' than one missing
60
+ Style/RedundantReturn:
61
+ Enabled: false
62
+
63
+ # Having if in the same line might not always be good
64
+ Style/IfUnlessModifier:
65
+ Enabled: false
66
+
67
+ # and and or is okay
68
+ Style/AndOr:
69
+ Enabled: false
70
+
71
+ # Configuration parameters: CountComments.
72
+ Metrics/ClassLength:
73
+ Max: 350
74
+
75
+ Metrics/CyclomaticComplexity:
76
+ Max: 17
77
+
78
+ # Configuration parameters: AllowURI, URISchemes.
79
+ Metrics/LineLength:
80
+ Max: 370
81
+
82
+ # Configuration parameters: CountKeywordArgs.
83
+ Metrics/ParameterLists:
84
+ Max: 10
85
+
86
+ Metrics/PerceivedComplexity:
87
+ Max: 18
88
+
89
+ # Sometimes it's easier to read without guards
90
+ Style/GuardClause:
91
+ Enabled: false
92
+
93
+ # something = if something_else
94
+ # that's confusing
95
+ Style/ConditionalAssignment:
96
+ Enabled: false
97
+
98
+ # Better to have too much self than missing a self
99
+ Style/RedundantSelf:
100
+ Enabled: false
101
+
102
+ Metrics/MethodLength:
103
+ Max: 60
104
+
105
+ # We're not there yet
106
+ Style/Documentation:
107
+ Enabled: false
108
+
109
+ # Adds complexity
110
+ Style/IfInsideElse:
111
+ Enabled: false
112
+
113
+ # danger specific
114
+
115
+ Style/BlockComments:
116
+ Enabled: false
117
+
118
+ Layout/MultilineMethodCallIndentation:
119
+ EnforcedStyle: indented
120
+
121
+ # FIXME: 25
122
+ Metrics/BlockLength:
123
+ Max: 345
124
+ Exclude:
125
+ - "**/*_spec.rb"
126
+
127
+ Style/MixinGrouping:
128
+ Enabled: false
129
+
130
+ Style/FileName:
131
+ Enabled: false
132
+
133
+ Layout/IndentHeredoc:
134
+ Enabled: false
135
+
136
+ Style/SpecialGlobalVars:
137
+ Enabled: false
138
+
139
+ PercentLiteralDelimiters:
140
+ PreferredDelimiters:
141
+ "%": ()
142
+ "%i": ()
143
+ "%q": ()
144
+ "%Q": ()
145
+ "%r": "{}"
146
+ "%s": ()
147
+ "%w": ()
148
+ "%W": ()
149
+ "%x": ()
150
+
151
+ Security/YAMLLoad:
152
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-kotlin_detekt.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,151 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-kotlin_detekt (0.0.3)
5
+ danger-plugin-api (~> 1.0)
6
+ oga
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.8.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ansi (1.5.0)
14
+ ast (2.4.0)
15
+ claide (1.0.3)
16
+ claide-plugins (0.9.2)
17
+ cork
18
+ nap
19
+ open4 (~> 1.3)
20
+ coderay (1.1.2)
21
+ colored2 (3.1.2)
22
+ cork (0.3.0)
23
+ colored2 (~> 3.1)
24
+ danger (8.0.4)
25
+ claide (~> 1.0)
26
+ claide-plugins (>= 0.9.2)
27
+ colored2 (~> 3.1)
28
+ cork (~> 0.1)
29
+ faraday (>= 0.9.0, < 2.0)
30
+ faraday-http-cache (~> 2.0)
31
+ git (~> 1.7)
32
+ kramdown (~> 2.0)
33
+ kramdown-parser-gfm (~> 1.0)
34
+ no_proxy_fix
35
+ octokit (~> 4.7)
36
+ terminal-table (~> 1)
37
+ danger-plugin-api (1.0.0)
38
+ danger (> 2.0)
39
+ diff-lcs (1.3)
40
+ faraday (1.0.1)
41
+ multipart-post (>= 1.2, < 3)
42
+ faraday-http-cache (2.2.0)
43
+ faraday (>= 0.8)
44
+ ffi (1.9.25)
45
+ formatador (0.2.5)
46
+ git (1.11.0)
47
+ rchardet (~> 1.8)
48
+ guard (2.14.2)
49
+ formatador (>= 0.2.4)
50
+ listen (>= 2.7, < 4.0)
51
+ lumberjack (>= 1.0.12, < 2.0)
52
+ nenv (~> 0.1)
53
+ notiffany (~> 0.0)
54
+ pry (>= 0.9.12)
55
+ shellany (~> 0.0)
56
+ thor (>= 0.18.1)
57
+ guard-compat (1.2.1)
58
+ guard-rspec (4.7.3)
59
+ guard (~> 2.1)
60
+ guard-compat (~> 1.1)
61
+ rspec (>= 2.99.0, < 4.0)
62
+ kramdown (2.3.1)
63
+ rexml
64
+ kramdown-parser-gfm (1.1.0)
65
+ kramdown (~> 2.0)
66
+ listen (3.0.7)
67
+ rb-fsevent (>= 0.9.3)
68
+ rb-inotify (>= 0.9.7)
69
+ lumberjack (1.0.13)
70
+ method_source (0.9.0)
71
+ multipart-post (2.1.1)
72
+ nap (1.1.0)
73
+ nenv (0.3.0)
74
+ no_proxy_fix (0.1.2)
75
+ notiffany (0.1.1)
76
+ nenv (~> 0.1)
77
+ shellany (~> 0.0)
78
+ octokit (4.18.0)
79
+ faraday (>= 0.9)
80
+ sawyer (~> 0.8.0, >= 0.5.3)
81
+ oga (2.15)
82
+ ast
83
+ ruby-ll (~> 2.1)
84
+ open4 (1.3.4)
85
+ parallel (1.12.1)
86
+ parser (2.5.1.2)
87
+ ast (~> 2.4.0)
88
+ powerpack (0.1.2)
89
+ pry (0.11.3)
90
+ coderay (~> 1.1.0)
91
+ method_source (~> 0.9.0)
92
+ public_suffix (4.0.6)
93
+ rainbow (2.2.2)
94
+ rake
95
+ rake (13.0.1)
96
+ rb-fsevent (0.10.3)
97
+ rb-inotify (0.9.10)
98
+ ffi (>= 0.5.0, < 2)
99
+ rchardet (1.8.0)
100
+ rexml (3.2.5)
101
+ rspec (3.8.0)
102
+ rspec-core (~> 3.8.0)
103
+ rspec-expectations (~> 3.8.0)
104
+ rspec-mocks (~> 3.8.0)
105
+ rspec-core (3.8.0)
106
+ rspec-support (~> 3.8.0)
107
+ rspec-expectations (3.8.1)
108
+ diff-lcs (>= 1.2.0, < 2.0)
109
+ rspec-support (~> 3.8.0)
110
+ rspec-mocks (3.8.0)
111
+ diff-lcs (>= 1.2.0, < 2.0)
112
+ rspec-support (~> 3.8.0)
113
+ rspec-support (3.8.0)
114
+ rubocop (0.49.1)
115
+ parallel (~> 1.10)
116
+ parser (>= 2.3.3.1, < 3.0)
117
+ powerpack (~> 0.1)
118
+ rainbow (>= 1.99.1, < 3.0)
119
+ ruby-progressbar (~> 1.7)
120
+ unicode-display_width (~> 1.0, >= 1.0.1)
121
+ ruby-ll (2.1.2)
122
+ ansi
123
+ ast
124
+ ruby-progressbar (1.10.0)
125
+ sawyer (0.8.2)
126
+ addressable (>= 2.3.5)
127
+ faraday (> 0.8, < 2.0)
128
+ shellany (0.0.1)
129
+ terminal-table (1.8.0)
130
+ unicode-display_width (~> 1.1, >= 1.1.1)
131
+ thor (0.20.0)
132
+ unicode-display_width (1.7.0)
133
+ yard (0.9.20)
134
+
135
+ PLATFORMS
136
+ ruby
137
+
138
+ DEPENDENCIES
139
+ bundler (~> 1.3)
140
+ danger-kotlin_detekt!
141
+ guard (~> 2.14)
142
+ guard-rspec (~> 4.7)
143
+ listen (= 3.0.7)
144
+ pry
145
+ rake (~> 13.0)
146
+ rspec (~> 3.4)
147
+ rubocop
148
+ yard
149
+
150
+ BUNDLED WITH
151
+ 1.16.5
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ # A guardfile for making Danger Plugins
2
+ # For more info see https://github.com/guard/guard#readme
3
+
4
+ # To run, use `bundle exec guard`.
5
+
6
+ guard :rspec, cmd: 'bundle exec rspec' do
7
+ require 'guard/rspec/dsl'
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2018 Nicolas Fesquet <n.fesquet@betclicgroup.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ ### kotlin_detekt
2
+
3
+ Detekt files of a gradle based Android project.
4
+ This is done using the Android's [Detekt](https://github.com/arturbosch/detekt) tool.
5
+ Results are passed out as tables in markdown.
6
+
7
+ <blockquote>Running KotlinDetekt with its basic configuration
8
+ <pre>
9
+ kotlin_detekt.detekt</pre>
10
+ </blockquote>
11
+
12
+ <blockquote>Running KotlinDetekt with a specific gradle task
13
+ <pre>
14
+ kotlin_detekt.gradle_task = "detektCheckMyFlavorDebug"
15
+ kotlin_detekt.detekt</pre>
16
+ </blockquote>
17
+
18
+ <blockquote>Running KotlinDetekt for a specific severity level and up
19
+ <pre>
20
+ # options are ["warning", "error"]
21
+ kotlin_detekt.severity = "error"
22
+ kotlin_detekt.detekt</pre>
23
+ </blockquote>
24
+
25
+
26
+
27
+ #### Attributes
28
+
29
+ `report_file` - Location of Detekt report file
30
+ If your Detekt task outputs to a different location, you can specify it here.
31
+ Defaults to "build/reports/detekt/detekt-checkstyle.xml".
32
+
33
+ `gradle_task` - Custom gradle task to run.
34
+ This is useful when your project has different flavors.
35
+ Defaults to "detektCheck".
36
+
37
+ `severity` - Defines the severity level of the execution.
38
+ Selected levels are the chosen one and up.
39
+ Possible values are "Warning", "Error" or "Fatal".
40
+ Defaults to "Warning".
41
+
42
+ `filtering` - Enable filtering
43
+ Only show messages within changed files.
44
+
45
+ `skip_gradle_task` - Skip gradle task
46
+
47
+
48
+
49
+
50
+ #### Methods
51
+
52
+ `detekt` - Calls Detekt task of your gradle project.
53
+ It fails if `gradlew` cannot be found inside current directory.
54
+ It fails if `severity` level is not a valid option.
55
+ It fails if `xmlReport` configuration is not set to `true` in your `build.gradle` file.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:specs)
6
+
7
+ task default: :specs
8
+
9
+ task :spec do
10
+ Rake::Task['specs'].invoke
11
+ Rake::Task['rubocop'].invoke
12
+ Rake::Task['spec_docs'].invoke
13
+ end
14
+
15
+ desc 'Run RuboCop on the lib/specs directory'
16
+ RuboCop::RakeTask.new(:rubocop) do |task|
17
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
18
+ end
19
+
20
+ desc 'Ensure that the plugin passes `danger plugins lint`'
21
+ task :spec_docs do
22
+ sh 'bundle exec danger plugins lint'
23
+ end
@@ -0,0 +1,51 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kotlin_detekt/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-detekt-instacart'
8
+ spec.version = KotlinDetekt::VERSION
9
+ spec.authors = ['Nicolas Fesquet', 'Chao Zhang']
10
+ spec.email = ['n.fesquet@betclicgroup.com', 'zhangchao6865@gmail.com']
11
+ spec.description = %q{A short description of danger-kotlin_detekt. This is a forked version to include detekt rule name.}
12
+ spec.summary = %q{A longer description of danger-kotlin_detekt. This is a forked version to include detekt rule name.}
13
+ spec.homepage = 'https://github.com/chao2zhang/danger-kotlin_detekt'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'oga'
22
+
23
+ spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
24
+
25
+ # General ruby development
26
+ spec.add_development_dependency 'bundler', '~> 1.3'
27
+ spec.add_development_dependency 'rake', '~> 13.0'
28
+
29
+ # Testing support
30
+ spec.add_development_dependency 'rspec', '~> 3.4'
31
+
32
+ # Linting code and docs
33
+ spec.add_development_dependency "rubocop"
34
+ spec.add_development_dependency "yard"
35
+
36
+ # Makes testing easy via `bundle exec guard`
37
+ spec.add_development_dependency 'guard', '~> 2.14'
38
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
39
+
40
+ # If you want to work on older builds of ruby
41
+ spec.add_development_dependency 'listen', '3.0.7'
42
+
43
+ # This gives you the chance to run a REPL inside your tests
44
+ # via:
45
+ #
46
+ # require 'pry'
47
+ # binding.pry
48
+ #
49
+ # This will stop test execution and let you inspect the results
50
+ spec.add_development_dependency 'pry'
51
+ end
@@ -0,0 +1 @@
1
+ require "kotlin_detekt/gem_version"
@@ -0,0 +1 @@
1
+ require "kotlin_detekt/plugin"
@@ -0,0 +1,3 @@
1
+ module KotlinDetekt
2
+ VERSION = "0.0.4".freeze
3
+ end
@@ -0,0 +1,181 @@
1
+ module Danger
2
+ # Detekt files of a gradle based Android project.
3
+ # This is done using the Android's [Detekt](https://github.com/arturbosch/detekt) tool.
4
+ # Results are passed out as tables in markdown.
5
+ #
6
+ # @example Running KotlinDetekt with its basic configuration
7
+ #
8
+ # kotlin_detekt.detekt
9
+ #
10
+ # @example Running KotlinDetekt with a specific gradle task
11
+ #
12
+ # kotlin_detekt.gradle_task = "detektCheckMyFlavorDebug"
13
+ # kotlin_detekt.detekt
14
+ #
15
+ # @example Running KotlinDetekt for a specific severity level and up
16
+ #
17
+ # # options are ["warning", "error"]
18
+ # kotlin_detekt.severity = "error"
19
+ # kotlin_detekt.detekt
20
+ #
21
+ # @see NFesquet/danger-kotlin_detekt
22
+ # @tags danger, detekt, kotlin
23
+ #
24
+ class DangerKotlinDetekt < Plugin
25
+ SEVERITY_LEVELS = %w(warning error).freeze
26
+
27
+ # Location of Detekt report file
28
+ # If your Detekt task outputs to a different location, you can specify it here.
29
+ # Defaults to "build/reports/detekt/detekt-checkstyle.xml".
30
+ # @return [String]
31
+ attr_accessor :report_file
32
+ # A getter for `report_file`.
33
+ # @return [String]
34
+ def report_file
35
+ return @report_file || "build/reports/detekt/detekt-checkstyle.xml"
36
+ end
37
+
38
+ # Custom gradle task to run.
39
+ # This is useful when your project has different flavors.
40
+ # Defaults to "detektCheck".
41
+ # @return [String]
42
+ attr_accessor :gradle_task
43
+
44
+ # Defines the severity level of the execution.
45
+ # Selected levels are the chosen one and up.
46
+ # Possible values are "Warning", "Error" or "Fatal".
47
+ # Defaults to "Warning".
48
+ # @return [String]
49
+ attr_writer :severity
50
+
51
+ # Enable filtering
52
+ # Only show messages within changed files.
53
+ attr_accessor :filtering
54
+
55
+ # Skip gradle task
56
+ attr_accessor :skip_gradle_task
57
+
58
+ # Calls Detekt task of your gradle project.
59
+ # It fails if `gradlew` cannot be found inside current directory.
60
+ # It fails if `severity` level is not a valid option.
61
+ # It fails if `xmlReport` configuration is not set to `true` in your `build.gradle` file.
62
+ # @return [void]
63
+ #
64
+ def detekt(inline_mode: false)
65
+ unless skip_gradle_task || gradlew_exists?
66
+ fail("Could not find `gradlew` inside current directory")
67
+ return
68
+ end
69
+
70
+ unless SEVERITY_LEVELS.include?(severity)
71
+ fail("'#{severity}' is not a valid value for `severity` parameter.")
72
+ return
73
+ end
74
+
75
+ system "./gradlew #{gradle_task || 'detektCheck'}" unless skip_gradle_task
76
+
77
+ unless File.exist?(report_file)
78
+ fail("Detekt report not found at `#{report_file}`. "\
79
+ "Have you forgot to add `xmlReport true` to your `build.gradle` file?")
80
+ end
81
+
82
+ issues = read_issues_from_report
83
+ filtered_issues = filter_issues_by_severity(issues)
84
+
85
+ if inline_mode
86
+ # Report with inline comment
87
+ send_inline_comment(filtered_issues)
88
+ else
89
+ message = message_for_issues(filtered_issues)
90
+ markdown("### Detekt found issues\n\n" + message) unless message.to_s.empty?
91
+ end
92
+ end
93
+
94
+ # A getter for `severity`, returning "warning" if value is nil.
95
+ # @return [String]
96
+ def severity
97
+ @severity || SEVERITY_LEVELS.first
98
+ end
99
+
100
+ private
101
+
102
+ def read_issues_from_report
103
+ file = File.open(report_file)
104
+
105
+ require "oga"
106
+ report = Oga.parse_xml(file)
107
+
108
+ report.xpath("//error")
109
+ end
110
+
111
+ def filter_issues_by_severity(issues)
112
+ issues.select do |issue|
113
+ severity_index(issue.get("severity")) >= severity_index(severity)
114
+ end
115
+ end
116
+
117
+ def severity_index(severity)
118
+ SEVERITY_LEVELS.index(severity) || 0
119
+ end
120
+
121
+ def message_for_issues(issues)
122
+ message = ""
123
+
124
+ SEVERITY_LEVELS.reverse.each do |level|
125
+ filtered = issues.select { |issue| issue.get("severity") == level }
126
+ message << parse_results(filtered, level) unless filtered.empty?
127
+ end
128
+
129
+ message
130
+ end
131
+
132
+ def parse_results(results, heading)
133
+ target_files = (git.modified_files - git.deleted_files) + git.added_files
134
+ dir = "#{Dir.pwd}/"
135
+ count = 0
136
+ message = ""
137
+
138
+ results.each do |r|
139
+ location = r.parent
140
+ filename = location.get("name").gsub(dir, "")
141
+ next unless !filtering || (target_files.include? filename)
142
+ line = r.get("line") || "N/A"
143
+ reason = r.get("message")
144
+ rule = r.get("source")
145
+ count += 1
146
+ message << "`#{filename}` | #{line} | #{reason} | #{rule} \n"
147
+ end
148
+ if count != 0
149
+ header = "#### #{heading} (#{count})\n\n"
150
+ header << "| File | Line | Reason | Rule |\n"
151
+ header << "| ---- | ---- | ------ | ---- |\n"
152
+ message = header + message
153
+ end
154
+
155
+ message
156
+ end
157
+
158
+ # Send inline comment with danger's warn or fail method
159
+ #
160
+ # @return [void]
161
+ def send_inline_comment(issues)
162
+ target_files = (git.modified_files - git.deleted_files) + git.added_files
163
+ dir = "#{Dir.pwd}/"
164
+ SEVERITY_LEVELS.reverse.each do |level|
165
+ filtered = issues.select { |issue| issue.get("severity") == level }
166
+ next if filtered.empty?
167
+ filtered.each do |r|
168
+ location = r.parent
169
+ filename = location.get("name").gsub(dir, "")
170
+ next unless !filtering || (target_files.include? filename)
171
+ line = (r.get("line") || "0").to_i
172
+ send(level == "warning" ? "warn" : "fail", r.get("message"), file: filename, line: line)
173
+ end
174
+ end
175
+ end
176
+
177
+ def gradlew_exists?
178
+ `ls gradlew`.strip.empty? == false
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <checkstyle version="4.3">
3
+ <file name="MyProject/app/src/main/java/com/company/package/model/Object1.kt">
4
+ <error line="5" column="28" severity="warning" message="The more parameters a method has the more complex it is. Long parameter lists are often used to control complex algorithms and violate the Single Responsibility Principle. Prefer methods with short parameter lists." source="detekt.LongParameterList" />
5
+ </file>
6
+ <file name="MyProject/app/src/main/java/com/company/package/model/Object2.kt">
7
+ <error line="41" column="22" severity="error" message="Thrown exception is too generic. Prefer throwing project specific exceptions to handle error cases." source="detekt.TooGenericExceptionCaught" />
8
+ </file>
9
+ <file name="MyProject/app/src/main/java/com/company/package/model/Object3.kt">
10
+ <error line="69" column="19" severity="warning" message="Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it&apos;s unclear what the purpose of this number is. It&apos;s better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers." source="detekt.MagicNumber" />
11
+ </file>
12
+ </checkstyle>
@@ -0,0 +1,76 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerKotlinDetekt do
5
+ it "should be a plugin" do
6
+ expect(Danger::DangerKotlinDetekt.new(nil)).to be_a Danger::Plugin
7
+ end
8
+
9
+ #
10
+ # You should test your custom attributes and methods here
11
+ #
12
+ describe "with Dangerfile" do
13
+ before do
14
+ @dangerfile = testing_dangerfile
15
+ @kotlin_detekt = @dangerfile.kotlin_detekt
16
+
17
+ allow(@kotlin_detekt.git).to receive(:deleted_files).and_return([])
18
+ allow(@kotlin_detekt.git).to receive(:added_files).and_return([])
19
+ allow(@kotlin_detekt.git).to receive(:modified_files).and_return([])
20
+ # # mock the PR data
21
+ # # you can then use this, eg. github.pr_author, later in the spec
22
+ # json = File.read(File.dirname(__FILE__) + "/support/fixtures/github_pr.json") # example json: `curl https://api.github.com/repos/danger/danger-plugin-template/pulls/18 > github_pr.json`
23
+ # allow(@kotlin_detekt.github).to receive(:pr_json).and_return(json)
24
+ end
25
+
26
+ it "Fails if gradlew does not exist" do
27
+ allow(@kotlin_detekt).to receive(:`).with("ls gradlew").and_return("")
28
+
29
+ @kotlin_detekt.detekt
30
+ expect(@kotlin_detekt.status_report[:errors]).to eq(["Could not find `gradlew` inside current directory"])
31
+ end
32
+
33
+ it "Fails if severity is an unknown value" do
34
+ allow(@kotlin_detekt).to receive(:`).with("ls gradlew").and_return("gradlew")
35
+ allow(File).to receive(:exists?).with(@kotlin_detekt.report_file).and_return(true)
36
+
37
+ @kotlin_detekt.severity = "Dummy"
38
+ @kotlin_detekt.detekt
39
+
40
+ expect(@kotlin_detekt.status_report[:errors]).to eq(["'Dummy' is not a valid value for `severity` parameter."])
41
+ end
42
+
43
+ it "Sets severity to 'warning' if no severity param is provided" do
44
+ allow(@kotlin_detekt).to receive(:`).with("ls gradlew").and_return("gradlew")
45
+ allow(File).to receive(:exists?).with(@kotlin_detekt.report_file).and_return(true)
46
+
47
+ fake_result = File.open("spec/fixtures/detekt-result-with-everything.xml")
48
+ allow(File).to receive(:open).with(@kotlin_detekt.report_file).and_return(fake_result)
49
+
50
+ @kotlin_detekt.detekt
51
+ expect(@kotlin_detekt.severity).to eq("warning")
52
+ end
53
+
54
+ # # Some examples for writing tests
55
+ # # You should replace these with your own.
56
+ #
57
+ # it "Warns on a monday" do
58
+ # monday_date = Date.parse("2016-07-11")
59
+ # allow(Date).to receive(:today).and_return monday_date
60
+ #
61
+ # @kotlin_detekt.warn_on_mondays
62
+ #
63
+ # expect(@dangerfile.status_report[:warnings]).to eq(["Trying to merge code on a Monday"])
64
+ # end
65
+ #
66
+ # it "Does nothing on a tuesday" do
67
+ # monday_date = Date.parse("2016-07-12")
68
+ # allow(Date).to receive(:today).and_return monday_date
69
+ #
70
+ # @kotlin_detekt.warn_on_mondays
71
+ #
72
+ # expect(@dangerfile.status_report[:warnings]).to eq([])
73
+ # end
74
+ end
75
+ end
76
+ end
@@ -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
+ if `git remote -v` == ""
13
+ puts "You cannot run tests without setting a local git remote on this repo"
14
+ puts "It's a weird side-effect of Danger's internals."
15
+ exit(0)
16
+ end
17
+
18
+ # Use coloured output, it's the best.
19
+ RSpec.configure do |config|
20
+ config.filter_gems_from_backtrace "bundler"
21
+ config.color = true
22
+ config.tty = true
23
+ end
24
+
25
+ require "danger_plugin"
26
+
27
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
28
+ # If you are expanding these files, see if it's already been done ^.
29
+
30
+ # A silent version of the user interface,
31
+ # it comes with an extra function `.string` which will
32
+ # strip all ANSI colours from the string.
33
+
34
+ # rubocop:disable Lint/NestedMethodDefinition
35
+ def testing_ui
36
+ @output = StringIO.new
37
+ def @output.winsize
38
+ [20, 9999]
39
+ end
40
+
41
+ cork = Cork::Board.new(out: @output)
42
+ def cork.string
43
+ out.string.gsub(/\e\[([;\d]+)?m/, "")
44
+ end
45
+ cork
46
+ end
47
+ # rubocop:enable Lint/NestedMethodDefinition
48
+
49
+ # Example environment (ENV) that would come from
50
+ # running a PR on TravisCI
51
+ def testing_env
52
+ {
53
+ "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
54
+ "TRAVIS_PULL_REQUEST" => "800",
55
+ "TRAVIS_REPO_SLUG" => "artsy/eigen",
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,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-detekt-instacart
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Fesquet
8
+ - Chao Zhang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2022-08-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oga
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: danger-plugin-api
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.3'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '13.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '13.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.4'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.4'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rubocop
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: yard
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: guard
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '2.14'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '2.14'
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard-rspec
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '4.7'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '4.7'
140
+ - !ruby/object:Gem::Dependency
141
+ name: listen
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '='
145
+ - !ruby/object:Gem::Version
146
+ version: 3.0.7
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '='
152
+ - !ruby/object:Gem::Version
153
+ version: 3.0.7
154
+ - !ruby/object:Gem::Dependency
155
+ name: pry
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ description: A short description of danger-kotlin_detekt. This is a forked version
169
+ to include detekt rule name.
170
+ email:
171
+ - n.fesquet@betclicgroup.com
172
+ - zhangchao6865@gmail.com
173
+ executables: []
174
+ extensions: []
175
+ extra_rdoc_files: []
176
+ files:
177
+ - ".gitignore"
178
+ - ".rubocop.yml"
179
+ - ".travis.yml"
180
+ - Gemfile
181
+ - Gemfile.lock
182
+ - Guardfile
183
+ - LICENSE.txt
184
+ - README.md
185
+ - Rakefile
186
+ - danger-kotlin_detekt.gemspec
187
+ - lib/danger_kotlin_detekt.rb
188
+ - lib/danger_plugin.rb
189
+ - lib/kotlin_detekt/gem_version.rb
190
+ - lib/kotlin_detekt/plugin.rb
191
+ - spec/fixtures/detekt-result-with-everything.xml
192
+ - spec/kotlin_detekt_spec.rb
193
+ - spec/spec_helper.rb
194
+ homepage: https://github.com/chao2zhang/danger-kotlin_detekt
195
+ licenses:
196
+ - MIT
197
+ metadata: {}
198
+ post_install_message:
199
+ rdoc_options: []
200
+ require_paths:
201
+ - lib
202
+ required_ruby_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ required_rubygems_version: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - ">="
210
+ - !ruby/object:Gem::Version
211
+ version: '0'
212
+ requirements: []
213
+ rubygems_version: 3.3.13
214
+ signing_key:
215
+ specification_version: 4
216
+ summary: A longer description of danger-kotlin_detekt. This is a forked version to
217
+ include detekt rule name.
218
+ test_files:
219
+ - spec/fixtures/detekt-result-with-everything.xml
220
+ - spec/kotlin_detekt_spec.rb
221
+ - spec/spec_helper.rb