ezcater_rubocop 0.50.2.rc0 → 0.50.2.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc2b72196c2d978e118d0d6f13ff45f2a06549fe
4
- data.tar.gz: 1d875ba7c900140c5f0f5c2ef99054d3eb297322
3
+ metadata.gz: 0d12c8292918b188ea1df51f50a4b2aaeba09808
4
+ data.tar.gz: '0219fcf647fe0325ac794de1498e822db2b429d9'
5
5
  SHA512:
6
- metadata.gz: 2ceece608ed580d16420ed3697c6ec01a7d9db5763985a8dfe6c2d10e5b8129667f4b7b3b3c93ef3d4cd5677e1f7ee6f1099ecbbb69f407c4640bdab653a56d5
7
- data.tar.gz: c22694f8ee893278028ebcd8451c75852fe267936489401bd681a3f2d291e4a465ff61fa9c9c4e9258fa06f8bcda947f191c0738240961beb0de1ec8303580bb
6
+ metadata.gz: b56adca97c94e2e92a1f9746ead3e0dab36b36f97f09dea46d5dd2f7c7ef0080391ae85814601ff0ebca93a7c4565306419267d8a7e8f6388caf7ea0ed14afbb
7
+ data.tar.gz: 7c2c268cf647c3dc634e17bb2d961663a1eaf00c0c284767240d0b427d4df2642d2465104fe79f97ea08137d229a197a3f585db3b9f06fc0d3623a80033ddb59
data/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # ezcater_rubocop
2
2
 
3
3
  ## v0.50.2 (unreleased)
4
+ - Add `Ezcater/PrivateAttr` custom cop.
5
+ - Configure `RSpec/ExampleLength` with a `Max` value of 25.
4
6
  - Add `circle_rubocop.rb` script.
5
7
 
6
8
  ## v0.50.1
data/README.md CHANGED
@@ -56,6 +56,17 @@ Run `rubocop` for an entire project:
56
56
  See the `rubocop` command-line for additional options including auto-generating
57
57
  configuration for existing offenses and auto-correction.
58
58
 
59
+ ### Circle Script
60
+
61
+ This gem contains a script, `circle_rubocop.rb`, that can be used to run RuboCop in CI.
62
+
63
+ The behavior of the script is that all files are checked on master or if the rubocop
64
+ configuration has changed. On non-master branches, only the files added or changed on
65
+ the branch are checked.
66
+
67
+ For non-master branches, `[rubocop skip]` can be included in the commit message to skip
68
+ running rubocop.
69
+
59
70
  ## Versioning
60
71
 
61
72
  This gem is versioned based on the MAJOR.MINOR version of `rubocop`. The first
@@ -71,6 +82,7 @@ the latest compatible version each time that the MAJOR.MINOR version of `rubocop
71
82
  is updated.
72
83
 
73
84
  ## Custom Cops
85
+ 1. [PrivateAttr](https://github.com/ezcater/ezcater_rubocop/blob/master/lib/rubocop/cop/ezcater/private_attr.rb) - Require methods from the `private_attr` gem.
74
86
  1. [RspecDotNotSelfDot](https://github.com/ezcater/ezcater_rubocop/blob/master/lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb) - Enforce ".<class method>" instead of "self.<class method>" for example group description.
75
87
  1. [RspecRequireBrowserMock](https://github.com/ezcater/ezcater_rubocop/blob/master/lib/rubocop/cop/ezcater/rspec_require_browser_mock.rb) - Enforce use of `mock_ezcater_app`, `mock_chrome_browser` & `mock_custom_browser` helpers instead of mocking `Browser` or `EzBrowser` directly.
76
88
  1. [RspecRequireFeatureFlagMock](https://github.com/ezcater/ezcater_rubocop/blob/master/lib/rubocop/cop/ezcater/rspec_require_feature_flag_mock.rb) - Enforce use of `mock_feature_flag` helper instead of mocking `FeatureFlag.is_active?` directly.
data/conf/rubocop.yml CHANGED
@@ -31,6 +31,9 @@ Metrics/PerceivedComplexity:
31
31
  Rails:
32
32
  Enabled: false
33
33
 
34
+ RSpec/ExampleLength:
35
+ Max: 25
36
+
34
37
  Style/FrozenStringLiteralComment:
35
38
  Enabled: false
36
39
 
data/config/default.yml CHANGED
@@ -1,3 +1,7 @@
1
+ Ezcater/PrivateAttr:
2
+ Description: 'Require methods from the private_attr gem'
3
+ Enabled: true
4
+
1
5
  Ezcater/RspecDotNotSelfDot:
2
6
  Description: 'Enforce ".<class method>" instead of "self.<class method>" for example group description.'
3
7
  Enabled: true
@@ -22,9 +22,20 @@ Gem::Specification.new do |spec|
22
22
  "public gem pushes."
23
23
  end
24
24
 
25
+ excluded_files = %w[.circleci/config.yml
26
+ .gitignore
27
+ .rspec
28
+ .rubocop.yml
29
+ .ruby-gemset
30
+ .ruby-version
31
+ .travis.yml
32
+ bin/console
33
+ bin/setup
34
+ Rakefile]
35
+
25
36
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
37
  f.match(%r{^(test|spec|features)/})
27
- end
38
+ end - excluded_files
28
39
  spec.bindir = "bin"
29
40
  spec.executables << "circle_rubocop.rb"
30
41
  spec.require_paths = ["lib"]
@@ -12,6 +12,7 @@ puts "configuration from #{DEFAULT_FILES}" if RuboCop::ConfigLoader.debug?
12
12
  config = RuboCop::ConfigLoader.merge_with_default(config, path)
13
13
  RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
14
14
 
15
+ require "rubocop/cop/ezcater/private_attr"
15
16
  require "rubocop/cop/ezcater/rspec_require_browser_mock"
16
17
  require "rubocop/cop/ezcater/rspec_require_feature_flag_mock"
17
18
  require "rubocop/cop/ezcater/rspec_dot_not_self_dot"
@@ -1,3 +1,3 @@
1
1
  module EzcaterRubocop
2
- VERSION = "0.50.2.rc0".freeze
2
+ VERSION = "0.50.2.rc1".freeze
3
3
  end
@@ -0,0 +1,91 @@
1
+ module RuboCop
2
+ module Cop
3
+ module Ezcater
4
+ # This cop checks for the use of `attr_accessor`, `attr_reader`, `attr_writer`
5
+ # and `alias_method` after the access modifiers `private` and `protected`
6
+ # and requires the use of methods from the private_attr gem instead.
7
+ #
8
+ # @example
9
+ #
10
+ # # bad
11
+ #
12
+ # class C
13
+ # private
14
+ #
15
+ # attr_accessor :foo
16
+ # attr_reader :bar
17
+ # attr_writer :baz
18
+ # alias_method :foobar, foo
19
+ # end
20
+ #
21
+ #
22
+ # @example
23
+ #
24
+ # # good
25
+ #
26
+ # class C
27
+ # private_attr_accessor :foo
28
+ # private_attr_reader :bar
29
+ # private_attr_writer :baz
30
+ # private_alias_method :foobar, :foo
31
+ #
32
+ # private
33
+ #
34
+ # def shy
35
+ # puts "hi"
36
+ # end
37
+ # end
38
+ class PrivateAttr < Cop
39
+ ATTR_METHODS = %i[attr_accessor
40
+ attr_reader
41
+ attr_writer].freeze
42
+
43
+ ACCESS_AFFECTED_METHODS = (ATTR_METHODS + %i[alias_method]).to_set.freeze
44
+
45
+ MSG = "Use `%s_%s` instead".freeze
46
+
47
+ def on_class(node)
48
+ check_node(node.children[2]) # class body
49
+ end
50
+
51
+ def on_module(node)
52
+ check_node(node.children[1]) # module body
53
+ end
54
+
55
+ private
56
+
57
+ def check_node(node)
58
+ return unless node&.begin_type?
59
+
60
+ check_scope(node)
61
+ end
62
+
63
+ def format_message(visibility, method_name)
64
+ format(MSG, visibility, method_name)
65
+ end
66
+
67
+ def check_scope(node, current_visibility = :public)
68
+ node.children.reduce(current_visibility) do |visibility, child|
69
+ check_child_scope(child, visibility)
70
+ end
71
+ end
72
+
73
+ def check_child_scope(node, current_visibility)
74
+ if node.send_type?
75
+ if node.access_modifier? && !node.method?(:module_function)
76
+ current_visibility = node.method_name
77
+ elsif ACCESS_AFFECTED_METHODS.include?(node.method_name) && current_visibility != :public
78
+ add_offense(node,
79
+ :expression,
80
+ format_message(current_visibility, node.method_name))
81
+ end
82
+ elsif node.kwbegin_type?
83
+ check_scope(node, current_visibility)
84
+ end
85
+
86
+ current_visibility
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezcater_rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.50.2.rc0
4
+ version: 0.50.2.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ezCater, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-18 00:00:00.000000000 Z
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -116,27 +116,18 @@ executables:
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
- - ".circleci/config.yml"
120
- - ".gitignore"
121
- - ".rspec"
122
- - ".rubocop.yml"
123
- - ".ruby-gemset"
124
- - ".ruby-version"
125
- - ".travis.yml"
126
119
  - CHANGELOG.md
127
120
  - Gemfile
128
121
  - LICENSE.txt
129
122
  - README.md
130
- - Rakefile
131
123
  - bin/circle_rubocop.rb
132
- - bin/console
133
- - bin/setup
134
124
  - conf/rubocop.yml
135
125
  - conf/rubocop_rails.yml
136
126
  - config/default.yml
137
127
  - ezcater_rubocop.gemspec
138
128
  - lib/ezcater_rubocop.rb
139
129
  - lib/ezcater_rubocop/version.rb
130
+ - lib/rubocop/cop/ezcater/private_attr.rb
140
131
  - lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
141
132
  - lib/rubocop/cop/ezcater/rspec_require_browser_mock.rb
142
133
  - lib/rubocop/cop/ezcater/rspec_require_feature_flag_mock.rb
data/.circleci/config.yml DELETED
@@ -1,46 +0,0 @@
1
- version: 2
2
- jobs:
3
- build:
4
- parallelism: 1
5
- working_directory: ~/ezcater
6
- docker:
7
- - image: circleci/ruby:2.4.1
8
- steps:
9
- - checkout
10
-
11
- # Restore bundle cache
12
- - restore_cache:
13
- keys:
14
- - ruby-cache-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "ezcater_rubocop.gemspec" }}
15
- - ruby-cache-{{ arch }}-{{ .Branch }}-
16
- - ruby-cache-
17
-
18
- # Bundle install dependencies
19
- - run: gem install bundler --no-document
20
- - run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
21
- - run: bundle clean --force
22
-
23
- # Store bundle cache
24
- - save_cache:
25
- key: ruby-cache-{{ .Branch }}-{{ checksum "Gemfile" }}-{{ checksum "ezcater_rubocop.gemspec" }}
26
- paths:
27
- - vendor/bundle
28
-
29
- # Run Rubocop
30
- - run:
31
- name: RuboCop
32
- command: bundle exec rubocop
33
-
34
- # Run rspec in parallel
35
- - type: shell
36
- command: |
37
- bundle exec rspec --profile 10 \
38
- --format RspecJunitFormatter \
39
- --out test_results/rspec.xml \
40
- --format progress
41
-
42
- # Save test results for timing analysis
43
- - store_test_results:
44
- path: test_results
45
- - store_test_results:
46
- path: tmp/capybara
data/.gitignore DELETED
@@ -1,12 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
-
11
- # rspec failure tracking
12
- .rspec_status
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --require spec_helper.rb
2
- --format documentation
3
- --color
data/.rubocop.yml DELETED
@@ -1,6 +0,0 @@
1
- inherit_from:
2
- - conf/rubocop.yml
3
-
4
- # Disable because aggregate_failures is configured globally
5
- RSpec/MultipleExpectations:
6
- Enabled: false
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- ezcater_rubocop
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.4.1
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.3
5
- before_install: gem install bundler -v 1.15.4
6
- script:
7
- - bundle exec rubocop
8
- - bundle exec rspec
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task default: :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "ezcater_rubocop"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
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