rubocop-blueapron 0.1.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
+ SHA1:
3
+ metadata.gz: 35d1077d0ea4cfb652e9729262175aac2b468b9e
4
+ data.tar.gz: bf51a2ffcbc66cecaae81f984f32c222a8723ba9
5
+ SHA512:
6
+ metadata.gz: 6162fc4ce3875fe1e60839b39aeb388d00ebe26e4f8961af196305e7781358e961716b5016ee8d2fd10a0ef1492d5d3e79564316b1315f920feafd157e6b1393
7
+ data.tar.gz: 625c9b0455298f4d93a017423e793d2159ad1cc64d9877865367adf9ae65bd1371641a653fb2bd57d2557ac9189383d156ac24d2ee468fb70b38bf920607661f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Blue Apron
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # RuboCop Blue Apron
2
+
3
+ Blue Apron Style Guide RuboCop extension.
4
+
5
+ ## Installation
6
+
7
+ Add `rubocop-blueapron` to your `Gemfile`
8
+
9
+ ```
10
+ gem 'rubocop-blueapron'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Configure RuboCop to load the extension in `.rubocop.yml`.
16
+
17
+ ```
18
+ require: rubocop-blueapron
19
+ ```
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork it!
24
+ 2. Create your feature branch: `git checkout -b my-new-feature`
25
+ 3. Commit your changes: `git commit -am 'Add some feature'`
26
+ 4. Push to the branch: `git push origin my-new-feature`
27
+ 5. Submit a pull request :D
28
+
29
+ For running the spec files, this project depends on RuboCop's spec helpers.
30
+ This means that in order to run the specs locally, you need a (shallow) clone
31
+ of the RuboCop repository:
32
+
33
+ ```bash
34
+ git clone --depth 1 git://github.com/bbatsov/rubocop.git vendor/rubocop
35
+ ```
36
+
37
+ ## Credits
38
+
39
+ Based on [rubocop-rspec](https://github.com/nevir/rubocop-rspec).
40
+
41
+ ## License
42
+
43
+ `rubocop-blueapron` is MIT licensed. [See the accompanying file](MIT-LICENSE.md) for
44
+ the full text.
@@ -0,0 +1,7 @@
1
+ Blueapron/DateTimeNowUtc:
2
+ Description: 'Check that DateTime.now is interpreted as UTC.'
3
+ Enabled: true
4
+
5
+ Blueapron/TimeNowUtc:
6
+ Description: 'Check that Time.now is interpreted as UTC.'
7
+ Enabled: true
@@ -0,0 +1,9 @@
1
+ require 'rubocop'
2
+
3
+ require 'rubocop/blueapron/version'
4
+ require 'rubocop/blueapron/inject'
5
+
6
+ RuboCop::Blueapron::Inject.defaults!
7
+
8
+ require 'rubocop/cop/blueapron/date_time_now_utc'
9
+ require 'rubocop/cop/blueapron/time_now_utc'
@@ -0,0 +1,21 @@
1
+ require 'yaml'
2
+
3
+ module RuboCop
4
+ module Blueapron
5
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
6
+ # bit of our configuration.
7
+ module Inject
8
+ DEFAULT_FILE = File.expand_path(
9
+ '../../../../config/default.yml', __FILE__
10
+ )
11
+
12
+ def self.defaults!
13
+ hash = YAML.load_file(DEFAULT_FILE)
14
+ puts "configuration from #{DEFAULT_FILE}" if ConfigLoader.debug?
15
+ config = ConfigLoader.merge_with_default(hash, DEFAULT_FILE)
16
+
17
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ module RuboCop
2
+ module Blueapron
3
+ MAJOR = '0'
4
+ MINOR = '1'
5
+ PATCH = '1'
6
+
7
+ VERSION = [MAJOR, MINOR, PATCH].join('.')
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Blueapron
4
+ class DateTimeNowUtc < Cop
5
+ DATE_TIME_NOW = s(:send, s(:const, nil, :DateTime), :now)
6
+
7
+ MESSAGE = 'DateTime.now should be interpreted as UTC.'
8
+
9
+ def on_send(node)
10
+ return if node != DATE_TIME_NOW
11
+ return if node.parent && node.parent.children.last == :utc
12
+
13
+ add_offense(node, :expression, MESSAGE)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Blueapron
4
+ class TimeNowUtc < Cop
5
+ TIME_NOW = s(:send, s(:const, nil, :Time), :now)
6
+
7
+ MESSAGE = 'Time.now should be interpreted as UTC.'
8
+
9
+ def on_send(node)
10
+ return if node != TIME_NOW
11
+ return if node.parent && node.parent.children.last == :utc
12
+
13
+ add_offense(node, :expression, MESSAGE)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe RuboCop::Cop::Blueapron::DateTimeNowUtc do
4
+ subject(:cop) { described_class.new }
5
+
6
+ it 'reports offense when DateTime.now is not interpreted as UTC' do
7
+ inspect_source(cop, "def foo\n DateTime.now\n end")
8
+ expect(cop.offenses.size).to eq(1)
9
+ expect(cop.offenses.map(&:line).sort).to eq([2])
10
+ expect(cop.messages).to eq(['DateTime.now should be interpreted as UTC.'])
11
+ end
12
+
13
+ it 'does not report offense when DateTime.now is interpreted as UTC' do
14
+ inspect_source(cop, "def foo\n DateTime.now.utc\n end")
15
+ expect(cop.offenses).to be_empty
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe RuboCop::Cop::Blueapron::TimeNowUtc do
4
+ subject(:cop) { described_class.new }
5
+
6
+ it 'reports offense when Time.now is not interpreted as UTC' do
7
+ inspect_source(cop, "def foo\n Time.now\n end")
8
+ expect(cop.offenses.size).to eq(1)
9
+ expect(cop.offenses.map(&:line).sort).to eq([2])
10
+ expect(cop.messages).to eq(['Time.now should be interpreted as UTC.'])
11
+ end
12
+
13
+ it 'does not report offense when Time.now is interpreted as UTC' do
14
+ inspect_source(cop, "def foo\n Time.now.utc\n end")
15
+ expect(cop.offenses).to be_empty
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ require 'rubocop'
2
+
3
+ rubocop_path = File.join(File.dirname(__FILE__), '../vendor/rubocop')
4
+ unless File.directory?(rubocop_path)
5
+ fail "Can't run specs without a local RuboCop checkout. Look in the README."
6
+ end
7
+ Dir["#{rubocop_path}/spec/support/**/*.rb"].each { |f| require f }
8
+
9
+ RSpec.configure do |config|
10
+ config.order = :random
11
+
12
+ config.expect_with :rspec do |expectations|
13
+ expectations.syntax = :expect # Disable `should`
14
+ end
15
+
16
+ config.mock_with :rspec do |mocks|
17
+ mocks.syntax = :expect # Disable `should_receive` and `stub`
18
+ end
19
+ end
20
+
21
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
22
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
23
+ require 'rubocop-blueapron'
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-blueapron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Blue Apron Engineering
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.34'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.34'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
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.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.11'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.11'
83
+ description: Blue Apron Style Guide RuboCop extension.
84
+ email:
85
+ - engineering@blueapron.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files:
89
+ - LICENSE
90
+ - README.md
91
+ files:
92
+ - LICENSE
93
+ - README.md
94
+ - config/default.yml
95
+ - lib/rubocop-blueapron.rb
96
+ - lib/rubocop/blueapron/inject.rb
97
+ - lib/rubocop/blueapron/version.rb
98
+ - lib/rubocop/cop/blueapron/date_time_now_utc.rb
99
+ - lib/rubocop/cop/blueapron/time_now_utc.rb
100
+ - spec/rubocop/cop/blueapron/date_time_now_utc_spec.rb
101
+ - spec/rubocop/cop/blueapron/time_now_utc_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: https://github.com/blueapron/rubocop-blueapron
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.4.5.1
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Blue Apron Style Guide RuboCop extension.
127
+ test_files:
128
+ - spec/rubocop/cop/blueapron/date_time_now_utc_spec.rb
129
+ - spec/rubocop/cop/blueapron/time_now_utc_spec.rb
130
+ - spec/spec_helper.rb