Skip to content

Commit

Permalink
Make code compatible with Shopify ruby style.
Browse files Browse the repository at this point in the history
Add .editorconfig to support common config for editors.
Update Github action workflow to run Linter task.
Update code to support Shopify ruby style.
  • Loading branch information
miry committed May 25, 2022
1 parent 1d532d5 commit 4693e30
Show file tree
Hide file tree
Showing 57 changed files with 1,306 additions and 1,032 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# EditorConfig is awesome: https://EditorConfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 2
trim_trailing_whitespace = true

[{*.rb,*.rake}]
indent_size = 2
indent_style = space

[{*.har,*.json}]
indent_size = 2
indent_style = space

[{*.lock,*.yaml,*.yml}]
indent_size = 2
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Gemfile.lock linguist-generated
34 changes: 34 additions & 0 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Analysis

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
schedule:
- cron: 13 7 * * 6

concurrency:
group: ${{ github.ref }}-analysis
cancel-in-progress: true

jobs:
linting:
env:
BUNDLE_WITHOUT: test

name: Ruby linter
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
bundler-cache: true
-
name: Linting
run: bundle exec rubocop

20 changes: 17 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
inherit_from:
- http://shopify.github.io/ruby-style-guide/rubocop.yml
require:
- rubocop-minitest
- rubocop-rake

inherit_from: .rubocop_todo.yml

inherit_gem:
rubocop-shopify: rubocop.yml

AllCops:
TargetRubyVersion: '2.6'
TargetRubyVersion: '2.7'
NewCops: enable

Naming/InclusiveLanguage:
Enabled: false

Style/GlobalVars:
Exclude:
- ext/semian/extconf.rb
15 changes: 15 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-05-19 18:59:22 UTC using RuboCop version 1.29.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 4
# Configuration parameters: AllowComments, AllowNil.
Lint/SuppressedException:
Exclude:
- 'test/helpers/circuit_breaker_helper.rb'
- 'test/net_http_test.rb'
- 'test/protected_resource_test.rb'
7 changes: 4 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"recommendations": [
"ms-vscode-remote.vscode-remote-extensionpack"
],
"recommendations": [
"ms-vscode-remote.vscode-remote-extensionpack",
"EditorConfig.EditorConfig"
]
}
44 changes: 27 additions & 17 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
source 'https://rubygems.org'
# frozen_string_literal: true

gem 'benchmark-memory'
gem 'grpc'
gem 'hiredis', '~> 0.6'
gem 'memory_profiler'
gem 'minitest'
gem 'mocha'
gem 'mysql2', '~> 0.5', github: 'brianmario/mysql2'
gem 'pry-byebug', require: false
gem 'rake-compiler'
gem 'rake'
gem 'redis-client', '0.2.0'
gem 'redis'
gem 'rubocop'
gem 'timecop'
gem 'toxiproxy'
gem 'webrick'
source "https://rubygems.org"

group :test do
gem "benchmark-memory"
gem "grpc"
gem "hiredis", "~> 0.6"
gem "memory_profiler"
gem "minitest"
gem "mocha"
gem "mysql2", "~> 0.5", github: "brianmario/mysql2"
gem "pry-byebug", require: false
gem "rake-compiler"
gem "rake"
gem "redis-client", "0.2.0"
gem "redis"
gem "timecop"
gem "toxiproxy"
gem "webrick"
end

group :lint do
gem "rubocop-minitest", require: false
gem "rubocop-rake", require: false
gem "rubocop-shopify", require: false
gem "rubocop", require: false
end

gemspec
9 changes: 9 additions & 0 deletions Gemfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 24 additions & 20 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,59 +1,63 @@
require 'bundler/gem_tasks'
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
rescue LoadError
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rubocop/rake_task"
RuboCop::RakeTask.new do |task|
task.requires << "rubocop-minitest"
task.requires << "rubocop-rake"
end

# ==========================================================
# Packaging
# ==========================================================

GEMSPEC = eval(File.read('semian.gemspec'))
GEMSPEC = eval(File.read("semian.gemspec")) # rubocop:disable Security/Eval

require 'rubygems/package_task'
require "rubygems/package_task"
Gem::PackageTask.new(GEMSPEC) do |_pkg|
end

# ==========================================================
# Ruby Extension
# ==========================================================

$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require 'semian/platform'
$LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
require "semian/platform"
if Semian.sysv_semaphores_supported?
require 'rake/extensiontask'
Rake::ExtensionTask.new('semian', GEMSPEC) do |ext|
ext.ext_dir = 'ext/semian'
ext.lib_dir = 'lib/semian'
require "rake/extensiontask"
Rake::ExtensionTask.new("semian", GEMSPEC) do |ext|
ext.ext_dir = "ext/semian"
ext.lib_dir = "lib/semian"
end
desc "Build gem"
task build: :compile
else
task :build do
desc "Build gem"
task :build do # rubocop:disable Rake/DuplicateTask
end
end

# ==========================================================
# Testing
# ==========================================================

require 'rake/testtask'
Rake::TestTask.new 'test' do |t|
t.libs = %w(lib test)
require "rake/testtask"
Rake::TestTask.new("test") do |t|
t.libs = ["lib", "test"]
t.pattern = "test/*_test.rb"
t.warning = false
if ENV["CI"] || ENV["VERBOSE"]
t.options = '-v'
t.options = "-v"
end
end

# ==========================================================
# Documentation
# ==========================================================
require 'rdoc/task'
require "rdoc/task"
RDoc::Task.new do |rdoc|
rdoc.rdoc_files.include("lib/*.rb", "ext/semian/*.c")
end

task default: :build
task default: :test
task default: :test # rubocop:disable Rake/DuplicateTask
40 changes: 21 additions & 19 deletions ext/semian/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
$LOAD_PATH.unshift File.expand_path("../../../lib", __FILE__)
# frozen_string_literal: true

require 'semian/platform'
$LOAD_PATH.unshift(File.expand_path("../../../lib", __FILE__))

require "semian/platform"

unless Semian.sysv_semaphores_supported?
File.write "Makefile", <<MAKEFILE
all:
clean:
install:
MAKEFILE
File.write("Makefile", <<~MAKEFILE)
all:
clean:
install:
MAKEFILE
exit
end

require 'mkmf'
require "mkmf"

abort 'openssl is missing. please install openssl.' unless find_header('openssl/sha.h')
abort 'openssl is missing. please install openssl.' unless find_library('crypto', 'SHA1')
abort "openssl is missing. please install openssl." unless find_header("openssl/sha.h")
abort "openssl is missing. please install openssl." unless find_library("crypto", "SHA1")

have_header 'sys/ipc.h'
have_header 'sys/sem.h'
have_header 'sys/types.h'
have_header "sys/ipc.h"
have_header "sys/sem.h"
have_header "sys/types.h"

have_func 'rb_thread_blocking_region'
have_func 'rb_thread_call_without_gvl'
have_func "rb_thread_blocking_region"
have_func "rb_thread_call_without_gvl"

$CFLAGS = "-D_GNU_SOURCE -Werror -Wall "
if ENV.key?('DEBUG')
$CFLAGS << "-O0 -g -DDEBUG"
$CFLAGS += if ENV.key?("DEBUG")
"-O0 -g -DDEBUG"
else
$CFLAGS << "-O3"
"-O3"
end

create_makefile('semian/semian')
create_makefile("semian/semian")
Loading

0 comments on commit 4693e30

Please sign in to comment.