diff --git a/.rubocop.yml b/.rubocop.yml index e6a0981..0c3b2c9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,10 @@ +inherit_gem: + rubocop-shopify: rubocop.yml + +require: + - rubocop-performance + - rubocop-sorbet + AllCops: TargetRubyVersion: 2.6 SuggestExtensions: false diff --git a/Gemfile b/Gemfile index cb5084c..ea14755 100644 --- a/Gemfile +++ b/Gemfile @@ -8,8 +8,9 @@ gemspec # TODO: Move to gemspec after merged https://github.com/Shopify/packwerk/pull/375 gem "packwerk", git: "https://github.com/richardmarbach/packwerk", branch: "configurable_parser_interface" -gem "rake", "~> 13.0" - -gem "minitest", "~> 5.16" - -gem "rubocop", "~> 1.21" +gem "minitest" +gem "rake" +gem "rubocop", require: false +gem "rubocop-performance", require: false +gem "rubocop-sorbet", require: false +gem "rubocop-shopify", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 76b26ff..103b909 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -69,6 +69,8 @@ GEM mutex_m (0.2.0) nokogiri (1.16.0-arm64-darwin) racc (~> 1.4) + nokogiri (1.16.0-x86_64-linux) + racc (~> 1.4) parallel (1.24.0) parser (3.2.2.4) ast (~> 2.4.1) @@ -98,6 +100,13 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) + rubocop-performance (1.20.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-shopify (2.14.0) + rubocop (~> 1.51) + rubocop-sorbet (0.7.6) + rubocop (>= 0.90.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) smart_properties (1.17.0) @@ -110,13 +119,17 @@ GEM PLATFORMS arm64-darwin-21 + x86_64-linux DEPENDENCIES - minitest (~> 5.16) + minitest packwerk! packwerk_yard! - rake (~> 13.0) - rubocop (~> 1.21) + rake + rubocop + rubocop-performance + rubocop-shopify + rubocop-sorbet BUNDLED WITH 2.4.18 diff --git a/Rakefile b/Rakefile index 2bf771f..83a04c0 100644 --- a/Rakefile +++ b/Rakefile @@ -9,4 +9,4 @@ require "rubocop/rake_task" RuboCop::RakeTask.new -task default: %i[test rubocop] +task default: [:test, :rubocop] diff --git a/lib/packwerk_yard.rb b/lib/packwerk_yard.rb index 4470cde..745eb12 100644 --- a/lib/packwerk_yard.rb +++ b/lib/packwerk_yard.rb @@ -1,3 +1,4 @@ +# typed: false # frozen_string_literal: true require "packwerk" @@ -6,5 +7,5 @@ require_relative "packwerk_yard/version" require_relative "packwerk_yard/parser" -module PackwerkYard # rubocop:disable Style/Documentation +module PackwerkYard end diff --git a/lib/packwerk_yard/parser.rb b/lib/packwerk_yard/parser.rb index 2e45822..001b35a 100644 --- a/lib/packwerk_yard/parser.rb +++ b/lib/packwerk_yard/parser.rb @@ -1,7 +1,8 @@ +# typed: false # frozen_string_literal: true module PackwerkYard - class Parser # rubocop:disable Style/Documentation + class Parser include Packwerk::FileParser # Array Syntax e.g. Array @@ -21,8 +22,8 @@ def call(io:, file_path: "") to_ruby_ast( types.map { |type| to_evaluable_type(type) } .reject { |type| to_constant(type).nil? } - .inspect.gsub('"', ""), - file_path + .inspect.delete('"'), + file_path, ) end @@ -58,7 +59,7 @@ def to_evaluable_type(type) end def to_constant(name) - Object.const_get(name) + Object.const_get(name) # rubocop:disable Sorbet/ConstantsFromStrings rescue NameError nil end @@ -66,7 +67,7 @@ def to_constant(name) def to_ruby_ast(code, file_path) @ruby_parser.call( io: StringIO.new(code), - file_path: file_path + file_path: file_path, ) end end diff --git a/lib/packwerk_yard/version.rb b/lib/packwerk_yard/version.rb index 0d18288..ed82be0 100644 --- a/lib/packwerk_yard/version.rb +++ b/lib/packwerk_yard/version.rb @@ -1,3 +1,4 @@ +# typed: false # frozen_string_literal: true module PackwerkYard diff --git a/packwerk_yard.gemspec b/packwerk_yard.gemspec index 8db57e8..5c05108 100644 --- a/packwerk_yard.gemspec +++ b/packwerk_yard.gemspec @@ -23,15 +23,15 @@ Gem::Specification.new do |spec| # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(__dir__) do - `git ls-files -z`.split("\x0").reject do |f| + %x(git ls-files -z).split("\x0").reject do |f| (File.expand_path(f) == __FILE__) || - f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile]) + f.start_with?("bin/", "test/", "spec/", "features/", ".git", ".github", "appveyor", "Gemfile") end end spec.bindir = "exe" spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_dependency "parser" - spec.add_dependency "yard" + spec.add_dependency("parser") + spec.add_dependency("yard") end diff --git a/test/test_helper.rb b/test/test_helper.rb index 6abbc9b..90211fc 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,7 @@ +# typed: false # frozen_string_literal: true -$LOAD_PATH.unshift File.expand_path("../lib", __dir__) +$LOAD_PATH.unshift(File.expand_path("../lib", __dir__)) require "packwerk_yard" require "minitest/autorun" diff --git a/test/unit/packwerk_yard/parser_test.rb b/test/unit/packwerk_yard/parser_test.rb index 32710ea..0842e02 100644 --- a/test/unit/packwerk_yard/parser_test.rb +++ b/test/unit/packwerk_yard/parser_test.rb @@ -1,3 +1,4 @@ +# typed: false # frozen_string_literal: true require "test_helper" @@ -9,9 +10,9 @@ def test_call_returns_node_with_valid_file io = StringIO.new(File.read("test/fixtures/yard/valid.rb")) node = parser.call(io: io, file_path: "test/fixtures/yard/valid.rb") - assert_instance_of Parser::AST::Node, node - assert node.type, :array - assert node.children[0].children[1], :String + assert_instance_of(::Parser::AST::Node, node) + assert(node.type, :array) + assert(node.children[0].children[1], :String) end def test_call_return_node_with_not_exists_class_args_file @@ -19,9 +20,9 @@ def test_call_return_node_with_not_exists_class_args_file io = StringIO.new(File.read("test/fixtures/yard/not_exists_class_args.rb")) node = parser.call(io: io, file_path: "test/fixtures/yard/not_exists_class_args.rb") - assert_instance_of Parser::AST::Node, node - assert node.type, :array - assert node.children.size, 0 + assert_instance_of(::Parser::AST::Node, node) + assert(node.type, :array) + assert(node.children.size, 0) end end end