[Django] #35007: Add prettier to format CSS and JS

17 views
Skip to first unread message

Django

unread,
Nov 30, 2023, 7:46:07 AM11/30/23
to django-...@googlegroups.com
#35007: Add prettier to format CSS and JS
------------------------------------------------+------------------------
Reporter: Tom Carrick | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
https://forum.djangoproject.com/t/adding-a-formatter-for-css-js/25754

--
Ticket URL: <https://code.djangoproject.com/ticket/35007>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 30, 2023, 7:46:19 AM11/30/23
to django-...@googlegroups.com
#35007: Add prettier to format CSS and JS
-------------------------------------+-------------------------------------
Reporter: Tom Carrick | Owner: Tom
Type: | Carrick
Cleanup/optimization | Status: assigned

Component: Core (Other) | Version: dev
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tom Carrick):

* owner: nobody => Tom Carrick
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/35007#comment:1>

Django

unread,
Nov 30, 2023, 7:52:36 AM11/30/23
to django-...@googlegroups.com
#35007: Add prettier to format CSS and JS
-------------------------------------+-------------------------------------
Reporter: Tom Carrick | Owner: Tom
Type: | Carrick
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* stage: Unreviewed => Accepted


Old description:

> https://forum.djangoproject.com/t/adding-a-formatter-for-css-js/25754

New description:

From https://forum.djangoproject.com/t/adding-a-formatter-for-css-
js/25754:

The idea is to add formatting for CSS and JS.

For motivation, I find myself fairly often in the admin CSS (especially
lately) and it’s reasonably laid out for the most part, but there are
things that are a little off. Sometimes the indentation is different from
the rest of the file, for example. The JS is in a bit worse shape I think,
some of the files have whitespace issues. These could be fixed but it
would be better to enforce them in a way that’s easier to review, so I
think a formatter makes sense here. What’s annoying (for me) is that when
editing files, sometimes my editor “fixes” the issues for me, then I have
to revert them and save without formatting. If I don’t spot my editor’s
work, it’s more annoying to fix. Of course I could turn this stuff off
somewhere, but if it’s annoying for me I’m sure it’ll be annoying for
others as well.

I’m open to suggestions, but Thibaud suggested prettier, and I also use it
myself. It doesn’t really require any configuration, though is
configurable if people do have strong opinions.

But barring differing opinions there, the process would be something like:

Make a PR with three commits. The first sets up the machinery, installs
prettier, adds to pre-commit, etc. The second does the work and the third
adds the second commit to .git-blame-ignore-revs. As far as I know, the
same as when black was set up.

--

Comment:

The forum topic has had very positive reactions, accepting.

--
Ticket URL: <https://code.djangoproject.com/ticket/35007#comment:2>

Django

unread,
Nov 30, 2023, 12:23:33 PM11/30/23
to django-...@googlegroups.com
#35007: Add prettier to format CSS and JS
-------------------------------------+-------------------------------------
Reporter: Tom Carrick | Owner: Tom
Type: | Carrick
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

We're already using `ESLint` for JS files.

--
Ticket URL: <https://code.djangoproject.com/ticket/35007#comment:3>

Django

unread,
Nov 30, 2023, 1:22:59 PM11/30/23
to django-...@googlegroups.com
#35007: Add prettier to format CSS and JS
-------------------------------------+-------------------------------------
Reporter: Tom Carrick | Owner: Tom
Type: | Carrick
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tom Carrick):

We can have some discussion about whether ESLint's formatting rules are
enough, but I don't think they are. For example, they don't seem to catch
obvious whitespace issues (whitespace only lines in SelectFilter2.js,
whitespace at end of line in RelatedObjectLookups.js I found in the first
two files I opened, so there are probably others).

It was suggested in the forum post to use ESLint only for linting, and use
prettier for formatting, and I think this is a good idea.

--
Ticket URL: <https://code.djangoproject.com/ticket/35007#comment:4>

Django

unread,
Dec 6, 2023, 12:35:09 PM12/6/23
to django-...@googlegroups.com
#35007: Add prettier to format CSS and JS
-------------------------------------+-------------------------------------
Reporter: Tom Carrick | Owner: Tom
Type: | Carrick
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Thibaud Colas):

ESLint’s formatting rules definitely aren’t enough. It’s more "auto-fix
white-space in a few very specific scenarios" than "format everything".
ESLint themselves have also [https://eslint.org/blog/2023/10/deprecating-
formatting-rules/ deprecated their formatting rules and recommend using a
dedicated formatter].

--
Ticket URL: <https://code.djangoproject.com/ticket/35007#comment:5>

Reply all
Reply to author
Forward
0 new messages