rubocop-g2 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 93db5770ceb2c22b543018310d3861508680cbb7b19c72a234ce5a37ebae7b45
4
+ data.tar.gz: 07fc64c88d2bacd823c5a8334b0767c747d9df1c50adec62e0cbb2b11bddda09
5
+ SHA512:
6
+ metadata.gz: 3c171ab233dece2ebb9cacadb7994ede48542a8e03dee1304e8be97caa42b3ecb4d18d0df71bd696aa8e05b1d725c9b414cf3fe9ac1cd13c290acde155c006d9
7
+ data.tar.gz: 982b0cd0addf3ca594555d9343c1466448cac5abe0fa09f70db7e086772b6f0d5bfd379dee13b90aa3686ed5704db408b8b03e8e5b01b31023a364d1262ebbca
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /.idea
2
+ /.bundle
3
+ .rspec_status
4
+ /pkg
data/.rubocop.yml ADDED
@@ -0,0 +1,102 @@
1
+ require:
2
+ - rubocop-rspec
3
+
4
+ Layout/SpaceAroundMethodCallOperator:
5
+ Enabled: false
6
+
7
+ Layout/SpaceBeforeFirstArg:
8
+ Enabled: false
9
+
10
+ Layout/MultilineOperationIndentation:
11
+ Enabled: false
12
+
13
+ Layout/ClassStructure:
14
+ Enabled: true
15
+
16
+ Layout/MultilineMethodCallIndentation:
17
+ EnforcedStyle: indented_relative_to_receiver
18
+
19
+ Layout/EmptyLineAfterGuardClause:
20
+ Enabled: false
21
+
22
+ Layout/LineLength:
23
+ Max: 120
24
+ IgnoredPatterns:
25
+ - ^#
26
+
27
+ Lint/AssignmentInCondition:
28
+ Enabled: false
29
+
30
+ Lint/RaiseException:
31
+ Enabled: true
32
+
33
+ Lint/StructNewOverride:
34
+ Enabled: true
35
+
36
+ Metrics/AbcSize:
37
+ Max: 20
38
+
39
+ Metrics/BlockLength:
40
+ Enabled: false
41
+
42
+ Metrics/ClassLength:
43
+ Max: 500
44
+
45
+ Metrics/MethodLength:
46
+ Max: 15
47
+
48
+ Metrics/ParameterLists:
49
+ Max: 5
50
+
51
+ Style/AndOr:
52
+ Enabled: false
53
+
54
+ Style/ClassAndModuleChildren:
55
+ AutoCorrect: true
56
+
57
+ Style/Documentation:
58
+ Enabled: false
59
+
60
+ Style/EmptyMethod:
61
+ Enabled: false
62
+
63
+ Style/ExponentialNotation:
64
+ Enabled: false
65
+
66
+ Style/FormatStringToken:
67
+ EnforcedStyle: template
68
+
69
+ Style/FrozenStringLiteralComment:
70
+ Enabled: false
71
+
72
+ Style/HashEachMethods:
73
+ Enabled: true
74
+
75
+ Style/HashTransformKeys:
76
+ Enabled: false
77
+
78
+ Style/HashTransformValues:
79
+ Enabled: false
80
+
81
+ Style/Lambda:
82
+ Enabled: false
83
+
84
+ Style/LambdaCall:
85
+ Enabled: false
86
+
87
+ Style/NumericLiterals:
88
+ Enabled: false
89
+
90
+ Style/PercentLiteralDelimiters:
91
+ PreferredDelimiters:
92
+ default: ()
93
+ '%w': '()'
94
+ '%W': '()'
95
+ '%i': '()'
96
+ '%I': '()'
97
+
98
+ Style/SingleLineBlockParams:
99
+ Enabled: false
100
+
101
+ Style/SymbolProc:
102
+ Enabled: false
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.6.6
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubocop-g2 (1.0.0)
5
+ rubocop (= 0.82.0)
6
+ rubocop-rspec (= 1.39.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.0)
12
+ coderay (1.1.2)
13
+ diff-lcs (1.3)
14
+ jaro_winkler (1.5.4)
15
+ method_source (0.9.2)
16
+ parallel (1.19.1)
17
+ parser (2.7.1.2)
18
+ ast (~> 2.4.0)
19
+ pry (0.12.2)
20
+ coderay (~> 1.1.0)
21
+ method_source (~> 0.9.0)
22
+ rainbow (3.0.0)
23
+ rake (12.3.3)
24
+ rexml (3.2.4)
25
+ rspec (3.8.0)
26
+ rspec-core (~> 3.8.0)
27
+ rspec-expectations (~> 3.8.0)
28
+ rspec-mocks (~> 3.8.0)
29
+ rspec-core (3.8.2)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-expectations (3.8.4)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.8.0)
34
+ rspec-mocks (3.8.1)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.8.0)
37
+ rspec-support (3.8.3)
38
+ rubocop (0.82.0)
39
+ jaro_winkler (~> 1.5.1)
40
+ parallel (~> 1.10)
41
+ parser (>= 2.7.0.1)
42
+ rainbow (>= 2.2.2, < 4.0)
43
+ rexml
44
+ ruby-progressbar (~> 1.7)
45
+ unicode-display_width (>= 1.4.0, < 2.0)
46
+ rubocop-rspec (1.39.0)
47
+ rubocop (>= 0.68.1)
48
+ ruby-progressbar (1.10.1)
49
+ unicode-display_width (1.7.0)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ bundler (~> 1.17)
56
+ pry
57
+ rake (~> 12.3.1)
58
+ rspec (~> 3.7)
59
+ rubocop-g2!
60
+
61
+ BUNDLED WITH
62
+ 1.17.3
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # rubocop-g2
2
+
3
+ This repo contains custom rubocop rules for G2.
4
+
5
+ A good starting point for writing a custom parser is the `ruby-parse` command. This parses a snippet of ruby code with the same parser that rubocop ultimately uses to analyze code.
6
+
7
+ For example, `ruby-parse -e "class Foo < Draper; end"` returns
8
+ ```
9
+ (class
10
+ (const nil :Foo)
11
+ (const nil :Draper) nil)
12
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,20 @@
1
+ Rails:
2
+ Enabled: true
3
+
4
+ Rails/DynamicFindBy:
5
+ Whitelist:
6
+ - find_by_sql
7
+ - find_by_friendly_id
8
+
9
+ Rails/FilePath:
10
+ EnforcedStyle: slashes
11
+
12
+ Rails/SkipsModelValidations:
13
+ Enabled: false
14
+
15
+ Rails/UnknownEnv:
16
+ Environments:
17
+ - production
18
+ - test
19
+ - development
20
+ - staging
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ RSpec:
3
+ Patterns:
4
+ - '_spec.rb$'
5
+
6
+ Lint/Void:
7
+ Enabled: false
8
+
9
+ RSpec/LetSetup:
10
+ Enabled: false
11
+
12
+ RSpec/NestedGroups:
13
+ Max: 6
@@ -0,0 +1,96 @@
1
+ Layout/SpaceAroundMethodCallOperator:
2
+ Enabled: false
3
+
4
+ Layout/SpaceBeforeFirstArg:
5
+ Enabled: false
6
+
7
+ Layout/MultilineOperationIndentation:
8
+ Enabled: false
9
+
10
+ Layout/ClassStructure:
11
+ Enabled: true
12
+
13
+ Layout/MultilineMethodCallIndentation:
14
+ EnforcedStyle: indented_relative_to_receiver
15
+
16
+ Layout/EmptyLineAfterGuardClause:
17
+ Enabled: false
18
+
19
+ Layout/LineLength:
20
+ Max: 120
21
+ IgnoredPatterns:
22
+ - ^#
23
+
24
+ Lint/AssignmentInCondition:
25
+ Enabled: false
26
+
27
+ Lint/RaiseException:
28
+ Enabled: true
29
+
30
+ Lint/StructNewOverride:
31
+ Enabled: true
32
+
33
+ Metrics/AbcSize:
34
+ Max: 20
35
+
36
+ Metrics/BlockLength:
37
+ Enabled: false
38
+
39
+ Metrics/ClassLength:
40
+ Max: 500
41
+
42
+ Metrics/MethodLength:
43
+ Max: 15
44
+
45
+ Metrics/ParameterLists:
46
+ Max: 5
47
+
48
+ Style/AndOr:
49
+ Enabled: false
50
+
51
+ Style/ClassAndModuleChildren:
52
+ AutoCorrect: true
53
+
54
+ Style/EmptyMethod:
55
+ Enabled: false
56
+
57
+ Style/ExponentialNotation:
58
+ Enabled: false
59
+
60
+ Style/FormatStringToken:
61
+ EnforcedStyle: template
62
+
63
+ Style/FrozenStringLiteralComment:
64
+ Enabled: false
65
+
66
+ Style/HashEachMethods:
67
+ Enabled: true
68
+
69
+ Style/HashTransformKeys:
70
+ Enabled: false
71
+
72
+ Style/HashTransformValues:
73
+ Enabled: false
74
+
75
+ Style/Lambda:
76
+ Enabled: false
77
+
78
+ Style/LambdaCall:
79
+ Enabled: false
80
+
81
+ Style/NumericLiterals:
82
+ Enabled: false
83
+
84
+ Style/PercentLiteralDelimiters:
85
+ PreferredDelimiters:
86
+ default: ()
87
+ '%w': '()'
88
+ '%W': '()'
89
+ '%i': '()'
90
+ '%I': '()'
91
+
92
+ Style/SingleLineBlockParams:
93
+ Enabled: false
94
+
95
+ Style/SymbolProc:
96
+ Enabled: false
@@ -0,0 +1,38 @@
1
+ module RuboCop
2
+ module Cop
3
+ module G2
4
+ class AggregatesModelBoundary < RuboCop::Cop::Cop
5
+ MSG = 'Do not directly reference an aggregate model outside of the aggregates engine. You should do all CRUD'\
6
+ ' operations through new or existing service objects in the engine.'.freeze
7
+
8
+ AGGREGATE_MODELS = %w(
9
+ :AnswerAggregateValue
10
+ :AnswerAggregateDistribution
11
+ :ReportQuarterAnswerAggregateValue
12
+ :ReportQuarterAnswerAggregateDistribution
13
+ :HighestRatedAnswerAggregate
14
+ :HighestRatedAnswerAggregateDistribution
15
+ ).freeze
16
+
17
+ AGGREGATES_ENGINE_PATH = 'engines/aggregates'.freeze
18
+ SPEC_PATH = 'spec'.freeze
19
+
20
+ def_node_matcher :direct_model_reference?, <<~PATTERN
21
+ (const (const _ :Aggregates) {#{AGGREGATE_MODELS.join(' ')}})
22
+ PATTERN
23
+
24
+ def on_const(node)
25
+ return if ignored_file?
26
+ add_offense(node, location: :expression) if direct_model_reference?(node)
27
+ end
28
+
29
+ private
30
+
31
+ def ignored_file?
32
+ file_path = processed_source.path || ''
33
+ file_path.include?(AGGREGATES_ENGINE_PATH) || file_path.include?(SPEC_PATH)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,29 @@
1
+ module RuboCop
2
+ module Cop
3
+ module G2
4
+ class BanDecorators < RuboCop::Cop::Cop
5
+ MSG = 'Please avoid creating new Draper decorators or extending existing decorators.'.freeze
6
+
7
+ DECORATOR_CLASSES = %w(Draper::Decorator).freeze
8
+
9
+ def on_class(node)
10
+ parent_class = full_class_name(node)
11
+ add_offense(node, location: :expression) if DECORATOR_CLASSES.include?(parent_class)
12
+ end
13
+
14
+ private
15
+
16
+ def full_class_name(node)
17
+ parent_class = node.parent_class
18
+ return if parent_class.nil?
19
+
20
+ modules = [parent_class.children[1].to_s]
21
+ parent_class.each_descendant do |desc|
22
+ modules << desc.children[1].to_s
23
+ end
24
+ modules.reverse.join('::')
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ module RuboCop
2
+ module Cop
3
+ module G2
4
+ class PredicateMemoization < RuboCop::Cop::Cop
5
+ MSG = 'Do not use `@foo ||= bar` to memoize predicate methods, since `false` or `nil` return values will not'\
6
+ ' be memoized with this approach.'.freeze
7
+
8
+ def on_def(node)
9
+ return unless predicate_method?(node)
10
+
11
+ offending_nodes(node).each do |offender|
12
+ add_offense(offender, location: :expression)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def predicate_method?(node)
19
+ node.method_name.to_s.end_with?('?')
20
+ end
21
+
22
+ def offending_nodes(node)
23
+ node.each_descendant(:or_asgn).select do |or_assignment|
24
+ instance_var_assignment?(or_assignment)
25
+ end
26
+ end
27
+
28
+ def instance_var_assignment?(assignment)
29
+ assignment.children.first.type == :ivasgn
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ module RuboCop
2
+ module Cop
3
+ module G2
4
+ class RawConnectionExecute < RuboCop::Cop::Cop
5
+ MSG = 'The result returned by this statement is manually memory managed. Please use one of the'\
6
+ ' exec_query/exec_update/exec_insert/exec_delete wrappers instead.'.freeze
7
+
8
+ def_node_matcher :raw_connection_execute?, <<~PATTERN
9
+ (send (send _ :connection) :execute _)
10
+ PATTERN
11
+
12
+ def on_send(node)
13
+ return unless raw_connection_execute?(node)
14
+ add_offense(node)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module RuboCop
2
+ module G2
3
+ VERSION = '1.0.0'.freeze
4
+ end
5
+ end
data/lib/rubocop-g2.rb ADDED
@@ -0,0 +1,3 @@
1
+ # rubocop:disable Naming/FileName
2
+ require 'rubocop_g2'
3
+ # rubocop:enable Naming/FileName
data/lib/rubocop_g2.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubocop'
2
+
3
+ require_relative 'rubocop/g2/version'
4
+ require_relative 'rubocop/cop/g2/ban_decorators'
5
+ require_relative 'rubocop/cop/g2/predicate_memoization'
6
+ require_relative 'rubocop/cop/g2/raw_connection_execute'
7
+ require_relative 'rubocop/cop/g2/aggregates_model_boundary'
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rubocop/g2/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rubocop-g2'
7
+ spec.version = RuboCop::G2::VERSION
8
+ spec.authors = ['Paul Mannino']
9
+ spec.email = ['pmannino@g2.com']
10
+
11
+ spec.summary = 'Custom cops for G2.'
12
+ spec.homepage = 'https://g2.com'
13
+
14
+ # Specify which files should be added to the gem when it is released.
15
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'rubocop', '0.82.0'
24
+ spec.add_dependency 'rubocop-rspec', '1.39.0'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.17'
27
+ spec.add_development_dependency 'pry'
28
+ spec.add_development_dependency 'rake', '~> 12.3.1'
29
+ spec.add_development_dependency 'rspec', '~> 3.7'
30
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-g2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Mannino
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-08 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.82.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.82.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop-rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.39.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.39.0
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.17'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 12.3.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 12.3.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.7'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.7'
97
+ description:
98
+ email:
99
+ - pmannino@g2.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rubocop.yml"
106
+ - ".tool-versions"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - README.md
110
+ - Rakefile
111
+ - config/rails/default.yml
112
+ - config/rspec/default.yml
113
+ - config/ruby/default.yml
114
+ - lib/rubocop-g2.rb
115
+ - lib/rubocop/cop/g2/aggregates_model_boundary.rb
116
+ - lib/rubocop/cop/g2/ban_decorators.rb
117
+ - lib/rubocop/cop/g2/predicate_memoization.rb
118
+ - lib/rubocop/cop/g2/raw_connection_execute.rb
119
+ - lib/rubocop/g2/version.rb
120
+ - lib/rubocop_g2.rb
121
+ - rubocop-g2.gemspec
122
+ homepage: https://g2.com
123
+ licenses: []
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubygems_version: 3.0.3
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Custom cops for G2.
144
+ test_files: []