diff --git a/README.md b/README.md index 7b1dca4..16cc4f8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/erb_lint/linter_registry.rb b/lib/erb_lint/linter_registry.rb index 3fff5b7..7494835 100644 --- a/lib/erb_lint/linter_registry.rb +++ b/lib/erb_lint/linter_registry.rb @@ -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 @@ -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 diff --git a/spec/erb_lint/linter_registry_spec.rb b/spec/erb_lint/linter_registry_spec.rb index d9f9b63..5f5b7b1 100644 --- a/spec/erb_lint/linter_registry_spec.rb +++ b/spec/erb_lint/linter_registry_spec.rb @@ -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