diff --git a/.github/workflows/prek.yaml b/.github/workflows/prek.yaml new file mode 100644 index 0000000..c936dc2 --- /dev/null +++ b/.github/workflows/prek.yaml @@ -0,0 +1,10 @@ +name: Prek checks +"on": [push, pull_request] +jobs: + prek: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: j178/prek-action@v2 + with: + extra-args: '-q' diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml deleted file mode 100644 index 7211711..0000000 --- a/.github/workflows/style.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Check style -on: [push, pull_request] # yamllint disable-line rule:truthy -jobs: - style: - defaults: - run: - shell: bash -l {0} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - with: - fetch-depth: 1 - show-progress: false - - run: sudo apt update - - name: Install shellcheck, checkbashisms, and yamllint - run: sudo apt -y install devscripts shellcheck shfmt yamllint - - name: Install markdownlint - run: npm install markdownlint-cli2 --global - - name: Install uv - uses: astral-sh/setup-uv@v9.0.0 - - name: Check style - run: make style-check diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d114f5e..3ffe2df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,5 @@ name: Run Small test -on: [push, pull_request] # yamllint disable-line rule:truthy +on: [push, pull_request] # yamllint disable-line rule:truthy jobs: test: runs-on: ubuntu-latest diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 0000000..501e1cd --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,69 @@ +line-length = 100 +output-format = "concise" + +[lint] +preview = true +extend-select = [ + "I", + "D", + "DOC", + "B", + "A", + "COM", + "C4", + "DTZ", + "EM", + "EXE", + "FA", + "INT", + "ISC", + "ICN", + "PIE", + "PYI", + "Q", + "RET", + "SLF", + "SIM", + "SLOT", + "TID", + "TC", + "ARG", + "PTH", + "FLY", + "NPY", + "PD", + "N", + "PERF", + "E", + "W", + "F", + "PLC", + "PLE", + "UP", + "FURB", + "RUF", + "TRY", +] +extend-ignore = [ + "COM812", + "D203", + "D213", + "D400", + "D413", + "DOC501", + "E266", + "EM101", + "PLC1901", + "RET504", + "SIM102", + "SIM108", + "TRY002", + "TRY003", + "TRY300", +] + +[lint.pycodestyle] +max-line-length = 100 + +[format] +docstring-code-format = false diff --git a/.yamlfmt.yaml b/.yamlfmt.yaml new file mode 100644 index 0000000..ef4ff50 --- /dev/null +++ b/.yamlfmt.yaml @@ -0,0 +1,4 @@ +formatter: + retain_line_breaks: true + scan_folded_as_literal: true + drop_unnecessary_doc_start: false diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..38c68ba --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,5 @@ +extends: default + +rules: + document-start: disable + line-length: disable diff --git a/Makefile b/Makefile index 1d47c87..71701cd 100644 --- a/Makefile +++ b/Makefile @@ -7,11 +7,3 @@ test: clean: ${MAKE} -C tests clean - -PLUME_SCRIPTS ?= .plume-scripts - -# Code style; defines `style-check` and `style-fix`. -ifeq (,$(wildcard ${PLUME_SCRIPTS})) -dummy := $(shell git clone --depth=1 -q https://github.com/plume-lib/plume-scripts.git ${PLUME_SCRIPTS}) -endif -include ${PLUME_SCRIPTS}/code-style.mak diff --git a/prek.toml b/prek.toml new file mode 100644 index 0000000..e935abf --- /dev/null +++ b/prek.toml @@ -0,0 +1,234 @@ +# Configuration file for `prek`, a git hook framework written in Rust. +# See https://prek.j178.dev for more information. +#:schema https://www.schemastore.org/prek.json + +[[repos]] +repo = "builtin" +hooks = [ + { id = "check-added-large-files" }, + { id = "check-case-conflict" }, + { id = "check-executables-have-shebangs", exclude = { glob = [ + "search", + ] } }, + { id = "check-json" }, + { id = "check-merge-conflict" }, + { id = "check-shebang-scripts-are-executable" }, + { id = "check-symlinks", exclude = { glob = [ + ".subversion/auth", + "dots/.subversion/auth", + ] } }, + { id = "check-toml" }, + { id = "check-vcs-permalinks" }, + { id = "check-xml" }, + { id = "check-yaml" }, + { id = "destroyed-symlinks" }, + { id = "detect-private-key" }, + { id = "end-of-file-fixer", exclude = { glob = [ + "bugs/jikes-patches/*", + "**/non-conflicted-file-without-terminator.txt", + "**/native-image/**", + "**/tests/squeeze-blank-lines-test/**", + ] } }, + { id = "fix-byte-order-marker" }, + { id = "forbid-new-submodules" }, + { id = "mixed-line-ending" }, + { id = "trailing-whitespace", exclude = { glob = [ + "**/*.diff", + "**/*.diff3", + "**/*.patch", + "**/tests/squeeze-blank-lines-test/**", + ".aspell.en.prepl", + ".aspell.en.pws", + "bugs/BUGS.to-do", + "bugs/bug-mew", + "bugs/jikes-patches/*", + "dots/.aspell.en.prepl", + "dots/.aspell.en.pws", + "dots/en_US_apostrophe.aff", + "dots/enscript.st", + "emacs/bug/crypted.UUE", + "en_US_apostrophe.aff", + "enscript.st", + ] } }, +] + +## GitHub Actions + +[[repos]] +repo = "https://github.com/rhysd/actionlint" +rev = "v1.7.12" +hooks = [{ id = "actionlint" }] + +## HTML + +[[repos]] +repo = "https://github.com/Lucas-C/pre-commit-hooks-java" +rev = "1.3.10" +hooks = [{ id = "validate-html", exclude = { glob = ["**/bytopic-headfoot.html"] }}] + +## Makefiles + +[[repos]] +repo = "https://github.com/checkmake/checkmake.git" +rev = "0.2.2" +hooks = [{ id = "checkmake" }] + +## Markdown + +[[repos]] +repo = "https://github.com/DavidAnson/markdownlint-cli2" +rev = "v0.23.1" +hooks = [{ id = "markdownlint-cli2" }] + +## Pre-commit itself + +[[repos]] +repo = "https://github.com/pre-commit/sync-pre-commit-deps" +rev = "v0.0.4" +hooks = [{ id = "sync-pre-commit-deps" }] + +## Python + +[[repos]] +repo = "https://github.com/astral-sh/ruff-pre-commit" +rev = "v0.15.22" # Ruff version. +hooks = [ + # Run the linter. + { id = "ruff-check", args = ["--fix"], types_or = ["python", "pyi"] }, + + # Run the formatter. + { id = "ruff-format", types_or = ["python", "pyi"] }, +] + +[[repos]] +repo = "https://github.com/astral-sh/ty-pre-commit" +rev = "v0.0.62" # ty version. +hooks = [{ id = "ty", types_or = ["python", "pyi"] }] + +[[repos]] +repo = "https://github.com/asottile/pyupgrade" +rev = "v3.21.2" +hooks = [{ id = "pyupgrade" }] + +## Secrets + +[[repos]] +repo = "https://github.com/gitleaks/gitleaks" +rev = "v8.24.2" +hooks = [{ id = "gitleaks", exclude = { glob = ["**/AdjacentTest*"] } }] + +[[repos]] +repo = "https://github.com/Yelp/detect-secrets" +rev = "v1.5.0" +hooks = [{ id = "detect-secrets", exclude = { glob = ["**/AdjacentTest*"] } }] + +## Shell scripts + +[[repos]] +repo = "https://github.com/shellcheck-py/shellcheck-py" +rev = "v0.11.0.1" +hooks = [ + { id = "shellcheck", args = [ + "-x", + "-P", + "SCRIPTDIR", + ], exclude = { glob = [ + "share/csail-athena-tickets.bash", + "share/addrfilter", + "share/print-mail", + "share/javapp", + "share/myxapps", + "cronic-orig", + "classfile_check_version", + ] } }, +] + +[[repos]] +repo = "https://github.com/scop/pre-commit-shfmt" +rev = "v3.13.1-1" +hooks = [ + { id = "shfmt", args = [ + "-i", + "2", + "-ci", + "-bn", + "-sr", + ], exclude = { glob = [ + "gradlew", + "share/addrfilter", + "dots/conda-initialize.sh", + "conda-initialize.sh", + ] } }, +] + +# TODO: checkbashisms (I need to write my own). +# [[repos]] +# repo = "TODO" +# hooks = [ +# { id = "checkbashisms", types = [ +# "shell", +# ], exclude = { glob = [ +# "share/addrfilter", +# "share/print-mail", +# "share/myxapps", +# "share/javapp", +# "gradlew", +# ] } }, +# ] + +# Problems: +# * False positives for E011. +# * It requires indent to be a multiple of 4. +# [[repos]] +# repo = "https://github.com/openstack/bashate" +# rev = "2.1.1" +# hooks = [ +# { id = "bashate", exclude = { glob = ["share/csail-athena-tickets.bash" ] } }, +# ] + +## Text + +# Very noisy. +# [[repos]] +# repo = "https://github.com/errata-ai/vale" +# rev = "16d3a7f" +# hooks = [ #{id = "vale", name = "vale sync", pass_filenames = false, args = ["sync"], }, +# { id = "vale", args = [ +# "--output=line", +# "--minAlertLevel=error", +# ] }, +# ] + +# Very disruptive. Perhaps re-enable later. +# [[repos]] +# repo = "https://github.com/crate-ci/typos" +# rev = "v1.48.0" +# hooks = [ +# { id = "typos", exclude = { glob = [".abbrev_defs", "share/mail-review-spam", "bugs/jikes-patches/*", "share/checkbashisms", "dots/.aspell.en.prepl", ".aspell.en.prepl", "dots/en_US_apostrophe.dic", "dots/.aspell.en.pws", ".aspell.en.pws", "dots/en_US_apostrophe.aff", "en_US_apostrophe.aff" ] } } +# ] + +# Very noisy. Perhaps re-enable later. +# [[repos]] +# repo = "https://github.com/codespell-project/codespell" +# rev = "v2.4.1" +# hooks = [ +# { id = "codespell", exclude = { glob = [ "en_US_apostrophe.dic", ".ssh/known_hosts", "enscript.st" ] } }, +# ] + +# proselint does not understand fenced code blocks in markdown files. +# [[repos]] +# repo = "https://github.com/amperser/proselint" +# rev = "v0.16.0" +# hooks = [{ id = "proselint", args = ["check"], }] + +## YAML + +[[repos]] +repo = "https://github.com/google/yamlfmt" +rev = "v0.19.0" +hooks = [{ id = "yamlfmt" }] + +[[repos]] +repo = "https://github.com/adrienverge/yamllint.git" +rev = "v1.29.0" +hooks = [{ id = "yamllint" }] diff --git a/tests/Makefile b/tests/Makefile index 375b00a..c6052c2 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,3 +1,5 @@ +.PHONY: all clean test + test: ${MAKE} -C git-clone-related-test test ${MAKE} -C resolve-adjacent-conflicts-test diff --git a/tests/git-clone-related-test/Makefile b/tests/git-clone-related-test/Makefile index a476804..f3187c0 100644 --- a/tests/git-clone-related-test/Makefile +++ b/tests/git-clone-related-test/Makefile @@ -1,7 +1,9 @@ +.PHONY: all clean test + test: test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 # Here are the repositories and branches that exist. -# +# # Upstreams: # plume-lib/git-clone-related-test-repo1 # * branch-upstream-all @@ -14,7 +16,7 @@ test: test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 # * branch-fallback # plume-lib/git-clone-related-test-repo3 # * branch-fallback -# +# # Forks: # mernst/git-clone-related-test-repo1 # * branch-downstream-all @@ -25,7 +27,7 @@ test: test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 # * branch-downstream-all # * branch-fallback # DOES NOT EXIST: mernst/git-clone-related-test-repo3 -# +# # The tests run commands from clones of the two repo1 repositories, # trying to create clones of the repo2 and repo3 repositories. @@ -33,17 +35,17 @@ test: test1 test2 test3 test4 test5 test6 test7 test8 test9 test10 # * branch ${MYBRANCH} of https://github.com/${MYORG}/${REPO_NAME}.git # test1: mernst/repo1, branch-downstream-all => mernst/repo2, branch-downstream-all # test2: plume-lib/repo1, branch-upstream-all => plume-lib/repo2, branch-upstream-all -# +# # * branch ${MYBRANCH} of https://github.com/${UPSTREAM_ORG}/${REPO_NAME}.git # test3: mernst/repo1, branch-not-in-downstream-repo2 => plume-lib/repo2, branch-not-in-downstream-repo2 # test4: plume-lib/repo1, branch-not-in-downstream-repo2 => plume-lib/repo2, branch-not-in-downstream-repo2 # test9: mernst/repo1, master => plume-lib/repo3, master # test10: mernst/repo1, branch-fallback => plume-lib/repo3, branch-fallback -# +# # * branch ${FALLBACK_BRANCH} of https://github.com/${UPSTREAM_ORG}/${REPO_NAME}.git # test5: mernst/repo1, branch-downstream-repo1 => plume-lib/repo2, master # test6: plume-lib/repo1, branch-upstream-repo1 => plume-lib/repo2, master -# +# # * branch ${FALLBACK_BRANCH} of https://github.com/${UPSTREAM_ORG}/${REPO_NAME}.git # test7: mernst/repo1, branch-downstream-repo1 => plume-lib/repo2, branch-fallback # test8: plume-lib/repo1, branch-upstream-repo1 => plume-lib/repo2, branch-fallback @@ -90,5 +92,5 @@ test10: USER=mernst ./test-git-clone-related.sh https://github.com/mernst/git-clone-related-test-repo1 branch-fallback "plume-lib git-clone-related-test-repo3" https://github.com/plume-lib/git-clone-related-test-repo3.git branch-fallback -clean: +clean: # Nothing to do diff --git a/tests/resolve-adjacent-conflicts-test/Makefile b/tests/resolve-adjacent-conflicts-test/Makefile index 0a642cc..4891241 100644 --- a/tests/resolve-adjacent-conflicts-test/Makefile +++ b/tests/resolve-adjacent-conflicts-test/Makefile @@ -1,5 +1,8 @@ +.PHONY: all clean test + RESOLVER=../../resolve-adjacent-conflicts +.PHONY: diff test: diff diff: Merged_ConflictStyleMerge.diff Merged_ConflictStyleDiff3.diff diff --git a/tests/resolve-import-conflicts-test/Makefile b/tests/resolve-import-conflicts-test/Makefile index 7147848..fc01adf 100644 --- a/tests/resolve-import-conflicts-test/Makefile +++ b/tests/resolve-import-conflicts-test/Makefile @@ -1,7 +1,10 @@ +.PHONY: all clean test + RESOLVER=../../resolve-import-conflicts test: diff +.PHONY: diff diff: Merged_ConflictStyleMerge.diff Merged_ConflictStyleDiff3.diff Merged_ConflictStyleMerge.diff: Merged_ConflictStyleMerge.goal Merged_ConflictStyleMerge.java