Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnnecessaryStringOutput reports false positives on nested interpolation #29

Closed
fshowalter opened this issue Sep 14, 2014 · 1 comment
Closed
Labels

Comments

@fshowalter
Copy link
Contributor

Hey all,

I think there's a problem with the UnnecessaryStringOutput linter.

When dealing with nested values, if there's interpolation, Haml treats it like a script tag, triggering a false positive.

The following spec illustrates the problem.

context 'when tag contains nested text with interpolation' do
    let(:haml) { <<-'HAML' }
      %tag
        Some #{interpolation} text
    HAML
    it { should_not report_lint }
end

Unfortunately, fixing this by checking for interpolation breaks the following spec:

context 'when script outputs literal string in double quotes' do
    let(:haml) { '= "hello #{world}"' }
    it { should report_lint }
end

As Haml parses each of these as a script node. You might be able to get around it by checking for a space before the quote as that would give you some indication that an equals sign was present, but that would depend on the SpaceBeforeScript linter to ensure all the matches.

Anyone have any ideas?

@sds sds added the bug label Sep 14, 2014
@sds
Copy link
Owner

sds commented Sep 14, 2014

Thanks for the report @fshowalter, and for trying out our unreleased code.

This situation can fortunately be detected by the absence of a leading = to indicate that it is an explicitly defined script node instead of a special case one generated by the HAML parser.

I've gone ahead and fixed this in 84b3681.

@sds sds closed this as completed Sep 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants