Repository navigation
[ADD] checks_odoo_module_scss: new scss-font-legacy-format check with autofix - #205
Merged
Merged
Conversation
This was referenced Nov 30, 2026
moylop260
force-pushed
the
scss-font-legacy-format-moy
branch
2 times, most recently
from
November 30, 2026 09:28
5c5b9db to
917fabb
Compare
… autofix A `@font-face` that serves its font as .otf, .ttf, .eot or .woff and no .woff2 makes every visitor download a bigger file than needed. WOFF2 compresses with Brotli: measured on 13 real fonts of Odoo 19.0 it is 44-72 % smaller than the .ttf/.otf (63 % in total) and 12-30 % smaller than the .woff (26 % in total). Every browser still supported reads it (Chrome 36, Firefox 39, Safari 12, Edge 14), so no other format is needed as a fallback. With the default font-display the text stays invisible while the font downloads, so its size shows in the paint metrics (GTmetrix: "Enormous network payloads"). The message explains how to convert the font without touching its glyphs. The autofix rewrites the url() and its format() when the .woff2 already sits next to the old file, keeping the quotes and the line endings; it does not convert the font, since that is a binary file that has to be reviewed. The stylesheets of the PDF report bundles (`report_assets_*`) are not reported: wkhtmltopdf renders them with an old QtWebKit that does not read WOFF2, and a PDF whose @font-face has only a .woff2 falls back to another font. The bundle is read from the "assets" of the manifest. This adds the scss checker: the hook now also runs on .scss and .css files, and reads the ones declared in the "assets" of the manifest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
scss-font-legacy-format: a@font-facethat serves its font as.otf,.ttf,.eotor.woffand no.woff2.Why WOFF2 and not the other formats
.ttf/.otf.eot/.svg.woff.woff2Measured on 13 real fonts of Odoo 19.0 (fontTools 4.69.1, brotli 1.2.1): woff2 is 44.7 % to 71.6 % smaller than the ttf/otf (62.8 % in total, 1 699 716 B to 632 892 B) and 12.5 % to 29.7 % smaller than the woff (26.3 % in total). The CFF
.otffonts gain less than the TrueType ones. On the 17 faces of a real theme, 1 579 500 bytes as otf/ttf/woff became 645 840 bytes as woff2, with the same glyphs (the cmap, the glyph order and count, the advances, the GSUB/GPOS features and the vertical metrics were compared one by one).Every browser still supported reads WOFF2: Chrome 36, Firefox 39, Safari 12 (partial since 10), Edge 14, 97 % of global use (caniuse and MDN). A
srcthat lists woff2 first and a.woffafter it is not reported, because the browser downloads only the first one it understands. With the defaultfont-displaythe text stays invisible while the font downloads, so its size shows in the First and Largest Contentful Paint (GTmetrix: "Enormous network payloads").wkhtmltopdf does not read WOFF2
The stylesheets of the PDF report bundles (
web.report_assets_common,web.report_assets_pdf,snailmail.report_assets_snailmail, read from theassetsof the manifest) are not reported and not fixed. Tested with wkhtmltopdf 0.12.6.1 (patched Qt) and reading the fonts embedded in each PDF: a@font-facewith only.ttfor only.woffembeds the font; with only.woff2the PDF falls back to DejaVuSans and the font is lost; with.woff2first and.ttfafter it, the font is embedded. Without this exemption 36 of 47 findings in public repositories (odoo 14-19, OCA) pointed to a PDF font.How to migrate (also in the message of the check)
pip install fonttools brotli && fonttools ttLib.woff2 compress Font.otf(orwoff2_compress Font.otf) writesFont.woff2next to the file and keeps every glyph, because only the container changes. Then useurl("Font.woff2") format("woff2")and delete the old file. Fonts in.eotor.svgare converted from the original.ttf/.otf.Autofix
It rewrites the
url()and itsformat()when the.woff2is already next to the old file, keeping the quotes and the line endings. It does not convert the font: that is a binary file that has to be reviewed and committed, so the check reports it and leaves the file alone. It is idempotent.Scope
This is the first check that reads stylesheets, so it adds the scss checker: the
oca-checks-odoo-modulehook now also runs on.scssand.cssfiles (types_orandfilesof.pre-commit-hooks.yaml) and the checker reads the ones declared in theassetsof the manifest. A Sass partial that is only reached through an@import, and.sassor.lessfiles, are not read. Comments are blanked before looking for@font-face, keeping the length, so the line numbers are the ones of the file; Sass interpolation (#{...}) inside the face is supported.Known limitation, left for another pull request: the
**of theassetsglobs is not expanded recursively by the existing code (glob.globwithoutrecursive=True), so about 40 % of the stylesheets of odoo 19.0 are not read by any check that usesassets.Tests
Full suite: 140 passed, 7 skipped (15 new unit tests for the checker, plus the fixture with the autofix and the report bundle). Real corpus: 61 public checkouts (odoo 14-19 and OCA, 4 893 manifests): 47 findings in 5 repositories, 0 in the 35 OCA 18.0 repositories. The README sections were added by hand because the generated README changes its indentation with the Python version.