Skip to content

Commit

Permalink
Deprecate .erb-linters in favour of .erb_linters
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshenny authored and george-ma committed Sep 6, 2024
1 parent 5567a06 commit bcb4cda
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,11 @@ Good ✅

## Custom Linters

`erb_lint` allows you to create custom linters specific to your project. It will load linters from the `.erb-linters` directory in the root of your
`erb_lint` allows you to create custom linters specific to your project. It will load linters from the `.erb_linters` directory in the root of your
repository. See the [linters directory](lib/erb_lint/linters) for examples of how to write linters.

```ruby
# .erb-linters/custom_linter.rb
# .erb_linters/custom_linter.rb
module ERBLint
module Linters
Expand Down
12 changes: 11 additions & 1 deletion lib/erb_lint/linter_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
module ERBLint
# Stores all linters available to the application.
module LinterRegistry
CUSTOM_LINTERS_DIR = ".erb-linters"
DEPRECATED_CUSTOM_LINTERS_DIR = ".erb-linters"
CUSTOM_LINTERS_DIR = ".erb_linters"
@loaded_linters = []

class << self
Expand All @@ -28,6 +29,15 @@ def linters

def load_custom_linters(directory = CUSTOM_LINTERS_DIR)
ruby_files = Dir.glob(File.expand_path(File.join(directory, "**", "*.rb")))

deprecated_ruby_files = Dir.glob(File.expand_path(File.join(DEPRECATED_CUSTOM_LINTERS_DIR, "**", "*.rb")))
if deprecated_ruby_files.any?
deprecation_message = "The '#{DEPRECATED_CUSTOM_LINTERS_DIR}' directory for custom linters is deprecated. " \
"Please rename it to '#{CUSTOM_LINTERS_DIR}'"
warn(Rainbow(deprecation_message).yellow)
ruby_files.concat(deprecated_ruby_files)
end

ruby_files.each { |file| require file }
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/erb_lint/linter_registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,14 @@ class FakeLinter < ERBLint::Linter
.with(File.join(custom_directory, "custom_linter.rb")).once)
described_class.load_custom_linters(custom_directory)
end

it "warns when using the deprecated custom linters directory" do
stub_const("ERBLint::LinterRegistry::DEPRECATED_CUSTOM_LINTERS_DIR", custom_directory)

expected_warning = Rainbow("The '#{custom_directory}' directory for custom linters is deprecated. " \
"Please rename it to '.erb_linters'").yellow
expect(described_class).to(receive(:warn).with(expected_warning).once)
described_class.load_custom_linters
end
end
end

0 comments on commit bcb4cda

Please sign in to comment.