Page MenuHomePhabricator

lint: add new python script to check file names and permissions
ClosedPublic

Authored by PiRK on Feb 15 2024, 17:13.

Details

Summary

Replaces existing filenames and shebang linters, as well as adding some new and increased testing.
Summary of tests:

  • Checks every file in the repository against an allowed regexp to make sure only lowercase or uppercase alphanumerics (a-zA-Z0-9), underscores (_), hyphens (-), at (@) and dots (.) are used in repository filenames.
  • Checks only source files (*.cpp, *.h, *.py, *.sh, *.rs) against a stricter allowed regexp to make sure only lowercase alphanumerics (a-z0-9), underscores (_), hyphens (-) and dots (.) are used in source code filenames. Additionally there is an exception regexp for directories or files which are excepted from matching this regexp (replaces existing filename linter)
  • Checks all files in the repository match an allowed executable or non-executable file permission octal. Additionally checks that for executable files, the file contains a shebang line.
  • Checks that for executable .py and .sh files, the shebang line used matches an allowable list of shebangs (replacethe two existing shebang linters)
  • Checks every file that contains a shebang line to ensure it has an executable permission.

This is a backport of core#21740, core#24762, core#21873 and core#25015

Benchmark, before this diff:

$ time arc lint --everything
...
real	3m37,360s
user	17m17,366s
sys	3m29,937s

After this diff:

$ time arc lint --everything
...
real	3m38,471s
user	17m27,795s
sys	3m32,067s

Linter on its own:

$ time test/lint/lint-files.py

real	0m0,132s
user	0m0,164s
sys	0m0,099s
Test Plan

arc lint
arc lint --everything

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK retitled this revision from test: add new python linter to check file names and permissions to lint: add new python script to check file names and permissions.
PiRK published this revision for review.Feb 15 2024, 19:25
Fabien requested changes to this revision.Feb 16 2024, 10:19
Fabien added a subscriber: Fabien.

electrum/contrib/build-linux/appimage/scripts/common.sh is certainly not expected to be run directly and can remain non executable

arcanist/linter/CheckFilenamesAndPermissions.php
69 ↗(On Diff #45272)

it's obvious it's a linter error

test/lint/lint-files.py
44 ↗(On Diff #45272)

Third party code should be excluded from the linter entirely in .arclint

84–87 ↗(On Diff #45272)

Would that work ? It's probably faster than involving exceptions

This revision now requires changes to proceed.Feb 16 2024, 10:19

address review comments.

The way the linter works makes it impossible to exclude files directly in .arclint, but I made the third party code exception global to all tests. Any file in that directory will be completly ignored.

This revision is now accepted and ready to land.Feb 16 2024, 16:33