Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-05-31 14:47:36 +0300
committerYorick Peterse <yorickpeterse@gmail.com>2017-05-31 15:03:37 +0300
commitcd74c1434e42f7e6aa12fe2e2b8d9b1e56aea78f (patch)
tree2eee709fcc756fde8a597c3079c1bf471788ed76 /rubocop
parent3d160480c07cd967480716d7cfbe332dfc53507e (diff)
Added Cop to blacklist the use of serialize
This Cop blacklists the use of ActiveRecord's "serialize" method, except for cases where we already use this.
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/activerecord_serialize.rb24
-rw-r--r--rubocop/rubocop.rb1
2 files changed, 25 insertions, 0 deletions
diff --git a/rubocop/cop/activerecord_serialize.rb b/rubocop/cop/activerecord_serialize.rb
new file mode 100644
index 00000000000..bfa0cff9a67
--- /dev/null
+++ b/rubocop/cop/activerecord_serialize.rb
@@ -0,0 +1,24 @@
+module RuboCop
+ module Cop
+ # Cop that prevents the use of `serialize` in ActiveRecord models.
+ class ActiverecordSerialize < RuboCop::Cop::Cop
+ MSG = 'Do not store serialized data in the database, use separate columns and/or tables instead'.freeze
+
+ def on_send(node)
+ return unless in_models?(node)
+
+ add_offense(node, :selector) if node.children[1] == :serialize
+ end
+
+ def models_path
+ File.join(Dir.pwd, 'app', 'models')
+ end
+
+ def in_models?(node)
+ path = node.location.expression.source_buffer.name
+
+ path.start_with?(models_path)
+ end
+ end
+ end
+end
diff --git a/rubocop/rubocop.rb b/rubocop/rubocop.rb
index b65efbc41f4..17d2bf6aa1c 100644
--- a/rubocop/rubocop.rb
+++ b/rubocop/rubocop.rb
@@ -1,5 +1,6 @@
require_relative 'cop/custom_error_class'
require_relative 'cop/gem_fetcher'
+require_relative 'cop/activerecord_serialize'
require_relative 'cop/migration/add_column'
require_relative 'cop/migration/add_column_with_default_to_large_table'
require_relative 'cop/migration/add_concurrent_foreign_key'