Last active
June 23, 2016 20:30
-
-
Save alloy-d/cac53cd86ba490b0fda6c3f4f30b9b9d to your computer and use it in GitHub Desktop.
Inconsistent indenting in the project? Brute-force it away!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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