Skip to content

Commit

Permalink
update rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichaelgo committed Jan 17, 2022
1 parent d38956d commit d1a7367
Show file tree
Hide file tree
Showing 24 changed files with 233 additions and 218 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ AllCops:
TargetRubyVersion: 2.5
Exclude:
- 'vendor/bundle/**/*'
- 'tmp/**/*'

Style/GlobalVars:
Exclude:
Expand Down
19 changes: 10 additions & 9 deletions Gemfile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# frozen_string_literal: true
source 'https://rubygems.org'

source "https://rubygems.org"
git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git"
end

gemspec

gem 'liquid', github: 'Shopify/liquid', ref: 'master'
gem "liquid", github: "Shopify/liquid", ref: "master"

group :test do
gem 'rubocop', '~> 0.93.1', require: false
gem 'rubocop-performance', '~> 1.8.1', require: false
gem 'rubocop-shopify', '~> 1.0.6', require: false
gem 'spy', '0.4.1'
gem 'benchmark-ips'
gem 'ruby_memcheck'
gem "rubocop", "~> 1.24.1", require: false
gem "rubocop-performance", "~> 1.13.2", require: false
gem "rubocop-shopify", "~> 2.4.0", require: false
gem "spy", "0.4.1"
gem "benchmark-ips"
gem "ruby_memcheck"
end

group :development do
gem 'byebug'
gem "byebug"
end
19 changes: 10 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# frozen_string_literal: true
require 'rake'
require 'rake/testtask'
require 'bundler/gem_tasks'
require 'rake/extensiontask'
require 'benchmark'
require 'ruby_memcheck'

ENV['DEBUG'] ||= 'true'
require "rake"
require "rake/testtask"
require "bundler/gem_tasks"
require "rake/extensiontask"
require "benchmark"
require "ruby_memcheck"

ENV["DEBUG"] ||= "true"

RubyMemcheck.config(binary_name: "liquid_c")

task default: [:test, :rubocop]

task test: ['test:unit', 'test:integration:all']
task test: ["test:unit", "test:integration:all"]

namespace :test do
task valgrind: ['test:unit:valgrind', 'test:integration:valgrind:all']
task valgrind: ["test:unit:valgrind", "test:integration:valgrind:all"]
end
23 changes: 12 additions & 11 deletions ext/liquid_c/extconf.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# frozen_string_literal: true
require 'mkmf'
$CFLAGS << ' -std=c11 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers'
append_cflags('-fvisibility=hidden')

require "mkmf"
$CFLAGS << " -std=c11 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers"
append_cflags("-fvisibility=hidden")
# In Ruby 2.6 and earlier, the Ruby headers did not have struct timespec defined
valid_headers = RbConfig::CONFIG['host_os'] !~ /linux/ || Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7")
pedantic = !ENV['LIQUID_C_PEDANTIC'].to_s.empty?
valid_headers = RbConfig::CONFIG["host_os"] !~ /linux/ || Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7")
pedantic = !ENV["LIQUID_C_PEDANTIC"].to_s.empty?
if pedantic && valid_headers
$CFLAGS << ' -Werror'
$CFLAGS << " -Werror"
end
if ENV['DEBUG'] == 'true'
append_cflags('-fbounds-check')
CONFIG['optflags'] = ' -O0'
if ENV["DEBUG"] == "true"
append_cflags("-fbounds-check")
CONFIG["optflags"] = " -O0"
else
$CFLAGS << ' -DNDEBUG'
$CFLAGS << " -DNDEBUG"
end

if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7.0") # added in 2.7
$CFLAGS << ' -DHAVE_RB_HASH_BULK_INSERT'
$CFLAGS << " -DHAVE_RB_HASH_BULK_INSERT"
end

$warnflags&.gsub!(/-Wdeclaration-after-statement/, "")
Expand Down
10 changes: 5 additions & 5 deletions lib/liquid/c.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true

require 'liquid/c/version'
require 'liquid'
require 'liquid_c'
require 'liquid/c/compile_ext'
require "liquid/c/version"
require "liquid"
require "liquid_c"
require "liquid/c/compile_ext"

Liquid::C::BlockBody.class_eval do
def render(context)
render_to_output_buffer(context, +'')
render_to_output_buffer(context, +"")
end
end

Expand Down
19 changes: 11 additions & 8 deletions liquid-c.gemspec
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# coding: utf-8
# frozen_string_literal: true
lib = File.expand_path('../lib', __FILE__)

# rubocop:disable Gemspec/RubyVersionGlobalsUsage

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'liquid/c/version'
require "liquid/c/version"

Gem::Specification.new do |spec|
spec.name = "liquid-c"
Expand All @@ -13,19 +16,19 @@ Gem::Specification.new do |spec|
spec.homepage = "https://github.com/shopify/liquid-c"
spec.license = "MIT"

spec.extensions = ['ext/liquid_c/extconf.rb']
spec.extensions = ["ext/liquid_c/extconf.rb"]
spec.files = %x(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.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.5.0"

spec.add_dependency('liquid', '>= 5.0.1')
spec.add_dependency("liquid", ">= 5.0.1")

spec.add_development_dependency('bundler', ">= 1.5") # has bugfix for segfaulting deploys
spec.add_development_dependency("bundler", ">= 1.5") # has bugfix for segfaulting deploys
spec.add_development_dependency("minitest")
spec.add_development_dependency("rake")
spec.add_development_dependency('rake-compiler')
spec.add_development_dependency('minitest')
spec.add_development_dependency('stackprof') if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.1.0")
spec.add_development_dependency("rake-compiler")
spec.add_development_dependency("stackprof") if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.1.0")
end
7 changes: 4 additions & 3 deletions performance.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true
require 'liquid'
require 'liquid/c' if ARGV.shift == "c"
liquid_lib_dir = $LOAD_PATH.detect { |p| File.exist?(File.join(p, 'liquid.rb')) }

require "liquid"
require "liquid/c" if ARGV.shift == "c"
liquid_lib_dir = $LOAD_PATH.detect { |p| File.exist?(File.join(p, "liquid.rb")) }

(script = ARGV.shift) || abort("unspecified performance script")
require File.join(File.dirname(liquid_lib_dir), "performance/#{script}")
10 changes: 5 additions & 5 deletions performance/c_profile.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

require 'liquid'
require 'liquid/c'
liquid_lib_dir = $LOAD_PATH.detect { |p| File.exist?(File.join(p, 'liquid.rb')) }
require "liquid"
require "liquid/c"
liquid_lib_dir = $LOAD_PATH.detect { |p| File.exist?(File.join(p, "liquid.rb")) }
require File.join(File.dirname(liquid_lib_dir), "performance/theme_runner")

TASK_NAMES = %w(run compile render)
task_name = ARGV.first || 'run'
TASK_NAMES = ["run", "compile", "render"]
task_name = ARGV.first || "run"
unless TASK_NAMES.include?(task_name)
raise "Unsupported task '#{task_name}' (must be one of #{TASK_NAMES})"
end
Expand Down
4 changes: 2 additions & 2 deletions rakelib/compile.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
ext_task = Rake::ExtensionTask.new("liquid_c")

# For MacOS, generate debug information that ruby can read
dsymutil = RbConfig::CONFIG['dsymutil']
dsymutil = RbConfig::CONFIG["dsymutil"]
unless dsymutil.to_s.empty?
ext_lib_path = "lib/#{ext_task.binary}"
dsym_path = "#{ext_lib_path}.dSYM"

file dsym_path => [ext_lib_path] do
sh dsymutil, ext_lib_path
end
Rake::Task['compile'].enhance([dsym_path])
Rake::Task["compile"].enhance([dsym_path])
end
16 changes: 8 additions & 8 deletions rakelib/integration_test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

namespace :test do
integration_test_config = lambda do |t|
t.libs << 'lib'
t.test_files = ['test/integration_test.rb']
t.libs << "lib"
t.test_files = ["test/integration_test.rb"]
end

desc 'run test suite with default parser'
desc "run test suite with default parser"
Rake::TestTask.new(integration: :compile, &integration_test_config)

namespace :integration do
define_env_integration_tests = lambda do |task_name|
rake_task = Rake::Task[task_name]

[
[:lax, { 'LIQUID_PARSER_MODE' => 'lax' }],
[:strict, { 'LIQUID_PARSER_MODE' => 'strict' }],
[:without_vm, { 'LIQUID_C_DISABLE_VM' => 'true' }],
[:lax, { "LIQUID_PARSER_MODE" => "lax" }],
[:strict, { "LIQUID_PARSER_MODE" => "strict" }],
[:without_vm, { "LIQUID_C_DISABLE_VM" => "true" }],
].each do |name, env_vars|
task(name) do
old_env_values = ENV.to_hash.slice(*env_vars.keys)
Expand All @@ -33,11 +33,11 @@ namespace :test do
task(all: [:lax, :strict, :without_vm])
end

define_env_integration_tests.call('test:integration')
define_env_integration_tests.call("test:integration")

RubyMemcheck::TestTask.new(valgrind: :compile, &integration_test_config)
namespace :valgrind do
define_env_integration_tests.call('test:integration:valgrind')
define_env_integration_tests.call("test:integration:valgrind")
end
end
end
4 changes: 2 additions & 2 deletions rakelib/performance.rake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace :benchmark do
end

namespace :c_profile do
%i(run compile render).each do |task_name|
[:run, :compile, :render].each do |task_name|
task(task_name) do
ruby "./performance/c_profile.rb #{task_name}"
end
Expand All @@ -33,7 +33,7 @@ namespace :profile do
end

namespace :compare do
%w(lax warn strict).each do |type|
["lax", "warn", "strict"].each do |type|
desc "Compare Liquid to Liquid-C in #{type} mode"
task type.to_sym do
ruby "./performance.rb bare benchmark #{type}"
Expand Down
2 changes: 1 addition & 1 deletion rakelib/rubocop.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

task :rubocop do
require 'rubocop/rake_task'
require "rubocop/rake_task"
RuboCop::RakeTask.new
end
4 changes: 2 additions & 2 deletions rakelib/unit_test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace :test do
unit_test_config = lambda do |t|
t.libs << 'lib' << 'test'
t.test_files = FileList['test/unit/**/*_test.rb']
t.libs << "lib" << "test"
t.test_files = FileList["test/unit/**/*_test.rb"]
end

Rake::TestTask.new(unit: :compile, &unit_test_config)
Expand Down
6 changes: 3 additions & 3 deletions test/integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

at_exit { GC.start }

require_relative 'liquid_test_helper'
require_relative "liquid_test_helper"

test_files = Dir[File.join(LIQUID_TEST_DIR, 'integration/**/*_test.rb')]
test_files << File.join(LIQUID_TEST_DIR, 'unit/tokenizer_unit_test.rb')
test_files = Dir[File.join(LIQUID_TEST_DIR, "integration/**/*_test.rb")]
test_files << File.join(LIQUID_TEST_DIR, "unit/tokenizer_unit_test.rb")
test_files.each do |test_file|
require test_file
end
16 changes: 8 additions & 8 deletions test/liquid_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
# For example, you could run a single liquid test as follows:
# $ ruby -r./test/liquid_test_helper `bundle info liquid --path`/test/integration/template_test.rb

require 'bundler/setup'
require "bundler/setup"

liquid_lib_dir = $LOAD_PATH.detect { |p| File.exist?(File.join(p, 'liquid.rb')) }
LIQUID_TEST_DIR = File.join(File.dirname(liquid_lib_dir), 'test')
$LOAD_PATH << LIQUID_TEST_DIR << File.expand_path('../lib', __dir__)
liquid_lib_dir = $LOAD_PATH.detect { |p| File.exist?(File.join(p, "liquid.rb")) }
LIQUID_TEST_DIR = File.join(File.dirname(liquid_lib_dir), "test")
$LOAD_PATH << LIQUID_TEST_DIR << File.expand_path("../lib", __dir__)

require 'test_helper'
require 'liquid/c'
require "test_helper"
require "liquid/c"

if ENV['LIQUID_C_DISABLE_VM']
if ENV["LIQUID_C_DISABLE_VM"]
puts "-- Liquid-C VM Disabled"
Liquid::ParseContext.liquid_c_nodes_disabled = true
end

GC.stress = true if ENV['GC_STRESS']
GC.stress = true if ENV["GC_STRESS"]
6 changes: 3 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

at_exit { GC.start }

require 'minitest/autorun'
require 'liquid/c'
require "minitest/autorun"
require "liquid/c"

if GC.respond_to?(:verify_compaction_references)
# This method was added in Ruby 3.0.0. Calling it this way asks the GC to
# move objects around, helping to find object movement bugs.
GC.verify_compaction_references(double_heap: true, toward: :empty)
end

GC.stress = true if ENV['GC_STRESS']
GC.stress = true if ENV["GC_STRESS"]
13 changes: 7 additions & 6 deletions test/unit/block_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true
require 'test_helper'

require "test_helper"

class BlockTest < MiniTest::Test
def test_no_allocation_of_trimmed_strings
Expand All @@ -22,7 +23,7 @@ def test_raise_on_output_with_non_utf8_encoding
def test_write_unicode_characters
output = String.new(encoding: Encoding::UTF_8)
template = Liquid::Template.parse("ü{{ unicode_char }}")
assert_equal("üñ", template.render!({ 'unicode_char' => 'ñ' }, output: output))
assert_equal("üñ", template.render!({ "unicode_char" => "ñ" }, output: output))
end

def test_op_write_raw_w
Expand Down Expand Up @@ -91,7 +92,7 @@ def test_disassemble
def test_exception_renderer_exception
original_error = Liquid::Error.new("original")
handler_error = RuntimeError.new("exception handler error")
context = Liquid::Context.new('raise_error' => ->(_ctx) { raise(original_error) })
context = Liquid::Context.new("raise_error" => ->(_ctx) { raise(original_error) })
context.exception_renderer = lambda do |exc|
if exc == original_error
raise(handler_error)
Expand All @@ -115,9 +116,9 @@ def test_include_partial_with_syntax_error
old_file_system = Liquid::Template.file_system
begin
Liquid::Template.file_system = StubFileSystem.new(
'invalid' => "{% foo %}",
'valid' => '{% include "nested" %}',
'nested' => 'valid',
"invalid" => "{% foo %}",
"valid" => '{% include "nested" %}',
"nested" => "valid",
)

template = Liquid::Template.parse("{% include 'invalid' %},{% include 'valid' %}")
Expand Down
Loading

0 comments on commit d1a7367

Please sign in to comment.