From 1d8f956167790afb5870714334dd01280be89882 Mon Sep 17 00:00:00 2001 From: Matthew Hutchinson Date: Sat, 28 Dec 2024 21:29:13 +0000 Subject: [PATCH] add Rubocop with omakse rules, correct them, add to gh workflow --- .github/workflows/ci.yml | 46 ++++--- .rubocop.yml | 2 + Gemfile | 6 +- Rakefile | 2 +- lib/lolcommits/plugin/tranzlate.rb | 4 +- lib/lolcommits/tranzlate.rb | 4 +- lib/lolcommits/tranzlate/lolspeak.rb | 151 +++++++++++------------ lolcommits-tranzlate.gemspec | 10 +- test/lolcommits/plugin/tranzlate_test.rb | 4 +- test/test_helper.rb | 12 +- 10 files changed, 131 insertions(+), 110 deletions(-) create mode 100644 .rubocop.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3889e6..7be9e4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,21 @@ on: - main jobs: + rubocop: + name: RuboCop + runs-on: ubuntu-latest + env: + BUNDLE_ONLY: rubocop + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Ruby and install gems + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.3.0 + bundler-cache: true + - name: Run Rubocop + run: bundle exec rubocop --parallel test: name: ${{ format('Unit tests (Ruby {0})', matrix.ruby-version) }} runs-on: ubuntu-latest @@ -21,18 +36,19 @@ jobs: - "3.4" continue-on-error: true steps: - - uses: actions/checkout@v4 - - name: Set up Ruby and install gems - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true - - name: Configure Git - run: | - git config --global user.name $NAME - git config --global user.email $EMAIL - env: - NAME: "George Costanza" - EMAIL: "george.costanza@vandelay.com" - - name: Run tests - run: bundle exec rake test + - name: Checkout code + - uses: actions/checkout@v4 + - name: Setup Ruby and install gems + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + - name: Configure Git + run: | + git config --global user.name $NAME + git config --global user.email $EMAIL + env: + NAME: "George Costanza" + EMAIL: "george.costanza@vandelay.com" + - name: Run tests + run: bundle exec rake test diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..dc9c9b4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,2 @@ +inherit_gem: + rubocop-rails-omakase: rubocop.yml diff --git a/Gemfile b/Gemfile index 851fabc..b816373 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,6 @@ -source 'https://rubygems.org' +source "https://rubygems.org" gemspec + +group :rubocop do + gem "rubocop-rails-omakase", require: false +end diff --git a/Rakefile b/Rakefile index 5a6e947..84cea98 100644 --- a/Rakefile +++ b/Rakefile @@ -18,4 +18,4 @@ Rake::TestTask.new(:test) do |t| t.test_files = FileList["test/**/*_test.rb"] end -task :default => ['test'] +task default: [ "test" ] diff --git a/lib/lolcommits/plugin/tranzlate.rb b/lib/lolcommits/plugin/tranzlate.rb index dad3d1a..86c09db 100644 --- a/lib/lolcommits/plugin/tranzlate.rb +++ b/lib/lolcommits/plugin/tranzlate.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'lolcommits/plugin/base' -require 'lolcommits/tranzlate/lolspeak' +require "lolcommits/plugin/base" +require "lolcommits/tranzlate/lolspeak" module Lolcommits module Plugin diff --git a/lib/lolcommits/tranzlate.rb b/lib/lolcommits/tranzlate.rb index 2ffb228..3bd2d0f 100644 --- a/lib/lolcommits/tranzlate.rb +++ b/lib/lolcommits/tranzlate.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true -require 'lolcommits/tranzlate/version' -require 'lolcommits/plugin/tranzlate' +require "lolcommits/tranzlate/version" +require "lolcommits/plugin/tranzlate" diff --git a/lib/lolcommits/tranzlate/lolspeak.rb b/lib/lolcommits/tranzlate/lolspeak.rb index 5cc2c7b..867ee01 100644 --- a/lib/lolcommits/tranzlate/lolspeak.rb +++ b/lib/lolcommits/tranzlate/lolspeak.rb @@ -3,82 +3,81 @@ module Lolcommits module Tranzlate module Lolspeak - # Adapted and expanded from https://github.com/rwtnorton/moar-lolspeak LOL_DICTIONARY = { - /what/ => %w(wut whut), - /you\b/ => %w(yu yous yoo u yooz), - /cture/ => %w(kshur), - /ss\b/ => %w(s zz z), - /the\b/ => %w(teh), - /more/ => %w(moar), - /my/ => %w(mah mai), - /are/ => %w(is ar), - /eese/ => %w(eez), - /ph/ => %w(f), - /as\b/ => %w(az), - /seriously/ => %w(srsly), - /sion/ => %w(shun), - /just/ => %w(jus), - /ose\b/ => %w(oze), - /eady/ => %w(eddy), - /ome?\b/ => %w(um), - /of\b/ => %w(of ov of), - /uestion/ => %w(wesjun), - /want/ => %w(wants), - /ead\b/ => %w(edd), - /ck/ => %w(kk kkk), - /cat|kitten|kitty/ => %w(kitteh kittehz cat fuzzeh fuzzyrumpus foozles fuzzbut fluffernutter beast mew), - /eak/ => %w(ekk), - /age/ => %w(uj), - /like/ => %w(likez liek licks), - /love/ => %w(lovez lub lubs luv lurve lurves), - /\bis\b/ => ['ar teh', 'ar'], - /nd\b/ => %w(n n'), - /who/ => %w(hoo), - /'/ => [''], - /ese\b/ => %w(eez), - /outh/ => %w(owf), - /scio/ => %w(shu), - /esque/ => %w(esk), - /ture/ => %w(chur), - /\btoo?\b/ => %w(to t 2 to t), - /tious/ => %w(shus), - /sure\b/ => %w(shur), - /tty\b/ => %w(tteh), - /were/ => %w(was), - /ok\b|okay/ => %w(kthxbye!), - /\ba\b/ => %w(uh), - /ym/ => %w(im), - /fish/ => %w(ghoti), - /thy\b/ => %w(fee), - /\wly\w/ => %w(li), - /que\w/ => %w(kwe), - /\both/ => %w(udd), - /though\b/ => %w(tho), - /(t|r|en)ough/ => %w(\1uff), - /ought/ => %w(awt), - /ease/ => %w(eez), - /ing\b/ => %w(in ins ng ing in'), - /have/ => ['haz', 'hav', 'haz a'], - /has/ => %w(haz gots), - /your/ => %w(yur ur yore yoar), - /ove\b/ => %w(oov ove uuv uv oove), - /for/ => %w(for 4 fr fur for foar), - /thank/ => %w(fank tank thx thnx), - /good/ => %w(gud goed guud gude gewd goot gut), - /really/ => %w(rly rily rilly rilleh), - /world/ => %w(wurrld whirld wurld wrld), - /i'?m\b/ => ['im', 'i yam', 'i iz'], - /(?!e)ight/ => %w(ite), - /(?!ues)tion/ => %w(shun), - /you'?re/ => %w(yore yr), - /er\b|are|ere/ => %w(r), - /y\b|ey\b/ => %w(eh), - /ea/ => %w(ee), - /can\si\s(?:ple(?:a|e)(?:s|z)e?)?\s?have\sa/ => ['i can haz'], - /(?:hello|\bhi\b|\bhey\b|howdy|\byo\b),?/ => ['oh hai,'], - /(?:god\b|allah|buddah?|diety|lord)/ => ['ceiling cat'] + /what/ => %w[wut whut], + /you\b/ => %w[yu yous yoo u yooz], + /cture/ => %w[kshur], + /ss\b/ => %w[s zz z], + /the\b/ => %w[teh], + /more/ => %w[moar], + /my/ => %w[mah mai], + /are/ => %w[is ar], + /eese/ => %w[eez], + /ph/ => %w[f], + /as\b/ => %w[az], + /seriously/ => %w[srsly], + /sion/ => %w[shun], + /just/ => %w[jus], + /ose\b/ => %w[oze], + /eady/ => %w[eddy], + /ome?\b/ => %w[um], + /of\b/ => %w[of ov of], + /uestion/ => %w[wesjun], + /want/ => %w[wants], + /ead\b/ => %w[edd], + /ck/ => %w[kk kkk], + /cat|kitten|kitty/ => %w[kitteh kittehz cat fuzzeh fuzzyrumpus foozles fuzzbut fluffernutter beast mew], + /eak/ => %w[ekk], + /age/ => %w[uj], + /like/ => %w[likez liek licks], + /love/ => %w[lovez lub lubs luv lurve lurves], + /\bis\b/ => [ "ar teh", "ar" ], + /nd\b/ => %w[n n'], + /who/ => %w[hoo], + /'/ => [ "" ], + /ese\b/ => %w[eez], + /outh/ => %w[owf], + /scio/ => %w[shu], + /esque/ => %w[esk], + /ture/ => %w[chur], + /\btoo?\b/ => %w[to t 2 to t], + /tious/ => %w[shus], + /sure\b/ => %w[shur], + /tty\b/ => %w[tteh], + /were/ => %w[was], + /ok\b|okay/ => %w[kthxbye!], + /\ba\b/ => %w[uh], + /ym/ => %w[im], + /fish/ => %w[ghoti], + /thy\b/ => %w[fee], + /\wly\w/ => %w[li], + /que\w/ => %w[kwe], + /\both/ => %w[udd], + /though\b/ => %w[tho], + /(t|r|en)ough/ => %w[\1uff], + /ought/ => %w[awt], + /ease/ => %w[eez], + /ing\b/ => %w[in ins ng ing in'], + /have/ => [ "haz", "hav", "haz a" ], + /has/ => %w[haz gots], + /your/ => %w[yur ur yore yoar], + /ove\b/ => %w[oov ove uuv uv oove], + /for/ => %w[for 4 fr fur for foar], + /thank/ => %w[fank tank thx thnx], + /good/ => %w[gud goed guud gude gewd goot gut], + /really/ => %w[rly rily rilly rilleh], + /world/ => %w[wurrld whirld wurld wrld], + /i'?m\b/ => [ "im", "i yam", "i iz" ], + /(?!e)ight/ => %w[ite], + /(?!ues)tion/ => %w[shun], + /you'?re/ => %w[yore yr], + /er\b|are|ere/ => %w[r], + /y\b|ey\b/ => %w[eh], + /ea/ => %w[ee], + /can\si\s(?:ple(?:a|e)(?:s|z)e?)?\s?have\sa/ => [ "i can haz" ], + /(?:hello|\bhi\b|\bhey\b|howdy|\byo\b),?/ => [ "oh hai," ], + /(?:god\b|allah|buddah?|diety|lord)/ => [ "ceiling cat" ] }.freeze def tranzlate(str) @@ -87,8 +86,8 @@ def tranzlate(str) lolstr.gsub!(english, lolspeak.sample) end - lolstr << '! kthxbye!' if rand(10) == 2 - lolstr.gsub!(/(\?|!|,|\.)+/, '!') + lolstr << "! kthxbye!" if rand(10) == 2 + lolstr.gsub!(/(\?|!|,|\.)+/, "!") lolstr.upcase end diff --git a/lolcommits-tranzlate.gemspec b/lolcommits-tranzlate.gemspec index 594e254..8eaa3d4 100644 --- a/lolcommits-tranzlate.gemspec +++ b/lolcommits-tranzlate.gemspec @@ -5,12 +5,12 @@ require 'lolcommits/tranzlate/version' Gem::Specification.new do |spec| spec.name = "lolcommits-tranzlate" spec.version = Lolcommits::Tranzlate::VERSION - spec.authors = ["Matthew Hutchinson"] - spec.email = ["matt@hiddenloop.com"] - spec.summary = %q{lolcommits lolspekk tranzlation plugin} + spec.authors = [ "Matthew Hutchinson" ] + spec.email = [ "matt@hiddenloop.com" ] + spec.summary = %q(lolcommits lolspekk tranzlation plugin) spec.homepage = "https://github.com/lolcommits/lolcommits-tranzlate" spec.license = "LGPL-3.0" - spec.description = %q{TRANZLATE YOAR LOLCOMMIT MSG TO LOLSPEKK} + spec.description = %q(TRANZLATE YOAR LOLCOMMIT MSG TO LOLSPEKK) spec.metadata = { "homepage_uri" => "https://github.com/lolcommits/lolcommits-tranzlate", @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| spec.test_files = `git ls-files -- {test,features}/*`.split("\n") spec.bindir = "bin" spec.executables = [] - spec.require_paths = ["lib"] + spec.require_paths = [ "lib" ] spec.required_ruby_version = ">= 3.1" spec.add_runtime_dependency "lolcommits", ">= 0.17.2" diff --git a/test/lolcommits/plugin/tranzlate_test.rb b/test/lolcommits/plugin/tranzlate_test.rb index a31d17b..23b58cd 100644 --- a/test/lolcommits/plugin/tranzlate_test.rb +++ b/test/lolcommits/plugin/tranzlate_test.rb @@ -1,13 +1,13 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TestLolcommitsPluginTranzlate < Minitest::Test include Lolcommits::TestHelpers::GitRepo include Lolcommits::TestHelpers::FakeIO def test_enabled_returns_false_by_default - refute plugin.enabled? + assert_equal false, plugin.enabled? end def test_enabled_returns_true_when_configured diff --git a/test/test_helper.rb b/test/test_helper.rb index 502bdd9..709b770 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) # lolcommits gem -require 'lolcommits' +require "lolcommits" # lolcommit test helpers -require 'lolcommits/test_helpers/git_repo' -require 'lolcommits/test_helpers/fake_io' +require "lolcommits/test_helpers/git_repo" +require "lolcommits/test_helpers/fake_io" # plugin gem test libs -require 'lolcommits/tranzlate' -require 'minitest/autorun' +require "lolcommits/tranzlate" +require "minitest/autorun" # swallow all debug output during test runs def debug(msg); end