Skip to content

Use standardrb for code formatting #1300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,27 @@ jobs:

- name: Run tests
run: docker compose run ci


standardrb:
name: Code linting and formatting
runs-on: ubuntu-20.04 # TODO: Change back to 'ubuntu-latest' when https://github.com/microsoft/mssql-docker/issues/899 resolved.

env:
COMPOSE_FILE: compose.ci.yaml

strategy:
fail-fast: false
matrix:
ruby:
- 3.4.1

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Build docker images
run: docker compose build --build-arg TARGET_VERSION=${{ matrix.ruby }}

- name: Run standardrb
run: docker compose run standardrb
14 changes: 6 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gemspec

gem "bcrypt"
gem "pg", ">= 0.18.0"
gem "pg", ">= 0.18.0"
gem "sqlite3", ">= 1.6.6"
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem "benchmark-ips"
Expand All @@ -27,14 +27,14 @@ else
require "net/http"
require "yaml"

spec = eval(File.read("activerecord-sqlserver-adapter.gemspec"))
ver = spec.dependencies.detect { |d| d.name == "activerecord" }.requirement.requirements.first.last.version
spec = Gem::Specification.load("activerecord-sqlserver-adapter.gemspec")
ver = spec.dependencies.detect { |d| d.name == "activerecord" }.requirement.requirements.first.last.version
major, minor, _tiny, pre = ver.split(".")

if pre
ver
else
uri = URI.parse("https://rubygems.org/api/v1/versions/activerecord.yaml")
uri = URI.parse("https://rubygems.org/api/v1/versions/activerecord.yaml")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
Expand Down Expand Up @@ -68,9 +68,7 @@ end
group :guard do
gem "guard"
gem "guard-minitest"
gem "terminal-notifier-guard" if RbConfig::CONFIG["host_os"] =~ /darwin/
gem "terminal-notifier-guard" if /darwin/.match?(RbConfig::CONFIG["host_os"])
end

group :rubocop do
gem "rubocop", require: false
end
gem "standard", require: false
4 changes: 2 additions & 2 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ clearing :on
notification :terminal_notifier if defined?(TerminalNotifier)
ignore %r{debug\.log}

ar_lib = File.join ARTest::SQLServer.root_activerecord, "lib"
ar_lib = File.join ARTest::SQLServer.root_activerecord, "lib"
ar_test = File.join ARTest::SQLServer.root_activerecord, "test"

guard :minitest, {
Expand All @@ -24,7 +24,7 @@ guard :minitest, {
else
watch(%r{^test/cases/\w+_test_sqlserver\.rb$})
watch(%r{^test/cases/coerced_tests\.rb$}) { "test/cases/coerced_tests.rb" }
watch(%r{^lib/active_record/connection_adapters/sqlserver/([^/]+)\.rb$}) { |m| "test/cases/#{m[1]}_test_sqlserver.rb" }
watch(%r{^lib/active_record/connection_adapters/sqlserver/([^/]+)\.rb$}) { |m| "test/cases/#{m[1]}_test_sqlserver.rb" }
watch(%r{^test/cases/helper_sqlserver\.rb$}) { "test" }
end
end
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ task default: [:test]
namespace :test do
ENV["ARCONN"] = "sqlserver"

%w(dblib).each do |mode|
%w[dblib].each do |mode|
Rake::TestTask.new(mode) do |t|
t.libs = ARTest::SQLServer.test_load_paths
t.test_files = test_files
Expand Down
27 changes: 13 additions & 14 deletions activerecord-sqlserver-adapter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@
version = File.read(File.expand_path("VERSION", __dir__)).strip

Gem::Specification.new do |spec|
spec.name = "activerecord-sqlserver-adapter"
spec.platform = Gem::Platform::RUBY
spec.version = version
spec.name = "activerecord-sqlserver-adapter"
spec.platform = Gem::Platform::RUBY
spec.version = version

spec.required_ruby_version = ">= 3.2.0"

spec.license = "MIT"
spec.authors = ["Ken Collins", "Anna Carey", "Will Bond", "Murray Steele", "Shawn Balestracci", "Joe Rafaniello", "Tom Ward", "Aidan Haran"]
spec.email = ["[email protected]", "[email protected]"]
spec.homepage = "http://github.com/rails-sqlserver/activerecord-sqlserver-adapter"
spec.summary = "ActiveRecord SQL Server Adapter."
spec.description = "ActiveRecord SQL Server Adapter. SQL Server 2012 and upward."
spec.license = "MIT"
spec.authors = ["Ken Collins", "Anna Carey", "Will Bond", "Murray Steele", "Shawn Balestracci", "Joe Rafaniello", "Tom Ward", "Aidan Haran"]
spec.email = ["[email protected]", "[email protected]"]
spec.homepage = "http://github.com/rails-sqlserver/activerecord-sqlserver-adapter"
spec.summary = "ActiveRecord SQL Server Adapter."
spec.description = "ActiveRecord SQL Server Adapter. SQL Server 2012 and upward."

spec.metadata = {
spec.metadata = {
"bug_tracker_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues",
"changelog_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v#{version}/CHANGELOG.md",
"source_code_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v#{version}",
"source_code_uri" => "https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v#{version}"
}

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "activerecord", "~> 8.1.0.alpha"
Expand Down
7 changes: 7 additions & 0 deletions compose.ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ services:
command: wait-for sqlserver:1433 -- bundle exec rake test
depends_on:
- "sqlserver"
standardrb:
environment:
- RAILS_BRANCH=main
build:
context: .
dockerfile: Dockerfile.ci
command: bundle exec standardrb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def attributes_for_update(attribute_names)

super(attribute_names).reject do |name|
column = self.class.columns_hash[name]
column && column.respond_to?(:is_identity?) && column.is_identity?
column&.respond_to?(:is_identity?) && column.is_identity?
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def unprepare_sqlserver_statement(sql, binds)
executesql = executesql.match(SQLSERVER_STATEMENT_REGEXP).to_a[1]

binds.each_with_index do |bind, index|

value = if bind.is_a?(::ActiveModel::Attribute) then
value = if bind.is_a?(::ActiveModel::Attribute)
connection.quote(bind.value_for_database)
else
connection.quote(bind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ def construct_relation_for_exists(conditions)
def _construct_relation_for_exists(conditions)
conditions = sanitize_forbidden_attributes(conditions)

if distinct_value && offset_value
relation = if distinct_value && offset_value
# Start of monkey-patch
if select_values.present?
relation = order(*select_values).limit!(1)
order(*select_values).limit!(1)
else
relation = except(:order).limit!(1)
except(:order).limit!(1)
end
# End of monkey-patch
else
relation = except(:select, :distinct, :order)._select!(Arel.sql(::ActiveRecord::FinderMethods::ONE_AS_ONE, retryable: true)).limit!(1)
except(:select, :distinct, :order)._select!(Arel.sql(::ActiveRecord::FinderMethods::ONE_AS_ONE, retryable: true)).limit!(1)
end

case conditions
Expand Down
Loading
Loading