Skip to content

Instantly share code, notes, and snippets.

@bgvo
Created July 8, 2015 16:14
Show Gist options
  • Save bgvo/8a190a5c77aad1d6a64b to your computer and use it in GitHub Desktop.
Save bgvo/8a190a5c77aad1d6a64b to your computer and use it in GitHub Desktop.
Find (never-ending) syntax errors (Ruby).

Sometimes a linter is not enough. Trying its best, it will point out to the end of file. That's ok if the file is short enough to go through it and spot it. Hoewever, sometimes that's not the case and the error is not so obvious. It's in these cases where one has to apply other techniques.

Instead of going through all the code line by line, what about using your Text Editor Fold/Unfold? For Sublime Text you have the option of folding different lvels of code.

Consider the following code:

module A
  method one
  end
end
module B
  method one
  end
  
  method two
  end
  
  class A
  end
  
end
module C
  method one
  end
  
  method two
  end
end

Normally, you would have all this code unfolded, meaning that you see evrything. Here you have two approaches:

  • Firstly, folding the code where you thing the error should be (probably the last thing you have been working on).
  • If you have no idea where the error is, go for the top-bottom apprach. Fold level 1 first (cmnd+k+1 in ST). If you don't see something like:
module A
end

end

module B
end

module C
end

The error is a level deeper (note the second end). In that case, select all code and press cmnd+k+2 (ST again). If not, then you will have to go more specific and go deeper levels. Until you see an extra end or something that doesn't make sense.

This "technique" has saved me some time today. Hope that it does for you at some point as well :)

Best!

B.

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