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

[Question] Is there any plan to Linter integration for Editor/IDE? #13

Closed
yaegassy opened this issue Sep 15, 2021 · 19 comments
Closed

[Question] Is there any plan to Linter integration for Editor/IDE? #13

yaegassy opened this issue Sep 15, 2021 · 19 comments
Assignees
Labels
❓ question Further information is requested released 🚂 enhancement New feature or request

Comments

@yaegassy
Copy link
Contributor

Thanks for this tool. Do you have any plans for djlint as a linter to run from the Editor or IDE?

Also, in that case, it might be good to have stdin support as well.

Example:

cat polls/templates/index.html | djlint --check  -
@christopherpickering
Copy link
Contributor

Thanks, I haven't used --check in an ide yet, but do plan to add --reformat to the sublime text linter as a keyboard shortcut to reformat an open file.

Sublime uses temp files so there was no need for stdin, but its something to consider. What editor would you use it in?

@christopherpickering christopherpickering self-assigned this Sep 16, 2021
@christopherpickering christopherpickering added 🚂 enhancement New feature or request ❓ question Further information is requested labels Sep 16, 2021
@yaegassy
Copy link
Contributor Author

Thanks reply. I'm using Vim.

If stdin is not supported, you can of course create a tempfile and use that. Is it possible that djlint is more of a formatter tool than a pure linter?

If stdin is supported by linter, it is possible to run lint in some real time without saving the file.

For example, a tool similar to djlint is curlylint.

If you want to support stdin in linter, the implementation of curlylint may be helpful.

@christopherpickering
Copy link
Contributor

Thanks, I'll check it out! Feel free to pr if you have free time :)

djlint does both linting and formatting, but the codebases are completely separate. The linter is more to check for potential html problems, not formatting problems.

@yaegassy
Copy link
Contributor Author

This is an aside.

I'm working on a Vim/Neovim (use coc.nvim plugin) extension for some linter and formatter.

In the case of django html, the formatter uses djhtml.

It would be nice if djlint's linter feature could also be easier to integrate. 🙇

@christopherpickering
Copy link
Contributor

I'll create a new release on pypi shortly with this feature.
You can use it w/

echo "<div></div>" | djlint -

Thanks for the idea!

@yaegassy
Copy link
Contributor Author

@christopherpickering

Does this not require the --check option?

none:

djLint$ poetry shell
Spawning shell within /Users/yaegassy/_Dev/source/djLint/.venv
. /Users/yaegassy/_Dev/source/djLint/.venv/bin/activate
djLint$ . /Users/yaegassy/_Dev/source/djLint/.venv/bin/activate
(.venv) djLint$ echo "  <div></div>" | djlint -

Linting 1/1 files ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00


Linted 1 file, found 0 errors.

add --check:

djLint$ poetry shell
Spawning shell within /Users/yaegassy/_Dev/source/djLint/.venv
. /Users/yaegassy/_Dev/source/djLint/.venv/bin/activate
djLint$ . /Users/yaegassy/_Dev/source/djLint/.venv/bin/activate
(.venv) djLint$ echo "  <div></div>" | djlint --check -

Checking 1/1 files ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00


/var/folders/v_/b5wzz2q96q5cqgdtl3fq066r0000gn/T/tmps6shebjj
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
@@ -1 +1 @@

-  <div></div>
+<div></div>

1 file would be updated.

@christopherpickering
Copy link
Contributor

christopherpickering commented Sep 16, 2021

Both are correct.

  • no args > code will be linted using the linter rules. The linter does not check formatting. http://djlint.com/djlint/rules.html
  • --check > does the code need to be reformatted? - shows what will happen if you run --reformat
  • --reformat > reformat the code

for your check

    <div></div>

will be reformatted to

<div></div>

note, no leading space.

@christopherpickering
Copy link
Contributor

I'd recommend using no args for an IDE, and make a keyboard shortcut to run the --reformat option. the --check is only for when you are feeling insecure about changes that might be coming ;)

@yaegassy
Copy link
Contributor Author

I'm sorry to bring up a different topic in this issue, but is it possible to output the row numbers and columns with errors?

This is an example of curlylint.

(.venv) curlylintcheck$ echo "  <div>{{</div>" | curlylint --quiet --format json -
[{"file_path": "-", "line": 1, "column": 0, "message": "Parse error: expected one of '-', 'any character', '}}' at 1:0", "code": "parse_error"}]

@christopherpickering
Copy link
Contributor

christopherpickering commented Sep 16, 2021

image

@yaegassy
Copy link
Contributor Author

yaegassy commented Sep 16, 2021

Oh, I see. I understand. Thanks!!!

djlint-ok

@christopherpickering
Copy link
Contributor

np, check out this regex for parsing: https://github.com/christopherpickering/Sublimelinter-contrib-djlint/blob/master/linter.py

@yaegassy
Copy link
Contributor Author

I'll try a regex. Thank you so much!!!
(If there is also a "json" output option, parsing is reliable and easy, but...)

@christopherpickering
Copy link
Contributor

#18

@yaegassy
Copy link
Contributor Author

Wow. Thank you very much for considering responding. 🙇

Perhaps now the various editors/IDEs will be able to work with djLint smoothly!

@yaegassy
Copy link
Contributor Author

@christopherpickering I supported djlint integration in my "Vim" extension. Thank you once again!

DEMO

coc-htmldjango-djlint-integration.mp4

@christopherpickering
Copy link
Contributor

Pretty nice, thanks for sharing! I wonder if we should add an "integrations" section to the docs... Is there a link to instructions on how to use this that I can add?

@yaegassy
Copy link
Contributor Author

In the integrations section, my plugin (extension) is not a djLint-specific plugin, so it is not necessary. 🙇

@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question Further information is requested released 🚂 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants