Skip to content

Commit 0787317

Browse files
authored
Update all dependencies (#29)
1 parent 204e4bf commit 0787317

8 files changed

Lines changed: 101 additions & 130 deletions

File tree

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
!.editorconfig
33
!entry.ts
44
!stylesheet.xml
5+
!svgo.config.js

.editorconfig

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,7 @@ indent_size=2
1515
max_line_length=80
1616

1717
[*.py]
18-
# TODO: We originally set this value to true, but an isort bug caused it to be
19-
# ignored for several months. We now have a workaround for that bug, but we set
20-
# this value to false in order to preserve existing behavior and avoid diff
21-
# churn unrelated to the bug workaround (which is much higher urgency than
22-
# combine_as_imports). We should set this value back to true the next time we
23-
# upgrade Black, which will probably cause significant diff churn anyway.
24-
# https://github.com/duolingo/pre-commit-hooks/pull/28
25-
combine_as_imports=false
18+
combine_as_imports=true
2619
force_grid_wrap=0
2720
include_trailing_comma=true
2821
indent_size=4

Dockerfile

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
FROM alpine:3.14.1
1+
FROM alpine:3.15.4
2+
3+
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
4+
ENV PIP_NO_CACHE_DIR=1
25

36
# Dependencies
47
RUN apk add --no-cache --virtual .build-deps \
@@ -13,33 +16,33 @@ RUN apk add --no-cache --virtual .build-deps \
1316
openjdk11-jre-headless \
1417
py3-pip \
1518
python3 \
16-
&& pip3 install --no-cache-dir --upgrade pip \
17-
&& pip3 install --no-cache-dir \
19+
&& pip3 install \
1820
autoflake==1.4 \
19-
black==21.7b0 \
20-
click==8.0.4 \
21-
isort==5.9.3 \
21+
black==22.3.0 \
22+
isort==5.10.1 \
23+
&& python3 -m venv /black21-venv \
24+
&& source /black21-venv/bin/activate \
25+
&& pip3 install black==21.12b0 click==8.0.4 \
26+
&& deactivate \
27+
&& echo 'source /black21-venv/bin/activate && black "$@"' > /usr/bin/black21 \
28+
&& chmod +x /usr/bin/black21 \
2229
&& npm install -g \
2330
@prettier/plugin-xml@2.0.1 \
24-
@types/node@16.6.2 \
25-
prettier@2.3.2 \
26-
svgo@1.3.2 \
27-
typescript@4.3.5 \
31+
@types/node@17.0.23 \
32+
prettier@2.6.2 \
33+
svgo@2.8.0 \
34+
typescript@4.6.3 \
2835
&& apk del .build-deps \
29-
&& wget https://github.com/google/google-java-format/releases/download/v1.11.0/google-java-format-1.11.0-all-deps.jar -O google-java-format \
30-
&& wget https://search.maven.org/remotecontent?filepath=com/facebook/ktfmt/0.28/ktfmt-0.28-jar-with-dependencies.jar -O ktfmt \
31-
&& wget https://github.com/mvdan/sh/releases/download/v3.3.1/shfmt_v3.3.1_linux_amd64 -O shfmt \
36+
&& wget https://github.com/google/google-java-format/releases/download/v1.15.0/google-java-format-1.15.0-all-deps.jar -O google-java-format \
37+
&& wget https://search.maven.org/remotecontent?filepath=com/facebook/ktfmt/0.35/ktfmt-0.35-jar-with-dependencies.jar -O ktfmt \
38+
&& wget https://github.com/mvdan/sh/releases/download/v3.4.3/shfmt_v3.4.3_linux_amd64 -O shfmt \
3239
&& chmod +x shfmt \
33-
&& wget https://releases.hashicorp.com/terraform/0.12.29/terraform_0.12.29_linux_amd64.zip -O tf.zip \
34-
&& unzip tf.zip \
35-
&& rm tf.zip \
36-
&& mv terraform terraform0.12 \
37-
&& wget https://releases.hashicorp.com/terraform/0.11.14/terraform_0.11.14_linux_amd64.zip -O tf.zip \
40+
&& wget https://releases.hashicorp.com/terraform/1.1.8/terraform_1.1.8_linux_amd64.zip -O tf.zip \
3841
&& unzip tf.zip \
3942
&& rm tf.zip \
40-
&& wget https://github.com/coursier/coursier/releases/download/v2.0.6/coursier -O /bin/coursier \
43+
&& wget https://github.com/coursier/coursier/releases/download/v2.0.16/coursier -O /bin/coursier \
4144
&& chmod +x /bin/coursier \
42-
&& coursier bootstrap org.scalameta:scalafmt-cli_2.13:2.7.5 \
45+
&& coursier bootstrap org.scalameta:scalafmt-cli_2.13:3.5.1 \
4346
-r sonatype:snapshots --main org.scalafmt.cli.Cli \
4447
--standalone \
4548
-o scalafmt \

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
This repo currently contains a single [pre-commit](https://pre-commit.com/) hook that internally runs several code formatters in parallel.
44

5-
- [Prettier](https://github.com/prettier/prettier) v2.3.2 for CSS, HTML, JS, JSX, Markdown, Sass, TypeScript, XML, YAML
6-
- [Black](https://github.com/psf/black) v21.7b0<!-- TODO: The next time we upgrade Black, we should also address the isort comment in .editorconfig --> for Python
5+
- [Prettier](https://github.com/prettier/prettier) v2.6.2 for CSS, HTML, JS, JSX, Markdown, Sass, TypeScript, XML, YAML
6+
- [Black](https://github.com/psf/black) v22.3.0 for Python 3, v21.12b0 for Python 2
77
- [autoflake](https://github.com/myint/autoflake) v1.4 for Python
8-
- [isort](https://github.com/PyCQA/isort) v5.9.3 for Python
9-
- [google-java-format](https://github.com/google/google-java-format) v1.11.0 for Java
10-
- [ktfmt](https://github.com/facebookincubator/ktfmt) v0.28 for Kotlin
11-
- [scalafmt](https://scalameta.org/scalafmt/) v2.7.5 for Scala
12-
- [shfmt](https://github.com/mvdan/sh) v3.3.1 for Shell
8+
- [isort](https://github.com/PyCQA/isort) v5.10.1 for Python
9+
- [google-java-format](https://github.com/google/google-java-format) v1.15.0 for Java
10+
- [ktfmt](https://github.com/facebookincubator/ktfmt) v0.35 for Kotlin
11+
- [scalafmt](https://scalameta.org/scalafmt/) v3.5.1 for Scala
12+
- [shfmt](https://github.com/mvdan/sh) v3.4.3 for Shell
1313
- [xsltproc](http://www.xmlsoft.org/xslt/xsltproc.html) from libxslt v10135 for XML
14-
- [terraform fmt](https://github.com/hashicorp/terraform) v0.11.14 and v0.12.29 for Terraform
15-
- [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) v11.1.0 for Protobuf
16-
- [SVGO](https://github.com/svg/svgo) v1.3.2 for SVG
14+
- [terraform fmt](https://github.com/hashicorp/terraform) v1.1.8 for Terraform
15+
- [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) v13.0.1 for Protobuf
16+
- [SVGO](https://github.com/svg/svgo) v2.8.0 for SVG
1717
- Custom regex transformations (basically [sed](https://en.wikipedia.org/wiki/Sed)), for example:
1818
- Trimming trailing whitespace and newlines
1919
- Removing unnecessary `coding` pragmas and `object` base classes in Python 3
@@ -31,11 +31,13 @@ Repo maintainers can declare this hook in `.pre-commit-config.yaml`:
3131
rev: 1.5.4
3232
hooks:
3333
- id: duolingo
34-
args: [--python-version=2] # Optional, defaults to Python 3
34+
args: # Optional
35+
- --python-version=2 # Defaults to Python 3
36+
- --scala-version=3 # Defaults to Scala 2.12
3537
```
3638
3739
Directories named `build` and `node_modules` are excluded by default - no need to declare them in the hook's `exclude` key.
3840

39-
Contributors can copy this repo's `.editorconfig` file to their home directory in order to have their [text editors and IDEs](https://editorconfig.org/) automatically pick up the same linter/formatter settings that this hook uses.
41+
Contributors can copy or symlink this repo's `.editorconfig` file to their home directory in order to have their [text editors and IDEs](https://editorconfig.org/) automatically pick up the same linter/formatter settings that this hook uses.
4042

4143
_Duolingo is hiring! Apply at https://www.duolingo.com/careers_

entry.ts

Lines changed: 55 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const enum HookName {
8484

8585
/** Arguments passed into this hook via the `args` pre-commit config key */
8686
type Args = Partial<Record<Arg, string>>;
87-
type Arg = "python-version";
87+
type Arg = "python-version" | "scala-version";
8888

8989
interface Hook {
9090
/**
@@ -143,21 +143,22 @@ const HOOKS: Record<HookName, LockableHook> = {
143143
runAfter: [HookName.Sed],
144144
}),
145145
[HookName.Black]: createLockableHook({
146-
action: async (sources, args) => {
147-
const pythonVersionArgs = args["python-version"]?.startsWith("2")
148-
? ["--fast", "--target-version", "py27"]
149-
: ["--target-version", "py36"];
150-
await run(
151-
"black",
146+
action: async (sources, args) =>
147+
run(
148+
// Black 21.x was the last major version with Python 2 support. It also
149+
// had a bug that requires pinning click==8.0.4. Both packages should
150+
// be removed once we drop Python 2 support.
151+
// https://github.com/psf/black/issues/2964
152+
...(args["python-version"]?.startsWith("2")
153+
? ["black21", "--fast", "--target-version", "py27"]
154+
: ["black", "--target-version", "py310"]),
152155
"--config",
153156
EMPTY_FILE,
154157
"--line-length",
155158
`${PYTHON_LINE_LENGTH}`,
156159
"--quiet",
157-
...pythonVersionArgs,
158160
...sources,
159-
);
160-
},
161+
),
161162
include: /\.py$/,
162163
runAfter: [HookName.Isort],
163164
}),
@@ -187,19 +188,26 @@ const HOOKS: Record<HookName, LockableHook> = {
187188
runAfter: [HookName.Autoflake],
188189
}),
189190
[HookName.Ktfmt]: createLockableHook({
190-
action: sources =>
191-
run(
192-
"java",
193-
// By default, ktfmt was OOMing our 36-core CI server with crazy errors like "There is
194-
// insufficient memory for the Java Runtime Environment to continue. Native memory
195-
// allocation (mmap) failed to map 3697278976 bytes for committing reserved memory." Capping
196-
// at 256m works and only increases my laptop's time to format a test repo from 64s to 72s
197-
"-Xmx256m",
198-
"-jar",
199-
"/ktfmt",
200-
"--google-style",
201-
...sources,
202-
),
191+
action: async sources => {
192+
/** Try to avoid ktfmt OOMs presumably caused by too many input files */
193+
const MAX_FILES_PER_PROCESS = 200;
194+
for (let i = 0; i < sources.length; i += MAX_FILES_PER_PROCESS) {
195+
await run(
196+
"java",
197+
// By default, ktfmt was OOMing our 36-core CI server with errors
198+
// like "There is insufficient memory for the Java Runtime
199+
// Environment to continue. Native memory allocation (mmap) failed to
200+
// map 3697278976 bytes for committing reserved memory." Capping at
201+
// 256m works and only increases my laptop's time to format a test
202+
// repo from 64s to 72s
203+
"-Xmx256m",
204+
"-jar",
205+
"/ktfmt",
206+
"--google-style",
207+
...sources.slice(i, i + MAX_FILES_PER_PROCESS),
208+
);
209+
}
210+
},
203211
include: /\.kts?$/,
204212
runAfter: [HookName.Sed],
205213
}),
@@ -222,8 +230,26 @@ const HOOKS: Record<HookName, LockableHook> = {
222230
runAfter: [HookName.Sed, HookName.Xsltproc],
223231
}),
224232
[HookName.Scalafmt]: createLockableHook({
225-
action: sources =>
226-
run("/scalafmt", "--config-str", "preset=IntelliJ", ...sources),
233+
action: async (sources, args) =>
234+
run(
235+
"/scalafmt",
236+
"--config-str",
237+
Object.entries({
238+
"docstrings.oneline": "fold",
239+
"docstrings.wrap": "no",
240+
preset: "IntelliJ",
241+
"runner.dialect": `scala${(args["scala-version"] ?? "2.12")
242+
.split(".")
243+
.slice(0, 2)
244+
.join("")}`,
245+
version: (await run("/scalafmt", "--version")).split(" ")[1],
246+
})
247+
.map(kv => kv.join("="))
248+
.join(","),
249+
"--non-interactive",
250+
"--quiet",
251+
...sources,
252+
),
227253
include: /\.(scala|sbt|sc)$/,
228254
runAfter: [HookName.Sed],
229255
}),
@@ -315,62 +341,7 @@ const HOOKS: Record<HookName, LockableHook> = {
315341
runAfter: [HookName.Sed],
316342
}),
317343
[HookName.Svgo]: createLockableHook({
318-
action: sources =>
319-
run(
320-
"svgo",
321-
`--disable=${[
322-
"addAttributesToSVGElement",
323-
"addClassesToSVGElement",
324-
"cleanupEnableBackground",
325-
"cleanupIDs",
326-
"cleanupListOfValues",
327-
"cleanupNumericValues",
328-
"collapseGroups", // Can cause shape misalignment
329-
"convertColors",
330-
"convertEllipseToCircle",
331-
"convertPathData",
332-
"convertShapeToPath",
333-
"convertStyleToAttrs",
334-
"convertTransform",
335-
"inlineStyles",
336-
"mergePaths",
337-
"minifyStyles",
338-
"moveElemsAttrsToGroup",
339-
"moveGroupAttrsToElems",
340-
"prefixIds",
341-
"removeAttributesBySelector",
342-
"removeAttrs",
343-
"removeDesc",
344-
"removeDimensions",
345-
"removeDoctype",
346-
"removeEditorsNSData",
347-
"removeElementsByAttr",
348-
"removeEmptyAttrs",
349-
"removeEmptyContainers",
350-
"removeEmptyText",
351-
"removeHiddenElems",
352-
"removeMetadata",
353-
"removeNonInheritableGroupAttrs",
354-
"removeOffCanvasPaths",
355-
"removeRasterImages",
356-
"removeScriptElement",
357-
"removeStyleElement",
358-
"removeTitle",
359-
"removeUnknownsAndDefaults", // Can turn shapes black
360-
"removeUnusedNS",
361-
"removeUselessDefs", // Blows away SVG fonts
362-
"removeUselessStrokeAndFill",
363-
"removeViewBox",
364-
"removeXMLNS",
365-
"removeXMLProcInst",
366-
"reusePaths",
367-
"sortAttrs",
368-
"sortDefsChildren",
369-
].join(",")}`,
370-
`--enable=${["cleanupAttrs", "removeComments"].join(",")}`,
371-
"--quiet",
372-
...sources,
373-
),
344+
action: sources => run("svgo", "--config", "/svgo.config.js", ...sources),
374345
include: /\.svg$/,
375346
runAfter: [HookName.Sed],
376347
}),
@@ -386,13 +357,7 @@ const HOOKS: Record<HookName, LockableHook> = {
386357
// parallelizes multiple runs of this hook. This in turn can create a
387358
// race condition that results in a source file getting unintentionally
388359
// deleted!) https://github.com/hashicorp/terraform/pull/20040
389-
sources.map(async source => {
390-
try {
391-
await run("/terraform", "fmt", "-write=true", source);
392-
} catch (ex) {
393-
await run("/terraform0.12", "fmt", "-write=true", source);
394-
}
395-
}),
360+
sources.map(source => run("/terraform", "fmt", "-write=true", source)),
396361
),
397362
include: /\.tf$/,
398363
runAfter: [HookName.Sed],
@@ -427,6 +392,8 @@ const prefixLines = (() => {
427392
lines
428393
.split("\n")
429394
.filter(line => line.trim().length)
395+
// Black 21.12b0 spams this when running on Python 2 source code
396+
.filter(line => !line.includes("DEPRECATION: Python 2 support"))
430397
.map(line => `${prefix}:`.padEnd(maxPrefixLength + 2) + line)
431398
.join("\n");
432399
})();

svgo.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { plugins: ["cleanupAttrs", "removeComments"], quiet: true };

test/after/hello.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
resource "hello" "world" {
1+
resource "hello" "world" { foo = "bar" }
2+
resource "hello" "moon" {
23
foo = "bar"
34
}

test/before/hello.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
resource"hello" "world"{foo= "bar"}
1+
resource"hello" "world"{foo= "bar"}
2+
resource"hello" "moon"{
3+
foo= "bar"
4+
}

0 commit comments

Comments
 (0)