drewcoo-cops 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f28c869ea830f6613fbdd0ba6ff6d90864a2c6fd4ba234b8fe59a765c548a9db
4
+ data.tar.gz: 44f739680638c85c814efeb52a0d17fb33e61e56af025f2c65468b8427a0a1e2
5
+ SHA512:
6
+ metadata.gz: cf1bd79a9ca51c04be01a45da33df8f831d226f86a407a9d531fdf6ff181a03f6dc7b39928c3d8056860bb850b5e03e7775bda774a5f47bc581d6e750eda84b3
7
+ data.tar.gz: f967b8382c0dea1cced7eeb4f0e20156acbfc95294b1b5c5d39c10bd6958bd5fabd4141c46a116489dd5b04d1468a45b0e6d13344342cd0dc5be78e2c4590f4b
@@ -0,0 +1,53 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.4.1-node-browsers
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+ - restore_cache:
22
+ keys:
23
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
24
+ # fallback to using the latest cache if no exact match is found
25
+ - v1-dependencies-
26
+
27
+ - run:
28
+ name: install dependencies
29
+ command: |
30
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
31
+
32
+ - save_cache:
33
+ paths:
34
+ - ./vendor/bundle
35
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
36
+
37
+ - run:
38
+ name: run tests
39
+ command: |
40
+ mkdir /tmp/test-results
41
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
42
+
43
+ bundle exec rspec --format progress \
44
+ --format RspecJunitFormatter \
45
+ --out /tmp/test-results/rspec.xml \
46
+ --format progress \
47
+ $TEST_FILES
48
+
49
+ - store_test_results:
50
+ path: /tmp/test-results
51
+ - store_artifacts:
52
+ path: /tmp/test-results
53
+ destination: test-results
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: u0A2L26aq3qwfYjPKMudkvjiYZb79VsqG
@@ -0,0 +1,13 @@
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
12
+
13
+ Gemfiile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,11 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ require: rubocop-rspec
4
+
5
+ AllCops:
6
+ DefaultFormatter: progress
7
+ DisplayCopNames: true
8
+ DisplayStyleGuide: true
9
+ ExtraDetails: true
10
+ # Multiline strings with <<~foo require MRI >= 2.3
11
+ TargetRubyVersion: 2.3
@@ -0,0 +1,20 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-05-26 20:00:18 -0700 using RuboCop version 0.56.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 3
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: EnforcedStyle.
12
+ # SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
13
+ Layout/IndentHeredoc:
14
+ Exclude:
15
+ - 'spec/rubocop/cop/style_sleepcop_spec.rb'
16
+
17
+ # Offense count: 2
18
+ # Configuration parameters: CountComments, ExcludedMethods.
19
+ Metrics/BlockLength:
20
+ Max: 73
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Drew Cooper
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.
@@ -0,0 +1,92 @@
1
+ # Drewcoo-Cops
2
+
3
+ [![TravisCI](https://api.travis-ci.org/drewcoo/drewcoo-cops.svg)](https://travis-ci.org/drewcoo/drewcoo-cops)
4
+ [![CircleCI](https://circleci.com/gh/drewcoo/drewcoo-cops.svg?style=shield)](https://circleci.com/gh/drewcoo/drewcoo-cops)
5
+ [![Coverage Status](https://coveralls.io/repos/github/drewcoo/drewcoo-cops/badge.svg?branch=master)](https://coveralls.io/github/drewcoo/drewcoo-cops?branch=master)
6
+ [![Gem Version](https://badge.fury.io/rb/drewcoo-cops.svg)](https://badge.fury.io/rb/drewcoo-cops)
7
+
8
+ # Who? What?
9
+
10
+ Hi, I'm Drew, drewcoo on [Github](https://github.com/drewcoo) and this is my
11
+ collection of custom [RuboCop](http://batsov.com/rubocop/) cops. Well, ok, so
12
+ there's only one so far but I expect the collection to grow. Right now there's
13
+ a cop to find sleep methods.
14
+
15
+ ## Why Sleeping Is Bad
16
+
17
+ You'll see a lot of test code peppered with sleeps for MAGIC_SECONDS, and
18
+ DIFFERENT_MAGIC_SECONDS, and loops while STILL_OTHER_MAGIC_SECONDS time goes
19
+ by. Often this is punctuated with some exception catching and throwing which
20
+ also takes up magical amounts of time of its own. All of these things
21
+ constantly need to be adjusted for the competing frenemies, speed and
22
+ stability, as the underlying code, which is probably messy UI code, shifts
23
+ mercilessly underfoot. This is not pretty, my fellow testers.
24
+
25
+ I'd like to suggest having common polling code somewhere in your codebase.
26
+ Call that whenever you need to wait for something or check if something's ready.
27
+ Pick a quick polling time (10ths of a sec or less), a long-enough timeout (on
28
+ the order of seconds), and pass a proc or lambda with the checks into your
29
+ polling method.
30
+
31
+ Ok. Are you with me so far? Now get rid of all that buggy nightmare of sleeps.
32
+ Get rid of all of them except the one in your shiny new polling method. You
33
+ can run this cop to check for stray sleeps.
34
+
35
+ ### Dirty Secrets
36
+
37
+ I sometimes do horrible things to code. I even insert sleeps when I'm trying
38
+ to debug something the quick and dirty way. My secret is that I usually have
39
+ something like this gem to know what to clean up afterward so that my code
40
+ looks clean.
41
+
42
+ ## Installation
43
+
44
+ Add this line to your application's Gemfile:
45
+
46
+ ```ruby
47
+ gem 'drewcoo-cops'
48
+ ```
49
+
50
+ And then execute:
51
+
52
+ $ bundle
53
+
54
+ Or install it yourself as:
55
+
56
+ $ gem install drewcoo-cops
57
+
58
+ ## Usage
59
+
60
+ In your .rubocop.yml just do this to have RuboCop yell at you for all of
61
+ your sleeps:
62
+
63
+ ```ruby
64
+ require: drewcoo-cops
65
+ ```
66
+ And shut the cops up for that one special polling method, which is what you
67
+ use instead of peppering your code with sleeps and making an unmaintainable
68
+ mess, right?
69
+
70
+ ```ruby
71
+ # rubocop:disable Style/SleepCop
72
+ def polling_method
73
+ some stuff
74
+ sleep A_NUMBER_OF_SECONDS
75
+ maybe some other stuff
76
+ end
77
+ # rubocop:enable Style/SleepCop
78
+ ```
79
+
80
+ ## Development
81
+
82
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
83
+
84
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
85
+
86
+ ## Contributing
87
+
88
+ Bug reports and pull requests are welcome on GitHub at https://github.com/drewcoo/drewcoo-cops.
89
+
90
+ ## License
91
+
92
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,12 @@
1
+ require "bundler/setup"
2
+ require "drewcoo/cops"
3
+
4
+ # You can add fixtures and/or initialization code here to make experimenting
5
+ # with your gem easier. You can also use a different console, if you like.
6
+
7
+ # (If you use this, don't forget to add pry to your Gemfile!)
8
+ # require "pry"
9
+ # Pry.start
10
+
11
+ require "irb"
12
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,40 @@
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 'version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'drewcoo-cops'
9
+ spec.version = Drewcoo::Cops::VERSION
10
+ spec.authors = ['Drew Cooper']
11
+ spec.email = ['drewcoo@gmail.com']
12
+
13
+ spec.summary = 'Custom Rubocop cops'
14
+ spec.description = 'Presently only a cop that complains about sleeps.'
15
+ spec.homepage = 'https://github.com/drewcoo/drewcoo-cops'
16
+ spec.license = 'MIT'
17
+
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org/drewcoo/drewcoo-cops'
20
+ else
21
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
22
+ 'public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ # bundler 1.15 and no higher for CircleCI
33
+ spec.add_development_dependency 'bundler', '~> 1.15'
34
+ spec.add_development_dependency 'coveralls', '~> 0.8'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'rspec_junit_formatter', '~> 0.3'
38
+ spec.add_development_dependency 'rubocop', '~> 0.56'
39
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.25'
40
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'version'
4
+ require 'rubocop/style/sleepcop'
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ module RuboCop
6
+ module Cop
7
+ module Style
8
+ #
9
+ # A cap to warn on any sleep calls.
10
+ #
11
+ class SleepCop < Cop
12
+ MSG = 'Do not call sleep. Only call it your polling method ' \
13
+ 'and decorate that with: rubocop:disable Style/SleepCop.'
14
+
15
+ def on_send(node)
16
+ return unless node.method_name == :sleep
17
+ add_offense(node, severity: :warning)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Drewcoo
4
+ module Cops
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drewcoo-cops
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Drew Cooper
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec_junit_formatter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.3'
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.56'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.56'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.25'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.25'
111
+ description: Presently only a cop that complains about sleeps.
112
+ email:
113
+ - drewcoo@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".circleci/config.yml"
119
+ - ".coveralls.yml"
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".rubocop.yml"
123
+ - ".rubocop_todo.yml"
124
+ - ".travis.yml"
125
+ - Gemfile
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - bin/console
130
+ - bin/setup
131
+ - drewcoo-cops.gemspec
132
+ - lib/drewcoo-cops.rb
133
+ - lib/rubocop/style/sleepcop.rb
134
+ - lib/version.rb
135
+ homepage: https://github.com/drewcoo/drewcoo-cops
136
+ licenses:
137
+ - MIT
138
+ metadata:
139
+ allowed_push_host: https://rubygems.org/drewcoo/drewcoo-cops
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.7.6
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Custom Rubocop cops
160
+ test_files: []