aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/linters
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-07-02 01:32:03 +0900
committernsfisis <nsfisis@gmail.com>2026-07-02 01:34:49 +0900
commiteab3a31c5750013c53c0eb02adc976d6757dc9f7 (patch)
treec84b4bc6243668eb79c00af98e00800c2951077b /scripts/linters
parentdda045eb663524b40e277047e3cea301738e5c26 (diff)
downloadphp-shirabe-eab3a31c5750013c53c0eb02adc976d6757dc9f7.tar.gz
php-shirabe-eab3a31c5750013c53c0eb02adc976d6757dc9f7.tar.zst
php-shirabe-eab3a31c5750013c53c0eb02adc976d6757dc9f7.zip
chore(lint): ban std::io::Read/Write, Any, Command use imports
Extends no_banned_use to cover std::any::Any, std::io::Read/Write, and std::process::Command, and teaches the linter to allow `as _` imports so trait methods can still be brought into scope without binding the banned name. Fully qualifies all existing usages across the codebase.
Diffstat (limited to 'scripts/linters')
-rw-r--r--scripts/linters/no_banned_use.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/scripts/linters/no_banned_use.rb b/scripts/linters/no_banned_use.rb
index 341a2b9..311d03c 100644
--- a/scripts/linters/no_banned_use.rb
+++ b/scripts/linters/no_banned_use.rb
@@ -1,5 +1,9 @@
BANNED_USE_PATHS = %w[
anyhow::Result
+ std::any::Any
+ std::io::Read
+ std::io::Write
+ std::process::Command
].freeze
def no_banned_use(root_dir, excludes = [])
@@ -14,7 +18,8 @@ def no_banned_use(root_dir, excludes = [])
return true if errors.empty?
puts 'Found banned `use` imports.'
- puts 'These items must always be referenced by their fully-qualified path:'
+ puts 'These items must always be referenced by their fully-qualified path.'
+ puts 'For imports to use trait methods, use `as _` (e.g., `use std::io::Write as _;`).'
errors.each do |err|
puts " #{err}"
end
@@ -63,7 +68,10 @@ def expand_use_tree(tree)
brace = tree.index('{')
if brace.nil?
- return [strip_use_alias(tree)].reject(&:empty?)
+ stripped = strip_use_alias(tree)
+ return [] if stripped.nil?
+
+ return [stripped].reject(&:empty?)
end
prefix = tree[0...brace].sub(/::\s*\z/, '').strip
@@ -83,6 +91,8 @@ def expand_use_tree(tree)
end
def strip_use_alias(segment)
+ return nil if segment =~ /\s+as\s+_\s*\z/
+
segment.sub(/\s+as\s+\S+\s*\z/, '').strip
end