Skip to content

A platform for community discussion. Free, open, simple.

DEV: Fix bin/lint and bin/qunit directory path handling (#38569)

Sérgio Saquetim614600d7b573
diff --git a/bin/lint b/bin/lint
index 58790e8e3c9..b3d3bc0d77d 100755
--- a/bin/lint
+++ b/bin/lint
@@ -49,7 +49,17 @@ class LefthookLinter
end
files
- .map { |f| normalize_relative_path(f) }
+ .flat_map { |f|
+ path = normalize_relative_path(f)
+ if File.directory?(path)
+ expanded = Dir.glob(File.join(path, "**", "*"))
+ .select { |g| File.file?(g) && lintable_file?(g) }
+ abort "Error: No lintable files found in directory: #{path}" if expanded.empty?
+ expanded
+ else
+ [path]
+ end
+ }
.select { |f| File.file?(f) && lintable_file?(f) }
.uniq
end
@@ -222,7 +232,7 @@ def parse_options
OptionParser
.new do |parser|
- parser.banner = "Usage: bin/lint [options] [files...]"
+ parser.banner = "Usage: bin/lint [options] [files|directories...]"
parser.on("-h", "--help", "Show this help message") do
puts parser
@@ -235,6 +245,7 @@ def parse_options
puts " bin/lint --wip # Lint staged + unstaged + files changed since main"
puts " bin/lint --fix app.rb file2.js # Fix specific file/s"
puts " bin/lint app/models/*.rb # Lint multiple files"
+ puts " bin/lint frontend/discourse/app/ # Lint all lintable files in directory"
puts
puts "Note: This script now uses lefthook to run linters."
puts "Check lefthook.yml for linting configuration."
diff --git a/bin/qunit b/bin/qunit
index 6a19f9e6397..e3143deb515 100755
--- a/bin/qunit
+++ b/bin/qunit
@@ -122,6 +122,7 @@ class QunitRunner
opts.separator <<~NOTES
\nExamples:
bin/qunit frontend/discourse/tests/unit/models/user-test.js
+ bin/qunit frontend/discourse/tests/unit/ # Run all tests in directory
bin/qunit --standalone --target plugins # Run all plugin tests
bin/qunit --standalone --target chat # Run single plugin tests
bin/qunit --standalone plugins/chat/test/javascripts/unit/lib/chat-audio-test.js
@@ -183,7 +184,7 @@ class QunitRunner
if File.directory?(path)
test_files = Dir.glob(File.join(path, "**", "*-test.{js,gjs}"))
if test_files.empty?
- puts "Warning: No test files found in directory: #{path}" if @verbose
+ abort "Error: No test files found in directory: #{path}"
else
expanded.concat(test_files)
end