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

Indentation of multiline method chains in script tags #59

Closed
thibaudcolas opened this issue Feb 26, 2022 · 2 comments · Fixed by #77
Closed

Indentation of multiline method chains in script tags #59

thibaudcolas opened this issue Feb 26, 2022 · 2 comments · Fixed by #77

Comments

@thibaudcolas
Copy link

The following JS within HTML:

<script>
window.fetch('/test.html')
    .then((html) => {
        document.body.innerHTML = html;
    });
</script>

gets indented as:

<script>
    window.fetch('/test.html')
        .then((html) => {
        document.body.innerHTML = html;
    });
</script>

I would have expected everything within the script tag to get one extra level of indentation. I’m not sure what is causing this, but I at least tried with both a function and the arrow function as above, so I suspect it’s the method chaining that might be the problem.

@JaapJoris
Copy link
Member

Thank you for reporting this bug. DjHTML's handling of chained methods is arguably sloppy. This is what happens:

First, the JavaScript is indented "normally" without regards for chained methods:

<script>
    window.fetch('/test.html')
    .then((html) => {
        document.body.innerHTML = html;
    });
</script>

Then, any line that starts with a . is shifted to the right:

<script>
    window.fetch('/test.html')
        .then((html) => {
        document.body.innerHTML = html;
    });
</script>

I find it hard to wrap my head around how chained methods could be handled otherwise. However, they definitely should, because the current way introduces all kinds of indentation errors like this.

@JaapJoris JaapJoris added the help wanted Extra attention is needed label Mar 21, 2022
@JaapJoris JaapJoris removed the help wanted Extra attention is needed label Feb 10, 2023
@JaapJoris JaapJoris self-assigned this Feb 10, 2023
JaapJoris added a commit that referenced this issue Feb 13, 2023
For this release, a substantial part the codebase has been refactored.
Here is a non-exhaustive summary of all the things that have changed:

- Support for Python 3.6 and 3.7 has been dropped
- A Django middleware class to indent HTML responses has been added
- Ignore both opening and closing comment tags
- New handling off both relative and absolute offsets
- Return correct `repr()` strings with the `--debug` option
- New token class "OpenDouble" and a revised indentation algorithm
- Additional `line` argument to `create_token()` methods
- Changed return value of `create_token()` methods
- Changed constructor arguments of Token and Line classes
- Refactored all `create_token()` methods to get rid of return statements
- Simplified test suite runner that reindents the expected output
- Don't indent the contents of template variables (closes #75)
- Improved handling of Django tags inside HTML elements
- Improved JavaScript `case` indentation (closes #76)
- Improved JavaScript method chaining (closes #59)
- Improved CSS multiline statements (closes #74)
- New multiline HTML element indentation (closes #50)
- New multiline HTML attribute value indentation
- Extensive test coverage with lots of edge cases
JaapJoris added a commit that referenced this issue Feb 13, 2023
For this release, a substantial part the codebase has been refactored.
Here is a non-exhaustive summary of all the things that have changed:

- Support for Python 3.6 and 3.7 has been dropped
- A Django middleware class to indent HTML responses has been added
- Ignore both opening and closing comment tags
- New handling off both relative and absolute offsets
- Return correct `repr()` strings with the `--debug` option
- New token class "OpenDouble" and a revised indentation algorithm
- Additional `line` argument to `create_token()` methods
- Changed return value of `create_token()` methods
- Changed constructor arguments of Token and Line classes
- Refactored all `create_token()` methods to get rid of return statements
- Simplified test suite runner that reindents the expected output
- Don't indent the contents of template variables (closes #75)
- Improved handling of Django tags inside HTML elements
- Improved JavaScript `case` indentation (closes #76)
- Improved JavaScript method chaining (closes #59)
- Improved CSS multiline statements (closes #74)
- New multiline HTML element indentation (closes #50)
- New multiline HTML attribute value indentation
- Extensive test coverage with lots of edge cases
JaapJoris added a commit that referenced this issue Feb 13, 2023
For this release, a substantial part the codebase has been refactored.
Here is a non-exhaustive summary of all the things that have changed:

- Support for Python 3.6 and 3.7 has been dropped
- A Django middleware class to indent HTML responses has been added
- Ignore both opening and closing comment tags
- New handling off both relative and absolute offsets
- Return correct `repr()` strings with the `--debug` option
- New token class "OpenDouble" and a revised indentation algorithm
- Additional `line` argument to `create_token()` methods
- Changed return value of `create_token()` methods
- Changed constructor arguments of Token and Line classes
- Refactored all `create_token()` methods to get rid of return statements
- Simplified test suite runner that reindents the expected output
- Don't indent the contents of template variables (closes #75)
- Improved handling of Django tags inside HTML elements
- Improved JavaScript `case` indentation (closes #76)
- Improved JavaScript method chaining (closes #59)
- Improved CSS multiline statements (closes #74)
- New multiline HTML element indentation (closes #50)
- New multiline HTML attribute value indentation
- Extensive test coverage with lots of edge cases
@JaapJoris JaapJoris removed their assignment Feb 21, 2023
@JaapJoris
Copy link
Member

Thanks again for reporting this bug. I'm happy to inform you DjHTML 3.0.0 has just been released with improved handling of JavaScript method chains, switch/case statements, multi-line variable assignments, and many more JS improvements!

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

Successfully merging a pull request may close this issue.

2 participants