Skip to content
New issue

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

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

Already on GitHub? # to your account

Prefer require_relative for internal requires #521

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
46 changes: 23 additions & 23 deletions lib/haml_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
# Need to load haml before we can reference some Haml modules in our code
require 'haml'

require 'haml_lint/constants'
require 'haml_lint/exceptions'
require 'haml_lint/configuration'
require 'haml_lint/configuration_loader'
require 'haml_lint/document'
require 'haml_lint/haml_visitor'
require 'haml_lint/lint'
require 'haml_lint/linter_registry'
require 'haml_lint/ruby_parser'
require 'haml_lint/linter'
require 'haml_lint/logger'
require 'haml_lint/reporter'
require 'haml_lint/report'
require 'haml_lint/linter_selector'
require 'haml_lint/file_finder'
require 'haml_lint/runner'
require 'haml_lint/utils'
require 'haml_lint/version'
require 'haml_lint/version_comparer'
require 'haml_lint/severity'
require_relative 'haml_lint/constants'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this not be ./constants? (Just curious)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

no because haml_lint is in lib, and constants is in lib/haml_lint/constants.rb, so the relative path does include haml_lint

lib/
├── haml_lint/
│   └── constants.rb
└── haml_lint.rb

This is a good reference in a (former) ruby core gem: https://github.com/ruby/logger/blob/d1d704a6336a82903011336a0116012e9aa4a504/lib/logger.rb#L17-L21

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other reference in Ruby core that are not linked in this PR:

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading from the GitHub app on my phone was throwing me off. Pathing makes sense 👍

require_relative 'haml_lint/exceptions'
require_relative 'haml_lint/configuration'
require_relative 'haml_lint/configuration_loader'
require_relative 'haml_lint/document'
require_relative 'haml_lint/haml_visitor'
require_relative 'haml_lint/lint'
require_relative 'haml_lint/linter_registry'
require_relative 'haml_lint/ruby_parser'
require_relative 'haml_lint/linter'
require_relative 'haml_lint/logger'
require_relative 'haml_lint/reporter'
require_relative 'haml_lint/report'
require_relative 'haml_lint/linter_selector'
require_relative 'haml_lint/file_finder'
require_relative 'haml_lint/runner'
require_relative 'haml_lint/utils'
require_relative 'haml_lint/version'
require_relative 'haml_lint/version_comparer'
require_relative 'haml_lint/severity'

# Lead all extensions to external source code
Dir[File.expand_path('haml_lint/extensions/*.rb', File.dirname(__FILE__))].sort.each do |file|
require file
end

# Load all parse tree node classes
require 'haml_lint/tree/node'
require 'haml_lint/node_transformer'
require_relative 'haml_lint/tree/node'
require_relative 'haml_lint/node_transformer'
Dir[File.expand_path('haml_lint/tree/*.rb', File.dirname(__FILE__))].sort.each do |file|
require file
end
Expand All @@ -47,7 +47,7 @@
end

# Load all the chunks for RubyExtraction
require 'haml_lint/ruby_extraction/base_chunk'
require_relative 'haml_lint/ruby_extraction/base_chunk'
Dir[File.expand_path('haml_lint/ruby_extraction/*.rb', File.dirname(__FILE__))].sort.each do |file|
require file
end
6 changes: 3 additions & 3 deletions lib/haml_lint/adapter.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require 'haml_lint/adapter/haml_5'
require 'haml_lint/adapter/haml_6'
require 'haml_lint/exceptions'
require_relative 'adapter/haml_5'
require_relative 'adapter/haml_6'
require_relative 'exceptions'

module HamlLint
# Determines the adapter to use for the current Haml version
Expand Down
4 changes: 2 additions & 2 deletions lib/haml_lint/cli.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'haml_lint'
require 'haml_lint/options'
require_relative '../haml_lint'
require_relative 'options'

require 'sysexits'

Expand Down
2 changes: 1 addition & 1 deletion lib/haml_lint/document.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'haml_lint/adapter'
require_relative 'adapter'

module HamlLint
# Represents a parsed Haml document and its associated metadata.
Expand Down
5 changes: 3 additions & 2 deletions lib/haml_lint/rake_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

require 'rake'
require 'rake/tasklib'
require 'haml_lint/constants'

require_relative 'constants'

module HamlLint
# Rake task interface for haml-lint command line interface.
Expand Down Expand Up @@ -93,7 +94,7 @@ def define

task(name, [:files]) do |_task, task_args|
# Lazy-load so task doesn't affect Rakefile load time
require 'haml_lint/cli'
require_relative 'cli'

run_cli(task_args)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/haml_lint/reporter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'haml_lint/reporter/hooks'
require_relative 'reporter/hooks'

module HamlLint
# Abstract lint reporter. Subclass and override {#display_report} to
Expand Down
2 changes: 1 addition & 1 deletion lib/haml_lint/reporter/default_reporter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'haml_lint/reporter/utils'
require_relative 'utils'

module HamlLint
# Outputs lints in a simple format with the filename, line number, and lint
Expand Down
2 changes: 1 addition & 1 deletion lib/haml_lint/reporter/disabled_config_reporter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'haml_lint/reporter/progress_reporter'
require_relative 'progress_reporter'

module HamlLint
# Outputs a YAML configuration file based on existing violations.
Expand Down
2 changes: 1 addition & 1 deletion lib/haml_lint/reporter/json_reporter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'haml_lint/reporter/hash_reporter'
require_relative 'hash_reporter'

module HamlLint
# Outputs report as a JSON document.
Expand Down
3 changes: 2 additions & 1 deletion lib/haml_lint/reporter/progress_reporter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

require 'rainbow'
require 'haml_lint/reporter/utils'

require_relative 'utils'

module HamlLint
# Outputs files as they are output as a simple symbol, then outputs
Expand Down
1 change: 1 addition & 0 deletions lib/haml_lint/runner.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'parallel'

require_relative 'source'

module HamlLint
Expand Down
8 changes: 4 additions & 4 deletions lib/haml_lint/spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'haml_lint/spec/normalize_indent'
require 'haml_lint/spec/shared_linter_context'
require 'haml_lint/spec/shared_rubocop_autocorrect_context'
require 'haml_lint/spec/matchers/report_lint'
require_relative 'spec/normalize_indent'
require_relative 'spec/shared_linter_context'
require_relative 'spec/shared_rubocop_autocorrect_context'
require_relative 'spec/matchers/report_lint'
2 changes: 1 addition & 1 deletion lib/haml_lint/tree/haml_comment_node.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'haml_lint/directive'
require_relative '../directive'

module HamlLint::Tree
# Represents a HAML comment node.
Expand Down
2 changes: 1 addition & 1 deletion lib/haml_lint/tree/node.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'haml_lint/comment_configuration'
require_relative '../comment_configuration'

module HamlLint::Tree
# Decorator class that provides a convenient set of helpers for HAML's
Expand Down
2 changes: 1 addition & 1 deletion lib/haml_lint/tree/root_node.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'haml_lint/tree/null_node'
require_relative 'null_node'

module HamlLint::Tree
# Represents the root node of a HAML document that contains all other nodes.
Expand Down
2 changes: 1 addition & 1 deletion lib/haml_lint/tree/script_node.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'haml_lint/parsed_ruby'
require_relative '../parsed_ruby'

module HamlLint::Tree
# Represents a node which produces output based on Ruby code.
Expand Down