danger-luacheck 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 90ae664418800c7bb1dc1cd2b73c1cb11424d20629a2f471266334a2402d57a7
4
+ data.tar.gz: 27cca245c74baf41b9589cd8de2c415767a40b6c5127e3e6ec5aa3932ffc2342
5
+ SHA512:
6
+ metadata.gz: 004f26f10456c13a4248d8f58c603139d15c48abeaa729754291e18ed4bc4fd5b6c3cb30d9b71b1f28831c642101b901eae66ab2374baf68f2a7eb195ae05c43
7
+ data.tar.gz: 39e9c2dadad39789add4113fcbf68c34f9258d5e2070aa1c84cd48ffe1fe4101cc411e1e03610771e99516d6de2cf2ee935cd66667034a7e9f84c17d082bc876
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
4
+ .yardoc
data/.rubocop.yml ADDED
@@ -0,0 +1,148 @@
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.6
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
+ # specs sometimes have useless assignments, which is fine
17
+ Lint/UselessAssignment:
18
+ Exclude:
19
+ - '**/spec/**/*'
20
+
21
+ # We could potentially enable the 2 below:
22
+ Layout/FirstHashElementIndentation:
23
+ Enabled: false
24
+
25
+ Layout/HashAlignment:
26
+ Enabled: false
27
+
28
+ # HoundCI doesn't like this rule
29
+ Layout/DotPosition:
30
+ Enabled: false
31
+
32
+ # We allow !! as it's an easy way to convert ot boolean
33
+ Style/DoubleNegation:
34
+ Enabled: false
35
+
36
+ # Cop supports --auto-correct.
37
+ Lint/UnusedBlockArgument:
38
+ Enabled: false
39
+
40
+ # We want to allow class Fastlane::Class
41
+ Style/ClassAndModuleChildren:
42
+ Enabled: false
43
+
44
+ Metrics/AbcSize:
45
+ Max: 60
46
+
47
+ # The %w might be confusing for new users
48
+ Style/WordArray:
49
+ MinSize: 19
50
+
51
+ # raise and fail are both okay
52
+ Style/SignalException:
53
+ Enabled: false
54
+
55
+ # Better too much 'return' than one missing
56
+ Style/RedundantReturn:
57
+ Enabled: false
58
+
59
+ # Having if in the same line might not always be good
60
+ Style/IfUnlessModifier:
61
+ Enabled: false
62
+
63
+ # and and or is okay
64
+ Style/AndOr:
65
+ Enabled: false
66
+
67
+ # Configuration parameters: CountComments.
68
+ Metrics/ClassLength:
69
+ Max: 350
70
+
71
+ Metrics/CyclomaticComplexity:
72
+ Max: 17
73
+
74
+ # Configuration parameters: AllowURI, URISchemes.
75
+ Layout/LineLength:
76
+ Max: 370
77
+
78
+ # Configuration parameters: CountKeywordArgs.
79
+ Metrics/ParameterLists:
80
+ Max: 10
81
+
82
+ Metrics/PerceivedComplexity:
83
+ Max: 18
84
+
85
+ # Sometimes it's easier to read without guards
86
+ Style/GuardClause:
87
+ Enabled: false
88
+
89
+ # something = if something_else
90
+ # that's confusing
91
+ Style/ConditionalAssignment:
92
+ Enabled: false
93
+
94
+ # Better to have too much self than missing a self
95
+ Style/RedundantSelf:
96
+ Enabled: false
97
+
98
+ Metrics/MethodLength:
99
+ Max: 60
100
+
101
+ # We're not there yet
102
+ Style/Documentation:
103
+ Enabled: false
104
+
105
+ # Adds complexity
106
+ Style/IfInsideElse:
107
+ Enabled: false
108
+
109
+ # danger specific
110
+
111
+ Style/BlockComments:
112
+ Enabled: false
113
+
114
+ Layout/MultilineMethodCallIndentation:
115
+ EnforcedStyle: indented
116
+
117
+ # FIXME: 25
118
+ Metrics/BlockLength:
119
+ Max: 345
120
+ Exclude:
121
+ - "**/*_spec.rb"
122
+
123
+ Style/MixinGrouping:
124
+ Enabled: false
125
+
126
+ Naming/FileName:
127
+ Enabled: false
128
+
129
+ Layout/HeredocIndentation:
130
+ Enabled: false
131
+
132
+ Style/SpecialGlobalVars:
133
+ Enabled: false
134
+
135
+ Style/PercentLiteralDelimiters:
136
+ PreferredDelimiters:
137
+ "%": ()
138
+ "%i": ()
139
+ "%q": ()
140
+ "%Q": ()
141
+ "%r": "{}"
142
+ "%s": ()
143
+ "%w": ()
144
+ "%W": ()
145
+ "%x": ()
146
+
147
+ Security/YAMLLoad:
148
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ cache:
3
+ directories:
4
+ - bundle
5
+
6
+ rvm:
7
+ - 2.6
8
+ - 2.7
9
+
10
+ script:
11
+ - bundle exec rake spec
@@ -0,0 +1,14 @@
1
+ {
2
+ // 使用 IntelliSense 了解相关属性。
3
+ // 悬停以查看现有属性的描述。
4
+ // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Debug Local File",
9
+ "type": "Ruby",
10
+ "request": "launch",
11
+ "program": "${workspaceRoot}/exe/danger-luacheck"
12
+ }
13
+ ]
14
+ }
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://gems.ruby-china.com"
4
+
5
+ # Specify your gem's dependencies in danger-luacheck.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,177 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-luacheck (0.0.1)
5
+ danger-plugin-api (~> 1.0)
6
+ nokogiri
7
+
8
+ GEM
9
+ remote: https://gems.ruby-china.com/
10
+ specs:
11
+ addressable (2.8.1)
12
+ public_suffix (>= 2.0.2, < 6.0)
13
+ ast (2.4.2)
14
+ claide (1.1.0)
15
+ claide-plugins (0.9.2)
16
+ cork
17
+ nap
18
+ open4 (~> 1.3)
19
+ coderay (1.1.3)
20
+ colored2 (3.1.2)
21
+ cork (0.3.0)
22
+ colored2 (~> 3.1)
23
+ danger (8.6.1)
24
+ claide (~> 1.0)
25
+ claide-plugins (>= 0.9.2)
26
+ colored2 (~> 3.1)
27
+ cork (~> 0.1)
28
+ faraday (>= 0.9.0, < 2.0)
29
+ faraday-http-cache (~> 2.0)
30
+ git (~> 1.7)
31
+ kramdown (~> 2.3)
32
+ kramdown-parser-gfm (~> 1.0)
33
+ no_proxy_fix
34
+ octokit (~> 4.7)
35
+ terminal-table (>= 1, < 4)
36
+ danger-plugin-api (1.0.0)
37
+ danger (> 2.0)
38
+ diff-lcs (1.5.0)
39
+ faraday (1.10.2)
40
+ faraday-em_http (~> 1.0)
41
+ faraday-em_synchrony (~> 1.0)
42
+ faraday-excon (~> 1.1)
43
+ faraday-httpclient (~> 1.0)
44
+ faraday-multipart (~> 1.0)
45
+ faraday-net_http (~> 1.0)
46
+ faraday-net_http_persistent (~> 1.0)
47
+ faraday-patron (~> 1.0)
48
+ faraday-rack (~> 1.0)
49
+ faraday-retry (~> 1.0)
50
+ ruby2_keywords (>= 0.0.4)
51
+ faraday-em_http (1.0.0)
52
+ faraday-em_synchrony (1.0.0)
53
+ faraday-excon (1.1.0)
54
+ faraday-http-cache (2.4.1)
55
+ faraday (>= 0.8)
56
+ faraday-httpclient (1.0.1)
57
+ faraday-multipart (1.0.4)
58
+ multipart-post (~> 2)
59
+ faraday-net_http (1.0.1)
60
+ faraday-net_http_persistent (1.2.0)
61
+ faraday-patron (1.0.0)
62
+ faraday-rack (1.0.0)
63
+ faraday-retry (1.0.3)
64
+ ffi (1.15.5)
65
+ formatador (1.1.0)
66
+ git (1.12.0)
67
+ addressable (~> 2.8)
68
+ rchardet (~> 1.8)
69
+ guard (2.18.0)
70
+ formatador (>= 0.2.4)
71
+ listen (>= 2.7, < 4.0)
72
+ lumberjack (>= 1.0.12, < 2.0)
73
+ nenv (~> 0.1)
74
+ notiffany (~> 0.0)
75
+ pry (>= 0.13.0)
76
+ shellany (~> 0.0)
77
+ thor (>= 0.18.1)
78
+ guard-compat (1.2.1)
79
+ guard-rspec (4.7.3)
80
+ guard (~> 2.1)
81
+ guard-compat (~> 1.1)
82
+ rspec (>= 2.99.0, < 4.0)
83
+ json (2.6.2)
84
+ kramdown (2.4.0)
85
+ rexml
86
+ kramdown-parser-gfm (1.1.0)
87
+ kramdown (~> 2.0)
88
+ listen (3.0.7)
89
+ rb-fsevent (>= 0.9.3)
90
+ rb-inotify (>= 0.9.7)
91
+ lumberjack (1.2.8)
92
+ method_source (1.0.0)
93
+ multipart-post (2.2.3)
94
+ nap (1.1.0)
95
+ nenv (0.3.0)
96
+ no_proxy_fix (0.1.2)
97
+ nokogiri (1.13.8-x86_64-darwin)
98
+ racc (~> 1.4)
99
+ notiffany (0.1.3)
100
+ nenv (~> 0.1)
101
+ shellany (~> 0.0)
102
+ octokit (4.25.1)
103
+ faraday (>= 1, < 3)
104
+ sawyer (~> 0.9)
105
+ open4 (1.3.4)
106
+ parallel (1.22.1)
107
+ parser (3.1.2.1)
108
+ ast (~> 2.4.1)
109
+ pry (0.14.1)
110
+ coderay (~> 1.1)
111
+ method_source (~> 1.0)
112
+ public_suffix (5.0.0)
113
+ racc (1.6.0)
114
+ rainbow (3.1.1)
115
+ rake (10.5.0)
116
+ rb-fsevent (0.11.2)
117
+ rb-inotify (0.10.1)
118
+ ffi (~> 1.0)
119
+ rchardet (1.8.0)
120
+ regexp_parser (2.5.0)
121
+ rexml (3.2.5)
122
+ rspec (3.11.0)
123
+ rspec-core (~> 3.11.0)
124
+ rspec-expectations (~> 3.11.0)
125
+ rspec-mocks (~> 3.11.0)
126
+ rspec-core (3.11.0)
127
+ rspec-support (~> 3.11.0)
128
+ rspec-expectations (3.11.0)
129
+ diff-lcs (>= 1.2.0, < 2.0)
130
+ rspec-support (~> 3.11.0)
131
+ rspec-mocks (3.11.1)
132
+ diff-lcs (>= 1.2.0, < 2.0)
133
+ rspec-support (~> 3.11.0)
134
+ rspec-support (3.11.0)
135
+ rubocop (1.35.1)
136
+ json (~> 2.3)
137
+ parallel (~> 1.10)
138
+ parser (>= 3.1.2.1)
139
+ rainbow (>= 2.2.2, < 4.0)
140
+ regexp_parser (>= 1.8, < 3.0)
141
+ rexml (>= 3.2.5, < 4.0)
142
+ rubocop-ast (>= 1.20.1, < 2.0)
143
+ ruby-progressbar (~> 1.7)
144
+ unicode-display_width (>= 1.4.0, < 3.0)
145
+ rubocop-ast (1.21.0)
146
+ parser (>= 3.1.1.0)
147
+ ruby-progressbar (1.11.0)
148
+ ruby2_keywords (0.0.5)
149
+ sawyer (0.9.2)
150
+ addressable (>= 2.3.5)
151
+ faraday (>= 0.17.3, < 3)
152
+ shellany (0.0.1)
153
+ terminal-table (3.0.2)
154
+ unicode-display_width (>= 1.1.1, < 3)
155
+ thor (1.2.1)
156
+ unicode-display_width (2.2.0)
157
+ webrick (1.7.0)
158
+ yard (0.9.28)
159
+ webrick (~> 1.7.0)
160
+
161
+ PLATFORMS
162
+ x86_64-darwin-20
163
+
164
+ DEPENDENCIES
165
+ bundler (~> 2.0)
166
+ danger-luacheck!
167
+ guard (~> 2.14)
168
+ guard-rspec (~> 4.7)
169
+ listen (= 3.0.7)
170
+ pry
171
+ rake (~> 10.0)
172
+ rspec (~> 3.4)
173
+ rubocop
174
+ yard
175
+
176
+ BUNDLED WITH
177
+ 2.2.11
data/Guardfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A guardfile for making Danger Plugins
4
+ # For more info see https://github.com/guard/guard#readme
5
+
6
+ # To run, use `bundle exec guard`.
7
+
8
+ guard :rspec, cmd: "bundle exec rspec" do
9
+ require "guard/rspec/dsl"
10
+ dsl = Guard::RSpec::Dsl.new(self)
11
+
12
+ # RSpec files
13
+ rspec = dsl.rspec
14
+ watch(rspec.spec_helper) { rspec.spec_dir }
15
+ watch(rspec.spec_support) { rspec.spec_dir }
16
+ watch(rspec.spec_files)
17
+
18
+ # Ruby files
19
+ ruby = dsl.ruby
20
+ dsl.watch_spec_files_for(ruby.lib_files)
21
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2022 baocq <baocq@yuanfudao.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,20 @@
1
+ # danger-luacheck
2
+
3
+ A description of danger-luacheck.
4
+
5
+ ## Installation
6
+
7
+ $ gem install danger-luacheck
8
+
9
+ ## Usage
10
+
11
+ Methods and attributes from this plugin are available in
12
+ your `Dangerfile` under the `luacheck` namespace.
13
+
14
+ ## Development
15
+
16
+ 1. Clone this repo
17
+ 2. Run `bundle install` to setup dependencies.
18
+ 3. Run `bundle exec rake spec` to run the tests.
19
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
20
+ 5. Make your changes.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:specs)
8
+
9
+ task default: :specs
10
+
11
+ task :spec do
12
+ Rake::Task["specs"].invoke
13
+ Rake::Task["rubocop"].invoke
14
+ Rake::Task["spec_docs"].invoke
15
+ end
16
+
17
+ desc "Run RuboCop on the lib/specs directory"
18
+ RuboCop::RakeTask.new(:rubocop) do |task|
19
+ task.patterns = ["lib/**/*.rb", "spec/**/*.rb"]
20
+ end
21
+
22
+ desc "Ensure that the plugin passes `danger plugins lint`"
23
+ task :spec_docs do
24
+ sh "bundle exec danger plugins lint"
25
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "luacheck/gem_version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "danger-luacheck"
9
+ spec.version = Luacheck::VERSION
10
+ spec.authors = ["baochuquan"]
11
+ spec.email = ["baochuquan@163.com"]
12
+ spec.description = "A short description of danger-luacheck."
13
+ spec.summary = "A longer description of danger-luacheck."
14
+ spec.homepage = "https://github.com/baocchuquan/danger-luacheck"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "danger-plugin-api", "~> 1.0"
23
+ spec.add_runtime_dependency "nokogiri"
24
+
25
+ # General ruby development
26
+ spec.add_development_dependency "bundler", "~> 2.0"
27
+ spec.add_development_dependency "rake", "~> 10.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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path("../../spec/spec_helper", __FILE__)
4
+
5
+ dangerfile = testing_dangerfile
6
+ plugin = dangerfile.luacheck
7
+
8
+
9
+ allow_any_instance_of(Danger::DangerfileGitPlugin).to receive(:added_files).and_return(['app/src/main/java/com/mataku/Model.kt'])
10
+ allow_any_instance_of(Danger::DangerfileGitPlugin).to receive(:modified_files).and_return([])
11
+
12
+ allow_any_instance_of(Kernel).to receive(:system).with('which ktlint > /dev/null 2>&1').and_return(true)
13
+ allow_any_instance_of(Kernel).to receive(:`).with('ktlint app/src/main/java/com/mataku/Model.kt --reporter=json --relative').and_return(dummy_ktlint_result)
14
+
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "luacheck/gem_version"
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "luacheck/plugin"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Luacheck
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,177 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "nokogiri"
5
+
6
+ module Danger
7
+ class DangerLuacheck < Plugin
8
+ class UnexpectedLimitTypeError < StandardError; end
9
+
10
+ class UnsupportdServiceError < StandardError
11
+ def initialize(message = "Unsupported service! Currently supported services are GitHub, GitLab and BitBucket server.")
12
+ super(message)
13
+ end
14
+ end
15
+
16
+ AVAILABLE_SERVICES = %i(github gitlab bitbucket_server)
17
+
18
+ # TODO: Lint all files if `filtering: false`
19
+
20
+ # An attribute that you can read/write from your Dangerfile
21
+ #
22
+ # @return [Array<String>]
23
+ attr_accessor :skip_lint, :report_file, :report_files_pattern
24
+
25
+ def limit
26
+ @limit ||= nil
27
+ end
28
+
29
+ def limit=(limit)
30
+ if !limit.nil? && limit.integer?
31
+ @limit = limit
32
+ else
33
+ raise UnexpectedLimitTypeError
34
+ end
35
+ end
36
+
37
+ # Run luacheck task using command lint interface
38
+ # Will fail if `luacheck` is not installed
39
+ # Skip luacheck task if files changed are empty
40
+ # @return (void)
41
+ # def lint(inlint_mode: false)
42
+ def lint(inline_mode: false)
43
+ unless supported_service?
44
+ raise UnsupportedServiceError
45
+ end
46
+
47
+ targets = target_files(git.added_files + git.modified_files)
48
+
49
+ results = luacheck_results(targets)
50
+ if results.nil? || results.empty?
51
+ return
52
+ end
53
+
54
+ if inline_mode
55
+ send_inline_comments(results, targets)
56
+ else
57
+ send_markdown_comment(results, targets)
58
+ end
59
+ end
60
+
61
+ # Comment to a PR by luacheck result json
62
+ def send_markdown_comment(luacheck_results, targets)
63
+ catch(:loop_break) do
64
+ count = 0
65
+ luacheck_results.each do |luacheck_result|
66
+ puts luacheck_result
67
+ failures = luacheck_result.xpath("//failure")
68
+ failures.each do |failure|
69
+ message = failure.attributes["message"].value
70
+ next unless message.split(":").size >= 2
71
+
72
+ file_path = message.split(":")[0]
73
+ line = message.split(":")[1]
74
+ next unless targets.include?(file_path)
75
+
76
+ message = "#{file_html_link(file_path, line)}: #{message}"
77
+ fail(message)
78
+ next if limit.nil?
79
+
80
+ count += 1
81
+ if count >= limit
82
+ throw(:loop_break)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ def send_inline_comments(luacheck_results, targets)
90
+ puts "============="
91
+ catch(:loop_break) do
92
+ count = 0
93
+ luacheck_results.each do |luacheck_result|
94
+ failures = luacheck_result.xpath("//failure")
95
+ failures.each do |failure|
96
+ message = failure.attributes["message"].value
97
+ next unless message.split(":").size >= 2
98
+
99
+ file_path = message.split(":")[0]
100
+ line = message.split(":")[1]
101
+ next unless targets.include?(file_path)
102
+
103
+ puts message
104
+ puts line
105
+ fail(message, file: file_path, line: line)
106
+ next if limit.nil?
107
+
108
+ count += 1
109
+ if count >= limit
110
+ throw(:loop_break)
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ def target_files(changed_files)
118
+ changed_files.select do |file|
119
+ file.end_with?(".lua")
120
+ end
121
+ end
122
+
123
+ # Make it a relative path so it can compare it to git.added_files
124
+ def relative_file_path(file_path)
125
+ file_path.gsub(%r{#{pwd}/}, "")
126
+ end
127
+
128
+ private
129
+
130
+ def file_html_link(file_path, line_number)
131
+ file = if danger.scm_provider == :github
132
+ "#{file_path}#L#{line_number}"
133
+ else
134
+ file_path
135
+ end
136
+ scm_provider_klass.html_link(file)
137
+ end
138
+
139
+ # `eval` may be dangerous, but it does not accept any input because it accepts only defined as danger.scm_provider
140
+ def scm_provider_klass
141
+ @scm_provider_klass ||= eval(danger.scm_provider.to_s)
142
+ end
143
+
144
+ def pwd
145
+ @pwd ||= `pwd`.chomp
146
+ end
147
+
148
+ def luacheck_exists?
149
+ system "which luacheck > /dev/null 2>&1"
150
+ end
151
+
152
+ def luacheck_results(targets)
153
+ unless luacheck_exists?
154
+ fail("Couldn't find luacheck command. Install first.")
155
+ return
156
+ end
157
+
158
+ return if targets.empty?
159
+
160
+ [Nokogiri::XML(`luacheck #{targets.join(" ")} --formatter JUnit`)]
161
+ end
162
+
163
+ def supported_service?
164
+ AVAILABLE_SERVICES.include?(danger.scm_provider.to_sym)
165
+ end
166
+
167
+ # def luacheck_result_files
168
+ # if !report_file.nil? && !report_file.empty? && File.exist?(report_file)
169
+ # [report_file]
170
+ # elsif !report_files_pattern.nil? && !report_files_pattern.empty?
171
+ # Dir.glob(report_files_pattern)
172
+ # else
173
+ # fail("Couldn't find luacheck result json file.\nYou must specify it with `luacheck.report_file=...` or `luacheck.report_files_pattern=...` in your Dangerfile.")
174
+ # end
175
+ # end
176
+ end
177
+ end
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <testsuite name="Luacheck report" tests="2">
3
+ <testcase name="AMClick/src/AMClickResManager.lua:1" classname="AMClick/src/AMClickResManager.lua">
4
+ <failure type="W614" message="AMClick/src/AMClickResManager.lua:20:30: trailing whitespace in a comment"/>
5
+ </testcase>
6
+ <testcase name="AMClick/src/AMClickResManager.lua:2" classname="AMClick/src/AMClickResManager.lua">
7
+ <failure type="W421" message="AMClick/src/AMClickResManager.lua:75:10: shadowing definition of variable &apos;fontString&apos; on line 66"/>
8
+ </testcase>
9
+ </testsuite>
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("spec_helper", __dir__)
4
+
5
+ module Danger
6
+ describe Danger::DangerLuacheck do
7
+ let(:dangerfile) { testing_dangerfile }
8
+ let(:plugin) { dangerfile.luacheck }
9
+
10
+ it "should be a plugin" do
11
+ expect(Danger::DangerLuacheck.new(nil)).to be_a Danger::Plugin
12
+ end
13
+
14
+ describe "#lint" do
15
+ before do
16
+ allow_any_instance_of(Danger::DangerfileGitPlugin).to receive(:added_files).and_return(["AMClick/src/AMClickResManager.lua"])
17
+ allow_any_instance_of(Danger::DangerfileGitPlugin).to receive(:modified_files).and_return([])
18
+ end
19
+
20
+ context "luacheck issues were found" do
21
+ before do
22
+ allow_any_instance_of(Kernel).to receive(:system).with("which luacheck > /dev/null 2>&1").and_return(true)
23
+ allow_any_instance_of(Kernel).to receive(:`).with("luacheck AMClick/src/AMClickResManager.lua --formatter JUnit").and_return(dummy_luacheck_result_1)
24
+ allow_any_instance_of(Danger::DangerfileGitHubPlugin).to receive(:html_link).with("AMClick/src/AMClickResManager.lua#L20").and_return("<a href='https://github.com/baochuquan/android/blob/561827e46167077b5e53515b4b7349b8ae04610b/AMClickResManager.lua'>AMClickResManager.lua</a>")
25
+ allow_any_instance_of(Danger::DangerfileGitHubPlugin).to receive(:html_link).with("AMClick/src/AMClickResManager.lua#L75").and_return("<a href='https://github.com/baochuquan/android/blob/561827e46167077b5e53515b4b7349b8ae04610b/AMClickResManager.lua'>AMClickResManager.lua</a>")
26
+ end
27
+
28
+ it "send markdown comment" do
29
+ plugin.lint
30
+ expect(dangerfile.status_report[:errors].size).to eq(2)
31
+ end
32
+ end
33
+
34
+ context "luacheck issues were found with inline_mode: true" do
35
+ before do
36
+ allow_any_instance_of(Kernel).to receive(:system).with("which luacheck > /dev/null 2>&1").and_return(true)
37
+ allow_any_instance_of(Kernel).to receive(:`).with("luacheck AMClick/src/AMClickResManager.lua --formatter JUnit").and_return(dummy_luacheck_result_1)
38
+ end
39
+
40
+ it "Sends inline comment" do
41
+ plugin.lint(inline_mode: true)
42
+ expect(dangerfile.status_report[:errors].size).to eq(2)
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "#send_markdown_comment" do
48
+ let(:limit) { 1 }
49
+
50
+ before do
51
+ allow_any_instance_of(Danger::DangerfileGitPlugin).to receive(:added_files).and_return(["AMClick/src/AMClickResManager.lua"])
52
+ allow_any_instance_of(Danger::DangerfileGitPlugin).to receive(:modified_files).and_return([])
53
+
54
+ allow_any_instance_of(Kernel).to receive(:system).with("which luacheck > /dev/null 2>&1").and_return(true)
55
+ allow_any_instance_of(Kernel).to receive(:`).with("luacheck AMClick/src/AMClickResManager.lua --formatter JUnit").and_return(dummy_luacheck_result_1)
56
+ plugin.limit = limit
57
+ end
58
+
59
+ context "limit is set" do
60
+ it "equals number of luacheck results to limit" do
61
+ plugin.lint(inline_mode: true)
62
+ expect(dangerfile.status_report[:errors].size).to eq(limit)
63
+ end
64
+ end
65
+ end
66
+ #
67
+ # You should test your custom attributes and methods here
68
+ #
69
+ # describe "with Dangerfile" do
70
+ # before do
71
+ # @dangerfile = testing_dangerfile
72
+ # @my_plugin = @dangerfile.luacheck
73
+
74
+ # # mock the PR data
75
+ # # you can then use this, eg. github.pr_author, later in the spec
76
+ # 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`
77
+ # allow(@my_plugin.github).to receive(:pr_json).and_return(json)
78
+ # end
79
+
80
+ # # Some examples for writing tests
81
+ # # You should replace these with your own.
82
+
83
+ # it "Warns on a monday" do
84
+ # monday_date = Date.parse("2016-07-11")
85
+ # allow(Date).to receive(:today).and_return monday_date
86
+
87
+ # @my_plugin.warn_on_mondays
88
+
89
+ # expect(@dangerfile.status_report[:warnings]).to eq(["Trying to merge code on a Monday"])
90
+ # end
91
+
92
+ # it "Does nothing on a tuesday" do
93
+ # monday_date = Date.parse("2016-07-12")
94
+ # allow(Date).to receive(:today).and_return monday_date
95
+
96
+ # @my_plugin.warn_on_mondays
97
+
98
+ # expect(@dangerfile.status_report[:warnings]).to eq([])
99
+ # end
100
+ # end
101
+ end
102
+ end
@@ -0,0 +1,80 @@
1
+ require "pathname"
2
+ ROOT = Pathname.new(File.expand_path("..", __dir__))
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
+ def testing_env
50
+ {
51
+ "BITRISE_PULL_REQUEST" => "4",
52
+ "BITRISE_IO" => "true",
53
+ "GIT_REPOSITORY_URL" => "git@github.com:artsy/eigen",
54
+ "DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
55
+ }
56
+ end
57
+
58
+ def testing_env_for_gitlab
59
+ {
60
+ "BITRISE_PULL_REQUEST" => "4",
61
+ "BITRISE_IO" => "true",
62
+ "GIT_REPOSITORY_URL" => "git@gitlab.com:artsy/eigen",
63
+ "DANGER_GITLAB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
64
+ }
65
+ end
66
+
67
+ # A stubbed out Dangerfile for use in tests
68
+ def testing_dangerfile
69
+ env = Danger::EnvironmentManager.new(testing_env)
70
+ Danger::Dangerfile.new(env, testing_ui)
71
+ end
72
+
73
+ def testing_dangerfile_for_gitlab
74
+ env = Danger::EnvironmentManager.new(testing_env_for_gitlab)
75
+ Danger::Dangerfile.new(env, testing_ui)
76
+ end
77
+
78
+ def dummy_luacheck_result_1
79
+ File.read(File.expand_path("fixtures/luacheck_result_1.xml", __dir__)).chomp
80
+ end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-luacheck
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - baochuquan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.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: 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: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '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'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.14'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.14'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '4.7'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '4.7'
139
+ - !ruby/object:Gem::Dependency
140
+ name: listen
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 3.0.7
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 3.0.7
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: A short description of danger-luacheck.
168
+ email:
169
+ - baochuquan@163.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rubocop.yml"
176
+ - ".travis.yml"
177
+ - ".vscode/launch.json"
178
+ - Gemfile
179
+ - Gemfile.lock
180
+ - Guardfile
181
+ - LICENSE.txt
182
+ - README.md
183
+ - Rakefile
184
+ - danger-luacheck.gemspec
185
+ - exe/danger-luacheck
186
+ - lib/danger_luacheck.rb
187
+ - lib/danger_plugin.rb
188
+ - lib/luacheck/gem_version.rb
189
+ - lib/luacheck/plugin.rb
190
+ - spec/fixtures/luacheck_result_1.xml
191
+ - spec/luacheck_spec.rb
192
+ - spec/spec_helper.rb
193
+ homepage: https://github.com/baocchuquan/danger-luacheck
194
+ licenses:
195
+ - MIT
196
+ metadata: {}
197
+ post_install_message:
198
+ rdoc_options: []
199
+ require_paths:
200
+ - lib
201
+ required_ruby_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ required_rubygems_version: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - ">="
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubygems_version: 3.0.9
213
+ signing_key:
214
+ specification_version: 4
215
+ summary: A longer description of danger-luacheck.
216
+ test_files:
217
+ - spec/fixtures/luacheck_result_1.xml
218
+ - spec/luacheck_spec.rb
219
+ - spec/spec_helper.rb