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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1d40596f0dc6a124e29d0c82f55f0ca48de0153c64cc164718ea504fcb22783
4
- data.tar.gz: ab0d3b8d41383d206f0f9694053b18b328b52d7a34e0aa9aba42da1b9a32da6d
3
+ metadata.gz: 3b1957eb40c18219d6399005554829139076afb1481427cc335ea8a662e22575
4
+ data.tar.gz: fb50f1e5dc4c6363f209cfb12fe87d17e9dd8ef1f646fc20850ec48a25e6ec3b
5
5
  SHA512:
6
- metadata.gz: 4ff62a7873f745ceca834c11722ccef1dd058e4b40128527d9fc2e4c2fe63b437066c5aee090ce9a70b316400c69b453d332684511833e1c13ab60208dd8e43e
7
- data.tar.gz: dbb960fa43c3a965159c1494a35904e09204d022f30b2715559efe2d3681350f32bf0f91a1db98b64a893d5e7e04799a952ea8691f44e56989771befa5e1e96a
6
+ metadata.gz: 4a93d2b695e0866debf34fd2373b248c1ea30eedc957ce6fb82a115c77d864a1bf97b409ed78ede2a157f71103e180545d65e871b3b2968b7f81ef609ba4b72a
7
+ data.tar.gz: 34e92438e92131d5b5f38161ca13f7e29e6f8583014fbe5316bfff824ed9dd389809ffde0092dc91ad8eabb151f4a7664bd550f312560c59a480f3a2eceef457
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails-cops (0.1.0)
4
+ rails-cops (0.1.1)
5
5
  activesupport (>= 4.2.0)
6
6
  rubocop (>= 1.33.0, < 2.0)
7
7
 
data/config/default.yml CHANGED
@@ -1,27 +1,5 @@
1
1
  # Common configuration.
2
2
 
3
- inherit_mode:
4
- merge:
5
- - Exclude
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rails
4
4
  module Cops
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
data/lib/rails/cops.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'rubocop'
4
4
  require_relative 'cops/version'
5
5
  require_relative 'cops/model_custom_validation_method_name'
6
+ require_relative 'cops/model_enum_setting'
6
7
 
7
8
  module Rails
8
9
  module Cops
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.0
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