mirror of
https://git.proxmox.com/git/fwupd
synced 2025-11-02 12:22:49 +00:00
trivial: Add pre-commit hooks for style
This commit is contained in:
parent
1079f08b85
commit
bb9390d45c
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,6 +21,7 @@
|
||||
/*.dsc
|
||||
/*.xz
|
||||
/*.gz
|
||||
/venv
|
||||
__pycache__
|
||||
plugins/acpi-dmar/tests/
|
||||
plugins/acpi-facp/tests/
|
||||
|
||||
37
.pre-commit-config.yaml
Normal file
37
.pre-commit-config.yaml
Normal file
@ -0,0 +1,37 @@
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v2.3.0
|
||||
hooks:
|
||||
- id: no-commit-to-branch
|
||||
args: [--branch, master, --pattern, 1_.*_X]
|
||||
- id: check-yaml
|
||||
- id: check-json
|
||||
- id: check-symlinks
|
||||
- id: check-xml
|
||||
- id: end-of-file-fixer
|
||||
types_or: [c, shell, python]
|
||||
- id: trailing-whitespace
|
||||
types_or: [c, shell, python]
|
||||
- id: check-docstring-first
|
||||
- id: check-merge-conflict
|
||||
- id: mixed-line-ending
|
||||
args: [--fix=lf]
|
||||
- repo: https://github.com/ambv/black
|
||||
rev: 20.8b1
|
||||
hooks:
|
||||
- id: black
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: check-deprecated
|
||||
name: check for use of any deprecated items
|
||||
language: script
|
||||
entry: ./contrib/ci/check-deprecated.sh
|
||||
- id: check-null-false-returns
|
||||
name: check for null / false return mistmatch
|
||||
language: script
|
||||
entry: ./contrib/ci/check-null-false-returns.py
|
||||
- id: shellcheck
|
||||
name: check shellscript style
|
||||
language: system
|
||||
entry: shellcheck --severity=error -e SC2068
|
||||
types: [shell]
|
||||
@ -1,3 +1,16 @@
|
||||
Getting started
|
||||
===============
|
||||
To set up your local environment, from the top level of the checkout run
|
||||
```
|
||||
./contrib/setup
|
||||
```
|
||||
|
||||
This will create pre-commit hooks to fixup many code style issues before your
|
||||
code is submitted.
|
||||
|
||||
On some Linux distributions this will install all build dependencies needed
|
||||
to compile fwupd as well.
|
||||
|
||||
Coding Style
|
||||
============
|
||||
|
||||
|
||||
15
contrib/ci/check-deprecated.sh
Executable file
15
contrib/ci/check-deprecated.sh
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/sh -e
|
||||
set -e
|
||||
|
||||
# these are deprecated in favor of INTERNAL flags
|
||||
deprecated="FWUPD_DEVICE_FLAG_NO_AUTO_INSTANCE_IDS
|
||||
FWUPD_DEVICE_FLAG_ONLY_SUPPORTED
|
||||
FWUPD_DEVICE_FLAG_MD_SET_NAME
|
||||
FWUPD_DEVICE_FLAG_MD_SET_VERFMT
|
||||
FWUPD_DEVICE_FLAG_NO_GUID_MATCHING
|
||||
FWUPD_DEVICE_FLAG_MD_SET_ICON"
|
||||
for val in $deprecated; do
|
||||
if grep -- $val plugins/*/*.c ; then
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
41
contrib/setup
Executable file
41
contrib/setup
Executable file
@ -0,0 +1,41 @@
|
||||
#!/bin/bash -e
|
||||
# Setup the repository.
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
# Add default vscode settings if not existing
|
||||
SETTINGS_FILE=./.vscode/settings.json
|
||||
SETTINGS_TEMPLATE_FILE=./contrib/vscode/settings.json
|
||||
if [ ! -f "$SETTINGS_FILE" ]; then
|
||||
mkdir ./.vscode
|
||||
echo "Copy $SETTINGS_TEMPLATE_FILE to $SETTINGS_FILE."
|
||||
cp "$SETTINGS_TEMPLATE_FILE" "$SETTINGS_FILE"
|
||||
fi
|
||||
|
||||
#if interactive install build deps
|
||||
if [ -n "$PS1" ] || [[ $- == *i* ]] || [ -f /dev/.cros_milestone ]; then
|
||||
read -p "Install build dependencies? (y/n) " question
|
||||
if [ "$question" = "y" ]; then
|
||||
DEPS=$(./contrib/ci/generate_dependencies.py)
|
||||
if ! which shellcheck >/dev/null 2>&1; then
|
||||
DEPS="$DEPS shellcheck"
|
||||
fi
|
||||
OS=$(python3 -c "import distro; print(distro.linux_distribution()[0].split()[0].lower())")
|
||||
if [ "$OS" = "debian" ] || [ "$OS" = "ubuntu" ]; then
|
||||
if ! python3 -c "import venv"; then
|
||||
DEPS="python3-venv"
|
||||
fi
|
||||
sudo apt install $DEPS
|
||||
elif [ "$OS" = "fedora" ]; then
|
||||
sudo dnf install $DEPS
|
||||
elif [ "$OS" = "arch" ]; then
|
||||
pacman -Syu --noconfirm --needed $DEPS
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
|
||||
python3 -m pip install pre-commit
|
||||
pre-commit install
|
||||
4
contrib/vscode/settings.json
Normal file
4
contrib/vscode/settings.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"editor.tabSize": 8,
|
||||
"mesonbuild.buildFolder": "build"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user