2019-09-04 21:01:54 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
require 'fast_spec_helper'
|
2019-09-04 21:01:54 +05:30
|
|
|
require 'haml_lint'
|
|
|
|
require 'haml_lint/spec'
|
2022-07-16 23:28:13 +05:30
|
|
|
|
|
|
|
require_relative '../../../haml_lint/linter/no_plain_nodes'
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
RSpec.describe HamlLint::Linter::NoPlainNodes, feature_category: :tooling do
|
2019-09-04 21:01:54 +05:30
|
|
|
include_context 'linter'
|
|
|
|
|
|
|
|
context 'reports when a tag has an inline plain node' do
|
|
|
|
let(:haml) { '%tag Hello Tanuki' }
|
|
|
|
let(:message) { "`Hello Tanuki` is a plain node. Please use an i18n method like `= _('Hello Tanuki')`" }
|
|
|
|
|
|
|
|
it { is_expected.to report_lint message: message }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'reports when a tag has multiline plain nodes' do
|
|
|
|
let(:haml) { <<-HAML }
|
|
|
|
%tag
|
|
|
|
Hello
|
|
|
|
Tanuki
|
|
|
|
HAML
|
|
|
|
|
|
|
|
it { is_expected.to report_lint count: 1 }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'reports when a tag has an inline plain node with interpolation' do
|
|
|
|
let(:haml) { '%tag Hello #{"Tanuki"}!' } # rubocop:disable Lint/InterpolationCheck
|
|
|
|
|
|
|
|
it { is_expected.to report_lint }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'does not report when a tag has an inline script' do
|
|
|
|
let(:haml) { '%tag= "Hello Tanuki"' }
|
|
|
|
|
|
|
|
it { is_expected.not_to report_lint }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'does not report when a tag is empty' do
|
|
|
|
let(:haml) { '%tag' }
|
|
|
|
|
|
|
|
it { is_expected.not_to report_lint }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'reports multiple when a tag has multiline plain nodes split by non-text nodes' do
|
|
|
|
let(:haml) { <<-HAML }
|
|
|
|
%tag
|
|
|
|
Hello
|
|
|
|
.split-node There
|
|
|
|
Tanuki
|
|
|
|
HAML
|
|
|
|
|
|
|
|
it { is_expected.to report_lint count: 3 }
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
context 'does not report when a html entity' do
|
|
|
|
let(:haml) { '%tag ' }
|
|
|
|
|
|
|
|
it { is_expected.not_to report_lint }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'does report when something that looks like a html entity' do
|
|
|
|
let(:haml) { '%tag &some text;' }
|
|
|
|
|
|
|
|
it { is_expected.to report_lint }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'does not report multiline when one or more html entities' do
|
2023-06-20 00:43:36 +05:30
|
|
|
%w[ > © »].each do |elem|
|
|
|
|
context "with #{elem}" do
|
|
|
|
let(:haml) { <<-HAML }
|
|
|
|
%tag
|
|
|
|
#{elem}
|
|
|
|
HAML
|
|
|
|
|
|
|
|
it { is_expected.not_to report_lint }
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'does report multiline when one or more html entities amidst plain text' do
|
2023-06-20 00:43:36 +05:30
|
|
|
%w[ Test Test> ©Hello Hello»].each do |elem|
|
|
|
|
context "with #{elem}" do
|
|
|
|
let(:haml) { <<-HAML }
|
|
|
|
%tag
|
|
|
|
#{elem}
|
|
|
|
HAML
|
|
|
|
|
|
|
|
it { is_expected.to report_lint }
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|