danger-flutter_lint 1.0.0

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: 470f9de8c74fbbfed295482c225a6e01172de443f24b161c395e11ec5b48aab9
4
+ data.tar.gz: 366c2f81649244425d66932f370c677756ca8f8c672479b5d650d7775db08c7f
5
+ SHA512:
6
+ metadata.gz: fbe232f469544a74e8cfa118b6910e1c5b30b596b80733d55386b683e952b46db2a5316e59b6bf2668dafbdbb66c441e447f347cc3a25a03f8a7f6385a2a1afb
7
+ data.tar.gz: af7110e37d702e8c6f4b7f45fde54364a752c1520082fd39762fcede2be5badfb80c1c8335af8752a6815c4fc564757dce0b12650e3a9e706fba81be04863609
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,120 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.2
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+ Enabled: true
7
+
8
+ Style/ClassCheck:
9
+ EnforcedStyle: kind_of?
10
+
11
+ Style/BracesAroundHashParameters:
12
+ Enabled: false
13
+
14
+ Lint/UselessAssignment:
15
+ Exclude:
16
+ - '**/spec/**/*'
17
+
18
+ Layout/IndentHash:
19
+ Enabled: false
20
+
21
+ Layout/AlignHash:
22
+ Enabled: false
23
+
24
+ Layout/DotPosition:
25
+ Enabled: false
26
+
27
+ Style/DoubleNegation:
28
+ Enabled: false
29
+
30
+ Lint/UnusedBlockArgument:
31
+ Enabled: false
32
+
33
+ Style/ClassAndModuleChildren:
34
+ Enabled: false
35
+
36
+ Metrics/AbcSize:
37
+ Max: 60
38
+
39
+ Style/WordArray:
40
+ MinSize: 19
41
+
42
+ Style/SignalException:
43
+ Enabled: false
44
+
45
+ Style/RedundantReturn:
46
+ Enabled: false
47
+
48
+ Style/IfUnlessModifier:
49
+ Enabled: false
50
+
51
+ Style/AndOr:
52
+ Enabled: false
53
+
54
+ Metrics/ClassLength:
55
+ Max: 350
56
+
57
+ Metrics/CyclomaticComplexity:
58
+ Max: 17
59
+
60
+ Metrics/LineLength:
61
+ Max: 370
62
+
63
+ Metrics/ParameterLists:
64
+ Max: 10
65
+
66
+ Metrics/PerceivedComplexity:
67
+ Max: 18
68
+
69
+ Style/GuardClause:
70
+ Enabled: false
71
+
72
+ Style/ConditionalAssignment:
73
+ Enabled: false
74
+
75
+ Style/RedundantSelf:
76
+ Enabled: false
77
+
78
+ Metrics/MethodLength:
79
+ Max: 60
80
+
81
+ Style/Documentation:
82
+ Enabled: false
83
+
84
+ Style/IfInsideElse:
85
+ Enabled: false
86
+
87
+ Style/BlockComments:
88
+ Enabled: false
89
+
90
+ Layout/MultilineMethodCallIndentation:
91
+ EnforcedStyle: indented
92
+
93
+ Metrics/BlockLength:
94
+ Max: 345
95
+ Exclude:
96
+ - "**/*_spec.rb"
97
+
98
+ Style/MixinGrouping:
99
+ Enabled: false
100
+
101
+ Layout/IndentHeredoc:
102
+ Enabled: false
103
+
104
+ Style/SpecialGlobalVars:
105
+ Enabled: false
106
+
107
+ PercentLiteralDelimiters:
108
+ PreferredDelimiters:
109
+ "%": ()
110
+ "%i": ()
111
+ "%q": ()
112
+ "%Q": ()
113
+ "%r": "{}"
114
+ "%s": ()
115
+ "%w": ()
116
+ "%W": ()
117
+ "%x": ()
118
+
119
+ Security/YAMLLoad:
120
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ sudo: false
2
+ language: ruby
3
+ os:
4
+ - osx
5
+
6
+ cache: bundler
7
+ rvm:
8
+ - 2.4.1
9
+
10
+ script: bundle install && bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,155 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-flutter_lint (1.0.0)
5
+ danger-plugin-api (~> 1.0)
6
+ flutter_analyze_parser (~> 0.1.2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.5.2)
12
+ public_suffix (>= 2.0.2, < 4.0)
13
+ ast (2.4.0)
14
+ claide (1.0.2)
15
+ claide-plugins (0.9.2)
16
+ cork
17
+ nap
18
+ open4 (~> 1.3)
19
+ codecov (0.1.14)
20
+ json
21
+ simplecov
22
+ url
23
+ coderay (1.1.2)
24
+ colored2 (3.1.2)
25
+ cork (0.3.0)
26
+ colored2 (~> 3.1)
27
+ danger (6.0.1)
28
+ claide (~> 1.0)
29
+ claide-plugins (>= 0.9.2)
30
+ colored2 (~> 3.1)
31
+ cork (~> 0.1)
32
+ faraday (~> 0.9)
33
+ faraday-http-cache (~> 1.0)
34
+ git (~> 1.5)
35
+ kramdown (~> 2.0)
36
+ kramdown-parser-gfm (~> 1.0)
37
+ no_proxy_fix
38
+ octokit (~> 4.7)
39
+ terminal-table (~> 1)
40
+ danger-plugin-api (1.0.0)
41
+ danger (> 2.0)
42
+ diff-lcs (1.3)
43
+ docile (1.3.1)
44
+ faraday (0.15.4)
45
+ multipart-post (>= 1.2, < 3)
46
+ faraday-http-cache (1.3.1)
47
+ faraday (~> 0.8)
48
+ ffi (1.10.0)
49
+ flutter_analyze_parser (0.1.2)
50
+ formatador (0.2.5)
51
+ git (1.5.0)
52
+ guard (2.15.0)
53
+ formatador (>= 0.2.4)
54
+ listen (>= 2.7, < 4.0)
55
+ lumberjack (>= 1.0.12, < 2.0)
56
+ nenv (~> 0.1)
57
+ notiffany (~> 0.0)
58
+ pry (>= 0.9.12)
59
+ shellany (~> 0.0)
60
+ thor (>= 0.18.1)
61
+ guard-compat (1.2.1)
62
+ guard-rspec (4.7.3)
63
+ guard (~> 2.1)
64
+ guard-compat (~> 1.1)
65
+ rspec (>= 2.99.0, < 4.0)
66
+ jaro_winkler (1.5.2)
67
+ json (2.2.0)
68
+ kramdown (2.1.0)
69
+ kramdown-parser-gfm (1.0.1)
70
+ kramdown (~> 2.0)
71
+ listen (3.1.5)
72
+ rb-fsevent (~> 0.9, >= 0.9.4)
73
+ rb-inotify (~> 0.9, >= 0.9.7)
74
+ ruby_dep (~> 1.2)
75
+ lumberjack (1.0.13)
76
+ method_source (0.9.2)
77
+ multipart-post (2.0.0)
78
+ nap (1.1.0)
79
+ nenv (0.3.0)
80
+ no_proxy_fix (0.1.2)
81
+ notiffany (0.1.1)
82
+ nenv (~> 0.1)
83
+ shellany (~> 0.0)
84
+ octokit (4.13.0)
85
+ sawyer (~> 0.8.0, >= 0.5.3)
86
+ open4 (1.3.4)
87
+ parallel (1.14.0)
88
+ parser (2.6.0.0)
89
+ ast (~> 2.4.0)
90
+ powerpack (0.1.2)
91
+ pry (0.12.2)
92
+ coderay (~> 1.1.0)
93
+ method_source (~> 0.9.0)
94
+ psych (3.1.0)
95
+ public_suffix (3.0.3)
96
+ rainbow (3.0.0)
97
+ rake (10.5.0)
98
+ rb-fsevent (0.10.3)
99
+ rb-inotify (0.10.0)
100
+ ffi (~> 1.0)
101
+ rb-readline (0.5.5)
102
+ rspec (3.8.0)
103
+ rspec-core (~> 3.8.0)
104
+ rspec-expectations (~> 3.8.0)
105
+ rspec-mocks (~> 3.8.0)
106
+ rspec-core (3.8.0)
107
+ rspec-support (~> 3.8.0)
108
+ rspec-expectations (3.8.2)
109
+ diff-lcs (>= 1.2.0, < 2.0)
110
+ rspec-support (~> 3.8.0)
111
+ rspec-mocks (3.8.0)
112
+ diff-lcs (>= 1.2.0, < 2.0)
113
+ rspec-support (~> 3.8.0)
114
+ rspec-support (3.8.0)
115
+ rubocop (0.65.0)
116
+ jaro_winkler (~> 1.5.1)
117
+ parallel (~> 1.10)
118
+ parser (>= 2.5, != 2.5.1.1)
119
+ powerpack (~> 0.1)
120
+ psych (>= 3.1.0)
121
+ rainbow (>= 2.2.2, < 4.0)
122
+ ruby-progressbar (~> 1.7)
123
+ unicode-display_width (~> 1.4.0)
124
+ ruby-progressbar (1.10.0)
125
+ ruby_dep (1.5.0)
126
+ sawyer (0.8.1)
127
+ addressable (>= 2.3.5, < 2.6)
128
+ faraday (~> 0.8, < 1.0)
129
+ shellany (0.0.1)
130
+ simplecov (0.16.1)
131
+ docile (~> 1.1)
132
+ json (>= 1.8, < 3)
133
+ simplecov-html (~> 0.10.0)
134
+ simplecov-html (0.10.2)
135
+ terminal-table (1.8.0)
136
+ unicode-display_width (~> 1.1, >= 1.1.1)
137
+ thor (0.20.3)
138
+ unicode-display_width (1.4.1)
139
+ url (0.3.2)
140
+
141
+ PLATFORMS
142
+ ruby
143
+
144
+ DEPENDENCIES
145
+ codecov (~> 0.1)
146
+ danger-flutter_lint!
147
+ guard-rspec (~> 4.7)
148
+ rake (~> 10.0)
149
+ rb-readline (~> 0.5)
150
+ rspec (~> 3.0)
151
+ rubocop (~> 0.6)
152
+ simplecov (~> 0.16)
153
+
154
+ BUNDLED WITH
155
+ 2.0.1
data/Guardfile ADDED
@@ -0,0 +1,14 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Mateusz Szklarek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # danger-flutter_lint
2
+
3
+ [![Build Status](https://travis-ci.org/mateuszszklarek/danger-flutter_lint.svg?branch=master)](https://travis-ci.org/mateuszszklarek/danger-flutter_lint)
4
+ [![codecov](https://codecov.io/gh/mateuszszklarek/danger-flutter_lint/branch/master/graph/badge.svg)](https://codecov.io/gh/mateuszszklarek/danger-flutter_lint)
5
+
6
+ A Danger Plugin to lint dart files using `flutter analyze` command line interface.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ $ gem 'danger-fluter_lint'
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install danger-fluter_lint
17
+
18
+ ## Usage
19
+
20
+ Flutter Analyze doesn't give an option to generate report but you can achieve this easily using regular shell command (locally or on CI):
21
+
22
+ ```sh
23
+ $ flutter analyze > flutter_analyze_report.txt
24
+ ```
25
+
26
+ It will add output from `flutter analyze` command to `flutter_analyze_report.txt`.
27
+
28
+ Now you need to set `report_path` and invoke `lint` in your Dangerfile.
29
+
30
+ ```ruby
31
+ flutter_lint.report_path = "flutter_analyze_report.txt"
32
+ flutter_lint.lint // or flutter_lint.lint(inline_mode: false)
33
+ ```
34
+
35
+ This will add markdown table with summary into your PR.
36
+
37
+ Or make Danger comment directly on the line instead of printing a Markdown table (GitHub only)
38
+
39
+ ```ruby
40
+ flutter_lint.lint(inline_mode: true)
41
+ ```
42
+
43
+ #### Lint only added/modified files
44
+
45
+ If you're dealing with a legacy project, with tons of warnings, you may want to lint only new/modified files. You can easily achieve that, setting the `only_modified_files` parameter to `true`.
46
+
47
+ ```ruby
48
+ flutter_lint.only_modified_files = true
49
+ flutter_lint.report_path = "flutter_analyze_report.txt"
50
+ flutter_lint.lint
51
+ ```
52
+
53
+ ## Development
54
+
55
+ 1. Clone this repo
56
+ 2. Run `bundle install` to setup dependencies.
57
+ 3. Run `bundle exec rake spec` to run the tests.
58
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
59
+ 5. Make your changes.
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mateuszszklarek/danger-flutter_lint.
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,17 @@
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
+ end
13
+
14
+ desc "Run RuboCop on the lib/specs directory"
15
+ RuboCop::RakeTask.new(:rubocop) do |task|
16
+ task.patterns = ["lib/**/*.rb"]
17
+ end
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "flutter_lint/gem_version.rb"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "danger-flutter_lint"
7
+ spec.version = FlutterLint::VERSION
8
+ spec.authors = ["Mateusz Szklarek"]
9
+ spec.email = ["mateusz.szklarek@gmail.com"]
10
+ spec.summary = "A Danger Plugin to lint dart files using flutter analyze command line interface."
11
+ spec.homepage = "https://github.com/mateuszszklarek/danger-flutterlint"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_runtime_dependency "danger-plugin-api", "~> 1.0"
20
+ spec.add_runtime_dependency "flutter_analyze_parser", "~> 0.1.2"
21
+
22
+ spec.add_development_dependency "codecov", "~> 0.1"
23
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rb-readline", "~> 0.5"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "rubocop", "~> 0.6"
28
+ spec.add_development_dependency "simplecov", "~> 0.16"
29
+ end
@@ -0,0 +1 @@
1
+ require "flutter_lint/gem_version"
@@ -0,0 +1 @@
1
+ require "flutter_lint/plugin"
@@ -0,0 +1,3 @@
1
+ module FlutterLint
2
+ VERSION = "1.0.0".freeze
3
+ end
@@ -0,0 +1,82 @@
1
+ require "flutter_analyze_parser"
2
+
3
+ module Danger
4
+ class DangerFlutterLint < Plugin
5
+ # Enable only_modified_files
6
+ # Only show messages within changed files.
7
+ attr_accessor :only_modified_files
8
+
9
+ # Report path
10
+ # You should set output from `flutter analyze` here
11
+ attr_accessor :report_path
12
+
13
+ def lint(inline_mode: false)
14
+ if flutter_exists?
15
+ lint_if_report_exists(inline_mode: inline_mode)
16
+ else
17
+ fail("Could not find `flutter` inside current directory")
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def lint_if_report_exists(inline_mode:)
24
+ if !report_path.nil? && File.exist?(report_path)
25
+ report = File.open(report_path)
26
+ violations = FlutterAnalyzeParser.violations(report)
27
+ lint_mode(inline_mode: inline_mode, violations: violations)
28
+ else
29
+ fail("Could not run lint without setting report path or report file doesn't exists")
30
+ end
31
+ end
32
+
33
+ def lint_mode(inline_mode:, violations:)
34
+ if inline_mode
35
+ send_inline_comments(violations)
36
+ else
37
+ markdown(summary_table(violations))
38
+ end
39
+ end
40
+
41
+ def send_inline_comments(violations)
42
+ filtered_violations = filtered_violations(violations)
43
+
44
+ filtered_violations.each do |violation|
45
+ send("warn", violation.description, file: violation.file, line: violation.line)
46
+ end
47
+ end
48
+
49
+ def summary_table(violations)
50
+ filtered_violations = filtered_violations(violations)
51
+
52
+ if filtered_violations.empty?
53
+ return "### Flutter Analyze found #{filtered_violations.length} issues ✅"
54
+ else
55
+ return markdown_table(filtered_violations)
56
+ end
57
+ end
58
+
59
+ def markdown_table(violations)
60
+ table = "### Flutter Analyze found #{violations.length} issues ❌\n\n"
61
+ table << "| File | Line | Rule |\n"
62
+ table << "| ---- | ---- | ---- |\n"
63
+
64
+ return violations.reduce(table) { |acc, violation| acc << table_row(violation) }
65
+ end
66
+
67
+ def table_row(violation)
68
+ "| `#{violation.file}` | #{violation.line} | #{violation.rule} |\n"
69
+ end
70
+
71
+ def filtered_violations(violations)
72
+ target_files = (git.modified_files - git.deleted_files) + git.added_files
73
+ filtered_violations = violations.select { |violation| target_files.include? violation.file }
74
+
75
+ return only_modified_files ? filtered_violations : violations
76
+ end
77
+
78
+ def flutter_exists?
79
+ `which flutter`.strip.empty? == false
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,6 @@
1
+
2
+ Analyzing my_flutter_project...
3
+
4
+ info • Name types using UpperCamelCase • lib/main.dart:5:7 • camel_case_types
5
+ info • Prefer const with constant constructors • lib/home/home_page.dart:13:13 • prefer_const_constructors
6
+ info • AVOID catches without on clauses • lib/profile/user/phone_widget.dart:19:7 • avoid_catches_without_on_clauses
@@ -0,0 +1,5 @@
1
+
2
+ Analyzing my_flutter_project...
3
+
4
+
5
+ No issues found! (ran in 1.8s)
@@ -0,0 +1,155 @@
1
+ require File.expand_path("spec_helper", __dir__)
2
+
3
+ module Danger
4
+ describe Danger::DangerFlutterLint do
5
+ it "should be a danger plugin" do
6
+ expect(Danger::DangerFlutterLint.new(nil)).to be_a Danger::Plugin
7
+ end
8
+
9
+ describe "with a Dangerfile" do
10
+ before do
11
+ @dangerfile = testing_dangerfile
12
+ @flutter_lint = @dangerfile.flutter_lint
13
+ allow(@flutter_lint.git).to receive(:deleted_files).and_return([])
14
+ allow(@flutter_lint.git).to receive(:added_files).and_return([])
15
+ allow(@flutter_lint.git).to receive(:modified_files).and_return([
16
+ "lib/home/home_page.dart",
17
+ "lib/profile/user/phone_widget.dart"
18
+ ])
19
+ end
20
+
21
+ context "when flutter is not installed" do
22
+ before do
23
+ allow(@flutter_lint).to receive(:`).with("which flutter").and_return("")
24
+ end
25
+
26
+ it "should fail when lint" do
27
+ @flutter_lint.lint
28
+
29
+ expect(@flutter_lint.status_report[:errors]).to eq(["Could not find `flutter` inside current directory"])
30
+ end
31
+ end
32
+
33
+ context "when flutter is installed and report is not set" do
34
+ before do
35
+ allow(@flutter_lint).to receive(:`).with("which flutter").and_return("/Users/johndoe/.flutter/bin/flutter")
36
+ end
37
+
38
+ it "should fail when lint" do
39
+ @flutter_lint.lint
40
+
41
+ expect(@flutter_lint.status_report[:errors]).to eq(["Could not run lint without setting report path or report file doesn't exists"])
42
+ end
43
+
44
+ context "when report is set but file not exists" do
45
+ before do
46
+ allow(@flutter_lint).to receive(:`).with("which flutter").and_return("/Users/johndoe/.flutter/bin/flutter")
47
+ end
48
+
49
+ it "should fail when lint" do
50
+ @flutter_lint.report_path = "users/johndoe/invalid_path/report.txt"
51
+ @flutter_lint.lint
52
+
53
+ expect(@flutter_lint.status_report[:errors]).to eq(["Could not run lint without setting report path or report file doesn't exists"])
54
+ end
55
+ end
56
+
57
+ context "when set `flutter analyze` report path without violations" do
58
+ before do
59
+ @flutter_lint.report_path = "spec/fixtures/flutter_analyze_without_violations.txt"
60
+ end
61
+
62
+ it "should NOT fail when lint" do
63
+ @flutter_lint.lint
64
+
65
+ expect(@flutter_lint.status_report[:errors]).to be_empty
66
+ end
67
+
68
+ it "should add markdown message with 0 violations when inline mode is off" do
69
+ @flutter_lint.lint(inline_mode: false)
70
+
71
+ markdown = @flutter_lint.status_report[:markdowns].first.message
72
+ expect(markdown).to eq("### Flutter Analyze found 0 issues ✅")
73
+ end
74
+
75
+ it "should NOT print markdown message when inline mode is on" do
76
+ @flutter_lint.lint(inline_mode: true)
77
+
78
+ markdown = @flutter_lint.status_report[:markdowns]
79
+ expect(markdown).to be_empty
80
+ end
81
+ end
82
+
83
+ context "when set `flutter analyze` report with some violations" do
84
+ before do
85
+ @flutter_lint.report_path = "spec/fixtures/flutter_analyze_with_violations.txt"
86
+ end
87
+
88
+ it "should NOT fail when lint" do
89
+ @flutter_lint.lint
90
+
91
+ expect(@flutter_lint.status_report[:errors]).to be_empty
92
+ end
93
+
94
+ it "should print markdown message with 3 violations when inline mode is off & only_modified_files not set" do
95
+ @flutter_lint.lint(inline_mode: false)
96
+
97
+ expected = <<~MESSAGE
98
+ ### Flutter Analyze found 3 issues ❌\n
99
+ | File | Line | Rule |
100
+ | ---- | ---- | ---- |
101
+ | `lib/main.dart` | 5 | camel_case_types |
102
+ | `lib/home/home_page.dart` | 13 | prefer_const_constructors |
103
+ | `lib/profile/user/phone_widget.dart` | 19 | avoid_catches_without_on_clauses |
104
+ MESSAGE
105
+
106
+ expect(@flutter_lint.status_report[:markdowns].first.message).to eq(expected)
107
+ end
108
+
109
+ it "should send 3 inline comment instead of markdown when inline mode is on & only_modified_files not set" do
110
+ @flutter_lint.lint(inline_mode: true)
111
+
112
+ warnings = @flutter_lint.status_report[:warnings]
113
+
114
+ exepcted_warnings = [
115
+ "Name types using UpperCamelCase",
116
+ "Prefer const with constant constructors",
117
+ "AVOID catches without on clauses"
118
+ ]
119
+
120
+ expect(warnings).to eq(exepcted_warnings)
121
+ end
122
+
123
+ it "should print markdown message with 2 violations when inline mode is off & only_modified_files set to true" do
124
+ @flutter_lint.only_modified_files = true
125
+ @flutter_lint.lint(inline_mode: false)
126
+
127
+ expected = <<~MESSAGE
128
+ ### Flutter Analyze found 2 issues ❌\n
129
+ | File | Line | Rule |
130
+ | ---- | ---- | ---- |
131
+ | `lib/home/home_page.dart` | 13 | prefer_const_constructors |
132
+ | `lib/profile/user/phone_widget.dart` | 19 | avoid_catches_without_on_clauses |
133
+ MESSAGE
134
+
135
+ expect(@flutter_lint.status_report[:markdowns].first.message).to eq(expected)
136
+ end
137
+
138
+ it "should send 2 inline comment instead of markdown when inline mode is on & only_modified_files set to true" do
139
+ @flutter_lint.only_modified_files = true
140
+ @flutter_lint.lint(inline_mode: true)
141
+
142
+ warnings = @flutter_lint.status_report[:warnings]
143
+
144
+ exepcted_warnings = [
145
+ "Prefer const with constant constructors",
146
+ "AVOID catches without on clauses"
147
+ ]
148
+
149
+ expect(warnings).to eq(exepcted_warnings)
150
+ end
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,58 @@
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 "simplecov"
7
+ SimpleCov.start
8
+
9
+ if ENV["CI"] == "true"
10
+ require "codecov"
11
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
12
+ end
13
+
14
+ require "bundler/setup"
15
+
16
+ require "rspec"
17
+ require "danger"
18
+ require "danger_plugin"
19
+ require "flutter_analyze_parser"
20
+
21
+ RSpec.configure do |config|
22
+ config.example_status_persistence_file_path = ".rspec_status"
23
+ config.filter_gems_from_backtrace "bundler"
24
+ config.expect_with :rspec do |c|
25
+ c.syntax = :expect
26
+ end
27
+ config.color = true
28
+ config.tty = true
29
+ end
30
+
31
+ # Testing
32
+ def testing_env
33
+ {
34
+ "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
35
+ "TRAVIS_PULL_REQUEST" => "800",
36
+ "TRAVIS_REPO_SLUG" => "artsy/eigen",
37
+ "TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
38
+ "DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
39
+ }
40
+ end
41
+
42
+ def testing_ui
43
+ @output = StringIO.new
44
+ def @output.winsize
45
+ [20, 9999]
46
+ end
47
+
48
+ cork = Cork::Board.new(out: @output)
49
+ def cork.string
50
+ out.string.gsub(/\e\[([;\d]+)?m/, "")
51
+ end
52
+ cork
53
+ end
54
+
55
+ def testing_dangerfile
56
+ env = Danger::EnvironmentManager.new(testing_env)
57
+ Danger::Dangerfile.new(env, testing_ui)
58
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-flutter_lint
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mateusz Szklarek
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-14 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: flutter_analyze_parser
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: codecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rb-readline
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.5'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.6'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.6'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.16'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.16'
139
+ description:
140
+ email:
141
+ - mateusz.szklarek@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".rubocop.yml"
149
+ - ".travis.yml"
150
+ - Gemfile
151
+ - Gemfile.lock
152
+ - Guardfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - danger-flutter_lint.gemspec
157
+ - lib/danger_flutter_lint.rb
158
+ - lib/danger_plugin.rb
159
+ - lib/flutter_lint/gem_version.rb
160
+ - lib/flutter_lint/plugin.rb
161
+ - spec/fixtures/flutter_analyze_with_violations.txt
162
+ - spec/fixtures/flutter_analyze_without_violations.txt
163
+ - spec/flutter_lint_spec.rb
164
+ - spec/spec_helper.rb
165
+ homepage: https://github.com/mateuszszklarek/danger-flutterlint
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubygems_version: 3.0.3
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: A Danger Plugin to lint dart files using flutter analyze command line interface.
188
+ test_files:
189
+ - spec/fixtures/flutter_analyze_with_violations.txt
190
+ - spec/fixtures/flutter_analyze_without_violations.txt
191
+ - spec/flutter_lint_spec.rb
192
+ - spec/spec_helper.rb