rubocop-codeur 0.1.15 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/quality.yml +34 -0
- data/.github/workflows/test.yml +41 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +9 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +79 -0
- data/LICENSE.txt +21 -0
- data/README.md +6 -3
- data/Rakefile +31 -0
- data/bin/console +15 -0
- data/bin/rake +29 -0
- data/bin/setup +8 -0
- data/config/default.yml +13 -0
- data/default.yml +106 -1
- data/lib/rubocop/codeur/inject.rb +20 -0
- data/lib/rubocop/codeur/version.rb +7 -0
- data/lib/rubocop/codeur.rb +17 -0
- data/lib/rubocop/cop/codeur/rails_app_patterns.rb +81 -0
- data/lib/rubocop/cop/codeur/rails_avoid_instance_methods_in_helpers.rb +37 -0
- data/lib/rubocop/cop/codeur_cops.rb +4 -0
- data/lib/rubocop-codeur.rb +11 -0
- data/rubocop-codeur.gemspec +28 -0
- metadata +45 -15
- data/MIT-LICENSE +0 -20
- data/lib/rubocop_codeur/version.rb +0 -5
- data/lib/rubocop_codeur.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c60553e7427774219eb421a3ad856abf774951523a9c72e6d0770990ef9f2d82
|
4
|
+
data.tar.gz: e7ce247889bdac1392bba4677ee6c916a3eadc2885afcfeff46c4db5af8f8a7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91b702d8c2c116a0542f85daaed265b3b2b8777da1f049462d8e309e8c0633cc7f59054d856c29cd7f2f3460ad2400f59ad90c4d8f8564b2683d90e9afb86e9b
|
7
|
+
data.tar.gz: 59f8a6b58226fc72fe8a039116078b546df45d99246a02211ac4700220d40af5a122322774ad484be0c2880ba8dec958487411c091a3885274d9746864124c69
|
@@ -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
data/.rubocop.yml
ADDED
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.0)
|
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.0)
|
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
|
-
#
|
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-
|
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
|
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
data/config/default.yml
ADDED
@@ -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,6 +25,16 @@ 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:
|
24
39
|
EnforcedStyle: outdent
|
25
40
|
IndentationWidth: 2
|
@@ -27,6 +42,86 @@ Layout/AccessModifierIndentation:
|
|
27
42
|
Layout/ArgumentAlignment:
|
28
43
|
EnforcedStyle: with_first_argument
|
29
44
|
|
45
|
+
Layout/ClassStructure:
|
46
|
+
Enabled: true
|
47
|
+
AutoCorrect: false
|
48
|
+
ExpectedOrder:
|
49
|
+
- devise
|
50
|
+
- module_inclusion
|
51
|
+
- constants
|
52
|
+
- attributes
|
53
|
+
- has_ancestry
|
54
|
+
- belongs_to
|
55
|
+
- has_many
|
56
|
+
- has_one
|
57
|
+
- attachments
|
58
|
+
- public_delegate
|
59
|
+
- class_macros
|
60
|
+
- callbacks
|
61
|
+
- state_machine
|
62
|
+
- aasm
|
63
|
+
- scope
|
64
|
+
- default_scope
|
65
|
+
- validations
|
66
|
+
- public_class_methods
|
67
|
+
- initializer
|
68
|
+
- public_methods
|
69
|
+
- protected_attribute_macros
|
70
|
+
- protected_methods
|
71
|
+
- private_attribute_macros
|
72
|
+
- private_delegate
|
73
|
+
- private_methods
|
74
|
+
Categories:
|
75
|
+
module_inclusion:
|
76
|
+
- include
|
77
|
+
- prepend
|
78
|
+
- extend
|
79
|
+
attachments:
|
80
|
+
- has_one_attached
|
81
|
+
- has_many_attached
|
82
|
+
- has_attached_file
|
83
|
+
attributes:
|
84
|
+
- attr_accessor
|
85
|
+
- attr_reader
|
86
|
+
- attr_writer
|
87
|
+
- attr_readonly
|
88
|
+
- emojify
|
89
|
+
- enum
|
90
|
+
- monetize
|
91
|
+
- serialize
|
92
|
+
- has_secure_token
|
93
|
+
- alias_attribute
|
94
|
+
- slug
|
95
|
+
class_macros:
|
96
|
+
- acts_as_voter
|
97
|
+
- pg_search_scope
|
98
|
+
- counter_culture
|
99
|
+
- accepts_nested_attributes_for
|
100
|
+
- paginates_per
|
101
|
+
- ransack_alias
|
102
|
+
- ransacker
|
103
|
+
- ratyrate_rater
|
104
|
+
callbacks:
|
105
|
+
- before_validation
|
106
|
+
- after_validation
|
107
|
+
- before_save
|
108
|
+
- around_save
|
109
|
+
- before_create
|
110
|
+
- around_create
|
111
|
+
- before_update
|
112
|
+
- around_update
|
113
|
+
- before_destroy
|
114
|
+
- around_destroy
|
115
|
+
- after_destroy
|
116
|
+
- after_create
|
117
|
+
- after_save
|
118
|
+
- after_commit
|
119
|
+
- after_rollback
|
120
|
+
validations:
|
121
|
+
- validates_associated
|
122
|
+
- validates
|
123
|
+
- validate
|
124
|
+
|
30
125
|
Layout/FirstArrayElementIndentation:
|
31
126
|
EnforcedStyle: consistent
|
32
127
|
|
@@ -50,6 +145,13 @@ Layout/ParameterAlignment:
|
|
50
145
|
EnforcedStyle: with_fixed_indentation
|
51
146
|
IndentationWidth: 2
|
52
147
|
|
148
|
+
Lint/DuplicateMethods:
|
149
|
+
Exclude:
|
150
|
+
- 'db/migrate/*'
|
151
|
+
|
152
|
+
Lint/MissingSuper:
|
153
|
+
Enabled: false
|
154
|
+
|
53
155
|
Lint/RaiseException:
|
54
156
|
Enabled: true
|
55
157
|
|
@@ -91,7 +193,7 @@ Minitest/TestMethodName:
|
|
91
193
|
Enabled: false
|
92
194
|
|
93
195
|
Minitest/MultipleAssertions:
|
94
|
-
Max:
|
196
|
+
Max: 30
|
95
197
|
|
96
198
|
# Disabled because it doesn't with symbols like: record_001
|
97
199
|
Naming/VariableNumber:
|
@@ -176,6 +278,9 @@ Style/NestedTernaryOperator:
|
|
176
278
|
Style/NumericPredicate:
|
177
279
|
Enabled: false
|
178
280
|
|
281
|
+
Style/StringLiterals:
|
282
|
+
EnforcedStyle: single_quotes
|
283
|
+
|
179
284
|
Style/SymbolArray:
|
180
285
|
MinSize: 7
|
181
286
|
|
@@ -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,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,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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- Codeur
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
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.
|
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.
|
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
|
-
-
|
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/
|
98
|
-
- lib/
|
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
|
-
|
104
|
-
post_install_message:
|
133
|
+
metadata: {}
|
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:
|
142
|
+
version: 2.6.0
|
113
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
144
|
requirements:
|
115
145
|
- - ">="
|
@@ -117,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
147
|
version: '0'
|
118
148
|
requirements: []
|
119
149
|
rubygems_version: 3.1.4
|
120
|
-
signing_key:
|
150
|
+
signing_key:
|
121
151
|
specification_version: 4
|
122
152
|
summary: Codeur rubocop config gem
|
123
153
|
test_files: []
|
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.
|