Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rubocop #20

Merged
merged 4 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more manual fixes
  • Loading branch information
Alex Evanczuk committed Sep 28, 2022
commit b97121168d76590dcf2ed1aa71b81dd238f86567
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ Layout/ArgumentAlignment:

Style/AccessorGrouping:
Enabled: false

Style/NumericPredicate:
Enabled: false
2 changes: 1 addition & 1 deletion lib/use_packwerk/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Logging
sig { params(title: String, block: T.proc.void).void }
def self.section(title, &block)
print_divider
out ColorizedString.new("#{title}").green.bold
out ColorizedString.new(title).green.bold
out "\n"
yield
end
Expand Down
27 changes: 11 additions & 16 deletions lib/use_packwerk/private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def self.create_pack!(pack_name:, enforce_privacy:, enforce_dependencies:)
end
def self.move_to_pack!(pack_name:, paths_relative_to_root:, per_file_processors: [])
pack_name = Private.clean_pack_name(pack_name)
package = ParsePackwerk.all.find { |package| package.name == pack_name }
package = ParsePackwerk.all.find { |p| p.name == pack_name }
if package.nil?
raise StandardError, "Can not find package with name #{pack_name}. Make sure the argument is of the form `packs/my_pack/`"
end
Expand All @@ -119,9 +119,9 @@ def self.move_to_pack!(pack_name:, paths_relative_to_root:, per_file_processors:
# Later, if we choose to go back to moving whole directories at a time, it should be a refactor and all tests should still pass
#
if origin_pathname.directory?
origin_pathname.glob('**/*.*').reject do |path|
path.to_s.include?(ParsePackwerk::PACKAGE_YML_NAME) ||
path.to_s.include?(ParsePackwerk::DEPRECATED_REFERENCES_YML_NAME)
origin_pathname.glob('**/*.*').reject do |origin_path|
origin_path.to_s.include?(ParsePackwerk::PACKAGE_YML_NAME) ||
origin_path.to_s.include?(ParsePackwerk::DEPRECATED_REFERENCES_YML_NAME)
end
else
origin_pathname
Expand All @@ -141,9 +141,7 @@ def self.move_to_pack!(pack_name:, paths_relative_to_root:, per_file_processors:
end
end

per_file_processors.each do |per_file_processor|
per_file_processor.print_final_message!
end
per_file_processors.each(&:print_final_message!)
end

sig do
Expand All @@ -159,13 +157,13 @@ def self.move_to_parent!(
per_file_processors: []
)
pack_name = Private.clean_pack_name(pack_name)
package = ParsePackwerk.all.find { |package| package.name == pack_name }
package = ParsePackwerk.all.find { |p| p.name == pack_name }
if package.nil?
raise StandardError, "Can not find package with name #{pack_name}. Make sure the argument is of the form `packs/my_pack/`"
end

parent_name = Private.clean_pack_name(parent_name)
parent_package = ParsePackwerk.all.find { |package| package.name == parent_name }
parent_package = ParsePackwerk.all.find { |p| p.name == parent_name }
if parent_package.nil?
parent_package = create_pack_if_not_exists!(pack_name: parent_name, enforce_privacy: true, enforce_dependencies: true)
end
Expand Down Expand Up @@ -272,13 +270,13 @@ def self.add_dependency!(pack_name:, dependency_name:)
all_packages = ParsePackwerk.all

pack_name = Private.clean_pack_name(pack_name)
package = all_packages.find { |package| package.name == pack_name }
package = all_packages.find { |p| p.name == pack_name }
if package.nil?
raise StandardError, "Can not find package with name #{pack_name}. Make sure the argument is of the form `packs/my_pack/`"
end

dependency_name = Private.clean_pack_name(dependency_name)
package_dependency = all_packages.find { |package| package.name == dependency_name }
package_dependency = all_packages.find { |p| p.name == dependency_name }
if package_dependency.nil?
raise StandardError, "Can not find package with name #{dependency_name}. Make sure the argument is of the form `packs/my_pack/`"
end
Expand Down Expand Up @@ -395,10 +393,7 @@ def self.create_pack_if_not_exists!(pack_name:, enforce_privacy:, enforce_depend
raise StandardError, "UsePackwerk only supports packages in the the following directories: #{PERMITTED_PACK_LOCATIONS.inspect}. Please make sure to pass in the name of the pack including the full directory path, e.g. `packs/my_pack`."
end

existing_package = ParsePackwerk.all.find { |package| package.name == pack_name }

package_location = Pathname.new(pack_name)

existing_package = ParsePackwerk.all.find { |p| p.name == pack_name }
if existing_package.nil?
should_enforce_dependenceies = enforce_dependencies.nil? ? UsePackwerk.config.enforce_dependencies : enforce_dependencies

Expand Down Expand Up @@ -428,7 +423,7 @@ def self.create_pack_if_not_exists!(pack_name:, enforce_privacy:, enforce_depend
sig { params(original_package: ParsePackwerk::Package).returns(ParsePackwerk::Package) }
def self.rewrite_package_with_original_packwerk_values(original_package)
ParsePackwerk.bust_cache!
package_with_protection_defaults = T.must(ParsePackwerk.all.find { |package| package.name == original_package.name })
package_with_protection_defaults = T.must(ParsePackwerk.all.find { |p| p.name == original_package.name })
# PackageProtections also sets `enforce_privacy` and `enforce_dependency` to be true, so we set these back down to their original values
package = ParsePackwerk::Package.new(
enforce_dependencies: original_package.enforce_dependencies,
Expand Down
1 change: 0 additions & 1 deletion lib/use_packwerk/private/file_move_operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def origin_pack
def self.destination_pathname_for_package_move(origin_pathname, new_package_root)
origin_pack = T.must(ParsePackwerk.package_from_path(origin_pathname))

new_implementation = nil
if origin_pack.name == ParsePackwerk::ROOT_PACKAGE_NAME
new_package_root.join(origin_pathname).cleanpath
else
Expand Down
8 changes: 4 additions & 4 deletions lib/use_packwerk/private/pack_relationship_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.list_top_privacy_violations(pack_name, limit)
to_package_names = all_packages.map(&:name)
else
pack_name = Private.clean_pack_name(pack_name)
package = all_packages.find { |package| package.name == pack_name }
package = all_packages.find { |p| p.name == pack_name }
if package.nil?
raise StandardError, "Can not find package with name #{pack_name}. Make sure the argument is of the form `packs/my_pack/`"
end
Expand Down Expand Up @@ -85,7 +85,7 @@ def self.list_top_privacy_violations(pack_name, limit)
if pack_name.nil?
violated_symbol = "#{violation.class_name} (#{violation.to_package_name})"
else
violated_symbol = "#{violation.class_name}"
violated_symbol = violation.class_name
end
violations_by_count[violated_symbol] ||= {}
violations_by_count[violated_symbol][:total_count] ||= 0
Expand Down Expand Up @@ -133,7 +133,7 @@ def self.list_top_dependency_violations(pack_name, limit)
to_package_names = all_packages.map(&:name)
else
pack_name = Private.clean_pack_name(pack_name)
package = all_packages.find { |package| package.name == pack_name }
package = all_packages.find { |p| p.name == pack_name }
if package.nil?
raise StandardError, "Can not find package with name #{pack_name}. Make sure the argument is of the form `packs/my_pack/`"
end
Expand Down Expand Up @@ -191,7 +191,7 @@ def self.list_top_dependency_violations(pack_name, limit)
if pack_name.nil?
violated_symbol = "#{violation.class_name} (#{violation.to_package_name})"
else
violated_symbol = "#{violation.class_name}"
violated_symbol = violation.class_name
end
violations_by_count[violated_symbol] ||= {}
violations_by_count[violated_symbol][:total_count] ||= 0
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
end
end

extend T::Sig
extend T::Sig # rubocop:disable Style/MixinUsage:

sig { params(path: String, content: String).returns(Integer) }
def write_file(path, content = '')
Expand Down
1 change: 0 additions & 1 deletion spec/use_packwerk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,6 @@ def expect_files_to_not_exist(files)
- spec/services/horse_like/donkey_spec.rb
CONTENTS

before_codeownership_yml = File.read(Pathname.new('config/code_ownership.yml'))
write_file('app/services/horse_like/donkey.rb')
write_file('spec/services/horse_like/donkey_spec.rb')
write_package_yml('packs/animals')
Expand Down
1 change: 1 addition & 0 deletions use_packwerk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
'public gem pushes.'
end

spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
# Specify which files should be added to the gem when it is released.
spec.files = Dir['README.md', 'lib/**/*', 'bin/**/*']

Expand Down