DEV Community

Olivia Mattiazzo
Olivia Mattiazzo

Posted on • Edited on

Super-helpful gem: syntax_suggest

One day at work, Code Climate flagged an error in one of my commits. Honestly, I don't remember exactly what it was, but it was something related to a missing closing parenthesis or brace, something along those lines. The problem was: I went back to my code and, at first glance, couldn't find exactly where the issue was, and there were no additional details anywhere to help. So, I started looking for a solution to better visualize potential syntax errors and stumbled upon a real gem: syntax_suggest! I thought it would be interesting to write a quick post about it here to document this solution for myself, in case I need to use it again in the future!

A red gem


That method to give you a little help.


First of all, I need to clarify that I used this gem in a very specific situation, more to find a problem than to actually fix it. So, what I'll present here is the most basic way to use this little gem. Finally, you can always find more about it on its GitHub repository.

Installation in your Ruby project

Open a console in your Ruby project's folder and install the gem as follows:

gem install syntax_suggest
Enter fullscreen mode Exit fullscreen mode

Checking the syntax of a file

I already knew which file had the issue thanks to Code Climate, so I went straight to the point with the following command (in the application console):

syntax_suggest [file-path]

#Example:
syntax_suggest app/services/file_xpto.rb
Enter fullscreen mode Exit fullscreen mode

An example of how the response is returned:

Unmatched keyword, missing `end' ?

> 1 class Dog
> 2 def bark
> 4 end
Enter fullscreen mode Exit fullscreen mode

If you need help within the console itself, you can always access the gem's help:

syntax_suggest --help
Enter fullscreen mode Exit fullscreen mode

And that's it! A simple and short post, but it was also a quick and easy solution to fix a problem I was facing. I hope it helps you as well!


โœ” Links consulted

๐Ÿ“€ syntax_suggest repository on GitHub


๐Ÿ“ฉ A Last Message

Did you like the text? Do you have anything to add? Any constructive criticism? Feedback? Suggestions? Requests? Feel free to contact me via email (oli.pmatt@gmail.com), LinkedIn (/in/oliviamattiazzo) or through the comments section below! Iโ€™d be delighted to chat with you! โœจ

You can also check the original post (in PT-BR) at my blog: oliviamattiazzo.dev

ko-fi


โฐ Other posts

๐Ÿ’Ž Rails Helpers โ€“ what are they and what are they used for?


๐Ÿชช Credits

The icons used to illustrate this post came from the following IconFinder users:

Top comments (0)