简体   繁体   中英

Double Quotation marks for html classes

When using Rubocop, they specify to use single quotation marks rather than double quotation in possible places other than interpolation. So what about the views of a rails app. The classes in the views are written as follows,

<div class="row-fluid">
</div>

Should this also be changed to single quotations? Do that have any performance change? I just want to know why does Rubocop prefer to use single quotation over double quotation.

TL;DR

  1. Rubocop does not care about views.
  2. HTML is not Ruby, thus it does not even make sense to follow Ruby conventions in HTML.

Should this also be changed to single quotations?

Rubocop does not check views, so it's up to your preferences.

I just want to know why does Rubocop prefer to use single quotation over double quotation.

Today there is no performance difference when using single/double quotes.

I think it is just a matter of taste. I prefer to use single quotes if there is no need in double ones (interpolation). And it occurs to be the opinion of the majority of active members of Ruby community .

  1. This is not a convention widely followed. For example I'd say that you will find more double quoted simple strings in Rails than single quoted ones (if you exclude requires which are typically single quoted).

  2. It's a rule I personally dislike because I usually do not know if a string will ever require a special character or interpolation (again except for requires). Example:

     raise ArgumentError, 'Expected a string' 

    could later become:

     raise ArgumentError, "Expected a string, got #{some_arg}" 

    I dislike having to change single quotes to double quotes.

  3. I don't think there is much to gain with such a rule. If there was to be a rule, then I'd say prefer single-quoted strings for strings that should not have special characters nor interpolation (like files to require), but for everything else, I think it should be a personal choice as many policies, eg double quote only when needed, or on the contrary single quote only when needed (my preference), both make sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM