Skip to content

Commit

Permalink
Update hound and rubocop configuration
Browse files Browse the repository at this point in the history
When we moved to our own organization from the thoughtbot org, we lost
the hound-provided rubocop config associated with the thoughtbot org.
This change updates to the prefered hound config format that references
our own `.rubocop.yml` file.

How did I settle on the rubocop rules? Well, I ran rubocop on the
codebase and either fixed what came up or added exceptions. We have lots
of line length violations that I didn't fix. For the most part, I like
the encouragement to stay at 80 characters, but sometimes it's not worth
it. I think getting the hound reminder in the PR is sufficient enough
for us to have a conversation.
  • Loading branch information
derekprior committed Feb 9, 2019
1 parent bfa3984 commit b51ed69
Show file tree
Hide file tree
Showing 21 changed files with 222 additions and 80 deletions.
6 changes: 2 additions & 4 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
DotPosition:
EnforcedStyle: leading
Style/AlignParameters:
EnforcedStyle: with_fixed_indentation
rubocop:
config_file: .rubocop.yml
129 changes: 129 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
AllCops:
TargetRubyVersion: 2.3.0
Exclude:
- "tmp/**/*"
- "bin/*"
- "spec/dummy/**/*"

Bundler/OrderedGems:
Enabled: false

Gemspec/OrderedDependencies:
Enabled: false

Layout/AlignParameters:
Enabled: true
EnforcedStyle: with_fixed_indentation
Layout/ConditionPosition:
Enabled: false
Layout/DotPosition:
EnforcedStyle: leading
Layout/ExtraSpacing:
Enabled: true
Layout/IndentAssignment:
Enabled: False
Layout/MultilineOperationIndentation:
Enabled: true
EnforcedStyle: indented
Layout/MultilineMethodCallIndentation:
Enabled: true
EnforcedStyle: indented

Lint/AmbiguousOperator:
Enabled: true
Lint/AmbiguousRegexpLiteral:
Enabled: true
Lint/DuplicatedKey:
Enabled: true

Metrics/ClassLength:
Enabled: false
Metrics/ModuleLength:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
CountComments: true # count full line comments?
Max: 25
ExcludedMethods: []
Exclude:
- "spec/**/*"
- "*.gemspec"
Metrics/CyclomaticComplexity:
Enabled: false
Metrics/LineLength:
Max: 80
Metrics/MethodLength:
Enabled: false

Security/Eval:
Enabled: true
Exclude:
- "spec/scenic/schema_dumper_spec.rb"
Style/BlockDelimiters:
Enabled: false
Style/CollectionMethods:
Enabled: true
PreferredMethods:
find: find
inject: reduce
collect: map
find_all: select
Style/ConditionalAssignment:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: true
Exclude:
- "spec/**/*"
Style/Documentation:
Enabled: false
Style/FrozenStringLiteralComment:
Description: >-
Add the frozen_string_literal comment to the top of files
to help transition from Ruby 2.3.0 to Ruby 3.0.
Enabled: false
Style/GuardClause:
Enabled: false
Style/IfUnlessModifier:
Enabled: false
Style/Lambda:
Enabled: false
Style/NumericLiterals:
Enabled: false
Style/OneLineConditional:
Enabled: false
Style/PercentLiteralDelimiters:
Enabled: false
Style/StringLiterals:
EnforcedStyle: double_quotes
Enabled: true
Style/TrailingCommaInArguments:
Description: 'Checks for trailing comma in argument lists.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
EnforcedStyleForMultiline: comma
SupportedStylesForMultiline:
- comma
- consistent_comma
- no_comma
Enabled: true
Style/TrailingCommaInArrayLiteral:
Description: 'Checks for trailing comma in array literals.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
EnforcedStyleForMultiline: comma
SupportedStylesForMultiline:
- comma
- consistent_comma
- no_comma
Enabled: true
Style/TrailingCommaInHashLiteral:
Description: 'Checks for trailing comma in hash literals.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
EnforcedStyleForMultiline: comma
SupportedStylesForMultiline:
- comma
- consistent_comma
- no_comma
Enabled: true
Style/WordArray:
Enabled: false

2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in scenic.gemspec
gemspec
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

Expand Down
4 changes: 2 additions & 2 deletions lib/generators/scenic/model/model_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Generators
# @api private
class ModelGenerator < Rails::Generators::NamedBase
include Scenic::Generators::Materializable
source_root File.expand_path("../templates", __FILE__)
source_root File.expand_path("templates", __dir__)

def invoke_rails_model_generator
invoke "model",
Expand All @@ -35,7 +35,7 @@ def invoke_view_generator

def evaluate_template(source)
source = File.expand_path(find_in_source_paths(source.to_s))
context = instance_eval("binding")
context = instance_eval("binding", __FILE__, __LINE__)
ERB.new(
::File.binread(source),
nil,
Expand Down
17 changes: 10 additions & 7 deletions lib/generators/scenic/view/view_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Generators
class ViewGenerator < Rails::Generators::NamedBase
include Rails::Generators::Migration
include Scenic::Generators::Materializable
source_root File.expand_path("../templates", __FILE__)
source_root File.expand_path("templates", __dir__)

def create_views_directory
unless views_directory_path.exist?
Expand Down Expand Up @@ -56,7 +56,7 @@ def version

def migration_class_name
if creating_new_view?
"Create#{class_name.gsub('.', '').pluralize}"
"Create#{class_name.tr('.', '').pluralize}"
else
"Update#{class_name.pluralize}ToVersion#{version}"
end
Expand All @@ -74,15 +74,15 @@ def activerecord_migration_class
private

def views_directory_path
@views_directory_path ||= Rails.root.join(*%w(db views))
@views_directory_path ||= Rails.root.join("db", "views")
end

def version_regex
/\A#{plural_file_name}_v(?<version>\d+)\.sql\z/
end

def creating_new_view?
previous_version == 0
previous_version.zero?
end

def definition
Expand All @@ -94,7 +94,7 @@ def previous_definition
end

def plural_file_name
@plural_file_name ||= file_name.pluralize.gsub(".", "_")
@plural_file_name ||= file_name.pluralize.tr(".", "_")
end

def destroying?
Expand All @@ -110,8 +110,11 @@ def formatted_plural_name
end

def create_view_options
return "" unless materialized?
", materialized: #{no_data? ? '{ no_data: true }' : true}"
if materialized?
", materialized: #{no_data? ? '{ no_data: true }' : true}"
else
""
end
end

def destroying_initial_view?
Expand Down
9 changes: 7 additions & 2 deletions lib/scenic/adapters/postgres/refresh_dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ def initialize(raw_dependencies, view_to_refresh)
def to_sorted_array
dependency_hash = parse_to_hash(raw_dependencies)
sorted_arr = tsort(dependency_hash)

idx = sorted_arr.find_index do |dep|
dep.include?(view_to_refresh.to_s)
end
return [] if idx.nil?
sorted_arr[0...idx]

if idx.present?
sorted_arr[0...idx]
else
[]
end
end

private
Expand Down
1 change: 1 addition & 0 deletions lib/scenic/adapters/postgres/views.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def to_scenic_view(result)

def pg_identifier(name)
return name if name =~ /^[a-zA-Z_][a-zA-Z0-9_]*$/

pgconn.quote_ident(name)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/scenic/schema_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def dumpable_views_in_database
def ignored?(table_name)
["schema_migrations", ignore_tables].flatten.any? do |ignored|
case ignored
when String; remove_prefix_and_suffix(table_name) == ignored
when Regexp; remove_prefix_and_suffix(table_name) =~ ignored
when String then remove_prefix_and_suffix(table_name) == ignored
when Regexp then remove_prefix_and_suffix(table_name) =~ ignored
else
raise StandardError, "ActiveRecord::SchemaDumper.ignore_tables accepts an array of String and / or Regexp values."
end
Expand Down
7 changes: 5 additions & 2 deletions lib/scenic/statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,11 @@ def definition(name, version)
end

def no_data(materialized)
return false unless materialized.is_a? Hash
materialized.fetch(:no_data, false)
if materialized.is_a?(Hash)
materialized.fetch(:no_data, false)
else
false
end
end
end
end
45 changes: 22 additions & 23 deletions scenic.gemspec
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'scenic/version'
require "scenic/version"

Gem::Specification.new do |spec|
spec.name = 'scenic'
spec.name = "scenic"
spec.version = Scenic::VERSION
spec.authors = ['Derek Prior', 'Caleb Thompson']
spec.email = ['[email protected]', '[email protected]']
spec.summary = %q{Support for database views in Rails migrations}
spec.authors = ["Derek Prior", "Caleb Thompson"]
spec.email = ["[email protected]", "[email protected]"]
spec.summary = "Support for database views in Rails migrations"
spec.description = <<-DESCRIPTION
Adds methods to ActiveRecord::Migration to create and manage database views
in Rails
DESCRIPTION
spec.homepage = 'https://github.com/scenic-views/scenic'
spec.license = 'MIT'
spec.homepage = "https://github.com/scenic-views/scenic"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.test_files = spec.files.grep(%r{^spec/})
spec.require_paths = ['lib']
spec.require_paths = ["lib"]

spec.add_development_dependency 'appraisal'
spec.add_development_dependency 'bundler', '>= 1.5'
spec.add_development_dependency 'database_cleaner'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', '>= 3.3'
spec.add_development_dependency 'pg', '~> 0.19'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'ammeter', '>= 1.1.3'
spec.add_development_dependency 'yard'
spec.add_development_dependency 'redcarpet'
spec.add_development_dependency "appraisal"
spec.add_development_dependency "bundler", ">= 1.5"
spec.add_development_dependency "database_cleaner"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", ">= 3.3"
spec.add_development_dependency "pg", "~> 0.19"
spec.add_development_dependency "pry"
spec.add_development_dependency "ammeter", ">= 1.1.3"
spec.add_development_dependency "yard"
spec.add_development_dependency "redcarpet"

spec.add_dependency 'activerecord', '>= 4.0.0'
spec.add_dependency 'railties', '>= 4.0.0'
spec.add_dependency "activerecord", ">= 4.0.0"
spec.add_dependency "railties", ">= 4.0.0"

spec.required_ruby_version = '>= 2.3.0'
spec.required_ruby_version = ">= 2.3.0"
end
3 changes: 2 additions & 1 deletion spec/acceptance/user_manages_views_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "acceptance_helper"
require "English"

describe "User manages views" do
it "handles simple views" do
Expand Down Expand Up @@ -56,7 +57,7 @@

def successfully(command)
`RAILS_ENV=test #{command}`
expect($?.exitstatus).to eq(0), "'#{command}' was unsuccessful"
expect($CHILD_STATUS.exitstatus).to eq(0), "'#{command}' was unsuccessful"
end

def write_definition(file, contents)
Expand Down
2 changes: 1 addition & 1 deletion spec/generators/scenic/model/model_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Scenic::Generators
before do
allow(ViewGenerator).to receive(:new)
.and_return(
instance_double("Scenic::Generators::ViewGenerator").as_null_object
instance_double("Scenic::Generators::ViewGenerator").as_null_object,
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/generators/scenic/view/view_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

run_generator ["aired_episode", "--materialized"]
migration = migration_file(
"db/migrate/update_aired_episodes_to_version_2.rb"
"db/migrate/update_aired_episodes_to_version_2.rb",
)
expect(migration).to contain "materialized: true"
end
Expand Down
12 changes: 6 additions & 6 deletions spec/scenic/adapters/postgres/refresh_dependencies_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ module Adapters
"SELECT * from third",
)

expect(adapter).to receive(:refresh_materialized_view).
with("public.first").ordered
expect(adapter).to receive(:refresh_materialized_view)
.with("public.first").ordered

expect(adapter).to receive(:refresh_materialized_view).
with("public.second").ordered
expect(adapter).to receive(:refresh_materialized_view)
.with("public.second").ordered

expect(adapter).to receive(:refresh_materialized_view).
with("public.third").ordered
expect(adapter).to receive(:refresh_materialized_view)
.with("public.third").ordered

described_class.call(:fourth, adapter, ActiveRecord::Base.connection)
end
Expand Down
Loading

0 comments on commit b51ed69

Please sign in to comment.