Skip to content

Commit

Permalink
Added haml-lint and fix warnings (mastodon#2773)
Browse files Browse the repository at this point in the history
* add haml_lint to Gemfile

* add .haml-lint.yml

* fix warnings of haml_lint
  • Loading branch information
yhirano55 authored and Gargron committed May 8, 2017
1 parent b18504a commit 48594b1
Show file tree
Hide file tree
Showing 39 changed files with 207 additions and 90 deletions.
108 changes: 108 additions & 0 deletions .haml-lint.yml
@@ -0,0 +1,108 @@
# Whether to ignore frontmatter at the beginning of HAML documents for
# frameworks such as Jekyll/Middleman
skip_frontmatter: false

exclude:
- 'vendor/**/*'
- 'spec/**/*'
- 'lib/templates/**/*'
- 'app/views/kaminari/**/*'

linters:
AltText:
enabled: false

ClassAttributeWithStaticValue:
enabled: true

ClassesBeforeIds:
enabled: true

ConsecutiveComments:
enabled: true

ConsecutiveSilentScripts:
enabled: true
max_consecutive: 2

EmptyObjectReference:
enabled: true

EmptyScript:
enabled: true

FinalNewline:
enabled: true
present: true

HtmlAttributes:
enabled: true

ImplicitDiv:
enabled: true

LeadingCommentSpace:
enabled: true

LineLength:
enabled: false
max: 80

MultilinePipe:
enabled: true

MultilineScript:
enabled: true

ObjectReferenceAttributes:
enabled: true

RuboCop:
enabled: true
# These cops are incredibly noisy when it comes to HAML templates, so we
# ignore them.
ignored_cops:
- Lint/BlockAlignment
- Lint/EndAlignment
- Lint/Void
- Metrics/BlockLength
- Metrics/LineLength
- Style/AlignParameters
- Style/BlockNesting
- Style/ElseAlignment
- Style/EndOfLine
- Style/FileName
- Style/FinalNewline
- Style/FrozenStringLiteralComment
- Style/IfUnlessModifier
- Style/IndentationWidth
- Style/Next
- Style/TrailingBlankLines
- Style/TrailingWhitespace
- Style/WhileUntilModifier

RubyComments:
enabled: true

SpaceBeforeScript:
enabled: true

SpaceInsideHashAttributes:
enabled: true
style: space

Indentation:
enabled: true
character: space # or tab

TagName:
enabled: true

TrailingWhitespace:
enabled: true

UnnecessaryInterpolation:
enabled: true

UnnecessaryStringOutput:
enabled: true
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -89,6 +89,7 @@ group :development do
gem 'brakeman', '~> 3.6.0', require: false
gem 'bundler-audit', '~> 0.4.0', require: false
gem 'scss_lint', '0.42.2', require: false
gem 'haml_lint', '~> 0.19.0', require: false

gem 'capistrano', '3.8.0'
gem 'capistrano-rails'
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Expand Up @@ -157,6 +157,13 @@ GEM
addressable (~> 2.4)
http (~> 2.0)
nokogiri (~> 1.6)
haml (4.0.7)
tilt
haml_lint (0.19.0)
haml (~> 4.0)
rake (>= 10, < 13)
rubocop (>= 0.36.0)
sysexits (~> 1.1)
hamlit (2.8.1)
temple (>= 0.8.0)
thor
Expand Down Expand Up @@ -431,6 +438,7 @@ GEM
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
statsd-instrument (2.1.2)
sysexits (1.2.0)
temple (0.8.0)
terminal-table (1.7.3)
unicode-display_width (~> 1.1.1)
Expand Down Expand Up @@ -495,6 +503,7 @@ DEPENDENCIES
fast_blank
fuubar
goldfinger
haml_lint (~> 0.19.0)
hamlit-rails
hiredis
htmlentities
Expand Down
2 changes: 1 addition & 1 deletion app/views/about/_contact.html.haml
Expand Up @@ -7,7 +7,7 @@
.name
= link_to TagManager.instance.url_for(contact.contact_account) do
%span.display_name.emojify= display_name(contact.contact_account)
%span.username= "@#{contact.contact_account.acct}"
%span.username @#{contact.contact_account.acct}

- if contact.site_contact_email
.contact-email
Expand Down
4 changes: 2 additions & 2 deletions app/views/about/_registration.html.haml
Expand Up @@ -11,12 +11,12 @@
required: true,
input_html: { 'aria-label' => t('simple_form.labels.defaults.email') }
= f.input :password,
autocomplete: "off",
autocomplete: 'off',
placeholder: t('simple_form.labels.defaults.password'),
required: true,
input_html: { 'aria-label' => t('simple_form.labels.defaults.password') }
= f.input :password_confirmation,
autocomplete: "off",
autocomplete: 'off',
placeholder: t('simple_form.labels.defaults.confirm_password'),
required: true,
input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_password') }
Expand Down
4 changes: 2 additions & 2 deletions app/views/about/more.html.haml
Expand Up @@ -8,7 +8,7 @@
%h2= site_hostname

- unless @instance_presenter.site_description.blank?
%p= @instance_presenter.site_description.html_safe
%p!= @instance_presenter.site_description

.information-board
.section
Expand All @@ -25,7 +25,7 @@
%span= t 'about.domain_count_after'

- unless @instance_presenter.site_extended_description.blank?
.panel= @instance_presenter.site_extended_description.html_safe
.panel!= @instance_presenter.site_extended_description

.sidebar
= render 'contact', contact: @instance_presenter
Expand Down
6 changes: 3 additions & 3 deletions app/views/about/show.html.haml
Expand Up @@ -20,7 +20,7 @@
= image_tag asset_pack_path('logo.png')
= Setting.site_title

%p= t('about.about_mastodon').html_safe
%p!= t('about.about_mastodon')

.screenshot-with-signup
.mascot= image_tag asset_pack_path('fluffy-elephant-friend.png')
Expand All @@ -32,7 +32,7 @@
- if @instance_presenter.closed_registrations_message.blank?
%p= t('about.closed_registrations')
- else
= @instance_presenter.closed_registrations_message.html_safe
!= @instance_presenter.closed_registrations_message
.info
= link_to t('auth.login'), new_user_session_path, class: 'webapp-btn'
·
Expand Down Expand Up @@ -74,7 +74,7 @@

- unless @instance_presenter.site_description.blank?
%h3= t('about.description_headline', domain: site_hostname)
%p= @instance_presenter.site_description.html_safe
%p!= @instance_presenter.site_description

.actions
.info
Expand Down
2 changes: 1 addition & 1 deletion app/views/accounts/_grid_card.html.haml
Expand Up @@ -4,5 +4,5 @@
.name
= link_to TagManager.instance.url_for(account) do
%span.display_name.emojify= display_name(account)
%span.username= "@#{account.acct}"
%span.username @#{account.acct}
%p.note.emojify= truncate(strip_tags(account.note), length: 150)
4 changes: 2 additions & 2 deletions app/views/accounts/_header.html.haml
@@ -1,4 +1,4 @@
.card.h-card.p-author{ style: "background-image: url(#{account.header.url( :original)})" }
.card.h-card.p-author{ style: "background-image: url(#{account.header.url(:original)})" }
- if user_signed_in? && current_account.id != account.id && !current_account.requested?(account)
.controls
- if current_account.following?(account)
Expand All @@ -13,7 +13,7 @@
%h1.name
%span.p-name.emojify= display_name(account)
%small
%span= "@#{account.username}"
%span @#{account.username}
= fa_icon('lock') if account.locked?
.details
.bio
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/accounts/_card.html.haml
Expand Up @@ -6,7 +6,7 @@
%tr
%td= t('admin.accounts.show.targeted_reports')
%td= link_to pluralize(account.targeted_reports.count, t('admin.accounts.show.report')), admin_reports_path(target_account_id: account.id)
- if account.silenced? or account.suspended?
- if account.silenced? || account.suspended?
%tr
%td= t('admin.accounts.moderation.title')
%td
Expand Down
6 changes: 3 additions & 3 deletions app/views/admin/reports/_report.html.haml
Expand Up @@ -6,15 +6,15 @@
%td.reporter
= link_to report.account.acct, admin_account_path(report.account.id)
%td.comment
%span{title: report.comment}
%span{ title: report.comment }
= truncate(report.comment, length: 30, separator: ' ')
%td.stats
- unless report.statuses.empty?
%span{title: t('admin.accounts.statuses')}
%span{ title: t('admin.accounts.statuses') }
= fa_icon('comment')
= report.statuses.count
- unless report.media_attachments.empty?
%span{title: t('admin.accounts.media_attachments')}
%span{ title: t('admin.accounts.media_attachments') }
= fa_icon('camera')
= report.media_attachments.count
%td
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/settings/edit.html.haml
Expand Up @@ -5,7 +5,7 @@
%table.table
%thead
%tr
%th{width: '40%'}
%th{ width: '40%' }
= t('admin.settings.setting')
%th
%tbody
Expand Down
2 changes: 1 addition & 1 deletion app/views/application/_flashes.html.haml
@@ -1,3 +1,3 @@
- user_facing_flashes.each do |key, value|
.flash-message{class: key}
.flash-message{ class: key }
%strong= value
2 changes: 1 addition & 1 deletion app/views/auth/confirmations/new.html.haml
Expand Up @@ -9,4 +9,4 @@
.actions
= f.button :button, t('auth.resend_confirmation'), type: :submit

.form-footer= render "auth/shared/links"
.form-footer= render 'auth/shared/links'
6 changes: 3 additions & 3 deletions app/views/auth/passwords/edit.html.haml
Expand Up @@ -5,10 +5,10 @@
= render 'shared/error_messages', object: resource
= f.input :reset_password_token, as: :hidden

= f.input :password, autofocus: true, autocomplete: "off", placeholder: t('simple_form.labels.defaults.new_password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.new_password') }
= f.input :password_confirmation, autocomplete: "off", placeholder: t('simple_form.labels.defaults.confirm_new_password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_new_password') }
= f.input :password, autofocus: true, autocomplete: 'off', placeholder: t('simple_form.labels.defaults.new_password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.new_password') }
= f.input :password_confirmation, autocomplete: 'off', placeholder: t('simple_form.labels.defaults.confirm_new_password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_new_password') }

.actions
= f.button :button, t('auth.set_new_password'), type: :submit

.form-footer= render "devise/shared/links"
.form-footer= render 'devise/shared/links'
2 changes: 1 addition & 1 deletion app/views/auth/passwords/new.html.haml
Expand Up @@ -9,4 +9,4 @@
.actions
= f.button :button, t('auth.reset_password'), type: :submit

.form-footer= render "auth/shared/links"
.form-footer= render 'auth/shared/links'
6 changes: 3 additions & 3 deletions app/views/auth/registrations/edit.html.haml
Expand Up @@ -5,9 +5,9 @@
= render 'shared/error_messages', object: resource

= f.input :email, placeholder: t('simple_form.labels.defaults.email'), input_html: { 'aria-label' => t('simple_form.labels.defaults.email') }
= f.input :password, autocomplete: "off", placeholder: t('simple_form.labels.defaults.new_password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.new_password') }
= f.input :password_confirmation, autocomplete: "off", placeholder: t('simple_form.labels.defaults.confirm_new_password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_new_password') }
= f.input :current_password, autocomplete: "off", placeholder: t('simple_form.labels.defaults.current_password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.current_password') }
= f.input :password, autocomplete: 'off', placeholder: t('simple_form.labels.defaults.new_password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.new_password') }
= f.input :password_confirmation, autocomplete: 'off', placeholder: t('simple_form.labels.defaults.confirm_new_password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_new_password') }
= f.input :current_password, autocomplete: 'off', placeholder: t('simple_form.labels.defaults.current_password'), input_html: { 'aria-label' => t('simple_form.labels.defaults.current_password') }

.actions
= f.button :button, t('generic.save_changes'), type: :submit
6 changes: 3 additions & 3 deletions app/views/auth/registrations/new.html.haml
Expand Up @@ -8,10 +8,10 @@
= ff.input :username, autofocus: true, placeholder: t('simple_form.labels.defaults.username'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.username') }

= f.input :email, placeholder: t('simple_form.labels.defaults.email'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.email') }
= f.input :password, autocomplete: "off", placeholder: t('simple_form.labels.defaults.password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.password') }
= f.input :password_confirmation, autocomplete: "off", placeholder: t('simple_form.labels.defaults.confirm_password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_password') }
= f.input :password, autocomplete: 'off', placeholder: t('simple_form.labels.defaults.password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.password') }
= f.input :password_confirmation, autocomplete: 'off', placeholder: t('simple_form.labels.defaults.confirm_password'), required: true, input_html: { 'aria-label' => t('simple_form.labels.defaults.confirm_password') }

.actions
= f.button :button, t('auth.register'), type: :submit

.form-footer= render "auth/shared/links"
.form-footer= render 'auth/shared/links'
2 changes: 1 addition & 1 deletion app/views/auth/sessions/new.html.haml
Expand Up @@ -8,4 +8,4 @@
.actions
= f.button :button, t('auth.login'), type: :submit

.form-footer= render "auth/shared/links"
.form-footer= render 'auth/shared/links'
2 changes: 1 addition & 1 deletion app/views/auth/sessions/two_factor.html.haml
Expand Up @@ -9,4 +9,4 @@
.actions
= f.button :button, t('auth.login'), type: :submit

.form-footer= render "auth/shared/links"
.form-footer= render 'auth/shared/links'
2 changes: 1 addition & 1 deletion app/views/authorize_follows/_card.html.haml
Expand Up @@ -6,7 +6,7 @@
%span.display-name
= link_to TagManager.instance.url_for(account), class: 'detailed-status__display-name p-author h-card', target: '_blank', rel: 'noopener' do
%strong.emojify= display_name(account)
%span= "@#{account.acct}"
%span @#{account.acct}

- if account.note?
.account__header__content.emojify= Formatter.instance.simplified_format(account)
2 changes: 1 addition & 1 deletion app/views/errors/403.html.haml
Expand Up @@ -2,4 +2,4 @@
= t('errors.403')

- content_for :content do
= t('errors.403')
= t('errors.403')
2 changes: 1 addition & 1 deletion app/views/errors/404.html.haml
Expand Up @@ -2,4 +2,4 @@
= t('errors.404')

- content_for :content do
= t('errors.404')
= t('errors.404')
4 changes: 2 additions & 2 deletions app/views/home/index.html.haml
@@ -1,6 +1,6 @@
- content_for :header_tags do
%script#initial-state{:type => 'application/json'}!= json_escape(render(file: 'home/initial_state', formats: :json))
%script#initial-state{ type: 'application/json' }!= json_escape(render(file: 'home/initial_state', formats: :json))

= javascript_pack_tag 'application', integrity: true, crossorigin: 'anonymous'

.app-holder#mastodon{ data: { props: Oj.dump(default_props) }}
.app-holder#mastodon{ data: { props: Oj.dump(default_props) } }
2 changes: 1 addition & 1 deletion app/views/layouts/admin.html.haml
Expand Up @@ -17,4 +17,4 @@

= yield

= render template: "layouts/application", locals: { body_classes: 'admin' }
= render template: 'layouts/application', locals: { body_classes: 'admin' }

0 comments on commit 48594b1

Please sign in to comment.