packwerk 1.2.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +3 -3
  3. data/Gemfile.lock +11 -8
  4. data/README.md +5 -4
  5. data/TROUBLESHOOT.md +3 -3
  6. data/USAGE.md +37 -22
  7. data/bin/m +29 -0
  8. data/bin/rake +29 -0
  9. data/bin/rubocop +29 -0
  10. data/bin/srb +29 -0
  11. data/bin/tapioca +29 -0
  12. data/dev.yml +6 -6
  13. data/exe/packwerk +7 -1
  14. data/lib/packwerk/application_load_paths.rb +19 -8
  15. data/lib/packwerk/application_validator.rb +28 -22
  16. data/lib/packwerk/cli.rb +31 -34
  17. data/lib/packwerk/configuration.rb +1 -1
  18. data/lib/packwerk/const_node_inspector.rb +3 -2
  19. data/lib/packwerk/constant_name_inspector.rb +1 -1
  20. data/lib/packwerk/deprecated_references.rb +19 -7
  21. data/lib/packwerk/file_processor.rb +39 -14
  22. data/lib/packwerk/files_for_processing.rb +15 -4
  23. data/lib/packwerk/formatters/offenses_formatter.rb +10 -1
  24. data/lib/packwerk/generators/templates/package.yml +1 -1
  25. data/lib/packwerk/graph.rb +2 -0
  26. data/lib/packwerk/inflector.rb +1 -0
  27. data/lib/packwerk/node.rb +1 -0
  28. data/lib/packwerk/node_processor.rb +10 -22
  29. data/lib/packwerk/node_processor_factory.rb +0 -2
  30. data/lib/packwerk/node_visitor.rb +4 -2
  31. data/lib/packwerk/offenses_formatter.rb +4 -0
  32. data/lib/packwerk/package.rb +34 -5
  33. data/lib/packwerk/package_set.rb +43 -8
  34. data/lib/packwerk/parse_run.rb +9 -7
  35. data/lib/packwerk/parsed_constant_definitions.rb +1 -0
  36. data/lib/packwerk/reference.rb +2 -1
  37. data/lib/packwerk/reference_checking/checkers/checker.rb +21 -0
  38. data/lib/packwerk/reference_checking/checkers/dependency_checker.rb +31 -0
  39. data/lib/packwerk/reference_checking/checkers/privacy_checker.rb +58 -0
  40. data/lib/packwerk/reference_checking/reference_checker.rb +33 -0
  41. data/lib/packwerk/reference_extractor.rb +2 -2
  42. data/lib/packwerk/reference_offense.rb +1 -0
  43. data/lib/packwerk/run_context.rb +9 -6
  44. data/lib/packwerk/sanity_checker.rb +1 -1
  45. data/lib/packwerk/version.rb +1 -1
  46. data/lib/packwerk/violation_type.rb +1 -1
  47. data/lib/packwerk.rb +14 -4
  48. data/packwerk.gemspec +3 -1
  49. data/service.yml +0 -2
  50. data/sorbet/rbi/gems/psych@3.3.2.rbi +24 -0
  51. metadata +28 -10
  52. data/lib/packwerk/checker.rb +0 -17
  53. data/lib/packwerk/dependency_checker.rb +0 -26
  54. data/lib/packwerk/generators/application_validation.rb +0 -62
  55. data/lib/packwerk/generators/templates/packwerk +0 -23
  56. data/lib/packwerk/generators/templates/packwerk_validator_test.rb +0 -11
  57. data/lib/packwerk/privacy_checker.rb +0 -53
@@ -1,62 +0,0 @@
1
- # typed: true
2
- # frozen_string_literal: true
3
-
4
- module Packwerk
5
- module Generators
6
- class ApplicationValidation
7
- class << self
8
- def generate(for_rails_app: false, root: ".", out: $stdout)
9
- new(root, out: out).generate(for_rails_app: for_rails_app)
10
- end
11
- end
12
-
13
- def initialize(root, out: $stdout)
14
- @root = root
15
- @out = out
16
- end
17
-
18
- def generate(for_rails_app:)
19
- @out.puts("📦 Generating application validator...")
20
- if for_rails_app
21
- generate_packwerk_validate_script
22
- else
23
- generate_validation_test
24
- end
25
- end
26
-
27
- private
28
-
29
- def generate_packwerk_validate_script
30
- destination_file_path = File.join(@root, "bin")
31
- FileUtils.mkdir_p(destination_file_path)
32
-
33
- if File.exist?(File.join(destination_file_path, "packwerk"))
34
- @out.puts("⚠️ Packwerk application validation bin script already exists.")
35
- return true
36
- end
37
-
38
- source_file_path = File.expand_path("templates/packwerk", __dir__)
39
- FileUtils.cp(source_file_path, destination_file_path)
40
-
41
- @out.puts("✅ Packwerk application validation bin script generated in #{destination_file_path}")
42
- true
43
- end
44
-
45
- def generate_validation_test
46
- destination_file_path = File.join(@root, "test")
47
- FileUtils.mkdir_p(destination_file_path)
48
-
49
- if File.exist?(File.join(destination_file_path, "packwerk_validator_test.rb"))
50
- @out.puts("⚠️ Packwerk application validation test already exists.")
51
- return true
52
- end
53
-
54
- source_file_path = File.expand_path("templates/packwerk_validator_test.rb", __dir__)
55
- FileUtils.cp(source_file_path, destination_file_path)
56
-
57
- @out.puts("✅ Packwerk application validation test generated in #{destination_file_path}")
58
- true
59
- end
60
- end
61
- end
62
- end
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- # This file was auto-generated by Packwerk through `packwerk init`
5
-
6
- # Needs to be run in test environment in order to have test helper paths available in the autoload paths
7
- ENV["RAILS_ENV"] = "test"
8
-
9
- # Command line arguments needs to be duplicated because spring modifies it
10
- packwerk_argv = ARGV.dup
11
-
12
- begin
13
- load(File.expand_path("spring", __dir__))
14
- rescue LoadError => e
15
- raise unless e.message.include?("spring")
16
- end
17
-
18
- require File.expand_path("../config/environment", __dir__)
19
-
20
- require "packwerk"
21
-
22
- cli = Packwerk::Cli.new
23
- cli.run(packwerk_argv)
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
- require "packwerk"
5
-
6
- # This test is necessary to make sure that the package system is working correctly
7
- class PackwerkValidatorTest < Minitest::Test
8
- def test_the_application_is_correctly_set_up_for_the_package_system
9
- assert(Packwerk::Cli.new.execute_command(["validate"]))
10
- end
11
- end
@@ -1,53 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- module Packwerk
5
- class PrivacyChecker
6
- extend T::Sig
7
- include Checker
8
-
9
- sig { override.returns(Packwerk::ViolationType) }
10
- def violation_type
11
- ViolationType::Privacy
12
- end
13
-
14
- sig do
15
- override
16
- .params(reference: Packwerk::Reference)
17
- .returns(T::Boolean)
18
- end
19
- def invalid_reference?(reference)
20
- return false if reference.constant.public?
21
-
22
- privacy_option = reference.constant.package.enforce_privacy
23
- return false if enforcement_disabled?(privacy_option)
24
-
25
- return false unless privacy_option == true ||
26
- explicitly_private_constant?(reference.constant, explicitly_private_constants: privacy_option)
27
-
28
- true
29
- end
30
-
31
- private
32
-
33
- sig do
34
- params(
35
- constant: ConstantDiscovery::ConstantContext,
36
- explicitly_private_constants: T::Array[String]
37
- ).returns(T::Boolean)
38
- end
39
- def explicitly_private_constant?(constant, explicitly_private_constants:)
40
- explicitly_private_constants.include?(constant.name) ||
41
- # nested constants
42
- explicitly_private_constants.any? { |epc| constant.name.start_with?(epc + "::") }
43
- end
44
-
45
- sig do
46
- params(privacy_option: T.nilable(T.any(T::Boolean, T::Array[String])))
47
- .returns(T::Boolean)
48
- end
49
- def enforcement_disabled?(privacy_option)
50
- [false, nil].include?(privacy_option)
51
- end
52
- end
53
- end