From eab3a31c5750013c53c0eb02adc976d6757dc9f7 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 2 Jul 2026 01:32:03 +0900 Subject: 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. --- scripts/linters/no_banned_use.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'scripts') 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 -- cgit v1.3.1