Skip to content

build-aux: Update formatter and linter scripts - #13743

Open
PatTheMav wants to merge 6 commits into
obsproject:masterfrom
PatTheMav:formatter-update
Open

build-aux: Update formatter and linter scripts#13743
PatTheMav wants to merge 6 commits into
obsproject:masterfrom
PatTheMav:formatter-update

Conversation

@PatTheMav

Copy link
Copy Markdown
Member

Description

Adds updated Bash, Zsh, and PowerShell scripts to run linters on the repository and adds support for Zizmor and xmllint.

The linter scripts are also capable of producing annotations in GitHub Actions format for later use in updated GitHub Actions workflows.

Because swift-format is now used in lint mode, additional code changes had to be made to meet the stricter demands of its linting mode.

Changes to CMake files are in preparation for current gersemi versions which can now handle string's REGEX REPLACE command correctly.

Motivation and Context

The main motivation is to provide linting and formatting scripts that can be used on the main supported platforms (Windows, macOS, and Linux) within their "native" scripting environments (Powershell, Zsh, and Bash, respectively).

The scripts will not install the formatters or linters (this exercise is left to the developer), but attempt to detect if the necessary linter is installed on the system.

A single launcher script is available to handle invocations on all platforms (using the symlink name to detect the desired linter), alternatively linters can be invoked directly:


Example

Invoking clang-format can be done either via

  • build-aux/run-clang-format [--verbose] [--check] [--github] on macOS and Linux,
  • .\build-aux\run-clang-format.ps1 [-Verbose] [-Check] [-GitHubStyle] (if symlink support is enabled for git on Windows)
  • .\build-aux\.run-format.ps1 -Linter clang-format [-Verbose] [-Check] [-GitHubStyle] (if symlink support is not enabled).

While clang-format is commonly available in a Visual Studio Developer Shell, zizmor and gersemi can simply be installed via winget and are then available via these scripts.

Both xmllint and swift-format are only available on macOS and Linux (the latter can be installed via Homebrew).

How Has This Been Tested?

Powershell variants have been tested on Windows 11, macOS variants on macOS 26, Linux variants were tested on Ubuntu 26.

In each case, formatting were deliberately misformatted and the linters then run on either files explicitly or across the entire repository.

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Code cleanup (non-breaking change which makes code smaller or more readable)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

Suppresses some warnings emitted by swift-format's linting report:

* "AlwaysUseLowerCamelCase" does not apply to functions exposed via
  C ABI for interoperability with libobs
* "AvoidRetroactiveConformances" has to be violated in the select
  instances in code (the decoration itself is used to silence a
  compiler warning).
Version 0.28.0 of gersemi has support for "REGEX REPLACE" string
operations and thus reverts the worse formatting introduced by a prior
version.
The updated script works as a formatter and linter launcher and is now
available for Zsh, Bash, and Powershell.

Symbolic links serve as easy entry points for the linter and use
the same universal launcher script (which is compatible with Csh and
Powershell) and identifies the desired linter by the used file name.

Because Powershell only executes script files that carry the ".ps1"
suffix, separate variants for Windows need to be provided, but still
all point to the same universal launcher under the hood.

New features:

* Bash version for linting and formatting
* Powershell version for linting and formatting
* Zizmor linting for GitHub Actions workflows
* Xmllint linting
* Linting only checks files but does not format them
* Linting mode has special "GitHub" syntax to annotate failed files
Updates invocations of the underlying format check script to the new
version of the script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant