Skip to content

Instantly share code, notes, and snippets.

@alloy
Forked from segiddins/sort_imports
Created September 25, 2015 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alloy/632094beb7d8200f99ac to your computer and use it in GitHub Desktop.
Save alloy/632094beb7d8200f99ac to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'pathname'
code_files = ARGV
code_files.each do |file|
file = Pathname(file)
contents = file.read
contents.gsub!(/(^#import .*\n)+/) do |imports|
imports = imports.split("\n")
imports.map! do |import|
if import =~ /^#import\s+<(.+?)\//
"@import #{$1};"
else
import
end
end
imports.sort.uniq.join("\n") << "\n"
end
file.open('w') { |f| f.write contents }
end
@trinalp
Copy link

trinalp commented Oct 23, 2015

Im know to this whatnam I supposed to do

@trinalp
Copy link

trinalp commented Oct 23, 2015

sort_imports

!/usr/bin/env ruby

require 'pathname'
code_files = ARGV
code_files.each do |file|
file = Pathname(file)
contents = file.read
contents.gsub!(/(^#import .*\n)+/) do |imports|
imports = imports.split("\n")
imports.map! do |import|
if import =~ /^#import\s+<(.+?)//
"@import #{$1};"
else
import
end
end
imports.sort.uniq.join("\n") << "\n"
end
file.open('w') { |f| f.write contents }
end
Comment on gist

Comment
Desktop version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment