Skip to content

Commit

Permalink
Allow projects to define their own Rubocop config
Browse files Browse the repository at this point in the history
The fix-db-schema-conflicts gem currently does not support rubocop
v0.54.0. The maintainer is considering solutions to allow projects to
set the rubocop configuration used by fix-db-schema-conflicts.

  jakeonrails#28
  • Loading branch information
tonyta committed Apr 3, 2018
1 parent d5400c9 commit fd9a105
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 18 additions & 2 deletions lib/fix-db-schema-conflicts.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
require 'fix_db_schema_conflicts/schema_dumper.rb'
require 'fix_db_schema_conflicts/schema_dumper'
require 'fix_db_schema_conflicts/autocorrect_configuration'

require 'fix_db_schema_conflicts/railtie' if defined?(Rails)

module FixDBSchemaConflicts
require 'fix_db_schema_conflicts/railtie' if defined?(Rails)
class << self
def rubocop_config=(config_path)
@rubocop_config = config_path
end

def rubocop_config
@rubocop_config || default_config
end

def default_config
relative_path = AutocorrectConfiguration.load
File.expand_path("../#{relative_path}", __dir__)
end
end
end
3 changes: 1 addition & 2 deletions lib/fix_db_schema_conflicts/tasks/db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ namespace :db do
else
"#{Rails.root}/db/schema.rb"
end
autocorrect_config = FixDBSchemaConflicts::AutocorrectConfiguration.load
rubocop_yml = File.expand_path("../../../../#{autocorrect_config}", __FILE__)
rubocop_yml = FixDBSchemaConflicts.rubocop_config
`bundle exec rubocop --auto-correct --config #{rubocop_yml} #{filename.shellescape}`
end
end
Expand Down

2 comments on commit fd9a105

@alexanderadam
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tonyta would (or did) you consider making a PR to the official gem?

@tonyta
Copy link
Author

@tonyta tonyta commented on fd9a105 Sep 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexanderadam This implementation was a bit naive and the maintainer looked like he was looking into strategies himself (jakeonrails#28), so I haven't bothered making a PR.

I am working on a spike with tests for multiple Ruby and Rails versions and compatibility thoughout different RuboCop versions as well. But haven't had the time to polish it up. Maybe someday soon...

Please sign in to comment.