Add pre-commit hooks (#9510)

This commit is contained in:
Maximilian Downey Twiss
2024-06-15 21:53:06 +10:00
committed by GitHub
parent 6d24a5e552
commit 659ae6eed6
13 changed files with 58 additions and 105 deletions

View File

@@ -24,7 +24,7 @@ Works properly:
- [ ] `armv7l` <!-- (reasons why it doesn't) -->
### Run the following to get this pull request's changes locally for testing.
```
```bash
CREW_REPO=https://github.com/<Please_enter_the_name_of_your_repo>/chromebrew.git CREW_BRANCH=<Please_enter_the_branch_name_for_this_PR> crew update
```

View File

@@ -5,6 +5,8 @@ rule 'MD029', style: :ordered
exclude_rule 'MD002' # We use HTML <h1> tag as the top level header
exclude_rule 'MD013' # Ignore 80 character line length limit.
exclude_rule 'MD022' # Ignore headers should be surrounded by blank lines
exclude_rule 'MD026' # Ignore trailing punctuation in header
exclude_rule 'MD028' # Ignore blank line inside blockquote
exclude_rule 'MD031' # Ignore code blocks should be surrounded by blank lines
exclude_rule 'MD032' # Ignore lists should be surrounded by blank lines
exclude_rule 'MD033' # We need HTML to center logo, which is not possible in pure Markdown

22
.pre-commit-config.yaml Normal file
View File

@@ -0,0 +1,22 @@
---
# To run these hooks, install pre-commit (https://pre-commit.com) and run 'pre-commit install'
# These pre-commit hooks mirror the Github CI, so running them locally will catch errors earlier.
repos:
- repo: https://github.com/rubocop/rubocop
rev: v1.64.1
hooks:
- id: rubocop
- repo: https://github.com/syntaqx/git-hooks
rev: v0.0.18
hooks:
- id: shellcheck
exclude: tools
- repo: https://github.com/markdownlint/markdownlint
rev: v0.13.0
hooks:
- id: markdownlint
args: [-s.mdl_style.rb]
- repo: https://github.com/adrienverge/yamllint
rev: v1.35.1
hooks:
- id: yamllint

View File

@@ -102,3 +102,11 @@ If the package is a dependency for another package, test commands of the other p
## Learn more
- Visit the [wiki](https://github.com/chromebrew/chromebrew/wiki)
## Pre-commit hooks.
Chromebrew has pre-commit hooks to catch errors before they make it to CI.
To install them, run `pre-commit install` in the root of the repository.
You will first need to install the pre-commit tool, which can be done via `crew install py3_pre_commit` on ChromeOS.

View File

@@ -110,7 +110,7 @@ crew install --keep [...]
## License
Copyright 2013-2024 Michal Siwek and [all the awesome contributors](https://github.com/chromebrew/chromebrew/graphs/contributors).
Copyright 2013-2024 Michal Siwek and [all the awesome contributors](https://github.com/chromebrew/chromebrew/graphs/contributors).
This project including all of its source files is released under the terms of [GNU General Public License (version 3 or later)](http://www.gnu.org/licenses/gpl.txt). This project embeds [docopt.rb](https://github.com/docopt/docopt.rb) at lib/docopt.rb. We retain its [MIT license](lib/docopt.LICENSE).

View File

@@ -90,9 +90,6 @@ class Buildessential < Package
# depends_on 'openjdk11'
# depends_on 'openjdk17'
# Linter
depends_on 'linter'
# Lisp
# depends_on 'ccl'
# depends_on 'clisp'

View File

@@ -56,5 +56,4 @@ class Caja < Autotools
gnome
configure_options '--enable-wayland'
end

View File

@@ -24,7 +24,7 @@ class Gvim < Autotools
depends_on 'glib' # R
depends_on 'gpm' # R
depends_on 'gtk3' # R
depends_on 'harfbuzz' #
depends_on 'harfbuzz'
depends_on 'libice' # R
depends_on 'libsm' # R
depends_on 'libsodium' # R

View File

@@ -1,92 +0,0 @@
require 'package'
class Linter < Package
description 'Comprehensive linter and code analysis for various file types.'
homepage 'https://github.com/chromebrew/chromebrew'
version '1.4'
license 'GPL-3'
compatibility 'all'
source_url 'SKIP'
no_compile_needed
no_upstream_update
depends_on 'py3_codespell'
depends_on 'ruby_mdl'
depends_on 'ruby_rubocop'
depends_on 'ruby_yaml_lint'
depends_on 'shellcheck'
def self.build
linter = <<~EOF
#!/bin/bash
export PATH=#{CREW_PREFIX}/bin:$PATH
if test "$1"; then
files="$*"
else
files="$(git ls-files -om | xargs)"
fi
for file in $files; do
ext="${file##*.}"
if ! [[ "$ext" =~ ^(md|rb|sh|yml|yaml)$ ]]; then
type="$(file -b "$file" | cut -d' ' -f1)"
case $type in
Bourne-Again)
ext="sh"
;;
HTML)
ext="md"
;;
Ruby)
ext="rb"
;;
esac
fi
case $ext in
md)
mdl -c "$HOME/.mdlrc" "$file"
;;
rb)
rubocop "$file"
;;
sh)
shellcheck "$file"
;;
yml|yaml)
yaml-lint "$file"
;;
*)
echo "Unable to check syntax of $file."
;;
esac
codespell "$file"
done
EOF
File.write('linter', linter)
mdlrc = <<~EOF
style "#{Dir.home}/.mdl_style.rb"
EOF
File.write('.mdlrc', mdlrc)
mdl_style = <<~EOF
all
# Ignore 80 character line length limit.
exclude_rule 'MD013'
# Ignore horizontal rule style.
exclude_rule 'MD035'
# Ignore emphasis used instead of a header.
exclude_rule 'MD036'
# Ignore first line in file should be a top level header.
exclude_rule 'MD041'
# Ignore code block style.
exclude_rule 'MD046'
EOF
File.write('.mdl_style.rb', mdl_style)
end
def self.install
FileUtils.mkdir_p CREW_DEST_HOME.to_s
FileUtils.mkdir_p "#{CREW_DEST_PREFIX}/bin"
FileUtils.install 'linter', "#{CREW_DEST_PREFIX}/bin", mode: 0o755
FileUtils.install ['.mdlrc', '.mdl_style.rb'], CREW_DEST_HOME.to_s, mode: 0o644
end
end

View File

@@ -10,7 +10,6 @@ class Openjdk < Package
description 'The JDK is a development environment for building applications, applets, and components using the Java programming language.'
homepage 'https://openjdk.org/'
key = 1
versions = []
@openjdk_versions = []
Dir["#{CREW_PACKAGES_PATH}/openjdk*.rb"].each do |openjdk_file|
next unless openjdk_file =~ /openjdk(\d+).rb/
@@ -20,8 +19,8 @@ class Openjdk < Package
@openjdk_versions.push [key, openjdk_name, openjdk_ver]
key += 1
end
@openjdk_versions.each do |openjdk_ver|
versions.push openjdk_ver[2]
versions = @openjdk_versions.map do |openjdk_ver|
openjdk_ver[2]
end
versions.sort!
version "#{versions.first}-#{versions.last}"

View File

@@ -0,0 +1,15 @@
require 'buildsystems/pip'
class Py3_pre_commit < Pip
description 'A framework for managing and maintaining multi-language pre-commit hooks.'
homepage 'https://pre-commit.com/'
@_ver = '3.6.2'
version "#{@_ver}-py3.12"
license 'MIT'
compatibility 'all'
source_url 'SKIP'
depends_on 'python3'
no_compile_needed
end

View File

@@ -80,9 +80,7 @@ class Webkit2gtk_4_1 < Package
system "sed -i 's,/usr/bin,/usr/local/bin,g' Source/JavaScriptCore/inspector/scripts/codegen/preprocess.pl"
@arch_flags = ''
@gcc_ver = ''
if ARCH == 'armv7l' || ARCH == 'aarch64'
@arch_flags = '-mfloat-abi=hard -mtls-dialect=gnu -mthumb -mfpu=vfpv3-d16 -mlibarch=armv7-a+fp -march=armv7-a+fp'
end
@arch_flags = '-mfloat-abi=hard -mtls-dialect=gnu -mthumb -mfpu=vfpv3-d16 -mlibarch=armv7-a+fp -march=armv7-a+fp' if ARCH == 'armv7l' || ARCH == 'aarch64'
end
def self.build

View File

@@ -7311,6 +7311,11 @@ url: https://github.com/pypa/pip/releases
activity: medium
---
kind: url
name: py3_pre_commit
url: https://github.com/pre-commit/pre-commit/releases
activity: medium
---
kind: url
name: py3_pylint
url: https://github.com/pylint-dev/pylint/releases
activity: high