rails-cops 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/config/default.yml +3 -25
- data/lib/rails/cops/model_enum_setting.rb +26 -0
- data/lib/rails/cops/version.rb +1 -1
- data/lib/rails/cops.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b1957eb40c18219d6399005554829139076afb1481427cc335ea8a662e22575
|
4
|
+
data.tar.gz: fb50f1e5dc4c6363f209cfb12fe87d17e9dd8ef1f646fc20850ec48a25e6ec3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a93d2b695e0866debf34fd2373b248c1ea30eedc957ce6fb82a115c77d864a1bf97b409ed78ede2a157f71103e180545d65e871b3b2968b7f81ef609ba4b72a
|
7
|
+
data.tar.gz: 34e92438e92131d5b5f38161ca13f7e29e6f8583014fbe5316bfff824ed9dd389809ffde0092dc91ad8eabb151f4a7664bd550f312560c59a480f3a2eceef457
|
data/Gemfile.lock
CHANGED
data/config/default.yml
CHANGED
@@ -1,27 +1,5 @@
|
|
1
1
|
# Common configuration.
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
-
|
6
|
-
|
7
|
-
AllCops:
|
8
|
-
Exclude:
|
9
|
-
- app/assets/**/*
|
10
|
-
- bin/*
|
11
|
-
# Exclude db/schema.rb and db/[CONFIGURATION_NAMESPACE]_schema.rb by default.
|
12
|
-
# See: https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application
|
13
|
-
- db/*schema.rb
|
14
|
-
- log/**/*
|
15
|
-
- public/**/*
|
16
|
-
- storage/**/*
|
17
|
-
# Enable checking Active Support extensions.
|
18
|
-
# See: https://docs.rubocop.org/rubocop/configuration.html#enable-checking-active-support-extensions
|
19
|
-
ActiveSupportExtensionsEnabled: true
|
20
|
-
# What version of Rails is the inspected code using? If a value is specified
|
21
|
-
# for TargetRailsVersion then it is used. Acceptable values are specified
|
22
|
-
# as a float (i.e. 5.1); the patch version of Rails should not be included.
|
23
|
-
# If TargetRailsVersion is not set, RuboCop will parse the Gemfile.lock or
|
24
|
-
# gems.locked file to find the version of Rails that has been bound to the
|
25
|
-
# application. If neither of those files exist, RuboCop will use Rails 5.0
|
26
|
-
# as the default.
|
27
|
-
TargetRailsVersion: ~
|
3
|
+
Cops/ModelEnumSetting:
|
4
|
+
Include:
|
5
|
+
- app/models/**/*.rb
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Cops
|
5
|
+
# This is for custom rubocop rule for model enum
|
6
|
+
class ModelEnumSetting < ::RuboCop::Cop::Base
|
7
|
+
MSG = 'You are using enum without _prefix or _suffix, please add _prefix or _suffix to the enum'
|
8
|
+
|
9
|
+
private_constant :MSG
|
10
|
+
|
11
|
+
def_node_matcher :enum_matcher, <<-PATTERN
|
12
|
+
(send nil? :enum
|
13
|
+
(hash $...))
|
14
|
+
PATTERN
|
15
|
+
|
16
|
+
# event handler
|
17
|
+
def on_send(node)
|
18
|
+
enum_matcher(node) do |matches|
|
19
|
+
next if matches.any? { |pair| pair.key.value.to_s.end_with?('_prefix', '_suffix') }
|
20
|
+
|
21
|
+
add_offense(node, message: MSG)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/rails/cops/version.rb
CHANGED
data/lib/rails/cops.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-cops
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lixibox
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- config/default.yml
|
60
60
|
- lib/rails/cops.rb
|
61
61
|
- lib/rails/cops/model_custom_validation_method_name.rb
|
62
|
+
- lib/rails/cops/model_enum_setting.rb
|
62
63
|
- lib/rails/cops/version.rb
|
63
64
|
- rails-cops.gemspec
|
64
65
|
- sig/rails/cops.rbs
|