rubocop-highlands 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.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +2 -0
  3. data/Gemfile +7 -0
  4. data/LICENSE.md +9 -0
  5. data/README.md +68 -0
  6. data/config/default.yml +39 -0
  7. data/config/rubocop-bundler.yml +8 -0
  8. data/config/rubocop-gemspec.yml +9 -0
  9. data/config/rubocop-highlands.yml +100 -0
  10. data/config/rubocop-layout.yml +560 -0
  11. data/config/rubocop-lint.yml +301 -0
  12. data/config/rubocop-metrics.yml +47 -0
  13. data/config/rubocop-naming.yml +85 -0
  14. data/config/rubocop-performance.yml +141 -0
  15. data/config/rubocop-rails.yml +208 -0
  16. data/config/rubocop-rspec.yml +331 -0
  17. data/config/rubocop-security.yml +17 -0
  18. data/config/rubocop-style.yml +983 -0
  19. data/lib/rubocop-highlands.rb +11 -0
  20. data/lib/rubocop/cop/highlands/class_name.rb +47 -0
  21. data/lib/rubocop/cop/highlands/class_or_module_declared_in_wrong_file.rb +138 -0
  22. data/lib/rubocop/cop/highlands/const_assigned_in_wrong_file.rb +74 -0
  23. data/lib/rubocop/cop/highlands/continuation_slash.rb +25 -0
  24. data/lib/rubocop/cop/highlands/default_scope.rb +20 -0
  25. data/lib/rubocop/cop/highlands/factory_attr_references_class.rb +74 -0
  26. data/lib/rubocop/cop/highlands/factory_class_use_string.rb +39 -0
  27. data/lib/rubocop/cop/highlands/mass_assignment_accessible_modifier.rb +18 -0
  28. data/lib/rubocop/cop/highlands/module_method_in_wrong_file.rb +104 -0
  29. data/lib/rubocop/cop/highlands/no_timeout.rb +19 -0
  30. data/lib/rubocop/cop/highlands/opt_arg_parameters.rb +38 -0
  31. data/lib/rubocop/cop/highlands/phrase_bundle_keys.rb +67 -0
  32. data/lib/rubocop/cop/highlands/risky_activerecord_invocation.rb +63 -0
  33. data/lib/rubocop/cop/highlands/rspec_describe_or_context_under_namespace.rb +114 -0
  34. data/lib/rubocop/cop/highlands/rspec_environment_modification.rb +58 -0
  35. data/lib/rubocop/cop/highlands/simple_modifier_conditional.rb +23 -0
  36. data/lib/rubocop/cop/highlands/simple_unless.rb +19 -0
  37. data/lib/rubocop/cop/highlands/spec_constant_assignment.rb +55 -0
  38. data/lib/rubocop/cop/highlands/unsafe_yaml_marshal.rb +47 -0
  39. data/lib/rubocop/highlands.rb +16 -0
  40. data/lib/rubocop/highlands/inflections.rb +14 -0
  41. data/lib/rubocop/highlands/inject.rb +20 -0
  42. data/lib/rubocop/highlands/rails_autoloading.rb +55 -0
  43. data/lib/rubocop/highlands/version.rb +8 -0
  44. data/rubocop-highlands.gemspec +31 -0
  45. data/spec/rubocop/cop/highlands/class_name_spec.rb +78 -0
  46. data/spec/rubocop/cop/highlands/class_or_module_declared_in_wrong_file_spec.rb +174 -0
  47. data/spec/rubocop/cop/highlands/const_assigned_in_wrong_file_spec.rb +178 -0
  48. data/spec/rubocop/cop/highlands/continuation_slash_spec.rb +162 -0
  49. data/spec/rubocop/cop/highlands/default_scope_spec.rb +38 -0
  50. data/spec/rubocop/cop/highlands/factory_attr_references_class_spec.rb +160 -0
  51. data/spec/rubocop/cop/highlands/factory_class_use_string_spec.rb +26 -0
  52. data/spec/rubocop/cop/highlands/mass_assignment_accessible_modifier_spec.rb +28 -0
  53. data/spec/rubocop/cop/highlands/module_method_in_wrong_file_spec.rb +181 -0
  54. data/spec/rubocop/cop/highlands/no_timeout_spec.rb +30 -0
  55. data/spec/rubocop/cop/highlands/opt_arg_parameter_spec.rb +103 -0
  56. data/spec/rubocop/cop/highlands/phrase_bundle_keys_spec.rb +74 -0
  57. data/spec/rubocop/cop/highlands/risky_activerecord_invocation_spec.rb +54 -0
  58. data/spec/rubocop/cop/highlands/rspec_describe_or_context_under_namespace_spec.rb +284 -0
  59. data/spec/rubocop/cop/highlands/rspec_environment_modification_spec.rb +64 -0
  60. data/spec/rubocop/cop/highlands/simple_modifier_conditional_spec.rb +122 -0
  61. data/spec/rubocop/cop/highlands/simple_unless_spec.rb +36 -0
  62. data/spec/rubocop/cop/highlands/spec_constant_assignment_spec.rb +80 -0
  63. data/spec/rubocop/cop/highlands/unsafe_yaml_marshal_spec.rb +50 -0
  64. data/spec/spec_helper.rb +35 -0
  65. metadata +151 -0
@@ -0,0 +1,36 @@
1
+ describe RuboCop::Cop::Highlands::SimpleUnless do
2
+ subject(:cop) { described_class.new }
3
+
4
+ it 'rejects unless with multiple conditionals' do
5
+ source = [
6
+ 'unless boolean_condition || another_method',
7
+ ' return true',
8
+ 'end',
9
+ ].join("\n")
10
+
11
+ inspect_source(source)
12
+ expect(cop.offenses.size).to eq(1)
13
+ end
14
+
15
+ it 'allows if with multiple conditionals' do
16
+ source = [
17
+ 'if boolean_condition || another_method',
18
+ ' return true',
19
+ 'end',
20
+ ].join("\n")
21
+
22
+ inspect_source(source)
23
+ expect(cop.offenses).to be_empty
24
+ end
25
+
26
+ it 'allows with modifier if operator conditional' do
27
+ source = [
28
+ 'unless boolean_condition',
29
+ ' return true',
30
+ 'end',
31
+ ].join("\n")
32
+
33
+ inspect_source(source)
34
+ expect(cop.offenses).to be_empty
35
+ end
36
+ end
@@ -0,0 +1,80 @@
1
+ describe RuboCop::Cop::Highlands::SpecConstantAssignment do
2
+ subject(:cop) { described_class.new }
3
+
4
+ it 'rejects constant definition inside of a describe block' do
5
+ source = [
6
+ 'describe Someclass do',
7
+ ' CONSTANT = 5',
8
+ 'end',
9
+ ].join("\n")
10
+
11
+ inspect_source(source)
12
+ expect(cop.offenses.size).to eq(1)
13
+ end
14
+
15
+ it 'allows constant defined inside of a module' do
16
+ source = [
17
+ 'module Someclass',
18
+ ' CONSTANT = 5',
19
+ 'end',
20
+ ].join("\n")
21
+
22
+ inspect_source(source)
23
+ expect(cop.offenses).to be_empty
24
+ end
25
+
26
+ it 'allows constant defined in global space' do
27
+ source = [
28
+ 'CONSTANT = 5',
29
+ ].join("\n")
30
+
31
+ inspect_source(source)
32
+ expect(cop.offenses.size).to eq(1)
33
+ end
34
+
35
+ it 'rejects constant assignment inside a before block' do
36
+ source = [
37
+ 'describe Someclass do',
38
+ ' before { CONSTANT = 5 }',
39
+ 'end',
40
+ ].join("\n")
41
+
42
+ inspect_source(source)
43
+ expect(cop.offenses.size).to eq(1)
44
+ end
45
+
46
+ it 'rejects namespaced constant assignment inside a before block' do
47
+ source = [
48
+ 'describe Someclass do',
49
+ ' before { MyModule::CONSTANT = 5 }',
50
+ 'end',
51
+ ].join("\n")
52
+
53
+ inspect_source(source)
54
+ expect(cop.offenses.size).to eq(1)
55
+ end
56
+
57
+ it 'rejects constant assignment inside it block' do
58
+ source = [
59
+ 'describe Someclass do',
60
+ ' it "tests stuff" do',
61
+ ' CONSTANT = 5',
62
+ ' end',
63
+ 'end',
64
+ ].join("\n")
65
+
66
+ inspect_source(source)
67
+ expect(cop.offenses.size).to eq(1)
68
+ end
69
+
70
+ it 'allows let statements that do not assign constants' do
71
+ source = [
72
+ 'describe Someclass do',
73
+ ' let(:constant) { 5 }',
74
+ 'end',
75
+ ].join("\n")
76
+
77
+ inspect_source(source)
78
+ expect(cop.offenses).to be_empty
79
+ end
80
+ end
@@ -0,0 +1,50 @@
1
+ describe RuboCop::Cop::Highlands::UnsafeYamlMarshal do
2
+ subject(:cop) { described_class.new }
3
+
4
+ context 'send' do
5
+ it 'rejects YAML.load' do
6
+ source = [
7
+ 'def some_method(a)',
8
+ ' YAML.load(a)',
9
+ 'end',
10
+ ].join("\n")
11
+ inspect_source(source)
12
+ expect(cop.offenses.size).to eql(1)
13
+ expect(cop.offenses.first.message).to match(/`safe_load`, `parse`, `parse_file`/)
14
+ end
15
+
16
+ it 'rejects Psych.load' do
17
+ source = [
18
+ 'def some_method(a)',
19
+ ' Psych.load(a)',
20
+ 'end',
21
+ ].join("\n")
22
+ inspect_source(source)
23
+ expect(cop.offenses.size).to eql(1)
24
+ expect(cop.offenses.first.message).to match(/`safe_load`, `parse`, `parse_file`/)
25
+ end
26
+
27
+ it 'accepts YAML.safe_load' do
28
+ source = [
29
+ 'def some_method(a)',
30
+ ' YAML.safe_load(a)',
31
+ 'end',
32
+ ].join("\n")
33
+ inspect_source(source)
34
+ expect(cop.offenses.size).to eql(0)
35
+ end
36
+
37
+ it 'rejects on Marshal.load' do
38
+ source = [
39
+ 'def some_method(a)',
40
+ ' Marshal.load(a)',
41
+ 'end',
42
+ ].join("\n")
43
+ inspect_source(source)
44
+ expect(cop.offenses.size).to eql(1)
45
+ expect(cop.offenses.first.message).to match(
46
+ /`Marshal.load` on untrusted input can lead to remote code execution/
47
+ )
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,35 @@
1
+ require 'rubocop'
2
+ require 'rubocop/rspec/support'
3
+ require 'pry'
4
+
5
+ module SpecHelper
6
+ ROOT = Pathname.new(__FILE__).parent.freeze
7
+ end
8
+
9
+ # Load in Rubocop cops
10
+ require File.expand_path('lib/rubocop-highlands')
11
+
12
+ spec_helper_glob = File.expand_path('{support,shared}/*.rb', SpecHelper::ROOT)
13
+ Dir.glob(spec_helper_glob).map(&method(:require))
14
+
15
+ RSpec.configure do |config|
16
+ config.order = :random
17
+
18
+ # Define spec metadata for all rspec cop spec files
19
+ cop_specs = 'spec/rubocop/cop/rspec/'
20
+ config.define_derived_metadata(file_path: /\b#{cop_specs}/) do |metadata|
21
+ # Attach metadata that signals the specified code is for an RSpec only cop
22
+ metadata[:rspec_cop] = true
23
+ end
24
+
25
+ config.expect_with :rspec do |expectations|
26
+ expectations.syntax = :expect # Disable `should`
27
+ end
28
+
29
+ config.mock_with :rspec do |mocks|
30
+ mocks.syntax = :expect # Disable `should_receive` and `stub`
31
+ end
32
+ end
33
+
34
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
35
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-highlands
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Church of the Highlands - Digital Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-21 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.58.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.58.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.30.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.30.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ description: |2
56
+ A plugin for RuboCop code style enforcing & linting tool. It includes Rubocop configuration
57
+ used at Church of the Highlands and a few custom rules that have caused internal issues at
58
+ Church of the Highlands but are not supported by core Rubocop.
59
+ email:
60
+ - info@churchofthehighlands.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - CHANGELOG.md
66
+ - Gemfile
67
+ - LICENSE.md
68
+ - README.md
69
+ - config/default.yml
70
+ - config/rubocop-bundler.yml
71
+ - config/rubocop-gemspec.yml
72
+ - config/rubocop-highlands.yml
73
+ - config/rubocop-layout.yml
74
+ - config/rubocop-lint.yml
75
+ - config/rubocop-metrics.yml
76
+ - config/rubocop-naming.yml
77
+ - config/rubocop-performance.yml
78
+ - config/rubocop-rails.yml
79
+ - config/rubocop-rspec.yml
80
+ - config/rubocop-security.yml
81
+ - config/rubocop-style.yml
82
+ - lib/rubocop-highlands.rb
83
+ - lib/rubocop/cop/highlands/class_name.rb
84
+ - lib/rubocop/cop/highlands/class_or_module_declared_in_wrong_file.rb
85
+ - lib/rubocop/cop/highlands/const_assigned_in_wrong_file.rb
86
+ - lib/rubocop/cop/highlands/continuation_slash.rb
87
+ - lib/rubocop/cop/highlands/default_scope.rb
88
+ - lib/rubocop/cop/highlands/factory_attr_references_class.rb
89
+ - lib/rubocop/cop/highlands/factory_class_use_string.rb
90
+ - lib/rubocop/cop/highlands/mass_assignment_accessible_modifier.rb
91
+ - lib/rubocop/cop/highlands/module_method_in_wrong_file.rb
92
+ - lib/rubocop/cop/highlands/no_timeout.rb
93
+ - lib/rubocop/cop/highlands/opt_arg_parameters.rb
94
+ - lib/rubocop/cop/highlands/phrase_bundle_keys.rb
95
+ - lib/rubocop/cop/highlands/risky_activerecord_invocation.rb
96
+ - lib/rubocop/cop/highlands/rspec_describe_or_context_under_namespace.rb
97
+ - lib/rubocop/cop/highlands/rspec_environment_modification.rb
98
+ - lib/rubocop/cop/highlands/simple_modifier_conditional.rb
99
+ - lib/rubocop/cop/highlands/simple_unless.rb
100
+ - lib/rubocop/cop/highlands/spec_constant_assignment.rb
101
+ - lib/rubocop/cop/highlands/unsafe_yaml_marshal.rb
102
+ - lib/rubocop/highlands.rb
103
+ - lib/rubocop/highlands/inflections.rb
104
+ - lib/rubocop/highlands/inject.rb
105
+ - lib/rubocop/highlands/rails_autoloading.rb
106
+ - lib/rubocop/highlands/version.rb
107
+ - rubocop-highlands.gemspec
108
+ - spec/rubocop/cop/highlands/class_name_spec.rb
109
+ - spec/rubocop/cop/highlands/class_or_module_declared_in_wrong_file_spec.rb
110
+ - spec/rubocop/cop/highlands/const_assigned_in_wrong_file_spec.rb
111
+ - spec/rubocop/cop/highlands/continuation_slash_spec.rb
112
+ - spec/rubocop/cop/highlands/default_scope_spec.rb
113
+ - spec/rubocop/cop/highlands/factory_attr_references_class_spec.rb
114
+ - spec/rubocop/cop/highlands/factory_class_use_string_spec.rb
115
+ - spec/rubocop/cop/highlands/mass_assignment_accessible_modifier_spec.rb
116
+ - spec/rubocop/cop/highlands/module_method_in_wrong_file_spec.rb
117
+ - spec/rubocop/cop/highlands/no_timeout_spec.rb
118
+ - spec/rubocop/cop/highlands/opt_arg_parameter_spec.rb
119
+ - spec/rubocop/cop/highlands/phrase_bundle_keys_spec.rb
120
+ - spec/rubocop/cop/highlands/risky_activerecord_invocation_spec.rb
121
+ - spec/rubocop/cop/highlands/rspec_describe_or_context_under_namespace_spec.rb
122
+ - spec/rubocop/cop/highlands/rspec_environment_modification_spec.rb
123
+ - spec/rubocop/cop/highlands/simple_modifier_conditional_spec.rb
124
+ - spec/rubocop/cop/highlands/simple_unless_spec.rb
125
+ - spec/rubocop/cop/highlands/spec_constant_assignment_spec.rb
126
+ - spec/rubocop/cop/highlands/unsafe_yaml_marshal_spec.rb
127
+ - spec/spec_helper.rb
128
+ homepage: https://github.com/highlands/ruby
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '2.1'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubygems_version: 3.0.2
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Custom code style checking for Church of the Highlands.
151
+ test_files: []