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

410 enforce a html formatter and linter #411

Merged
merged 10 commits into from
Nov 29, 2024

Conversation

reecehill
Copy link
Contributor

This pull request includes updates to configuration files, documentation, and HTML templates to enhance code formatting, linting, and developer experience. The most important changes include the addition of a new configuration file for DJLint, updates to VSCode settings and recommendations, and improvements to HTML templates for better readability and consistency.

Configuration Updates:

  • Added a new .djlintrc configuration file to enforce specific formatting and linting rules for Django templates.
  • Updated .vscode/settings.json to include settings for Python language server, file associations, editor configurations, and DJLint integration.
  • Updated .vscode/extensions.json to recommend extensions for spell checking, Python formatting, Django support, and linting.

Documentation Improvements:

  • Enhanced code-style.md with detailed instructions for linting and formatting Python files and Django templates, including usage of DJLint. [1] [2] [3]

HTML Template Enhancements:

  • Changed many HTML templates by adding required attributes (e.g., <html lang="">, reformatting meta tags, and ensuring consistent indentation and spacing. All to lint as per DJLint requirements. Note that "breaking changes" have been avoided where possible (e.g., adding weight/height attrs to images) - whilst these are recommended, they can be done in another branch. Some "breaking" changes were unavoidable, however, such as adding missing HTML tags. No gross changes to UI found. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Developer experience

As per documentation, developers are to continue to using VSCode. No change there.
However, .vscode/extensions.json will advise devs which extensions to have installed (optional). The biggest recommendation added in this PR is the use of "djlint" for linting and formatting Django template files.

To run djlint:

djlint ./project/npda/templates/* --configuration .djlintrc --reformat
djlint ./project/npda/templates/* --configuration .djlintrc --lint

Other linters

I had considered other methods of linting template files with django tags ({{ }}). Including "Django Template Support" and Prettier. The first does a great job, but offers no CLI utility (thinking CI/CD), and Prettier - whilst ideal for tailwindcss management - cannot handle Django tags.

@reecehill reecehill linked an issue Nov 29, 2024 that may be closed by this pull request
4 tasks
@reecehill
Copy link
Contributor Author

@mbarton What are your thoughts on adding linting/formatting to pre-commits or PR checks? By default, djlint does not return a non-zero exit code for lint issues. If you want to fail the pipeline on linting errors, we'd have to run djlint without the --reformat flag and handle warnings as errors?...

With this in the pipeline, templates with broken HTML would be prevented from being pushed to live.

Thinking wider than template .html files, there's MegaLinter that has black and djlint capabilities...

@eatyourpeas eatyourpeas merged commit 5d4ddae into live Nov 29, 2024
1 check passed
@eatyourpeas eatyourpeas deleted the 410-enforce-a-html-formatter-and-linter branch November 29, 2024 21:30
@mbarton
Copy link
Member

mbarton commented Nov 29, 2024

Seen on STAGING (created by @reecehill and merged by @eatyourpeas 9 minutes and 44 seconds ago) Please check your changes!

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

Successfully merging this pull request may close these issues.

Enforce a .html formatter and linter
3 participants