Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1

FROM alpine:3.20.3 AS entry
RUN apk add --no-cache npm && npm install -g typescript@5.6.3 @types/node@22.9.0
FROM alpine:3.23.2 AS entry
RUN apk add --no-cache npm && npm install -g typescript@5.9.3 @types/node@25.0.9
COPY entry.ts .
RUN tsc \
--noUnusedLocals \
Expand All @@ -16,7 +16,7 @@ RUN tsc \
# eclipse-temurin:21-alpine java --list-modules`, then removing modules by trial
# and error until `make test` throws ClassNotFoundException. When first
# implemented, this custom JRE reduced our image size from 574 MB to 469 MB
FROM amazoncorretto:21.0.6-alpine3.21 AS jre
FROM amazoncorretto:21.0.9-alpine3.22 AS jre
RUN apk add binutils && jlink \
--add-modules java.se,jdk.compiler,jdk.unsupported \
--compress zip-6 \
Expand All @@ -25,7 +25,7 @@ RUN apk add binutils && jlink \
--output /jre \
--strip-debug

FROM alpine:3.20.3
FROM alpine:3.23.2
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PIP_NO_CACHE_DIR=1
RUN <<EOF
Expand All @@ -46,7 +46,7 @@ apk add --no-cache \
pip3 install --break-system-packages \
autoflake==1.7.8 \
isort==5.13.2 \
ruff==0.7.3 \
ruff==0.14.13 \
PyYAML>=6.0

# Install Python dependencies
Expand All @@ -71,39 +71,39 @@ chmod +x /usr/bin/black21
# https://nodejs.org/en/blog/announcements/v22-release-announce#support-requireing-synchronous-esm-graphs
# https://github.com/eslint/eslint/issues/13684#issuecomment-722949152
npm install -g \
@prettier/plugin-xml@3.4.1 \
eslint@9.23.0 \
eslint-plugin-jsdoc@50.6.9 \
@prettier/plugin-xml@3.4.2 \
eslint@9.39.2 \
eslint-plugin-jsdoc@62.0.0 \
eslint-plugin-sort-keys@2.3.5 \
eslint-plugin-unicorn@56.0.1 \
prettier@3.5.3 \
svgo@3.3.2 \
typescript-eslint@8.29.0
prettier@3.8.0 \
svgo@4.0.0 \
typescript-eslint@8.53.1

# Install Scala dependencies
wget https://github.com/coursier/coursier/releases/download/v2.1.17/coursier -O /bin/coursier
wget https://github.com/coursier/coursier/releases/download/v2.1.24/coursier -O /bin/coursier
chmod +x /bin/coursier
coursier bootstrap org.scalameta:scalafmt-cli_2.13:3.8.3 \
coursier bootstrap org.scalameta:scalafmt-cli_2.13:3.10.4 \
-r sonatype:snapshots --main org.scalafmt.cli.Cli \
--standalone \
-o scalafmt

# Install static binaries
wget https://github.com/muttleyxd/clang-tools-static-binaries/releases/download/master-32d3ac78/clang-format-18_linux-amd64 -O clang-format
wget https://github.com/muttleyxd/clang-tools-static-binaries/releases/download/master-796e77c/clang-format-20_linux-amd64 -O clang-format
chmod +x clang-format
wget https://github.com/google/google-java-format/releases/download/v1.24.0/google-java-format-1.24.0-all-deps.jar -O google-java-format
wget https://search.maven.org/remotecontent?filepath=com/facebook/ktfmt/0.53/ktfmt-0.53-jar-with-dependencies.jar -O ktfmt
wget https://repo1.maven.org/maven2/com/squareup/sort-gradle-dependencies-app/0.14/sort-gradle-dependencies-app-0.14-all.jar -O gradle-dependencies-sorter
wget https://github.com/mvdan/sh/releases/download/v3.10.0/shfmt_v3.10.0_linux_amd64 -O shfmt
wget https://github.com/google/google-java-format/releases/download/v1.33.0/google-java-format-1.33.0-all-deps.jar -O google-java-format
wget https://repo1.maven.org/maven2/com/facebook/ktfmt/0.61/ktfmt-0.61-with-dependencies.jar -O ktfmt
wget https://repo1.maven.org/maven2/com/squareup/sort-gradle-dependencies-app/0.16/sort-gradle-dependencies-app-0.16-all.jar -O gradle-dependencies-sorter
wget https://github.com/mvdan/sh/releases/download/v3.12.0/shfmt_v3.12.0_linux_amd64 -O shfmt
chmod +x shfmt
wget https://github.com/tamasfe/taplo/releases/download/0.9.3/taplo-linux-x86_64.gz -O taplo.gz
wget https://github.com/tamasfe/taplo/releases/download/0.10.0/taplo-linux-x86_64.gz -O taplo.gz
gzip -d taplo.gz
chmod +x taplo
wget https://releases.hashicorp.com/terraform/1.9.8/terraform_1.9.8_linux_amd64.zip -O tf.zip
wget https://releases.hashicorp.com/terraform/1.14.3/terraform_1.14.3_linux_amd64.zip -O tf.zip
unzip tf.zip
rm tf.zip
rm LICENSE.txt
wget https://releases.hashicorp.com/packer/1.14.2/packer_1.14.2_linux_amd64.zip -O packer.zip
wget https://releases.hashicorp.com/packer/1.14.3/packer_1.14.3_linux_amd64.zip -O packer.zip
unzip packer.zip
rm packer.zip

Expand All @@ -114,16 +114,16 @@ touch /emptyfile
apk del .build-deps
rm -rf \
/bin/coursier \
/black21-venv/lib/python3.11/site-packages/pip \
/black21-venv/lib/python3.11/site-packages/pkg_resources \
/black21-venv/lib/python3.11/site-packages/setuptools \
/black21-venv/lib/python3.12/site-packages/pip \
/black21-venv/lib/python3.12/site-packages/pkg_resources \
/black21-venv/lib/python3.12/site-packages/setuptools \
/root/.cache \
/root/.npm \
/usr/bin/lto-dump \
/var/cache
EOF
# https://stackoverflow.com/a/59485924
COPY --from=golang:1.23.3-alpine3.20 /usr/local/go/bin/gofmt /gofmt
COPY --from=golang:1.25.6-alpine3.23 /usr/local/go/bin/gofmt /gofmt
ENV PATH="/jre/bin:${PATH}"
COPY --from=jre /jre /jre
COPY . .
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ This repo contains [pre-commit](https://pre-commit.com/) hooks for Duolingo deve

The main hook that runs several code formatters in parallel:

- [Prettier](https://github.com/prettier/prettier) v3.5.3 for CSS, HTML, JS, JSX, Markdown, Sass, TypeScript, XML, YAML
- [ESLint](https://eslint.org/) v9.23.0 for JS, TypeScript
- [Ruff](https://docs.astral.sh/ruff/) v0.7.3 for Python 3
- [Prettier](https://github.com/prettier/prettier) v3.8.0 for CSS, HTML, JS, JSX, Markdown, Sass, TypeScript, XML, YAML
- [ESLint](https://eslint.org/) v9.39.2 for JS, TypeScript
- [Ruff](https://docs.astral.sh/ruff/) v0.14.13 for Python 3
- [Black](https://github.com/psf/black) v21.12b0 for Python 2
- [autoflake](https://github.com/myint/autoflake) v1.7.8 for Python <!-- TODO: Upgrade to v2+, restrict to Python 2, and reenable Ruff rule F401 once our Python 3 repos that were converted from Python 2 no longer use type hint comments: https://github.com/PyCQA/autoflake/issues/222#issuecomment-1419089254 -->
- [isort](https://github.com/PyCQA/isort) v5.13.2 for Python 2
- [google-java-format](https://github.com/google/google-java-format) v1.24.0 for Java
- [ktfmt](https://github.com/facebookincubator/ktfmt) v0.53 for Kotlin
- [gradle-dependencies-sorter](https://github.com/square/gradle-dependencies-sorter) v0.14 for Gradle Kotlin
- [gofmt](https://pkg.go.dev/cmd/gofmt) v1.23.3 for Go
- [scalafmt](https://scalameta.org/scalafmt/) v3.8.3 for Scala
- [shfmt](https://github.com/mvdan/sh) v3.10.0 for Shell
- [xsltproc](http://www.xmlsoft.org/xslt/xsltproc.html) from libxslt v10139 for XML
- [terraform fmt](https://github.com/hashicorp/terraform) v1.9.8 for Terraform
- [packer fmt](https://github.com/hashicorp/packer) v1.14.2 for Packer
- [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) v18.1.8 for C++, Protobuf
- [SVGO](https://github.com/svg/svgo) v3.3.2 for SVG
- [Taplo](https://taplo.tamasfe.dev/) v0.9.3 for TOML
- [google-java-format](https://github.com/google/google-java-format) v1.33.0 for Java
- [ktfmt](https://github.com/facebookincubator/ktfmt) v0.61 for Kotlin
- [gradle-dependencies-sorter](https://github.com/square/gradle-dependencies-sorter) v0.16 for Gradle Kotlin
- [gofmt](https://pkg.go.dev/cmd/gofmt) v1.25.6 for Go
- [scalafmt](https://scalameta.org/scalafmt/) v3.10.4 for Scala
- [shfmt](https://github.com/mvdan/sh) v3.12.0 for Shell
- [xsltproc](http://www.xmlsoft.org/xslt/xsltproc.html) from libxslt v10143 for XML
- [terraform fmt](https://github.com/hashicorp/terraform) v1.14.3 for Terraform
- [packer fmt](https://github.com/hashicorp/packer) v1.14.3 for Packer
- [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) v20.1.0 for C++, Protobuf
- [SVGO](https://github.com/svg/svgo) v4.0.0 for SVG
- [Taplo](https://taplo.tamasfe.dev/) v0.10.0 for TOML
- Custom regex transformations (basically [sed](https://en.wikipedia.org/wiki/Sed)), for example:
- Trimming trailing whitespace and newlines
- Removing unnecessary `coding` pragmas and `object` base classes in Python 3
Expand Down
15 changes: 11 additions & 4 deletions entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const PRETTIER_OPTIONS = [
"/tmp/prettier-cache",
"--end-of-line",
"auto",
"--experimental-cli",
"--ignore-path",
EMPTY_FILE,
"--log-level",
Expand Down Expand Up @@ -87,8 +88,9 @@ const enum HookName {
Isort = "isort",
Ktfmt = "ktfmt",
PackerFmt = "packer fmt",
Prettier = "Prettier",
PrettierJs = "Prettier (JS)",
PrettierNonJs = "Prettier (non-JS)",
PrettierXml = "Prettier (XML)",
Ruff = "Ruff",
Scalafmt = "scalafmt",
Sed = "sed",
Expand Down Expand Up @@ -251,6 +253,11 @@ const HOOKS: Record<HookName, Hook> = {
include: /\.pkr\.hcl$/,
runAfter: [HookName.Sed],
},
[HookName.Prettier]: {
action: sources => run("prettier", ...PRETTIER_OPTIONS, ...sources),
include: /\.(css|html?|markdown|md|scss|tsx?|ya?ml)$/,
runAfter: [HookName.Sed, HookName.EsLint],
},
[HookName.PrettierJs]: {
action: sources =>
run(
Expand All @@ -264,7 +271,7 @@ const HOOKS: Record<HookName, Hook> = {
include: /\.jsx?$/,
runAfter: [HookName.Sed, HookName.EsLint],
},
[HookName.PrettierNonJs]: {
[HookName.PrettierXml]: {
action: sources =>
run(
"prettier",
Expand All @@ -274,8 +281,8 @@ const HOOKS: Record<HookName, Hook> = {
"/usr/local/lib/node_modules/@prettier/plugin-xml/src/plugin.js",
...sources,
),
include: /\.(css|html?|markdown|md|scss|tsx?|xml|ya?ml)$/,
runAfter: [HookName.Sed, HookName.Xsltproc, HookName.EsLint],
include: /\.xml$/,
runAfter: [HookName.Sed, HookName.Xsltproc],
},
[HookName.Ruff]: {
action: async (sources, args) => {
Expand Down
6 changes: 2 additions & 4 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ target-version = "py37"

[lint]
ignore = [
# This rule causes Ruff to warn "The following rule may cause conflicts when
# used with the formatter". TODO: Remove after updating to Ruff v0.9?
# https://github.com/astral-sh/ruff/issues/8272#issuecomment-2580594913
"ISC001",
# We disable Ruff's `unused-import` for now in favor of autoflake <2 because
# the latter preserves imports that are unused in code but "used" in type
# hint comments. Ruff also seems to have an unfortunate bug: it can end up
Expand All @@ -19,6 +15,8 @@ ignore = [
"SIM101",
# This rule correctly preserves logic but will delete comments :|
"SIM114",
# This rule adds visual noise and hurts readability/greppability
"SIM905",
]
# https://docs.astral.sh/ruff/rules/
select = [
Expand Down