firemind / ProjectFiremind-Issues

Issue Tracker for Project Firemind (firemind.ch)
1 stars 0 forks source link

cards submissions should use LF for line terminators instead of CRLF #29

Closed melvinzhang closed 10 years ago

melvinzhang commented 10 years ago

cards added to the repo are using the CRLF line terminators, whereas we use LF (Unix) style terminators in the main repo. This is currently resolved with a normalization commit post integration of the card scripts, eg https://github.com/magarena/magarena/commit/345a64a0a2dd247f681819ba45f29129747ce9bc

It will be great if card scripts can be converted to Unix style line endings pre-commit so as to eliminate the normalization commit altogether.

firemind commented 10 years ago

Well, the scripts are currently commited as submitted through the form on firemind.ch The better solution would probably be to strip out \r on those form submits. Any other operations you want done on those submits while I'm on it? Maybe tabs -> spaces, strip emtpy lines etc.

melvinzhang commented 10 years ago

Now that you mention it, tab to four spaces is another one that crops up often. The full set of normalization steps are:

# add newline to end of file
sed -i -e '$a\' script.txt script.groovy
# convert DOS newlines to UNIX newlines
sed -i -e 's/\x0D$//' script.txt script.groovy
# convert tab to four spaces
sed -i -e 's/\t/    /g' script.txt script.groovy
# remove empty lines in scripts
sed -i -e '/^\s*$/d' script.txt
firemind commented 10 years ago

This is now applied before saving a card script submission:

  def format_scripts
    if self.config
      self.config.gsub!(/\r/,'')
      self.config.gsub!(/^\s*/,'')
      self.config.gsub!(/^\s*$/,'')
    end
    if self.script
      self.script.gsub!(/\r/,'')
      self.script.gsub!(/\t/,'    ')
      self.script.gsub!(/^$\n/,'')
    end
  end
melvinzhang commented 10 years ago

Does the last gsub remove empty lines in groovy file? If so, I think we should leave it out as empty lines in the groovy file helps improve readability of the code. On 28 Oct 2014 02:44, "Mike" notifications@github.com wrote:

This is now applied before saving a card script submission:

def formatscripts if self.config self.config.gsub!(/\r/,'') self.config.gsub!(/^\s/,'') self.config.gsub!(/^\s_$/,'') end if self.script self.script.gsub!(/\r/,'') self.script.gsub!(/\t/,' ') self.script.gsub!(/^$\n/,'') end end

— Reply to this email directly or view it on GitHub https://github.com/firemind/ProjectFiremind-Issues/issues/29#issuecomment-60647595 .

firemind commented 10 years ago

Makes sense, I removed it for groovy files.