📜 ⬆️ ⬇️

Gem finding problems in a Rails application

Greetings, dear habravchane.
For some time now I've been carrying out the idea of ​​writing a gem that could find common mistakes when developing applications on Ruby On Rails.



Most of all I got:
1. The absence of indexes in the database on the keys of associations
2. Finding duplicate keys in localization files
3. Search for missing translations
4. Strings - single and double quotes

The absence of indexes in the database on the keys of associations



')
class User < ActiveRecord::Base has_many :comments #     user_id   Comment     ... end 

If you wish, you can automatically add the missing indexes by generating a migration.
 def AddIndexToComments < ActiveRecord::Migration def change add_index :comments, :user_id end end 


Finding duplicate keys in localization files



config / locales / ru.yml
 welcome: user:   ... #     welcome: user:  

If we call this translation
 I18n.t('welcome.user') #   "" 

What can cause confusion, since we are usually looking for top-down and we will only change the first translation, which will not affect the output of I18n in any way and even restarting the server will not help us :)

Search for missing translations


 %title= t('title') #      ,        TODO 

Alternatively, you can add translations with the text TODO to the locale file so that you can add all the missing translations at once.

Strings - single and double quotes


Displays statistics and automatically corrects strings with double quotes on single quotes, which work faster, since when executing the code, no special characters are searched for inside the string.
 "Welcome" #   'Welcome' #     "Welcome #{name}" 


Export


Export report in html format, the default text mode will be used. For the generation will be used an additional gem, which will be the generator of a beautiful html.

It would be interesting to hear your opinion.

Source: https://habr.com/ru/post/162059/


All Articles