Skip to content

Added Rubocop config and GitHub Actions configuration#73

Open
igor-alexandrov wants to merge 3 commits intorkrage:masterfrom
igor-alexandrov:chore/rubocop
Open

Added Rubocop config and GitHub Actions configuration#73
igor-alexandrov wants to merge 3 commits intorkrage:masterfrom
igor-alexandrov:chore/rubocop

Conversation

@igor-alexandrov
Copy link
Contributor

This PR partially covers #32 issue.

I added RuboCop configuration and GitHub Action (we can go with Circle if you want) to lint the code.

Rules that caused offenses and were fixed (with safe autocorrection):

  • Style/StringLiterals (Since there were both single quoted and double quoted strings, I decided to go with double quoted. This can be discussed)
  • Style/WordArray (Converted everything to %w[] notation)
  • Style/TrailingCommaInArguments
  • Style/PercentLiteralDelimiters
  • Style/NumericLiterals
  • Layout/HashAlignment
  • Layout/SpaceBeforeComma
  • Layout/SpaceBeforeBlockBraces
  • Layout/MultilineMethodCallIndentation

Also PR adds autogenerated .rubocop_todo.yml with offenses, that cannot be corrected automatically, they should be discussed individually.

Lets discuss.

@igor-alexandrov
Copy link
Contributor Author

@rkrage wow, it seems I already started to work on GitHub Actions. I will update this PR.

@igor-alexandrov
Copy link
Contributor Author

@rkrage this is ready to be merged.

I will add more Actions in a separate commit to transition from CircleCI.

@rkrage
Copy link
Owner

rkrage commented Oct 10, 2023

@igor-alexandrov can you rebase this and resolve the merge conflict?

Rakefile Outdated
"default"
else
gemfile
end
Copy link
Owner

Choose a reason for hiding this comment

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

I would prefer if this looked like:

output_prefix = if gemfile.empty? || gemfile == "Gemfile"
  "default"
else
  gemfile
end

Copy link
Contributor Author

@igor-alexandrov igor-alexandrov Oct 11, 2023

Choose a reason for hiding this comment

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

I prefer this style too, updated to pass Rubocop rules to:

output_prefix =
  if gemfile.empty? || gemfile == "Gemfile"
    "default"
  else
    gemfile
  end

attr_reader :config, :cache

def configure(&blk)
blk.call(config)
Copy link
Owner

Choose a reason for hiding this comment

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

I prefer the explicitness of blk.call over yield whenever possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted to blk.call, but seems that yield is faster: https://github.com/fastruby/fast-ruby#proccall-and-block-arguments-vs-yieldcode

"INCLUDING ALL"
else
'INCLUDING ALL EXCLUDING INDEXES'
"INCLUDING ALL EXCLUDING INDEXES"
Copy link
Owner

Choose a reason for hiding this comment

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

I guess I missed this one previously, but I would prefer if everything was moved over to the left like I mentioned in another comment above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to have the similar style as in the comment above.

like_option =
  if !partition_type || create_with_pks
    "INCLUDING ALL"
  else
    "INCLUDING ALL EXCLUDING INDEXES"
  end

if table_partitioned?(table_name)
add_index_only(table_name, type: index_type, name: updated_name, using: using, columns: index_columns,
options: index_options)
options: index_options)
Copy link
Owner

Choose a reason for hiding this comment

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

I think each keyword arg should be on its own line to look like the create_table_like calls above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Completely agree, updated.

_created_index_names << updated_name # Track as created before execution of concurrent index command
add_index_from_options(table_name, name: updated_name, type: index_type, algorithm: algorithm, using: using,
columns: index_columns, options: index_options)
columns: index_columns, options: index_options)
Copy link
Owner

Choose a reason for hiding this comment

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

Same comment as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

"SELECT relname FROM pg_class, pg_index WHERE pg_index.indisvalid = false AND "\
"pg_index.indexrelid = pg_class.oid AND relname = #{quote(index_name)}"
"SELECT relname FROM pg_class, pg_index WHERE pg_index.indisvalid = false AND " \
"pg_index.indexrelid = pg_class.oid AND relname = #{quote(index_name)}"
Copy link
Owner

Choose a reason for hiding this comment

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

This one should probably just use heredoc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

end

alias_method :hash_partition_key_in, :list_partition_key_in
alias hash_partition_key_in list_partition_key_in
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure how I feel about this one...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted back alias_method and updated Rubocop configuration to make alias_method preferred over alias.

algorithm: :concurrently,
where: "created_at > '#{current_date.to_time.iso8601}'"
algorithm: :concurrently,
where: "created_at > '#{current_date.to_time.iso8601}'"
Copy link
Owner

Choose a reason for hiding this comment

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

This looks pretty nasty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to match style, described above.

in_threads: index_threads, algorithm: :concurrently,
where: "created_at > '#{current_date.to_time.iso8601}'"
in_threads: index_threads, algorithm: :concurrently,
where: "created_at > '#{current_date.to_time.iso8601}'"
Copy link
Owner

Choose a reason for hiding this comment

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

Also looks pretty gross

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


adapter.add_index_on_all_partitions table_name, "#{table_name}_id", name: index_prefix,
in_threads: index_threads, algorithm: :concurrently, unique: true
in_threads: index_threads, algorithm: :concurrently, unique: true
Copy link
Owner

Choose a reason for hiding this comment

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

Don't love this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't love this too, fixed.

before do
allow(Parallel).to receive(:map).with([child_table_name, sibling_table_name], in_threads: index_threads)
.and_yield(child_table_name).and_yield(sibling_table_name)
.and_yield(child_table_name).and_yield(sibling_table_name)
Copy link
Owner

Choose a reason for hiding this comment

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

Seems like all of these would look better if we just move the .with call to its own line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

)
"`in_threads:` cannot be used within a transaction. If running in a migration, use " \
"`disable_ddl_transaction!` and break out this operation into its own migration."
)
Copy link
Owner

Choose a reason for hiding this comment

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

Don't like this much either

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

'in_threads: must be lower than your database connection pool size'
)
"in_threads: must be lower than your database connection pool size"
)
Copy link
Owner

Choose a reason for hiding this comment

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

Or this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

"success"
else
"failed"
end
Copy link
Owner

Choose a reason for hiding this comment

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

Same comment about if statements above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to match overall style

"success"
else
"failed"
end
Copy link
Owner

Choose a reason for hiding this comment

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

Same comment about if statements above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

run: |
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rubocop No newline at end of file
Copy link
Owner

Choose a reason for hiding this comment

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

Looks like we need a newline here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added newline

@igor-alexandrov igor-alexandrov force-pushed the chore/rubocop branch 2 times, most recently from f0a8e64 to bbb91e9 Compare October 11, 2023 08:12
Rakefile Outdated
"default"
else
gemfile
end
Copy link
Owner

Choose a reason for hiding this comment

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

This is better but I still prefer:

output_prefix = if gemfile.empty? || gemfile == "Gemfile"
  "default"
else
  gemfile
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rkrage I reverted my changes and updated rubocop_todo.yml

@key.first
else
@key
end
Copy link
Owner

Choose a reason for hiding this comment

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

Another nasty if / else

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted my changes and updated rubocop_todo.yml

"pg_index.indexrelid = pg_class.oid AND relname = #{quote(index_name)}",
"SCHEMA"
).empty?
select_values(<<-SQL, "SCHEMA").empty?
Copy link
Owner

Choose a reason for hiding this comment

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

Super tiny nitpick, but I think we should use squiggly heredoc (<<~SQL)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I followed the style of the previous heredoc in the project. I am also a fan of squiggly heredoc, so I replaced it within the whole project in a separate commit.

@rkrage
Copy link
Owner

rkrage commented Jan 4, 2025

@igor-alexandrov, sorry this one fell through the cracks a bit. This project is pretty much in maintenance mode at the moment so I'm not sure how helpful Rubocop will be anymore. Moving to GH actions though is probably a good idea, as I do plan to continue adding support for new Rails versions. All that being said though, if you feel strongly about the Rubocop stuff, feel free to rebase / resolve conflicts and I'll try to get this merged soon.

@igor-alexandrov
Copy link
Contributor Author

igor-alexandrov commented Jan 8, 2025

@rkrage I rebased the branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants