Skip to content

Commit 3d056c4

Browse files
authored
Setup StandardRB for code formatting & linting (#36)
1 parent dcb27fe commit 3d056c4

26 files changed

+135
-127
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424
ruby-version: ${{ matrix.ruby }}
2525
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
2626
- run: bundle exec rake
27+
# NOTE: calling "bundle install" because the cache apparently did not update due to the gemspec injection
28+
- run: bundle install && bundle exec standardrb
29+
if: matrix.ruby == '3.0' # not using "head" because rubocop won't work there yet
2730
# What's below helps having a single "status check" for mergeability, without
2831
# having to add each new version to the list of expected status checks in GitHub.
2932
# See https://github.community/t/status-check-for-a-matrix-jobs/127354/7

Changes.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ HEAD
33

44
- Drop support for Ruby < 2.5
55
- Add compatibility for Kiba 4
6+
- [StandardRB](https://github.com/testdouble/standard) has been added for formatting & linting the codebase.
7+
68

79
1.1.0
810
----

Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

33
gemspec

Rakefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
require 'rake/testtask'
1+
require "rake/testtask"
22

33
Rake::TestTask.new(:test) do |t|
4-
t.pattern = 'test/test_*.rb'
4+
t.pattern = "test/test_*.rb"
55
end
66

77
task default: :test

kiba-common.gemspec

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# -*- encoding: utf-8 -*-
2-
require File.expand_path('../lib/kiba-common/version', __FILE__)
1+
require File.expand_path("../lib/kiba-common/version", __FILE__)
32

43
Gem::Specification.new do |gem|
5-
gem.authors = ['Thibaut Barrère']
6-
gem.email = ['[email protected]']
7-
gem.description = gem.summary = 'Commonly used helpers for Kiba ETL'
8-
gem.homepage = 'https://github.com/thbar/kiba-common'
9-
gem.license = 'LGPL-3.0'
10-
gem.files = `git ls-files | grep -Ev '^(examples)'`.split("\n")
11-
gem.test_files = `git ls-files -- test/*`.split("\n")
12-
gem.name = 'kiba-common'
13-
gem.require_paths = ['lib']
14-
gem.version = Kiba::Common::VERSION
15-
gem.metadata = {
16-
'source_code_uri' => 'https://github.com/thbar/kiba-common',
17-
'documentation_uri' => 'https://github.com/thbar/kiba-common/blob/master/README.md',
4+
gem.authors = ["Thibaut Barrère"]
5+
gem.email = ["[email protected]"]
6+
gem.description = gem.summary = "Commonly used helpers for Kiba ETL"
7+
gem.homepage = "https://github.com/thbar/kiba-common"
8+
gem.license = "LGPL-3.0"
9+
gem.files = `git ls-files | grep -Ev '^(examples)'`.split("\n")
10+
gem.test_files = `git ls-files -- test/*`.split("\n")
11+
gem.name = "kiba-common"
12+
gem.require_paths = ["lib"]
13+
gem.version = Kiba::Common::VERSION
14+
gem.metadata = {
15+
"source_code_uri" => "https://github.com/thbar/kiba-common",
16+
"documentation_uri" => "https://github.com/thbar/kiba-common/blob/master/README.md"
1817
}
1918

20-
gem.add_dependency 'kiba', '>= 3.0.0', '< 5'
21-
gem.add_development_dependency 'rake'
22-
gem.add_development_dependency 'minitest'
23-
gem.add_development_dependency 'amazing_print'
24-
gem.add_development_dependency 'minitest-focus'
19+
gem.add_dependency "kiba", ">= 3.0.0", "< 5"
20+
gem.add_development_dependency "rake"
21+
gem.add_development_dependency "minitest"
22+
gem.add_development_dependency "amazing_print"
23+
gem.add_development_dependency "minitest-focus"
24+
gem.add_development_dependency "standard"
2525
end

lib/kiba-common/destinations/csv.rb

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
require 'csv'
1+
require "csv"
22

33
module Kiba
44
module Common
55
module Destinations
66
class CSV
77
attr_reader :filename, :csv_options, :csv, :headers
8-
8+
99
def initialize(filename:, csv_options: nil, headers: nil)
1010
@filename = filename
1111
@csv_options = csv_options || {}
1212
@headers = headers
1313
end
14-
14+
1515
def write(row)
16-
@csv ||= ::CSV.open(filename, 'wb', **csv_options)
16+
@csv ||= ::CSV.open(filename, "wb", **csv_options)
1717
@headers ||= row.keys
18-
@headers_written ||= (csv << headers ; true)
18+
@headers_written ||= begin
19+
csv << headers
20+
true
21+
end
1922
csv << row.fetch_values(*@headers)
2023
end
21-
24+
2225
def close
2326
csv&.close
2427
end
2528
end
2629
end
2730
end
28-
end
31+
end

lib/kiba-common/destinations/lambda.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Common
33
module Destinations
44
class Lambda
55
attr_reader :on_write, :on_close
6-
6+
77
def initialize(on_init: nil, on_write: nil, on_close: nil)
88
@on_write = on_write
99
@on_close = on_close

lib/kiba-common/dsl_extensions/logger.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'logger'
1+
require "logger"
22

33
module Kiba
44
module Common
@@ -10,7 +10,7 @@ def logger=(logger_instance)
1010
end
1111

1212
def logger
13-
@logger ||= self.logger = ::Logger.new(STDOUT)
13+
@logger ||= self.logger = ::Logger.new($stdout)
1414
end
1515
end
1616
end

lib/kiba-common/sources/csv.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'csv'
1+
require "csv"
22

33
module Kiba
44
module Common

lib/kiba-common/sources/enumerable.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Enumerable
77
def initialize(enumerable)
88
@enumerable = enumerable
99
end
10-
10+
1111
def unwrap_enumerable
1212
enumerable.respond_to?(:call) ? enumerable.call : enumerable
1313
end

lib/kiba-common/transforms/enumerable_exploder.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ def process(row)
99
end
1010
end
1111
end
12-
end
12+
end

lib/kiba-common/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Kiba
22
module Common
3-
VERSION = '1.1.0'
3+
VERSION = "1.1.0"
44
end
55
end

test/helper.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
require 'minitest/autorun'
2-
require 'minitest/pride'
3-
require 'minitest/focus'
1+
require "minitest/autorun"
2+
require "minitest/pride"
3+
require "minitest/focus"
44

5-
require 'kiba-common/sources/enumerable'
6-
require_relative 'support/assert_called'
5+
require "kiba-common/sources/enumerable"
6+
require_relative "support/assert_called"

test/support/assert_called.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ def assert_called(klass, method, args, return_value = nil)
77
end
88
mock.verify
99
end
10-
end
10+
end

test/support/test_array_destination.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ class TestArrayDestination
22
def initialize(array)
33
@array = array
44
end
5-
5+
66
def write(row)
77
@array << row
88
end
9-
end
9+
end

test/support/test_hash_configured_object.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class TestHashConfiguredObject
22
def initialize(config)
33
@config = config
44
end
5-
5+
66
def each
77
yield(@config)
88
end

test/support/test_keyword_proxy_source.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def initialize(mandatory:, optional: nil)
33
@mandatory = mandatory
44
@optional = optional
55
end
6-
6+
77
def each
88
yield({
99
mandatory: @mandatory,

test/test_csv_destination.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
require_relative 'helper'
2-
require 'kiba'
3-
require 'kiba-common/destinations/csv'
1+
require_relative "helper"
2+
require "kiba"
3+
require "kiba-common/destinations/csv"
44

55
class TestCSVDestination < Minitest::Test
6-
TEST_FILENAME = 'output.csv'
7-
6+
TEST_FILENAME = "output.csv"
7+
88
def teardown
99
File.delete(TEST_FILENAME) if File.exist?(TEST_FILENAME)
1010
end
@@ -21,24 +21,24 @@ def run_etl(csv_options: nil, headers: nil)
2121
end
2222

2323
Kiba.run(job)
24-
24+
2525
IO.read(TEST_FILENAME)
2626
end
27-
27+
2828
def test_classic
2929
assert_equal <<~CSV, run_etl
3030
name,age
3131
world,999
3232
CSV
3333
end
34-
34+
3535
def test_csv_options
36-
assert_equal <<~CSV, run_etl(csv_options: {col_sep: ';'})
36+
assert_equal <<~CSV, run_etl(csv_options: {col_sep: ";"})
3737
name;age
3838
world;999
3939
CSV
4040
end
41-
41+
4242
def test_headers_provided
4343
assert_equal <<~CSV, run_etl(headers: [:age])
4444
age

test/test_csv_source.rb

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
require_relative 'helper'
2-
require 'kiba'
3-
require 'kiba-common/sources/csv'
4-
require_relative 'support/test_array_destination'
1+
require_relative "helper"
2+
require "kiba"
3+
require "kiba-common/sources/csv"
4+
require_relative "support/test_array_destination"
55

66
class TestCSVSource < MiniTest::Test
7-
TEST_FILENAME = 'input.csv'
7+
TEST_FILENAME = "input.csv"
88

99
def setup
10-
CSV.open(TEST_FILENAME, 'wb') do |csv|
11-
csv << %w(first_name last_name)
12-
csv << %w(John Barry)
13-
csv << %w(Kate Bush)
10+
CSV.open(TEST_FILENAME, "wb") do |csv|
11+
csv << %w[first_name last_name]
12+
csv << %w[John Barry]
13+
csv << %w[Kate Bush]
1414
end
1515
end
1616

@@ -30,11 +30,11 @@ def run_job(args)
3030

3131
def test_with_csv_options
3232
rows = run_job filename: TEST_FILENAME,
33-
csv_options: { headers: true, header_converters: :symbol }
33+
csv_options: {headers: true, header_converters: :symbol}
3434

3535
assert_equal [CSV::Row], rows.map(&:class).uniq
3636
assert_equal([
37-
{first_name: "John", last_name: "Barry" },
37+
{first_name: "John", last_name: "Barry"},
3838
{first_name: "Kate", last_name: "Bush"}
3939
], rows.map(&:to_h))
4040
end
@@ -43,9 +43,9 @@ def test_without_csv_options
4343
rows = run_job(filename: TEST_FILENAME)
4444

4545
assert_equal [
46-
%w(first_name last_name),
47-
%w(John Barry),
48-
%w(Kate Bush)
46+
%w[first_name last_name],
47+
%w[John Barry],
48+
%w[Kate Bush]
4949
], rows
5050
end
5151
end
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
require_relative 'helper'
2-
require 'kiba'
3-
require_relative 'support/test_array_destination'
4-
require 'kiba-common/transforms/enumerable_exploder'
5-
require 'kiba/dsl_extensions/config'
1+
require_relative "helper"
2+
require "kiba"
3+
require_relative "support/test_array_destination"
4+
require "kiba-common/transforms/enumerable_exploder"
5+
require "kiba/dsl_extensions/config"
66

77
class TestEnumerableExploderTransform < Minitest::Test
88
def test_exploder
99
output = []
10-
input = [[1,2],[3,4,5]]
10+
input = [[1, 2], [3, 4, 5]]
1111

1212
job = Kiba.parse do
1313
extend Kiba::DSLExtensions::Config
@@ -18,7 +18,7 @@ def test_exploder
1818
destination TestArrayDestination, output
1919
end
2020
Kiba.run(job)
21-
21+
2222
assert_equal input.flatten, output
2323
end
24-
end
24+
end

test/test_enumerable_source.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
require_relative 'helper'
2-
require 'kiba'
3-
require_relative 'support/test_array_destination'
1+
require_relative "helper"
2+
require "kiba"
3+
require_relative "support/test_array_destination"
44

55
class TestEnumerableSource < Minitest::Test
66
def assert_enumerable_source(input:, expected_output:)
@@ -16,12 +16,12 @@ def assert_enumerable_source(input:, expected_output:)
1616
end
1717
Kiba.run(job)
1818
end
19-
19+
2020
def test_source_as_enumerable
2121
assert_enumerable_source(input: (1..10), expected_output: (2..20).step(2).to_a)
2222
end
23-
23+
2424
def test_source_as_callable
2525
assert_enumerable_source(input: -> { (1..10) }, expected_output: (2..20).step(2).to_a)
2626
end
27-
end
27+
end

0 commit comments

Comments
 (0)