Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand tabs #6094

Merged
merged 1 commit into from
Jul 21, 2022
Merged

Expand tabs #6094

merged 1 commit into from
Jul 21, 2022

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Jul 6, 2022

[Misc #18891]

The code I used to generate this diff

Because ruby-commit-hook's bin/auto-style.rb knows what kind of files should be skipped, I wrote this code based off of auto-style.rb.

DEFAULT_GEM_LIBS = %w[
  bundler
  cmath
  csv
  e2mmap
  fileutils
  forwardable
  ipaddr
  irb
  logger
  matrix
  mutex_m
  ostruct
  prime
  rdoc
  rexml
  rss
  scanf
  shell
  sync
  thwait
  tracer
  webrick
]

DEFAULT_GEM_EXTS = %w[
  bigdecimal
  date
  dbm
  etc
  fcntl
  fiddle
  gdbm
  io/console
  json
  openssl
  psych
  racc
  sdbm
  stringio
  strscan
  zlib
]

IGNORED_FILES = [
  # default gems whose master is GitHub
  %r{\Abin/(?!erb)\w+\z},
  *(DEFAULT_GEM_LIBS + DEFAULT_GEM_EXTS).flat_map { |lib|
    [
      %r{\Alib/#{lib}/},
      %r{\Alib/#{lib}\.gemspec\z},
      %r{\Alib/#{lib}\.rb\z},
      %r{\Atest/#{lib}/},
    ]
  },
  *DEFAULT_GEM_EXTS.flat_map { |ext|
    [
      %r{\Aext/#{ext}/},
      %r{\Atest/#{ext}/},
    ]
  },

  # vendoring (ccan)
  %r{\Accan/},

  # vendoring (nkf)
  %r{\Aext/nkf/nkf-utf8/},

  # vendoring (onigmo)
  %r{\Aenc/},
  %r{\Ainclude/ruby/onigmo\.h\z},
  %r{\Areg.+\.(c|h)\z},

  # explicit or implicit `c-file-style: "linux"`
  %r{\Aaddr2line\.c\z},
  %r{\Amissing/},
  %r{\Astrftime\.c\z},
  %r{\Avsnprintf\.c\z},

  # to respect the original statements of licenses
  %r{\ALEGAL\z},
]

paths = `git ls-files`.split(/\n/)
paths.select! do |l|
  /^\d/ !~ l and /\.bat\z/ !~ l and
  (/\A(?:config|[Mm]akefile|GNUmakefile|README)/ =~ File.basename(l) or
   /\A\z|\.(?:[chsy]|\d+|e?rb|tmpl|bas[eh]|z?sh|in|ma?k|def|src|trans|rdoc|ja|en|el|sed|awk|p[ly]|scm|mspec|html|)\z/ =~ File.extname(l))
end
files = paths.select {|n| File.file?(n) }
files.reject! do |f|
  IGNORED_FILES.any? { |re| f.match(re) }
end
files.select! do |f|
  f.end_with?('.c') || f.end_with?('.h') || f == 'insns.def' || f.end_with?('.c.tmpl') || f.end_with?('.inc.erb')
end

files.each_with_index do |file, index|
  print "\r#{index}/#{files.size}"
  src = File.read(file)
  src.gsub!(/^\t+/) { |tabs| ' ' * (8 * tabs.length) }
  File.write(file, src)
end

.git-blame-ignore-revs is supposed to be created after merging this.

@k0kubun k0kubun marked this pull request as ready for review July 6, 2022 07:15
@mame
Copy link
Member

mame commented Jul 6, 2022

I think ext/nkf/nkf-utf8/* should be also skipped.

@k0kubun
Copy link
Member Author

k0kubun commented Jul 6, 2022

Reflected that to the original script ruby/git.ruby-lang.org@29fdc8a and updated the commit in this PR.

@k0kubun k0kubun force-pushed the expand-tabs branch 2 times, most recently from b15a9d8 to 24a76ad Compare July 21, 2022 16:26
[Misc #18891]
@k0kubun k0kubun merged commit 5b21e94 into ruby:master Jul 21, 2022
@k0kubun k0kubun deleted the expand-tabs branch July 21, 2022 16:42
k0kubun added a commit that referenced this pull request Mar 9, 2023
I used the same script as #6094 but
for a .y file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants