Skip to content

Enable the unicorn/prefer-class-fields ESLint plugin rule#20657

Merged
timvandermeij merged 1 commit intomozilla:masterfrom
Snuffleupagus:unicorn-prefer-class-fields
Feb 14, 2026
Merged

Enable the unicorn/prefer-class-fields ESLint plugin rule#20657
timvandermeij merged 1 commit intomozilla:masterfrom
Snuffleupagus:unicorn-prefer-class-fields

Conversation

@Snuffleupagus
Copy link
Collaborator

This leads to slightly shorter code[1] when initializing classes, and in some cases we can even remove the constructors, which shouldn't hurt; see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-class-fields.md

It's probably possible to also change a lot of these class fields to private ones[2], however it's often difficult to tell at a glance if that's safe hence this patch only does this for the PDFRenderingQueue.


[1] This reduces the size of the gulp mozcentral output by 999 bytes, for a mostly mechanical code change.

[2] That sort of re-factoring should generally be done separately, on a class-by-class basis, to reduce the risk of regressions.

This leads to slightly shorter code[1] when initializing classes, and in some cases we can even remove the constructors, which shouldn't hurt; see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-class-fields.md

It's probably possible to also change a lot of these class fields to private ones[2], however it's often difficult to tell at a glance if that's safe hence this patch only does this for the `PDFRenderingQueue`.

---

[1] This reduces the size of the `gulp mozcentral` output by 999 bytes, for a mostly mechanical code change.

[2] That sort of re-factoring should generally be done separately, on a class-by-class basis, to reduce the risk of regressions.
@timvandermeij
Copy link
Contributor

/botio-linux preview

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.241.84.105:8877/ca09a331ec4e049/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/ca09a331ec4e049/output.txt

Total script time: 1.00 mins

Published

@timvandermeij
Copy link
Contributor

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://54.193.163.58:8877/7be9664833babe2/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://54.241.84.105:8877/2ab35c3488c7244/output.txt

Copy link
Contributor

@timvandermeij timvandermeij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me, with passing tests. Thanks!

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/2ab35c3488c7244/output.txt

Total script time: 42.15 mins

  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED
  different ref/snapshot: 1

Image differences available at: http://54.241.84.105:8877/2ab35c3488c7244/reftest-analyzer.html#web=eq.log

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/7be9664833babe2/output.txt

Total script time: 82.45 mins

  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED
  different ref/snapshot: 1

Image differences available at: http://54.193.163.58:8877/7be9664833babe2/reftest-analyzer.html#web=eq.log

@timvandermeij timvandermeij merged commit 1d6307f into mozilla:master Feb 14, 2026
11 checks passed
Snuffleupagus added a commit to Snuffleupagus/pdf.js that referenced this pull request Feb 19, 2026
This leads to slightly shorter code when initializing classes, and it reduces the size of the `gulp mozcentral` output by 894 bytes for a mostly mechanical code change.

Unfortunately it seems that the `unicorn/prefer-class-fields` ESLint plugin, see PR mozilla#20657, isn't able to find/fix these cases.
Snuffleupagus added a commit to Snuffleupagus/pdf.js that referenced this pull request Feb 19, 2026
This leads to slightly shorter code when initializing classes, and it reduces the size of the `gulp mozcentral` output by 894 bytes for a mostly mechanical code change.

Unfortunately it seems that the `unicorn/prefer-class-fields` ESLint plugin, see PR mozilla#20657, isn't able to find/fix these cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants