Open Bug 2023411 Opened 2 months ago Updated 20 days ago

mozlinter: port some linters to Rust

Categories

(Developer Infrastructure :: Lint and Formatting, task)

Tracking

(Not tracked)

REOPENED

People

(Reporter: Sylvestre, Assigned: Sylvestre, NeedInfo)

References

(Blocks 1 open bug, Regressed 2 open bugs)

Details

(Keywords: leave-open)

Attachments

(14 files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
No description provided.

Replaces the built-in regex linter type with an external linter backed by
the moz-linter Rust binary. Files are scanned in parallel using rayon.
The Python wrapper builds moz-linter from source if no pre-built binary
is available.

Replaces the Python permission-checking logic with the moz-linter Rust
binary. Checks executable bits in parallel using rayon, supports
--allow-shebang and --fix modes. Falls back to building from source
locally.

Replaces the Python whitespace-checking logic with the moz-linter Rust
binary. Detects and fixes trailing whitespace, missing final newlines,
empty trailing lines, and Windows CRLF line endings. Files are processed
in parallel using rayon.

Replaces the Python Unicode format-character detection with the
moz-linter Rust binary. Scans for Unicode Cf category characters
(CVE-2021-42572) in parallel using rayon.

Implement license check in Rust: validates files contain a recognized
license pattern, adds appropriate headers in fix mode, and checks
toolkit/content/license.html references.

If we port the regex ones, we could fix bug 1959706.

Attachment #9553501 - Attachment description: WIP: Bug 2023411 - Fix trailing whitespace in 4 files found by file-whitespace linter → Bug 2023411 - Fix trailing whitespace in 4 files found by file-whitespace linter
Attachment #9553497 - Attachment description: WIP: Bug 2023411 - Rewrite rejected-words linter in Rust with Python wrapper → Bug 2023411 - Rewrite rejected-words linter in Rust with Python wrapper r?#linter-reviewers
Attachment #9553498 - Attachment description: WIP: Bug 2023411 - Rewrite file-perm linter in Rust with Python wrapper → Bug 2023411 - Rewrite file-perm linter in Rust with Python wrapper r?#linter-reviewers
Attachment #9553499 - Attachment description: WIP: Bug 2023411 - Rewrite file-whitespace linter in Rust with Python wrapper → Bug 2023411 - Rewrite file-whitespace linter in Rust with Python wrapper r?#linter-reviewers
Attachment #9553500 - Attachment description: WIP: Bug 2023411 - Rewrite trojan-source linter in Rust with Python wrapper → Bug 2023411 - Rewrite trojan-source linter in Rust with Python wrapper r?#linter-reviewers
Attachment #9553502 - Attachment description: WIP: Bug 2023411 - Rewrite license linter in Rust with Python wrapper → Bug 2023411 - Rewrite license linter in Rust with Python wrapper r?#linter-reviewers
Attachment #9553501 - Attachment description: Bug 2023411 - Fix trailing whitespace in 4 files found by file-whitespace linter → Bug 2023411 - Fix trailing whitespace in 4 files found by file-whitespace linter r?#linter-reviewers
Pushed by sledru@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/c8be7046fc81 https://hg.mozilla.org/integration/autoland/rev/fab786399cbf Fix trailing whitespace in 4 files found by file-whitespace linter r=devtools-reviewers,nchevobbe DONTBUILD
Status: NEW → RESOLVED
Closed: 2 months ago
Resolution: --- → FIXED
Target Milestone: --- → 150 Branch

Reopened for unpublished changesets.

Status: RESOLVED → REOPENED
Keywords: leave-open
Resolution: FIXED → ---
Pushed by sledru@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/4450b820ea6e https://hg.mozilla.org/integration/autoland/rev/8833dcfe8085 Rewrite rejected-words linter in Rust with Python wrapper r=linter-reviewers,sergesanspaille,ahal https://github.com/mozilla-firefox/firefox/commit/13d700d21ede https://hg.mozilla.org/integration/autoland/rev/bc64f0011c3d Rewrite file-perm linter in Rust with Python wrapper r=linter-reviewers,ahal,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/45e041167e4d https://hg.mozilla.org/integration/autoland/rev/1da6752acedb Rewrite file-whitespace linter in Rust with Python wrapper r=linter-reviewers,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/a97b716a4b3a https://hg.mozilla.org/integration/autoland/rev/89806d24952b Rewrite trojan-source linter in Rust with Python wrapper r=linter-reviewers,ahal,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/c29a886b2043 https://hg.mozilla.org/integration/autoland/rev/d0136c69b85b Rewrite license linter in Rust with Python wrapper r=linter-reviewers,sergesanspaille

Addresses review comment from sergesanspaille on D288083. The inner
function was named after its execution strategy (run_lint_in_parallel)
rather than what it checks; rename it to check_reject_words and update
the batch.rs caller to match.

Addresses nit from sergesanspaille on D288084: make the intent of the
mode & 0o111 == 0 guard explicit with a "not executable" comment.

Pushed by sledru@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/95c876dd5b1d https://hg.mozilla.org/integration/autoland/rev/f5e8406f5136 Rewrite rejected-words linter in Rust with Python wrapper r=linter-reviewers,sergesanspaille,ahal https://github.com/mozilla-firefox/firefox/commit/f863bc0bf8ab https://hg.mozilla.org/integration/autoland/rev/1d3cf79cf3a4 Rewrite file-perm linter in Rust with Python wrapper r=linter-reviewers,ahal,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/98fbb17bc183 https://hg.mozilla.org/integration/autoland/rev/445eb6fd45c0 Rewrite file-whitespace linter in Rust with Python wrapper r=linter-reviewers,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/0315328b0932 https://hg.mozilla.org/integration/autoland/rev/a8e05981c4b2 Rewrite trojan-source linter in Rust with Python wrapper r=linter-reviewers,ahal,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/05e7ee23d696 https://hg.mozilla.org/integration/autoland/rev/c8ba14a19ea5 Rewrite license linter in Rust with Python wrapper r=linter-reviewers,sergesanspaille
Regressions: 2034945
Pushed by sledru@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/5a2dd4406199 https://hg.mozilla.org/integration/autoland/rev/e256f9ca619f Follow-up: rename rejected_words helper to check_reject_words r=linter-reviewers,sergesanspaille DONTBUILD https://github.com/mozilla-firefox/firefox/commit/331fecf6a726 https://hg.mozilla.org/integration/autoland/rev/064c1eb7f594 Follow-up: comment the non-executable early-return in file_perm r=linter-reviewers,sergesanspaille DONTBUILD

Replaces the Python MinGW header capitalization check with the mozcheck
Rust binary. Validates that Windows #include directives use lowercase
header names matching the MinGW headers list.

Move android_os_to_api_map out of mozinfo/platforminfo.py and into
mozinfo/android_os_to_api_map.yaml so it can be consumed both by Python
(mozinfo) and by Rust (tools/lint/mozcheck via include_str!).

Pushed by sledru@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/b630fb04c81e https://hg.mozilla.org/integration/autoland/rev/3e9f26230af2 Rewrite mingw-capitalization linter in Rust with Python wrapper r=linter-reviewers,sergesanspaille https://github.com/mozilla-firefox/firefox/commit/285374975ce0 https://hg.mozilla.org/integration/autoland/rev/421353098297 Extract Android OS-to-API map into a shared YAML file r=linter-reviewers,sergesanspaille
Pushed by sledru@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/e905604d1410 https://hg.mozilla.org/integration/autoland/rev/6728480377a8 Follow-up: fix clippy warnings in mozcheck license and file_whitespace r=linter-reviewers,sergesanspaille DONTBUILD
Pushed by sstanca@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/7190897e6864 https://hg.mozilla.org/integration/autoland/rev/47c76ae98ba6 Revert "Bug 2023411 - Extract Android OS-to-API map into a shared YAML file r=linter-reviewers,sergesanspaille" for causing mass failures.

Reverted this because it was causing mass failures.

Flags: needinfo?(sledru)
Pushed by sstanca@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/80ea10298fd6 https://hg.mozilla.org/integration/autoland/rev/43533d7870e4 Revert "Bug 2023411 - Follow-up: fix clippy warnings in mozcheck license and file_whitespace r=linter-reviewers,sergesanspaille DONTBUILD" because it is a leftover from the initial backout.
Attachment #9574002 - Attachment description: Bug 2023411 - Rewrite mingw-capitalization linter in Rust with Python wrapper r?#linter-reviewers → WIP: Bug 2023411 - Rewrite mingw-capitalization linter in Rust with Python wrapper r?#linter-reviewers

Rust port of testing/mozbase/manifestparser/manifestparser/, exposed as a
new crate at testing/mozbase/rust/manifestparser/.

Modules:

  • util / ini : path normalization, INI manifest reader, combine_fields
  • expression : Pratt-style boolean expression evaluator (nom-lexed)
  • filters : skip-if/run-if/fail-if + chunkers + tags + pathprefix
  • token : quote-aware whitespace normalization (strip_unquoted)
  • parser : nom-based primitives shared with downstream consumers
    (Op, CmpOp, parse_op, split_ops)
  • toml : read_toml + sort_paths
  • manifest : ManifestParser + TestManifest with active_tests pipeline

The tomlkit-backed formatter helpers (alphabetize_toml_str, add_skip_if,
remove_skip_if, replace_tbd_skip_if) are intentionally not ported because
they depend on tomlkit's stylistic round-trip with no Rust equivalent.

The token vocabulary (legal os/os_version/etc. values) lives with the
test-manifest-toml linter, which loads it from YAML at runtime, rather
than being hardcoded here a second time.

The MinGW capitalization linter requires Windows SDK headers to use
lowercase filenames so the MinGW build can resolve them. The previous
Python implementation was a silent no-op due to a re.search(line, re.I)
bug (the re.I flag was being passed as the pos argument), so these
five files slipped in with <Mferror.h> / <Mfidl.h>. The new mozcheck
Rust port catches them; lowercase the includes to match the headers list.

Pushed by sledru@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/4caddf6d2318 https://hg.mozilla.org/integration/autoland/rev/620086ee0637 Lowercase MinGW Windows header includes flagged by mozcheck r=tjr,media-playback-reviewers,padenot
Pushed by sledru@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/f4abf0169364 https://hg.mozilla.org/integration/autoland/rev/00856bc4cea0 Extract Android OS-to-API map into a shared YAML file r=linter-reviewers,sergesanspaille
Target Milestone: 150 Branch → ---
Regressions: 2037297
Regressions: 2038131
Regressions: 2038611
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: