Skip to content

Commit

Permalink
add standard rb
Browse files Browse the repository at this point in the history
  • Loading branch information
SethHorsley committed Mar 3, 2024
1 parent 170e66c commit e8f14b1
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 10 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,22 @@ on:
pull_request:

jobs:
build:
lint:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Lint code for consistent style
run: bundle exec standardrb

test:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
strategy:
Expand Down
6 changes: 6 additions & 0 deletions .overcommit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PreCommit:
StandardRB:
enabled: true
required: true
command: ['bundle', 'exec', 'standardrb']
flags: ['--fix']
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ gemspec
gem "rake", "~> 13.0"

gem "minitest", "~> 5.16"

gem "standard"
43 changes: 43 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,50 @@ PATH
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
json (2.7.1)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
minitest (5.22.2)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
racc (1.7.3)
rainbow (3.1.1)
rake (13.1.0)
regexp_parser (2.9.0)
rexml (3.2.6)
rubocop (1.61.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.1)
parser (>= 3.3.0.4)
rubocop-performance (1.20.2)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (1.13.0)
standard (1.34.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.60)
standard-custom (~> 1.0.0)
standard-performance (~> 1.3)
standard-custom (1.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.50)
standard-performance (1.3.1)
lint_roller (~> 1.1)
rubocop-performance (~> 1.20.2)
unicode-display_width (2.5.0)

PLATFORMS
arm64-darwin-23
Expand All @@ -17,6 +59,7 @@ DEPENDENCIES
clsx!
minitest (~> 5.16)
rake (~> 13.0)
standard

BUNDLED WITH
2.5.3
4 changes: 0 additions & 4 deletions lib/clsx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ def self.clsx(*args)
args.flat_map { |arg| parse(arg) }.compact.join(" ")
end

private

def self.parse(arg)
case arg
when String
Expand All @@ -20,8 +18,6 @@ def self.parse(arg)
arg.map { |k, v| k if v }.compact
when Array
arg.flat_map { |a| parse(a) }
else
nil
end
end
end
4 changes: 2 additions & 2 deletions lib/clsx/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Railtie < Rails::Railtie
end

module Helper
def clsx(*args)
Clsx.clsx(*args)
def clsx(*)
Clsx.clsx(*)
end
end
end
6 changes: 3 additions & 3 deletions test/test_clsx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def test_strings
end

def test_objects
assert_equal "foo baz", Clsx.clsx({ foo: true, bar: false, baz: true })
assert_equal "foo baz", Clsx.clsx({foo: true, bar: false, baz: true})
end

def test_objects_variadic
assert_equal "foo --foobar", Clsx.clsx({ foo: true }, { bar: false }, nil, { "--foobar" => "hello" })
assert_equal "foo --foobar", Clsx.clsx({foo: true}, {bar: false}, nil, {"--foobar" => "hello"})
end

def test_arrays
Expand All @@ -24,6 +24,6 @@ def test_arrays_variadic
end

def test_kitchen_sink
assert_equal "foo bar hello world cya", Clsx.clsx("foo", [1 && "bar", { baz: false, bat: nil }, ["hello", ["world"]]], "cya")
assert_equal "foo bar hello world cya", Clsx.clsx("foo", [1 && "bar", {baz: false, bat: nil}, ["hello", ["world"]]], "cya")
end
end

0 comments on commit e8f14b1

Please sign in to comment.