Skip to content

Instantly share code, notes, and snippets.

@alloy-d
Last active June 23, 2016 20:30
Show Gist options
  • Save alloy-d/cac53cd86ba490b0fda6c3f4f30b9b9d to your computer and use it in GitHub Desktop.
Save alloy-d/cac53cd86ba490b0fda6c3f4f30b9b9d to your computer and use it in GitHub Desktop.
Inconsistent indenting in the project? Brute-force it away!
#!/usr/bin/env ruby
globs = [
'src/**/*.js',
'src/**/*.less',
'test/**/*.js',
'test/**/*.json',
'*.js'
]
paths = globs.map{|glob| Dir[glob] }.reduce(:+)
# If there are any lines that start with _only_ two spaces,
# then the file uses two-space indentation.
is_twospaced = lambda do |text|
text.lines.any? do |line|
line.match(/^ [^ ]/)
end
end
paths.map do |path|
[path, File.read(path)]
end.reject do |(path, contents)|
is_twospaced.call(contents)
end.map do |(path, contents)|
[path, contents.gsub(/ {4}/, ' ')]
end.each do |(path, contents)|
File.open(path, 'w') {|f| f.write(contents) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment