rubocop-codeur 0.1.17 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec07747657e67f2e0133b7269c2b16f6e8365c34caef55aadc1c223cdd64dc8e
4
- data.tar.gz: 0f6d3187ff80bdd57013cbbee7a2583717de175e883b0968aff6608dfbebcdcf
3
+ metadata.gz: a60feca05023297b1988220f28f2f32f21525e2adc8c8601ba76f1487f5fd128
4
+ data.tar.gz: 58ec678e02c4f4bbf04698ea2dc2365e293d3f9114c8f65205da7e52c24181a4
5
5
  SHA512:
6
- metadata.gz: eebfcbb1e3f9c0c4c94ba9e1971c045195a093e653cfef449092bcb54a442d159285a79bca3e92a5c0823f6af0638deac29bec67b117503ec4099b796663d38a
7
- data.tar.gz: 1de8aeb5c7a4e30d924a2fd3c1758f677740af7975cd78381b326c93285ec4d66b47eb2bcfdd5b84766fde0fb204f44c67e258f9ffe88a5e85b1c4faa356cd79
6
+ metadata.gz: 4c1485ebe523b7e4d3f9d03c1ef3faf149cd652218f44fac0e6e2829f6a66f92405c5a88448346b2d189d621720675e361b4e77b69b4e2ae49fd93990fc271e0
7
+ data.tar.gz: bab88e2804dabb3b9212a49aa609ff33f125c4f823b0639fcb7154460913ca86a0b744892ef7ec66c47a7a868648f060d5046dce2aba297fff6267100f9ac422
@@ -0,0 +1,34 @@
1
+ name: Quality audit
2
+
3
+ on: [pull_request]
4
+
5
+ jobs:
6
+ rubocop:
7
+ name: rubocop
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - name: Check out code
11
+ uses: actions/checkout@v1
12
+ - uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: 2.7
15
+ bundler-cache: true
16
+ - name: Run Rubocop
17
+ uses: reviewdog/action-rubocop@v1
18
+ with:
19
+ github_token: ${{ secrets.github_token }}
20
+ rubocop_version: gemfile
21
+ reporter: github-pr-check
22
+
23
+ brakeman:
24
+ name: brakeman
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - name: Check out code
28
+ uses: actions/checkout@v1
29
+ - name: Run Brakeman
30
+ uses: reviewdog/action-brakeman@v1
31
+ with:
32
+ github_token: ${{ secrets.github_token }}
33
+ brakeman_version: 5.0.4
34
+ reporter: github-pr-check
@@ -0,0 +1,41 @@
1
+ name: Test
2
+
3
+ on: [pull_request]
4
+
5
+ env:
6
+ RAILS_ENV: test
7
+
8
+ jobs:
9
+ test:
10
+
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ ruby: ['2.7', '3.0']
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+
20
+ - name: Set up Ruby ${{ matrix.ruby }}
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler-cache: true
25
+
26
+ - name: Run tests
27
+ run: bin/rake test
28
+ env:
29
+ COVERAGE: true
30
+
31
+ - name: Simplecov Report
32
+ uses: aki77/simplecov-report-action@v1
33
+ with:
34
+ token: ${{ secrets.GITHUB_TOKEN }}
35
+ failedThreshold: 100
36
+
37
+ - name: Upload coverage
38
+ uses: actions/upload-artifact@v1
39
+ with:
40
+ name: Coverage
41
+ path: coverage
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .DS_Store
2
+ /spec/
3
+ /.bundle/
4
+ /.yardoc
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,9 @@
1
+ AllCops:
2
+ NewCops: enable
3
+
4
+ Naming/FileName:
5
+ Exclude:
6
+ - lib/rubocop-codeur.rb
7
+
8
+ Gemspec/RequireMFA:
9
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
+
6
+ # Specify your gem's dependencies in rubocop-codeur.gemspec
7
+ gemspec
8
+
9
+ gem 'minitest', '~> 5.0'
10
+ gem 'rake', '~> 12.0'
11
+ gem 'rubocop-minitest', '~> 0.17'
12
+ gem 'simplecov', require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,79 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubocop-codeur (0.2.2)
5
+ rubocop (~> 1.25)
6
+ rubocop-github (~> 0.17)
7
+ rubocop-minitest (~> 0.10, >= 0.10.2)
8
+ rubocop-performance (~> 1.9, >= 1.9.2)
9
+ rubocop-rails (~> 2.9, >= 2.9.1)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ activesupport (7.0.1)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ tzinfo (~> 2.0)
19
+ ast (2.4.2)
20
+ concurrent-ruby (1.1.9)
21
+ docile (1.4.0)
22
+ i18n (1.9.1)
23
+ concurrent-ruby (~> 1.0)
24
+ minitest (5.15.0)
25
+ parallel (1.21.0)
26
+ parser (3.1.0.0)
27
+ ast (~> 2.4.1)
28
+ rack (2.2.3)
29
+ rainbow (3.1.1)
30
+ rake (12.3.3)
31
+ regexp_parser (2.2.0)
32
+ rexml (3.2.5)
33
+ rubocop (1.25.0)
34
+ parallel (~> 1.10)
35
+ parser (>= 3.1.0.0)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ regexp_parser (>= 1.8, < 3.0)
38
+ rexml
39
+ rubocop-ast (>= 1.15.1, < 2.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 3.0)
42
+ rubocop-ast (1.15.1)
43
+ parser (>= 3.0.1.1)
44
+ rubocop-github (0.17.0)
45
+ rubocop
46
+ rubocop-performance
47
+ rubocop-rails
48
+ rubocop-minitest (0.17.0)
49
+ rubocop (>= 0.90, < 2.0)
50
+ rubocop-performance (1.13.2)
51
+ rubocop (>= 1.7.0, < 2.0)
52
+ rubocop-ast (>= 0.4.0)
53
+ rubocop-rails (2.13.2)
54
+ activesupport (>= 4.2.0)
55
+ rack (>= 1.1)
56
+ rubocop (>= 1.7.0, < 2.0)
57
+ ruby-progressbar (1.11.0)
58
+ simplecov (0.21.2)
59
+ docile (~> 1.1)
60
+ simplecov-html (~> 0.11)
61
+ simplecov_json_formatter (~> 0.1)
62
+ simplecov-html (0.12.3)
63
+ simplecov_json_formatter (0.1.3)
64
+ tzinfo (2.0.4)
65
+ concurrent-ruby (~> 1.0)
66
+ unicode-display_width (2.1.0)
67
+
68
+ PLATFORMS
69
+ ruby
70
+
71
+ DEPENDENCIES
72
+ minitest (~> 5.0)
73
+ rake (~> 12.0)
74
+ rubocop-codeur!
75
+ rubocop-minitest (~> 0.17)
76
+ simplecov
77
+
78
+ BUNDLED WITH
79
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright 2021 Codeur SARL
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.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Rubocop Codeur
1
+ # RuboCop Codeur
2
2
  Shared rubocop config gem for every Ruby projects at Codeur SARL
3
3
 
4
4
  ## Installation
@@ -25,9 +25,12 @@ Then run:
25
25
  `bundle exec rubocop`
26
26
 
27
27
  You don't need to include rubocop directly in your application's dependencies.
28
- `rubocop-codeur` will include `rubocop`, `rubocop-minitest`, `rubocop-performance` and `rubocop-rails` dependencies.
28
+ `rubocop-codeur` will include `rubocop`, `rubocop-github`, `rubocop-minitest`,
29
+ `rubocop-performance` and `rubocop-rails` dependencies.
29
30
 
30
- It might be necessary to override style rules set in this gem for some projects or to add specific ones. Rule inheritance provided by Rubocop works like the following:
31
+ It might be necessary to override style rules set in this gem for some projects
32
+ or to add specific ones. Rule inheritance provided by RuboCop works like the
33
+ following:
31
34
  `inherit_gem → inherit_from → local rules`
32
35
 
33
36
  For example:
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ task default: :test
13
+
14
+ desc 'Generate a new cop with a template'
15
+ task :new_cop, [:cop] do |_task, args|
16
+ require 'rubocop'
17
+
18
+ cop_name = args.fetch(:cop) do
19
+ warn 'usage: bundle exec rake new_cop[Department/Name]'
20
+ exit!
21
+ end
22
+
23
+ generator = RuboCop::Cop::Generator.new(cop_name)
24
+
25
+ generator.write_source
26
+ generator.write_spec
27
+ generator.inject_require(root_file_path: 'lib/rubocop/cop/codeur_cops.rb')
28
+ generator.inject_config(config_file_path: 'config/default.yml')
29
+
30
+ puts generator.todo
31
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'rubocop/codeur'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+
29
+ load Gem.bin_path('rake', 'rake')
data/bin/setup ADDED
@@ -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,13 @@
1
+ Codeur/RailsAppPatterns:
2
+ Description: 'Allows or forbids patterns in app directories'
3
+ Enabled: pending
4
+ VersionAdded: '0.2.0'
5
+ AllowedPatterns: []
6
+ ForbiddenPatterns: []
7
+
8
+ Codeur/RailsAvoidInstanceMethodsInHelpers:
9
+ Description: 'Forbids instance methods in Rails helpers'
10
+ Enabled: pending
11
+ VersionAdded: '0.2.0'
12
+ Include:
13
+ - app/helpers/**/*.rb
data/default.yml CHANGED
@@ -1,8 +1,13 @@
1
1
  require:
2
+ - rubocop-codeur
2
3
  - rubocop-minitest
3
4
  - rubocop-performance
4
5
  - rubocop-rails
5
6
 
7
+ inherit_gem:
8
+ rubocop-github:
9
+ - config/default.yml
10
+
6
11
  AllCops:
7
12
  Exclude:
8
13
  - 'db/schema.rb'
@@ -20,40 +25,143 @@ AllCops:
20
25
  Rails:
21
26
  Enabled: true
22
27
 
28
+ Codeur/RailsAppPatterns:
29
+ Enabled: true
30
+ ForbiddenPatterns:
31
+ - presenters
32
+ - view_objects
33
+ - modules
34
+
35
+ Codeur/RailsAvoidInstanceMethodsInHelpers:
36
+ Enabled: true
37
+
23
38
  Layout/AccessModifierIndentation:
39
+ Enabled: true
24
40
  EnforcedStyle: outdent
25
41
  IndentationWidth: 2
26
42
 
27
43
  Layout/ArgumentAlignment:
44
+ Enabled: true
28
45
  EnforcedStyle: with_first_argument
29
46
 
30
- Lint/DuplicateMethods:
31
- Exclude:
32
- - 'db/migrate/*'
47
+ Layout/ClassStructure:
48
+ Enabled: true
49
+ AutoCorrect: false
50
+ ExpectedOrder:
51
+ - devise
52
+ - module_inclusion
53
+ - constants
54
+ - attributes
55
+ - has_ancestry
56
+ - delegated_type
57
+ - belongs_to
58
+ - has_many
59
+ - has_one
60
+ - attachments
61
+ - public_delegate
62
+ - class_macros
63
+ - callbacks
64
+ - state_machine
65
+ - aasm
66
+ - scope
67
+ - default_scope
68
+ - validations
69
+ - public_class_methods
70
+ - initializer
71
+ - public_methods
72
+ - protected_attribute_macros
73
+ - protected_methods
74
+ - private_attribute_macros
75
+ - private_delegate
76
+ - private_methods
77
+ Categories:
78
+ module_inclusion:
79
+ - include
80
+ - prepend
81
+ - extend
82
+ attachments:
83
+ - has_one_attached
84
+ - has_many_attached
85
+ - has_attached_file
86
+ attributes:
87
+ - attr_accessor
88
+ - attr_reader
89
+ - attr_writer
90
+ - attr_readonly
91
+ - emojify
92
+ - enum
93
+ - monetize
94
+ - serialize
95
+ - has_secure_token
96
+ - alias_attribute
97
+ - slug
98
+ class_macros:
99
+ - acts_as_voter
100
+ - pg_search_scope
101
+ - counter_culture
102
+ - accepts_nested_attributes_for
103
+ - paginates_per
104
+ - ransack_alias
105
+ - ransacker
106
+ - ratyrate_rater
107
+ callbacks:
108
+ - before_validation
109
+ - after_validation
110
+ - before_save
111
+ - around_save
112
+ - before_create
113
+ - around_create
114
+ - before_update
115
+ - around_update
116
+ - before_destroy
117
+ - around_destroy
118
+ - after_destroy
119
+ - after_create
120
+ - after_save
121
+ - after_commit
122
+ - after_rollback
123
+ validations:
124
+ - validates_associated
125
+ - validates
126
+ - validate
33
127
 
34
128
  Layout/FirstArrayElementIndentation:
129
+ Enabled: true
35
130
  EnforcedStyle: consistent
36
131
 
37
132
  Layout/FirstHashElementIndentation:
133
+ Enabled: true
38
134
  EnforcedStyle: consistent
39
135
 
40
136
  Layout/HashAlignment:
137
+ Enabled: true
41
138
  EnforcedHashRocketStyle: table
42
139
  EnforcedColonStyle: table
43
140
 
44
141
  Layout/LineLength:
142
+ Enabled: true
45
143
  Max: 200
46
144
  AutoCorrect: false
47
145
  Exclude:
48
146
  - 'db/migrate/*'
49
147
 
50
148
  Layout/MultilineMethodCallIndentation:
149
+ Enabled: true
51
150
  EnforcedStyle: indented
52
151
 
53
152
  Layout/ParameterAlignment:
153
+ Enabled: true
54
154
  EnforcedStyle: with_fixed_indentation
55
155
  IndentationWidth: 2
56
156
 
157
+ Lint/DuplicateMethods:
158
+ Enabled: true
159
+ Exclude:
160
+ - 'db/migrate/*'
161
+
162
+ Lint/MissingSuper:
163
+ Enabled: false
164
+
57
165
  Lint/RaiseException:
58
166
  Enabled: true
59
167
 
@@ -61,11 +169,13 @@ Lint/StructNewOverride:
61
169
  Enabled: true
62
170
 
63
171
  Metrics/AbcSize:
172
+ Enabled: true
64
173
  Max: 65
65
174
  Exclude:
66
175
  - 'db/migrate/*'
67
176
 
68
177
  Metrics/BlockLength:
178
+ Enabled: true
69
179
  Max: 60
70
180
  Exclude:
71
181
  - 'config/routes.rb'
@@ -73,28 +183,34 @@ Metrics/BlockLength:
73
183
  - 'app/states/*'
74
184
 
75
185
  Metrics/ClassLength:
186
+ Enabled: true
76
187
  Max: 300
77
188
  Exclude:
78
189
  - 'app/models/**/*'
79
190
 
80
191
  Metrics/CyclomaticComplexity:
192
+ Enabled: true
81
193
  Max: 10
82
194
 
83
195
  Metrics/MethodLength:
196
+ Enabled: true
84
197
  Max: 60
85
198
  Exclude:
86
199
  - 'db/migrate/*'
87
200
 
88
201
  Metrics/ModuleLength:
202
+ Enabled: true
89
203
  Max: 300
90
204
 
91
205
  Metrics/PerceivedComplexity:
206
+ Enabled: true
92
207
  Max: 10
93
208
 
94
209
  Minitest/TestMethodName:
95
210
  Enabled: false
96
211
 
97
212
  Minitest/MultipleAssertions:
213
+ Enabled: true
98
214
  Max: 30
99
215
 
100
216
  # Disabled because it doesn't with symbols like: record_001
@@ -105,16 +221,20 @@ Rails/BulkChangeTable:
105
221
  Enabled: false
106
222
 
107
223
  Rails/CreateTableWithTimestamps:
224
+ Enabled: true
108
225
  Exclude:
109
226
  - 'db/migrate/{2012,2013,2014,2015,2016,2017,2018}*.rb'
110
227
 
111
228
  Rails/EnvironmentVariableAccess:
229
+ Enabled: true
112
230
  AllowReads: true
113
231
 
114
232
  Rails/FilePath:
233
+ Enabled: true
115
234
  EnforcedStyle: arguments
116
235
 
117
236
  Rails/ReversibleMigration:
237
+ Enabled: true
118
238
  Exclude:
119
239
  - 'db/migrate/{2012,2013,2014,2015,2016,2017,2018}*.rb'
120
240
 
@@ -132,6 +252,7 @@ Rails/TimeZone:
132
252
  AutoCorrect: false
133
253
 
134
254
  Rails/UnknownEnv:
255
+ Enabled: true
135
256
  Environments:
136
257
  - development
137
258
  - test
@@ -142,6 +263,7 @@ Style/AsciiComments:
142
263
  Enabled: false
143
264
 
144
265
  Style/ClassAndModuleChildren:
266
+ Enabled: true
145
267
  AutoCorrect: true
146
268
 
147
269
  Style/ConditionalAssignment:
@@ -151,15 +273,21 @@ Style/Documentation:
151
273
  Enabled: false
152
274
 
153
275
  Style/EmptyMethod:
276
+ Enabled: true
154
277
  EnforcedStyle: expanded
155
278
 
156
279
  Style/GuardClause:
280
+ Enabled: true
157
281
  MinBodyLength: 3
158
282
 
159
283
  Style/HashEachMethods:
160
284
  Enabled: true
161
285
  AutoCorrect: true
162
286
 
287
+ Style/HashSyntax:
288
+ Enabled: true
289
+ EnforcedStyle: ruby19
290
+
163
291
  Style/HashTransformKeys:
164
292
  Enabled: true
165
293
  AutoCorrect: true
@@ -180,7 +308,12 @@ Style/NestedTernaryOperator:
180
308
  Style/NumericPredicate:
181
309
  Enabled: false
182
310
 
311
+ Style/StringLiterals:
312
+ Enabled: true
313
+ EnforcedStyle: single_quotes
314
+
183
315
  Style/SymbolArray:
316
+ Enabled: true
184
317
  MinSize: 7
185
318
 
186
319
  Style/FormatStringToken:
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The original code is from https://github.com/rubocop/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
4
+ # See https://github.com/rubocop/rubocop-rspec/blob/master/MIT-LICENSE.md
5
+ module RuboCop
6
+ module Codeur
7
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
8
+ # bit of our configuration.
9
+ module Inject
10
+ def self.defaults!
11
+ path = CONFIG_DEFAULT.to_s
12
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
13
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
14
+ puts "configuration from #{path}" if ConfigLoader.debug?
15
+ config = ConfigLoader.merge_with_default(config, path)
16
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Codeur
5
+ VERSION = '0.2.2'
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop/codeur/version'
4
+ require 'yaml'
5
+
6
+ module RuboCop
7
+ # RuboCop Codeur project namespace
8
+ module Codeur
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
12
+ CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
13
+ CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
14
+
15
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
16
+ end
17
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Codeur
6
+ # This cop makes sure that Rails app only uses patterns (app subdirectories)
7
+ # defined in Cop config.
8
+ #
9
+ # @example ForbiddenPatterns: [presenters, view_objects, uploaders, modules]
10
+ # # bad
11
+ # app/presenters/order_presenter.rb
12
+ #
13
+ # # bad
14
+ # app/modules/stuffy.rb
15
+ #
16
+ # # good
17
+ # app/view_components/order_component.rb
18
+ #
19
+ # # good
20
+ # app/models/concerns/stuffy.rb
21
+ #
22
+ # @example AllowedPatterns: [assets, controllers, javascript, jobs, mailers, models, views]
23
+ # # bad
24
+ # app/controller/some_controller.rb
25
+ #
26
+ # # good
27
+ # app/controllers/some_controller.rb
28
+ #
29
+ class RailsAppPatterns < Base
30
+ MSG_FORBIDDEN = '`%<pattern>s` are forbidden.'
31
+ MSG_NOT_ALLOWED = '`%<pattern>s` are not allowed. Allowed patterns are: %<allowed_patterns>s.'
32
+
33
+ def on_new_investigation
34
+ file_path = processed_source.file_path
35
+ return if config.file_to_exclude?(file_path)
36
+
37
+ for_bad_patterns(file_path) { |msg| add_global_offense(msg, severity: :warning) }
38
+ end
39
+
40
+ private
41
+
42
+ def for_bad_patterns(file_path)
43
+ pattern = pattern_from_path(file_path)
44
+ return if pattern.nil?
45
+
46
+ if pattern_forbidden?(pattern)
47
+ msg = format(MSG_FORBIDDEN, pattern: pattern)
48
+ elsif pattern_not_allowed?(pattern)
49
+ msg = format(MSG_NOT_ALLOWED,
50
+ pattern: pattern,
51
+ allowed_patterns: allowed_patterns.map { |p| "`#{p}`" }.join(', '))
52
+ end
53
+
54
+ yield msg if msg
55
+ end
56
+
57
+ def pattern_from_path(path)
58
+ return nil unless path.match(%r{/app/(?<pattern>.+)/.+})
59
+
60
+ Regexp.last_match(:pattern)
61
+ end
62
+
63
+ def pattern_forbidden?(pattern)
64
+ forbidden_patterns.any? && forbidden_patterns.include?(pattern)
65
+ end
66
+
67
+ def pattern_not_allowed?(pattern)
68
+ allowed_patterns.any? && !allowed_patterns.include?(pattern)
69
+ end
70
+
71
+ def allowed_patterns
72
+ cop_config['AllowedPatterns'] || []
73
+ end
74
+
75
+ def forbidden_patterns
76
+ cop_config['ForbiddenPatterns'] || []
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Codeur
6
+ # This cop makes sure that Rails helpers only uses class methods in order
7
+ # to be able to use them in the test, views or from anywhere else.
8
+ # ApplicationHelper is excluded from this rule by default.
9
+ #
10
+ # @example
11
+ # # bad
12
+ # module CoolHelper
13
+ # def foobar
14
+ # # ...
15
+ # end
16
+ # end
17
+ #
18
+ # # good
19
+ # module CoolHelper
20
+ # def self.foobar
21
+ # # ...
22
+ # end
23
+ # end
24
+ #
25
+ class RailsAvoidInstanceMethodsInHelpers < Base
26
+ MSG = 'Prefer class methods in helpers.'
27
+
28
+ def on_def(node)
29
+ # NOTE: :sclass node is a "class << self" node
30
+ return if node.parent.sclass_type?
31
+
32
+ add_offense(node)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'codeur/rails_app_patterns'
4
+ require_relative 'codeur/rails_avoid_instance_methods_in_helpers'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ require_relative 'rubocop/codeur'
6
+ require_relative 'rubocop/codeur/version'
7
+ require_relative 'rubocop/codeur/inject'
8
+
9
+ RuboCop::Codeur::Inject.defaults!
10
+
11
+ require_relative 'rubocop/cop/codeur_cops'
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/rubocop/codeur/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rubocop-codeur'
7
+ spec.version = RuboCop::Codeur::VERSION
8
+ spec.authors = ['Codeur']
9
+ spec.email = ['dev@codeur.com']
10
+
11
+ spec.summary = 'Codeur rubocop config gem'
12
+ spec.description = 'Shared rubocop config gem for every Ruby projects at Codeur SARL'
13
+ spec.homepage = 'https://github.com/codeur/rubocop-codeur'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+
23
+ spec.add_dependency 'rubocop', '~> 1.25'
24
+ spec.add_dependency 'rubocop-github', '~> 0.17'
25
+ spec.add_dependency 'rubocop-minitest', '~> 0.10', '>=0.10.2'
26
+ spec.add_dependency 'rubocop-performance', '~> 1.9', '>= 1.9.2'
27
+ spec.add_dependency 'rubocop-rails', '~> 2.9', '>= 2.9.1'
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-codeur
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.17
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
- - Dev-team Codeur
7
+ - Codeur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-08 00:00:00.000000000 Z
11
+ date: 2022-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.9.1
19
+ version: '1.25'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.9.1
26
+ version: '1.25'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop-github
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.17'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.17'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rubocop-minitest
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -91,25 +105,41 @@ executables: []
91
105
  extensions: []
92
106
  extra_rdoc_files: []
93
107
  files:
94
- - MIT-LICENSE
108
+ - ".github/workflows/quality.yml"
109
+ - ".github/workflows/test.yml"
110
+ - ".gitignore"
111
+ - ".rubocop.yml"
112
+ - Gemfile
113
+ - Gemfile.lock
114
+ - LICENSE.txt
95
115
  - README.md
116
+ - Rakefile
117
+ - bin/console
118
+ - bin/rake
119
+ - bin/setup
120
+ - config/default.yml
96
121
  - default.yml
97
- - lib/rubocop_codeur.rb
98
- - lib/rubocop_codeur/version.rb
122
+ - lib/rubocop-codeur.rb
123
+ - lib/rubocop/codeur.rb
124
+ - lib/rubocop/codeur/inject.rb
125
+ - lib/rubocop/codeur/version.rb
126
+ - lib/rubocop/cop/codeur/rails_app_patterns.rb
127
+ - lib/rubocop/cop/codeur/rails_avoid_instance_methods_in_helpers.rb
128
+ - lib/rubocop/cop/codeur_cops.rb
129
+ - rubocop-codeur.gemspec
99
130
  homepage: https://github.com/codeur/rubocop-codeur
100
131
  licenses:
101
132
  - MIT
102
- metadata:
103
- homepage_uri: https://github.com/codeur/rubocop-codeur
133
+ metadata: {}
104
134
  post_install_message:
105
135
  rdoc_options: []
106
136
  require_paths:
107
137
  - lib
108
138
  required_ruby_version: !ruby/object:Gem::Requirement
109
139
  requirements:
110
- - - "~>"
140
+ - - ">="
111
141
  - !ruby/object:Gem::Version
112
- version: '2.6'
142
+ version: 2.6.0
113
143
  required_rubygems_version: !ruby/object:Gem::Requirement
114
144
  requirements:
115
145
  - - ">="
data/MIT-LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright 2021 Codeur SARL
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RubocopCodeur
4
- VERSION = '0.1.17'
5
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubocop_codeur/version'
4
-
5
- module RubocopCodeur
6
- end