diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-21 08:08:15 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-21 08:08:45 +0900 |
| commit | c899a4675ca90507a420d901ef7fa26d8b285f23 (patch) | |
| tree | 405b8049c3ac59c65d56792c96f4a8c316bf605b /scripts/linters/contiguous_use_block.rb | |
| parent | 6b16a2cd672edcbfeaf7988591db92ed4c594ddc (diff) | |
| download | php-shirabe-c899a4675ca90507a420d901ef7fa26d8b285f23.tar.gz php-shirabe-c899a4675ca90507a420d901ef7fa26d8b285f23.tar.zst php-shirabe-c899a4675ca90507a420d901ef7fa26d8b285f23.zip | |
refactor(lint): rewrite structural linters from Ruby to PHP
Fold scripts/lint and scripts/linters/*.rb into a standalone Composer
project under scripts/linters/, matching the scripts/plugin-class-classifier/
convention. Uses no external packages, only PHP + Composer autoloading.
Verified byte-for-byte identical output against the original Ruby
implementation, both on the current repo (all linters pass) and on a
synthetic fixture exercising every violation type.
Entry point moves from `scripts/lint` to `scripts/linters/lint`.
Diffstat (limited to 'scripts/linters/contiguous_use_block.rb')
| -rw-r--r-- | scripts/linters/contiguous_use_block.rb | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/scripts/linters/contiguous_use_block.rb b/scripts/linters/contiguous_use_block.rb deleted file mode 100644 index b535a038..00000000 --- a/scripts/linters/contiguous_use_block.rb +++ /dev/null @@ -1,82 +0,0 @@ -def contiguous_use_block(root_dir, excludes = []) - pattern = root_dir.join('crates', '**', '*.rs').to_s - errors = Dir.glob(pattern).sort.flat_map do |path| - relative = Pathname.new(path).relative_path_from(root_dir).to_s - next [] if excludes.include?(relative) - - find_split_use_block(path, relative) - end - - return true if errors.empty? - - puts 'Found blank lines splitting the leading `use` block into sections.' - puts 'All `use` statements at the top of the file must be contiguous (no blank lines between them):' - errors.each do |err| - puts " #{err}" - end - false -end - -USE_START_RE = /\A(?:pub(?:\([^)]*\))?\s+)?use\b/ - -def find_split_use_block(path, relative) - lines = File.readlines(path) - errors = [] - - i = skip_preamble(lines) - return [] if i.nil? - - loop do - i = consume_use_statement(lines, i) - break if i >= lines.length - - blanks = [] - j = i - while j < lines.length - stripped = lines[j].strip - if stripped.empty? - blanks << j - j += 1 - elsif stripped.start_with?('//') || stripped.start_with?('#[') - j += 1 - else - break - end - end - - if j < lines.length && lines[j].strip =~ USE_START_RE - blanks.each do |bi| - errors << "#{relative}:#{bi + 1}: blank line splits the leading `use` block" - end - i = j - else - break - end - end - - errors -end - -def skip_preamble(lines) - lines.each_with_index do |raw, idx| - stripped = raw.strip - return idx if stripped =~ USE_START_RE - next if stripped.empty? || stripped.start_with?('//') || stripped.start_with?('#![') || stripped.start_with?('#[') - - return nil - end - nil -end - -def consume_use_statement(lines, start_idx) - brace_depth = 0 - i = start_idx - while i < lines.length - line = lines[i] - brace_depth += line.count('{') - line.count('}') - done = brace_depth <= 0 && line.rstrip.end_with?(';') - i += 1 - return i if done - end - i -end |
