danger-rails_best_practices 0.1.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
+ SHA1:
3
+ metadata.gz: 031feabf20a7c5eec09939d71d5a14390bbdd54f
4
+ data.tar.gz: e4e7f0d41c8ff3f96bced9b3949739e03bbde3af
5
+ SHA512:
6
+ metadata.gz: ba632be929844a01ad5d43007a844eabb083b9e244eeae3cf8ebb7811bc3a52e73d5bc39247136d26e39e434ee6f5c4944e6d192a19edea8272783ff5823d8ef
7
+ data.tar.gz: b48432814c4b7a340890c74f61e5cb801e0f2cc3041636d93f5f1497ea6c02a98b129efa5b90ec29ba464be56d5fd313b69a4cb52e347ee5dca652acee8d38dd
data/.gitignore ADDED
@@ -0,0 +1,237 @@
1
+
2
+ # Created by https://www.gitignore.io/api/ruby,sublimetext,vim,visualstudiocode,jetbrains,linux,osx,windows
3
+
4
+ ### JetBrains ###
5
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
6
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
7
+
8
+ # User-specific stuff:
9
+ .idea/**/workspace.xml
10
+ .idea/**/tasks.xml
11
+ .idea/dictionaries
12
+
13
+ # Sensitive or high-churn files:
14
+ .idea/**/dataSources/
15
+ .idea/**/dataSources.ids
16
+ .idea/**/dataSources.xml
17
+ .idea/**/dataSources.local.xml
18
+ .idea/**/sqlDataSources.xml
19
+ .idea/**/dynamic.xml
20
+ .idea/**/uiDesigner.xml
21
+
22
+ # Gradle:
23
+ .idea/**/gradle.xml
24
+ .idea/**/libraries
25
+
26
+ # CMake
27
+ cmake-build-debug/
28
+
29
+ # Mongo Explorer plugin:
30
+ .idea/**/mongoSettings.xml
31
+
32
+ ## File-based project format:
33
+ *.iws
34
+
35
+ ## Plugin-specific files:
36
+
37
+ # IntelliJ
38
+ /out/
39
+
40
+ # mpeltonen/sbt-idea plugin
41
+ .idea_modules/
42
+
43
+ # JIRA plugin
44
+ atlassian-ide-plugin.xml
45
+
46
+ # Cursive Clojure plugin
47
+ .idea/replstate.xml
48
+
49
+ # Crashlytics plugin (for Android Studio and IntelliJ)
50
+ com_crashlytics_export_strings.xml
51
+ crashlytics.properties
52
+ crashlytics-build.properties
53
+ fabric.properties
54
+
55
+ ### JetBrains Patch ###
56
+ # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
57
+
58
+ # *.iml
59
+ # modules.xml
60
+ # .idea/misc.xml
61
+ # *.ipr
62
+
63
+ # Sonarlint plugin
64
+ .idea/sonarlint
65
+
66
+ ### Linux ###
67
+ *~
68
+
69
+ # temporary files which can be created if a process still has a handle open of a deleted file
70
+ .fuse_hidden*
71
+
72
+ # KDE directory preferences
73
+ .directory
74
+
75
+ # Linux trash folder which might appear on any partition or disk
76
+ .Trash-*
77
+
78
+ # .nfs files are created when an open file is removed but is still being accessed
79
+ .nfs*
80
+
81
+ ### OSX ###
82
+ *.DS_Store
83
+ .AppleDouble
84
+ .LSOverride
85
+
86
+ # Icon must end with two \r
87
+ Icon
88
+
89
+ # Thumbnails
90
+ ._*
91
+
92
+ # Files that might appear in the root of a volume
93
+ .DocumentRevisions-V100
94
+ .fseventsd
95
+ .Spotlight-V100
96
+ .TemporaryItems
97
+ .Trashes
98
+ .VolumeIcon.icns
99
+ .com.apple.timemachine.donotpresent
100
+
101
+ # Directories potentially created on remote AFP share
102
+ .AppleDB
103
+ .AppleDesktop
104
+ Network Trash Folder
105
+ Temporary Items
106
+ .apdisk
107
+
108
+ ### Ruby ###
109
+ *.gem
110
+ *.rbc
111
+ /.config
112
+ /coverage/
113
+ /InstalledFiles
114
+ /pkg/
115
+ /spec/reports/
116
+ /spec/examples.txt
117
+ /test/tmp/
118
+ /test/version_tmp/
119
+ /tmp/
120
+
121
+ # Used by dotenv library to load environment variables.
122
+ # .env
123
+
124
+ ## Specific to RubyMotion:
125
+ .dat*
126
+ .repl_history
127
+ build/
128
+ *.bridgesupport
129
+ build-iPhoneOS/
130
+ build-iPhoneSimulator/
131
+
132
+ ## Specific to RubyMotion (use of CocoaPods):
133
+ #
134
+ # We recommend against adding the Pods directory to your .gitignore. However
135
+ # you should judge for yourself, the pros and cons are mentioned at:
136
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
137
+ #
138
+ # vendor/Pods/
139
+
140
+ ## Documentation cache and generated files:
141
+ /.yardoc/
142
+ /_yardoc/
143
+ /doc/
144
+ /rdoc/
145
+
146
+ ## Environment normalization:
147
+ /.bundle/
148
+ /vendor/bundle
149
+ /lib/bundler/man/
150
+
151
+ # for a library or gem, you might want to ignore these files since the code is
152
+ # intended to run in multiple environments; otherwise, check them in:
153
+ # Gemfile.lock
154
+ # .ruby-version
155
+ # .ruby-gemset
156
+
157
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
158
+ .rvmrc
159
+
160
+ ### SublimeText ###
161
+ # cache files for sublime text
162
+ *.tmlanguage.cache
163
+ *.tmPreferences.cache
164
+ *.stTheme.cache
165
+
166
+ # workspace files are user-specific
167
+ *.sublime-workspace
168
+
169
+ # project files should be checked into the repository, unless a significant
170
+ # proportion of contributors will probably not be using SublimeText
171
+ # *.sublime-project
172
+
173
+ # sftp configuration file
174
+ sftp-config.json
175
+
176
+ # Package control specific files
177
+ Package Control.last-run
178
+ Package Control.ca-list
179
+ Package Control.ca-bundle
180
+ Package Control.system-ca-bundle
181
+ Package Control.cache/
182
+ Package Control.ca-certs/
183
+ Package Control.merged-ca-bundle
184
+ Package Control.user-ca-bundle
185
+ oscrypto-ca-bundle.crt
186
+ bh_unicode_properties.cache
187
+
188
+ # Sublime-github package stores a github token in this file
189
+ # https://packagecontrol.io/packages/sublime-github
190
+ GitHub.sublime-settings
191
+
192
+ ### Vim ###
193
+ # swap
194
+ [._]*.s[a-v][a-z]
195
+ [._]*.sw[a-p]
196
+ [._]s[a-v][a-z]
197
+ [._]sw[a-p]
198
+ # session
199
+ Session.vim
200
+ # temporary
201
+ .netrwhist
202
+ # auto-generated tag files
203
+ tags
204
+
205
+ ### VisualStudioCode ###
206
+ .vscode/*
207
+ !.vscode/settings.json
208
+ !.vscode/tasks.json
209
+ !.vscode/launch.json
210
+ !.vscode/extensions.json
211
+ .history
212
+
213
+ ### Windows ###
214
+ # Windows thumbnail cache files
215
+ Thumbs.db
216
+ ehthumbs.db
217
+ ehthumbs_vista.db
218
+
219
+ # Folder config file
220
+ Desktop.ini
221
+
222
+ # Recycle Bin used on file shares
223
+ $RECYCLE.BIN/
224
+
225
+ # Windows Installer files
226
+ *.cab
227
+ *.msi
228
+ *.msm
229
+ *.msp
230
+
231
+ # Windows shortcuts
232
+ *.lnk
233
+
234
+ # End of https://www.gitignore.io/api/ruby,sublimetext,vim,visualstudiocode,jetbrains,linux,osx,windows
235
+ Gemfile.lock
236
+ .ruby-version
237
+ .ruby-gemset
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.0
7
+
8
+ # kind_of? is a good way to check a type
9
+ Style/ClassCheck:
10
+ EnforcedStyle: kind_of?
11
+
12
+ # It's better to be more explicit about the type
13
+ Style/BracesAroundHashParameters:
14
+ Enabled: false
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/IndentHash:
23
+ Enabled: false
24
+
25
+ Layout/AlignHash:
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
+ Metrics/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
+ Style/FileName:
127
+ Enabled: false
128
+
129
+ Layout/IndentHeredoc:
130
+ Enabled: false
131
+
132
+ Style/SpecialGlobalVars:
133
+ Enabled: false
134
+
135
+ 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,27 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=$CC_TEST_REPORTER_ID
4
+
5
+ language: ruby
6
+ cache:
7
+ directories:
8
+ - bundle
9
+
10
+ rvm:
11
+ - 2.0
12
+ - 2.1.3
13
+ - 2.3.1
14
+
15
+ before_install:
16
+ - gem update bundler
17
+
18
+ before_script:
19
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
20
+ - chmod +x ./cc-test-reporter
21
+ - ./cc-test-reporter before-build
22
+
23
+ script:
24
+ - bundle exec rake spec
25
+
26
+ after_script:
27
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-rails_best_practices.gemspec
4
+ gemspec
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 ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 blooper05 <legend.of.blooper@gmail.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,39 @@
1
+ # danger-rails_best_practices
2
+
3
+ [![Build Status](https://img.shields.io/travis/blooper05/danger-rails_best_practices.svg)](https://travis-ci.org/blooper05/danger-rails_best_practices)
4
+ [![Code Climate](https://img.shields.io/codeclimate/github/blooper05/danger-rails_best_practices.svg)](https://codeclimate.com/github/blooper05/danger-rails_best_practices)
5
+ [![Coverage](https://img.shields.io/codeclimate/coverage/github/blooper05/danger-rails_best_practices.svg)](https://codeclimate.com/github/blooper05/danger-rails_best_practices)
6
+ [![Dependency Status](https://img.shields.io/gemnasium/blooper05/danger-rails_best_practices.svg)](https://gemnasium.com/blooper05/danger-rails_best_practices)
7
+ [![Gem Version](https://img.shields.io/gem/v/danger-rails_best_practices.svg)](https://rubygems.org/gems/danger-rails_best_practices)
8
+ [![License](https://img.shields.io/github/license/blooper05/danger-rails_best_practices.svg)](https://github.com/blooper05/danger-rails_best_practices/blob/master/LICENSE)
9
+
10
+ A [danger](https://rubygems.org/gems/danger) plugin for [rails_best_practices](https://rubygems.org/gems/rails_best_practices).
11
+
12
+ ## Installation
13
+
14
+ $ gem install danger-rails_best_practices
15
+
16
+ ## Usage
17
+
18
+ ### rails_best_practices
19
+
20
+ Lints Ruby files via [rails_best_practices](https://rubygems.org/gems/rails_best_practices).
21
+ Results are sent as inline comments.
22
+
23
+ <blockquote>Running rails_best_practices
24
+ <pre>
25
+ # Runs rails_best_practices on modified and added files in the PR
26
+ rails_best_practices.lint</pre>
27
+ </blockquote>
28
+
29
+ #### Methods
30
+
31
+ `lint` - Runs Ruby files through rails_best_practices.
32
+
33
+ ## Development
34
+
35
+ 1. Clone this repo
36
+ 2. Run `bundle install` to setup dependencies.
37
+ 3. Run `bundle exec rake spec` to run the tests.
38
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
39
+ 5. Make your changes.
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
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_best_practices/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-rails_best_practices'
8
+ spec.version = RailsBestPractices::VERSION
9
+ spec.authors = ['blooper05']
10
+ spec.email = ['legend.of.blooper@gmail.com']
11
+ spec.description = 'A Danger plugin to lint Ruby files through rails_best_practices.'
12
+ spec.summary = 'A Danger plugin to lint Ruby files through rails_best_practices.'
13
+ spec.homepage = 'https://github.com/blooper05/danger-rails_best_practices'
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_runtime_dependency 'danger-plugin-api', '~> 1.0'
22
+ spec.add_runtime_dependency 'rails_best_practices', '~> 1.16'
23
+
24
+ # General ruby development
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+
28
+ # Testing support
29
+ spec.add_development_dependency 'rspec', '~> 3.4'
30
+ spec.add_development_dependency 'simplecov', '~> 0.13'
31
+
32
+ # Linting code and docs
33
+ spec.add_development_dependency 'rubocop', '~> 0.41'
34
+ spec.add_development_dependency 'yard', '~> 0.8'
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 'rails_best_practices/plugin'
@@ -0,0 +1 @@
1
+ require 'rails_best_practices/gem_version'
@@ -0,0 +1,3 @@
1
+ module RailsBestPractices
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,48 @@
1
+ require 'rails_best_practices'
2
+
3
+ module Danger
4
+ # Lints Ruby files via [rails_best_practices](https://rubygems.org/gems/rails_best_practices).
5
+ # Results are sent as inline comments.
6
+ #
7
+ # @example Running rails_best_practices
8
+ #
9
+ # # Runs rails_best_practices on modified and added files in the PR
10
+ # rails_best_practices.lint
11
+ #
12
+ # @see blooper05/danger-rails_best_practices
13
+ # @tags ruby, rails, rails_best_practices, lint
14
+ class DangerRailsBestPractices < Plugin
15
+ # Runs Ruby files through rails_best_practices.
16
+ # @return [Array<RailsBestPractices::Core::Error, nil>]
17
+ def lint
18
+ files_to_lint = fetch_files_to_lint
19
+ lint_errors = run_linter(files_to_lint)
20
+ warn_each_line(lint_errors)
21
+ end
22
+
23
+ private
24
+
25
+ def run_linter(files_to_lint)
26
+ analyzer = ::RailsBestPractices::Analyzer.new(
27
+ '.', 'silent' => true, 'only' => files_to_lint
28
+ )
29
+ analyzer.analyze
30
+ analyzer.errors
31
+ end
32
+
33
+ def fetch_files_to_lint
34
+ files = git.modified_files + git.added_files
35
+ Array(files.map { |file| /#{file}/ })
36
+ end
37
+
38
+ def warn_each_line(lint_errors)
39
+ current_dir = "#{Dir.pwd}/"
40
+ lint_errors.each do |error|
41
+ message = error.message.capitalize
42
+ file = error.filename.sub(current_dir, '')
43
+ line = error.line_number.to_i
44
+ warn(message, file: file, line: line)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,79 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ module Danger
4
+ describe Danger::DangerRailsBestPractices do
5
+ it 'should be a plugin' do
6
+ expect(Danger::DangerRailsBestPractices.new(nil)).to be_a Danger::Plugin
7
+ end
8
+
9
+ describe 'with Dangerfile' do
10
+ let(:dangerfile) { testing_dangerfile }
11
+ let(:rails_best_practices) { dangerfile.rails_best_practices }
12
+
13
+ describe '#lint' do
14
+ subject { rails_best_practices.lint }
15
+
16
+ before { stubbings }
17
+ before { subject }
18
+
19
+ let(:changed_files) do
20
+ git = rails_best_practices.git
21
+ expect(git).to receive(:modified_files).and_return(modified_files)
22
+ expect(git).to receive(:added_files).and_return(added_files)
23
+ end
24
+
25
+ let(:status_reports) { dangerfile.status_report[:warnings] }
26
+ let(:violation_reports) { dangerfile.violation_report[:warnings] }
27
+
28
+ context 'with changed files' do
29
+ let(:modified_files) { [double('Modified Files')] }
30
+ let(:added_files) { [double('Added Files')] }
31
+
32
+ context 'with lint errors' do
33
+ let(:stubbings) { changed_files && lint_errors }
34
+
35
+ let(:lint_errors) do
36
+ linter = ::RailsBestPractices::Analyzer
37
+ errors = [double('Lint Errors', message: error_message,
38
+ filename: filename,
39
+ line_number: line_number)]
40
+ expect_any_instance_of(linter).to receive(:errors)
41
+ .and_return(errors)
42
+ end
43
+
44
+ let(:error_message) { 'error message' }
45
+ let(:filename) { "#{Dir.pwd}/path/to/file" }
46
+ let(:line_number) { '123' }
47
+
48
+ it 'returns warning reports' do
49
+ message = 'Error message'
50
+ violation = Violation.new(message, false, 'path/to/file', 123)
51
+ expect(status_reports).to eq([message])
52
+ expect(violation_reports).to eq([violation])
53
+ end
54
+ end
55
+
56
+ context 'with no lint errors' do
57
+ let(:stubbings) { changed_files }
58
+
59
+ it 'returns no warning reports' do
60
+ expect(status_reports).to be_empty
61
+ expect(violation_reports).to be_empty
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'with no changed files' do
67
+ let(:stubbings) { changed_files }
68
+ let(:modified_files) { [] }
69
+ let(:added_files) { [] }
70
+
71
+ it 'returns no warning reports' do
72
+ expect(status_reports).to be_empty
73
+ expect(violation_reports).to be_empty
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,68 @@
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 'simplecov'
7
+ SimpleCov.start
8
+
9
+ require 'bundler/setup'
10
+ require 'pry'
11
+
12
+ require 'rspec'
13
+ require 'danger'
14
+
15
+ if `git remote -v` == ''
16
+ puts 'You cannot run tests without setting a local git remote on this repo'
17
+ puts "It's a weird side-effect of Danger's internals."
18
+ exit(0)
19
+ end
20
+
21
+ # Use coloured output, it's the best.
22
+ RSpec.configure do |config|
23
+ config.filter_gems_from_backtrace 'bundler'
24
+ config.color = true
25
+ config.tty = true
26
+ end
27
+
28
+ require 'danger_plugin'
29
+
30
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
31
+ # If you are expanding these files, see if it's already been done ^.
32
+
33
+ # A silent version of the user interface,
34
+ # it comes with an extra function `.string` which will
35
+ # strip all ANSI colours from the string.
36
+
37
+ # rubocop:disable Lint/NestedMethodDefinition
38
+ def testing_ui
39
+ @output = StringIO.new
40
+ def @output.winsize
41
+ [20, 9999]
42
+ end
43
+
44
+ cork = Cork::Board.new(out: @output)
45
+ def cork.string
46
+ out.string.gsub(/\e\[([;\d]+)?m/, '')
47
+ end
48
+ cork
49
+ end
50
+ # rubocop:enable Lint/NestedMethodDefinition
51
+
52
+ # Example environment (ENV) that would come from
53
+ # running a PR on TravisCI
54
+ def testing_env
55
+ {
56
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
57
+ 'TRAVIS_PULL_REQUEST' => '800',
58
+ 'TRAVIS_REPO_SLUG' => 'artsy/eigen',
59
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
60
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
61
+ }
62
+ end
63
+
64
+ # A stubbed out Dangerfile for use in tests
65
+ def testing_dangerfile
66
+ env = Danger::EnvironmentManager.new(testing_env)
67
+ Danger::Dangerfile.new(env, testing_ui)
68
+ end
metadata ADDED
@@ -0,0 +1,229 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-rails_best_practices
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - blooper05
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-05 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: rails_best_practices
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.13'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.13'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.41'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.41'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.14'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.14'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '4.7'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '4.7'
153
+ - !ruby/object:Gem::Dependency
154
+ name: listen
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 3.0.7
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 3.0.7
167
+ - !ruby/object:Gem::Dependency
168
+ name: pry
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: A Danger plugin to lint Ruby files through rails_best_practices.
182
+ email:
183
+ - legend.of.blooper@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".rubocop.yml"
190
+ - ".travis.yml"
191
+ - Gemfile
192
+ - Guardfile
193
+ - LICENSE
194
+ - README.md
195
+ - Rakefile
196
+ - danger-rails_best_practices.gemspec
197
+ - lib/danger_plugin.rb
198
+ - lib/danger_rails_best_practices.rb
199
+ - lib/rails_best_practices/gem_version.rb
200
+ - lib/rails_best_practices/plugin.rb
201
+ - spec/rails_best_practices_spec.rb
202
+ - spec/spec_helper.rb
203
+ homepage: https://github.com/blooper05/danger-rails_best_practices
204
+ licenses:
205
+ - MIT
206
+ metadata: {}
207
+ post_install_message:
208
+ rdoc_options: []
209
+ require_paths:
210
+ - lib
211
+ required_ruby_version: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ required_rubygems_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ requirements: []
222
+ rubyforge_project:
223
+ rubygems_version: 2.6.13
224
+ signing_key:
225
+ specification_version: 4
226
+ summary: A Danger plugin to lint Ruby files through rails_best_practices.
227
+ test_files:
228
+ - spec/rails_best_practices_spec.rb
229
+ - spec/spec_helper.rb