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

Don't enforce indentation rules inside <pre> tags #33

Open
chris48s opened this issue Oct 4, 2020 · 3 comments
Open

Don't enforce indentation rules inside <pre> tags #33

chris48s opened this issue Oct 4, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@chris48s
Copy link

chris48s commented Oct 4, 2020

Describe the bug

Indentation rules are applied inside <pre>...</pre> blocks

Which terms did you search for in the documentation and issue tracker?

"pre"

Environment

Python 3.8
curlylint==0.12.0

Steps to reproduce

If I run curlylint --rule 'indent: 2' on a snippet like

<pre class="highlight"><code>SELECT
  pid,
  (CURRENT_TIMESTAMP - query_start) as query_time,
  datname,
  usename,
  query
FROM pg_stat_activity
ORDER BY query_time DESC;
</code></pre>

curlylint wants me to change it to

<pre class="highlight">
  <code>
    SELECT
    pid,
    (CURRENT_TIMESTAMP - query_start) as query_time,
    datname,
    usename,
    query
    FROM pg_stat_activity
    ORDER BY query_time DESC;
  </code>
</pre>

to resolve the indent errors. Doing this changes the meaning/display of this snippet from

SELECT
  pid,
  (CURRENT_TIMESTAMP - query_start) as query_time,
  datname,
  usename,
  query
FROM pg_stat_activity
ORDER BY query_time DESC;

to

  
    SELECT
    pid,
    (CURRENT_TIMESTAMP - query_start) as query_time,
    datname,
    usename,
    query
    FROM pg_stat_activity
    ORDER BY query_time DESC;
  

Expected behavior

Don't enforce indentation rules inside <pre>...</pre> blocks

Actual behavior

0:5     '<code>SELECT\n  p…' should be on the next line indent
0:11    Bad text indentation, expected 4, got 2 indent
0:11    Bad text indentation, expected 4, got 0 indent
8:0     Bad indentation, expected 2, got 0      indent
8:7     '</pre>' should be on the next line     indent
@chris48s chris48s added the bug Something isn't working label Oct 4, 2020
@thibaudcolas
Copy link
Owner

Hey @chris48s, thank you for the detailed report. This makes a lot of sense to me.

I’m not too familiar with the implementation of the indent rule, but it looks like the best place to add this special case could be here: https://github.com/thibaudcolas/curlylint/blob/main/curlylint/rules/indent/indent.py#L239

It might make sense to special-case other whitespace-sensitive tags, and-or have a way to configure this in the rule’s options.

@chris48s
Copy link
Author

chris48s commented Oct 8, 2020

Thanks. I've not really spent any time looking into the codebase, but another thing I notice is that there is a file in the test data that has an example of this: https://github.com/thibaudcolas/curlylint/blob/141d880fba52267b2db5465c3ec90bb85baf35bc/tests/jinja2-nunjucks/templates/code-sample.html but it doesn't seem to be causing a test to fail. Are you able to shed any light on how the data is used under test and whether you'd expect that example to be causing a failure?

@thibaudcolas
Copy link
Owner

Good question – currently the tests folder is only used for my manual testing. There are a few templates in there that I’ve gradually started pulling into unit tests, but that’s about it. There are no test cases at all for the indent rule currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants