From 900aa0da93e39e2556a745fb713abcec74b5eaf7 Mon Sep 17 00:00:00 2001 From: Julian Pasquale Date: Wed, 29 Nov 2023 10:33:17 -0300 Subject: [PATCH] Move dev dependencies to Gemfile and fix versions (#15) * Move dev dependencies to Gemfile and fix versions * Fix lint issue --- .gitignore | 1 + .rubocop.yml | 108 ++++-------------- Gemfile | 12 ++ Rakefile | 8 ++ bin/console | 1 + htmx-rails.gemspec | 40 +++---- lib/generators/htmx/install_generator.rb | 21 ++-- .../generators/install_generator_spec.rb | 15 ++- spec/spec_helper.rb | 2 +- 9 files changed, 76 insertions(+), 132 deletions(-) rename spec/{ => lib}/generators/install_generator_spec.rb (89%) diff --git a/.gitignore b/.gitignore index 431ecff..397b1fc 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ node_modules/ package.json spec/tmp/ yarn.lock +bun.lockb \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index 948d548..69c451e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,100 +1,34 @@ -AllCops: - TargetRubyVersion: 2.5 - -Style/Documentation: - Enabled: false +inherit_mode: + merge: + - Exclude -Layout/SpaceBeforeFirstArg: - Exclude: - -Layout/SpaceAroundMethodCallOperator: - Enabled: true - -Lint/AmbiguousBlockAssociation: - Exclude: - - spec/**/* +require: + - rubocop-rspec + - rubocop-rake -Lint/RaiseException: - Enabled: true - -Lint/StructNewOverride: - Enabled: true - -Metrics/AbcSize: - # The ABC size is a calculated magnitude, so this number can be an Integer or - # a Float. - Max: 15 +AllCops: + NewCops: enable + TargetRubyVersion: 2.7 -Metrics/BlockLength: - CountComments: false - Max: 25 +Naming/FileName: Exclude: - - '*.gemspec' - - config/**/* - - spec/**/* - ExcludedMethods: - - class_methods - -Metrics/BlockNesting: - Max: 4 - -Metrics/ClassLength: - CountComments: false - Max: 200 - -# Avoid complex methods. -Metrics/CyclomaticComplexity: - Max: 7 + - 'lib/htmx-rails.rb' -Metrics/MethodLength: - CountComments: false - Max: 24 - -Metrics/ModuleLength: - CountComments: false - Max: 200 - -Layout/LineLength: - Max: 100 - # To make it possible to copy or click on URIs in the code, we allow lines - # containing a URI to be longer than Max. - AllowURI: true - URISchemes: - - http - - https - -Metrics/ParameterLists: - Max: 5 - CountKeywordArgs: true - -Metrics/PerceivedComplexity: - Max: 12 - -Style/ExponentialNotation: - Enabled: true +Gemspec/RequireMFA: + Enabled: false -Style/FrozenStringLiteralComment: - Enabled: true +RSpec/BeforeAfterAll: + Enabled: false -Style/ModuleFunction: +Style/Documentation: Enabled: false -Style/RescueModifier: - Exclude: - - spec/**/* +RSpec/FilePath: + Enabled: false -Naming/PredicateName: +RSpec/SpecFilePathFormat: Enabled: false -Naming/FileName: +RSpec/AnyInstance: Exclude: - - lib/htmx-rails.rb - -Style/HashEachMethods: - Enabled: true - -Style/HashTransformKeys: - Enabled: true - -Style/HashTransformValues: - Enabled: true + - 'spec/lib/generators/install_generator_spec.rb' diff --git a/Gemfile b/Gemfile index 535ad56..2705ecf 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,16 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in htmx-rails.gemspec gemspec + +gem 'generator_spec', '~> 0.9.4' +gem 'psych', '>= 5.1.1.1' # pinned due to https://github.com/ruby/psych/issues/655 +gem 'rake', '~> 13.1' +gem 'reek', '~> 6.1' +gem 'rspec', '~> 3.12' +gem 'rubocop', '~> 1.57' +gem 'rubocop-rake', '~> 0.6' +gem 'rubocop-rspec', '~> 2.25' +gem 'simplecov', '~> 0.17.1' diff --git a/Rakefile b/Rakefile index 07fa488..dd41530 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,13 @@ # frozen_string_literal: true +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' + +RSpec::Core::RakeTask.new(:spec) + +task default: :spec + +desc 'Run analysis tools to ensure code quality' task :code_analysis do sh 'bundle exec rubocop lib spec' sh 'bundle exec reek lib' diff --git a/bin/console b/bin/console index fd51e5c..fe5cbc6 100755 --- a/bin/console +++ b/bin/console @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'bundler/setup' require 'htmx/rails' diff --git a/htmx-rails.gemspec b/htmx-rails.gemspec index e0ea975..b414660 100644 --- a/htmx-rails.gemspec +++ b/htmx-rails.gemspec @@ -3,31 +3,25 @@ require_relative 'lib/htmx/rails/version' Gem::Specification.new do |spec| - spec.name = 'htmx-rails' - spec.version = Htmx::Rails::VERSION - spec.authors = ['Julian Pasquale'] - spec.email = ['julian.pasquale@rootstrap.com'] - spec.summary = 'Ruby gem for use HTMX in Rails applications' - spec.description = 'Ruby gem for use HTMX in Rails applications' - spec.homepage = 'https://github.com/rootstrap/htmx-rails' - spec.license = 'MIT' - spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0') + spec.name = 'htmx-rails' + spec.version = Htmx::Rails::VERSION + spec.authors = ['Julian Pasquale'] + spec.email = ['julian.pasquale@rootstrap.com'] + spec.summary = 'Ruby gem for use HTMX in Rails applications' + spec.description = 'Ruby gem for use HTMX in Rails applications' + spec.homepage = 'https://github.com/rootstrap/htmx-rails' + spec.license = 'MIT' - spec.metadata["homepage_uri"] = spec.homepage - spec.metadata["source_code_uri"] = 'https://github.com/rootstrap/htmx-rails' - spec.metadata["changelog_uri"] = 'https://github.com/rootstrap/htmx-rails' + spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0') - spec.files = Dir['LICENSE.txt', 'README.md', 'lib/**/*'] - spec.bindir = 'exe' - spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } + spec.metadata['homepage_uri'] = spec.homepage + spec.metadata['source_code_uri'] = 'https://github.com/rootstrap/htmx-rails' + spec.metadata['changelog_uri'] = 'https://github.com/rootstrap/htmx-rails' + + spec.files = Dir['LICENSE.txt', 'README.md', 'lib/**/*'] + spec.bindir = 'exe' + spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - # Development dependencies. - spec.add_development_dependency 'generator_spec' - spec.add_development_dependency 'psych', '>= 5.1.1.1' # pinned due to https://github.com/ruby/psych/issues/655 - spec.add_development_dependency 'rake' - spec.add_development_dependency 'reek' - spec.add_development_dependency 'rspec' - spec.add_development_dependency 'rubocop' - spec.add_development_dependency 'simplecov', '~> 0.17.1' + spec.add_dependency 'rails', '>= 5.0' end diff --git a/lib/generators/htmx/install_generator.rb b/lib/generators/htmx/install_generator.rb index 22e48d8..21be15f 100644 --- a/lib/generators/htmx/install_generator.rb +++ b/lib/generators/htmx/install_generator.rb @@ -12,17 +12,12 @@ class InstallGenerator < ::Rails::Generators::Base # Setup HTMX def setup - if bun? - setup_bun - elsif importmap? - setup_importmap - elsif webpacker? - setup_webpacker - elsif sprockets? - setup_sprockets - else - raise 'No known asset pipeline detected' - end + return setup_bun if bun? + return setup_importmap if importmap? + return setup_webpacker if webpacker? + return setup_sprockets if sprockets? + + raise 'No known asset pipeline detected.' end private @@ -62,7 +57,7 @@ def setup_bun end def setup_importmap - run "bin/importmap pin htmx.org#{Htmx::Rails::HTMX_VERSION}" + run "bin/importmap pin htmx.org@#{Htmx::Rails::HTMX_VERSION}" add_to_manifest(manifest('app/javascript'), IMPORTMAP_SETUP) end @@ -72,7 +67,7 @@ def setup_sprockets end def setup_webpacker - run "yarn add htmx.org#{Htmx::Rails::HTMX_VERSION}" + run "yarn add htmx.org@#{Htmx::Rails::HTMX_VERSION}" add_to_manifest(manifest(webpack_source_path), WEBPACKER_SETUP) end diff --git a/spec/generators/install_generator_spec.rb b/spec/lib/generators/install_generator_spec.rb similarity index 89% rename from spec/generators/install_generator_spec.rb rename to spec/lib/generators/install_generator_spec.rb index eaa078a..43c4cf2 100644 --- a/spec/generators/install_generator_spec.rb +++ b/spec/lib/generators/install_generator_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Htmx::Generators::InstallGenerator, type: :generator do +RSpec.describe Htmx::Generators::InstallGenerator do include Support::FilesHelper destination File.expand_path('../tmp', __dir__) @@ -29,7 +29,7 @@ run_generator assert_file( 'app/assets/javascripts/application.js', - "\n#{Htmx::Generators::InstallGenerator::SPROCKETS_SETUP}" + "\n#{described_class::SPROCKETS_SETUP}" ) end end @@ -39,7 +39,7 @@ run_generator assert_file( 'app/assets/javascripts/application.js', - Htmx::Generators::InstallGenerator::SPROCKETS_SETUP + described_class::SPROCKETS_SETUP ) end end @@ -51,9 +51,8 @@ hide_const('Sprockets') hide_const('Importmap') - expect_any_instance_of(Htmx::Generators::InstallGenerator) + allow_any_instance_of(described_class) .to receive(:webpack_source_path) - .at_least(1).time .and_return(File.join("#{destination_root}/app/javascript/packs")) end @@ -66,7 +65,7 @@ run_generator assert_file( 'app/javascript/packs/application.js', - Htmx::Generators::InstallGenerator::WEBPACKER_SETUP + described_class::WEBPACKER_SETUP ) end end @@ -76,7 +75,7 @@ run_generator assert_file( 'app/javascript/packs/application.js', - Htmx::Generators::InstallGenerator::WEBPACKER_SETUP + described_class::WEBPACKER_SETUP ) end end @@ -152,7 +151,7 @@ end it 'raise an error' do - expect { run_generator }.to raise_error('No known asset pipeline detected') + expect { run_generator }.to raise_error('No known asset pipeline detected.') end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 20e3309..ea5c709 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,7 +11,7 @@ require 'htmx-rails' # Support files -require 'support/files_helper' +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f } RSpec.configure do |config| # Enable flags like --only-failures and --next-failure