Skip to content

Commit

Permalink
Switch to standard gem's rubocop configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
nertzy committed Feb 20, 2023
1 parent 1c84895 commit 23fe69d
Show file tree
Hide file tree
Showing 34 changed files with 614 additions and 692 deletions.
125 changes: 11 additions & 114 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,137 +1,34 @@
require:
- standard
- rubocop-performance
- rubocop-rails
- rubocop-rake
- rubocop-rspec

inherit_gem:
standard: config/base.yml

AllCops:
TargetRubyVersion: 2.7
NewCops: enable
NewCops: disable
Exclude:
- bin/**/*
- vendor/**/*

Style/StringLiterals:
Enabled: false

Layout/LineLength:
Max: 120

Metrics/MethodLength:
Max: 15

Metrics/BlockLength:
Exclude:
- spec/**/*

Layout/ParameterAlignment:
EnforcedStyle: with_fixed_indentation

Style/NumericPredicate:
Enabled: false

Style/PercentLiteralDelimiters:
PreferredDelimiters:
'%w': '[]'
'%W': '[]'

Style/GuardClause:
Enabled: false

Naming/VariableNumber:
EnforcedStyle: snake_case

Bundler/OrderedGems:
Enabled: false

Bundler/DuplicatedGem:
Enabled: false

Style/EmptyMethod:
EnforcedStyle: expanded

Layout/FirstArrayElementIndentation:
EnforcedStyle: consistent

Style/Documentation:
Enabled: false

Style/WordArray:
EnforcedStyle: percent
MinSize: 3

Style/HashEachMethods:
Lint/RedundantCopDisableDirective:
Enabled: true

Style/HashTransformKeys:
Lint/RedundantCopEnableDirective:
Enabled: true

Style/HashTransformValues:
Enabled: true

Rails/ApplicationRecord:
Bundler/DuplicatedGem:
Enabled: false

Rails/TimeZone:
Rails/ApplicationRecord:
Enabled: false

RSpec/ContextWording:
Prefixes:
- using
- via
- when
- with
- without

Lint/RaiseException:
Enabled: true

Lint/StructNewOverride:
Enabled: true

Layout/SpaceAroundMethodCallOperator:
Enabled: true

Style/ExponentialNotation:
Enabled: true

RSpec/DescribedClass:
Enabled: true

RSpec/ExpectInHook:
Rails/RakeEnvironment:
Enabled: false

RSpec/FilePath:
CustomTransform:
TSearch: "tsearch"
DMetaphone: "dmetaphone"

Layout/EmptyLinesAroundAttributeAccessor:
Enabled: true

Lint/DeprecatedOpenSSLConstant:
Enabled: true

Style/SlicingWithRange:
Enabled: true

Lint/MixedRegexpCaptureTypes:
Enabled: true

Style/RedundantFetchBlock:
Enabled: true

Style/RedundantRegexpCharacterClass:
Enabled: true

Style/RedundantRegexpEscape:
Enabled: true

RSpec/MultipleExpectations:
Max: 5

RSpec/ExampleLength:
Max: 15

Rails/RakeEnvironment:
Rails/TimeZone:
Enabled: false
39 changes: 20 additions & 19 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

gem 'pg', '>= 0.21.0', platform: :ruby
gem "pg", ">= 0.21.0", platform: :ruby
gem "activerecord-jdbcpostgresql-adapter", ">= 1.3.1", platform: :jruby

if ENV['ACTIVE_RECORD_BRANCH']
gem 'activerecord', git: 'https://github.com/rails/rails.git', branch: ENV.fetch('ACTIVE_RECORD_BRANCH', nil)
gem 'arel', git: 'https://github.com/rails/arel.git' if ENV.fetch('ACTIVE_RECORD_BRANCH', nil) == 'master'
if ENV["ACTIVE_RECORD_BRANCH"]
gem "activerecord", git: "https://github.com/rails/rails.git", branch: ENV.fetch("ACTIVE_RECORD_BRANCH", nil)
gem "arel", git: "https://github.com/rails/arel.git" if ENV.fetch("ACTIVE_RECORD_BRANCH", nil) == "master"
end

gem 'activerecord', ENV.fetch('ACTIVE_RECORD_VERSION', nil) if ENV['ACTIVE_RECORD_VERSION']
gem "activerecord", ENV.fetch("ACTIVE_RECORD_VERSION", nil) if ENV["ACTIVE_RECORD_VERSION"]

gem 'pry'
gem 'rake'
gem 'rspec'
gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-rails'
gem 'rubocop-rake'
gem 'rubocop-rspec'
gem 'simplecov'
gem 'simplecov-lcov'
gem 'undercover'
gem 'warning'
gem 'with_model'
gem "pry"
gem "rake"
gem "rspec"
gem "rubocop"
gem "rubocop-performance"
gem "rubocop-rails"
gem "rubocop-rake"
gem "rubocop-rspec"
gem "simplecov"
gem "simplecov-lcov"
gem "standard", ">= 1.23.0"
gem "undercover"
gem "warning"
gem "with_model"
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

require 'bundler'
require "bundler"
Bundler::GemHelper.install_tasks

require 'rspec/core/rake_task'
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)

require "rubocop/rake_task"
Expand Down
2 changes: 1 addition & 1 deletion lib/pg_search/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def order_within_rank
attr_reader :options

def default_options
{ using: :tsearch }
{using: :tsearch}
end

VALID_KEYS = %w[
Expand Down
2 changes: 1 addition & 1 deletion lib/pg_search/configuration/column.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'digest'
require "digest"

module PgSearch
class Configuration
Expand Down
2 changes: 1 addition & 1 deletion lib/pg_search/configuration/foreign_column.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'digest'
require "digest"

module PgSearch
class Configuration
Expand Down
14 changes: 7 additions & 7 deletions lib/pg_search/document.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

require 'logger'
require "logger"

module PgSearch
class Document < ActiveRecord::Base
include PgSearch::Model

self.table_name = 'pg_search_documents'
self.table_name = "pg_search_documents"
belongs_to :searchable, polymorphic: true

# The logger might not have loaded yet.
Expand All @@ -17,12 +17,12 @@ def self.logger

pg_search_scope :search, lambda { |*args|
options = if PgSearch.multisearch_options.respond_to?(:call)
PgSearch.multisearch_options.call(*args)
else
{ query: args.first }.merge(PgSearch.multisearch_options)
end
PgSearch.multisearch_options.call(*args)
else
{query: args.first}.merge(PgSearch.multisearch_options)
end

{ against: :content }.merge(options)
{against: :content}.merge(options)
}
end
end
2 changes: 1 addition & 1 deletion lib/pg_search/features/dmetaphone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Features
class DMetaphone
def initialize(query, options, columns, model, normalizer)
dmetaphone_normalizer = Normalizer.new(normalizer)
options = (options || {}).merge(dictionary: 'simple')
options = (options || {}).merge(dictionary: "simple")
@tsearch = TSearch.new(query, options, columns, model, dmetaphone_normalizer)
end

Expand Down
8 changes: 4 additions & 4 deletions lib/pg_search/features/trigram.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ def word_similarity?

def similarity_function
if word_similarity?
'word_similarity'
"word_similarity"
else
'similarity'
"similarity"
end
end

def infix_operator
if word_similarity?
'<%'
"<%"
else
'%'
"%"
end
end

Expand Down
18 changes: 9 additions & 9 deletions lib/pg_search/features/tsearch.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require "active_support/core_ext/module/delegation"
require 'active_support/deprecation'
require "active_support/deprecation"

module PgSearch
module Features
class TSearch < Feature # rubocop:disable Metrics/ClassLength
class TSearch < Feature
def self.valid_options
super + %i[dictionary prefix negation any_word normalization tsvector_column highlight]
end
Expand Down Expand Up @@ -36,7 +36,7 @@ def ts_headline
end

def ts_headline_options
return '' unless options[:highlight].is_a?(Hash)
return "" unless options[:highlight].is_a?(Hash)

headline_options
.merge(deprecated_headline_options)
Expand All @@ -58,7 +58,7 @@ def headline_options
end
end

def deprecated_headline_options # rubocop:disable Metrics/MethodLength
def deprecated_headline_options
indifferent_options = options.with_indifferent_access

%w[
Expand Down Expand Up @@ -94,11 +94,11 @@ def ts_headline_option_value(value)
end
end

DISALLOWED_TSQUERY_CHARACTERS = /['?\\:‘’ʻʼ]/.freeze
DISALLOWED_TSQUERY_CHARACTERS = /['?\\:‘’ʻʼ]/

def tsquery_for_term(unsanitized_term)
if options[:negation] && unsanitized_term.start_with?("!")
unsanitized_term[0] = ''
unsanitized_term[0] = ""
negated = true
end

Expand All @@ -116,7 +116,7 @@ def tsquery_for_term(unsanitized_term)
# If :negated is true, then the term will have ! prepended to the front.
def tsquery_expression(term_sql, negated:, prefix:)
terms = [
(Arel::Nodes.build_quoted('!') if negated),
(Arel::Nodes.build_quoted("!") if negated),
Arel::Nodes.build_quoted("' "),
term_sql,
Arel::Nodes.build_quoted(" '"),
Expand All @@ -133,7 +133,7 @@ def tsquery

query_terms = query.split.compact
tsquery_terms = query_terms.map { |term| tsquery_for_term(term) }
tsquery_terms.join(options[:any_word] ? ' || ' : ' && ')
tsquery_terms.join(options[:any_word] ? " || " : " && ")
end

def tsdocument
Expand All @@ -151,7 +151,7 @@ def tsdocument
end
end

tsdocument_terms.join(' || ')
tsdocument_terms.join(" || ")
end

# From http://www.postgresql.org/docs/8.3/static/textsearch-controls.html
Expand Down
4 changes: 2 additions & 2 deletions lib/pg_search/migration/dmetaphone_generator.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

require 'pg_search/migration/generator'
require "pg_search/migration/generator"

module PgSearch
module Migration
class DmetaphoneGenerator < Generator
def migration_name
'add_pg_search_dmetaphone_support_functions'
"add_pg_search_dmetaphone_support_functions"
end
end
end
Expand Down
Loading

0 comments on commit 23fe69d

Please sign in to comment.