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

Leading whitespace linter #47

Open
wezm opened this issue Sep 28, 2016 · 0 comments
Open

Leading whitespace linter #47

wezm opened this issue Sep 28, 2016 · 0 comments

Comments

@wezm
Copy link

wezm commented Sep 28, 2016

I'd like a linter that checks for verbatim text that has leading whitespace. I had a go at creating this linter and came up with the following:

module SlimLint
  # Searches for verbatim text with leading whitespace
  class Linter::LeadingWhitespace < Linter
    include LinterRegistry

    on [:slim, :text, :verbatim] do |sexp|
      _, _, _, content = sexp
      next unless content[/\A\s+/] # This line is obviously wrong

      report_lint(sexp, 'Line contains leading whitespace')
    end
  end
end

With this simple test:

context 'when line contains leading spaces' do
  let(:slim) { "'  Text with unecessary whitespace" }

  it { should report_lint line: 1 }
end

content ends up being:

[<#Atom :multi>, [<#Atom :slim>, <#Atom :interpolate>, <#Atom " Text with unecessary whitespace">]]

I'm not sure what the best way to match on this and extract the text so that it can be checked for leading whitespace.

Are you able to point me in the right direction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant