Skip to content

Commit 2e3071e

Browse files
upgrade eslint
1 parent f192e7d commit 2e3071e

File tree

117 files changed

+501
-630
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+501
-630
lines changed

.ncurc.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
{
2-
"reject": ["pixelmatch", "mime", "@types/mime", "file-typ"]
2+
"reject": [
3+
// These deps are esm only
4+
"pixelmatch",
5+
"mime",
6+
"@types/mime",
7+
"file-type",
8+
// We support node 18 and above
9+
"@types/node"
10+
]
311
}

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
1919
"release": "pnpm build && auto shipit",
2020
"generate-package": "turbo gen package",
21-
"generate-plugin": "turbo gen plugin"
21+
"generate-plugin": "turbo gen plugin",
22+
"check-updates": "ncu --packageFile '{,*/**/}package.json'"
2223
},
2324
"devDependencies": {
2425
"@auto-it/all-contributors": "^11.2.1",
@@ -28,6 +29,7 @@
2829
"@jimp/config-typescript": "workspace:*",
2930
"@turbo/gen": "^2.1.1",
3031
"auto": "^11.2.1",
32+
"npm-check-updates": "^17.1.1",
3133
"prettier": "^3.3.3",
3234
"turbo": "^2.1.1"
3335
}

packages/config-eslint/base.js

+24-40
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,28 @@
1-
const { resolve } = require("node:path");
1+
import js from "@eslint/js";
2+
import eslintConfigPrettier from "eslint-config-prettier";
3+
import turboPlugin from "eslint-plugin-turbo";
4+
import tseslint from "typescript-eslint";
25

3-
const project = resolve(process.cwd(), "tsconfig.json");
4-
5-
/** @type {import("eslint").Linter.Config} */
6-
module.exports = {
7-
extends: [
8-
"eslint:recommended",
9-
"prettier",
10-
"eslint-config-turbo",
11-
"plugin:@typescript-eslint/recommended",
12-
],
13-
plugins: ["only-warn"],
14-
globals: {
15-
React: true,
16-
JSX: true,
17-
},
18-
env: {
19-
node: true,
6+
export default [
7+
js.configs.recommended,
8+
eslintConfigPrettier,
9+
...tseslint.configs.recommended,
10+
{
11+
ignores: [
12+
// Ignore dotfiles
13+
".*.js",
14+
"node_modules/",
15+
"dist/",
16+
"**/browser.js",
17+
],
2018
},
21-
settings: {
22-
"import/resolver": {
23-
typescript: {
24-
project,
25-
},
19+
{
20+
name: "eslint-config-turbo (recreated flat)",
21+
plugins: {
22+
turbo: { rules: turboPlugin.rules },
2623
},
27-
},
28-
parser: "@typescript-eslint/parser",
29-
parserOptions: {
30-
project,
31-
},
32-
ignorePatterns: [
33-
// Ignore dotfiles
34-
".*.js",
35-
"node_modules/",
36-
"dist/",
37-
"**/browser.js",
38-
],
39-
overrides: [
40-
{
41-
files: ["*.js?(x)", "*.ts?(x)"],
24+
rules: {
25+
"turbo/no-undeclared-env-vars": "error",
4226
},
43-
],
44-
};
27+
},
28+
];

packages/config-eslint/package.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
"license": "MIT",
55
"private": true,
66
"main": "base.js",
7+
"type": "module",
78
"scripts": {
89
"clean": "rm -rf node_modules .tshy .tshy-build dist .turbo"
910
},
1011
"devDependencies": {
11-
"@typescript-eslint/eslint-plugin": "^7.2.0",
12-
"@typescript-eslint/parser": "^7.2.0",
1312
"eslint-config-prettier": "^9.1.0",
14-
"eslint-config-turbo": "^1.12.5",
15-
"eslint-plugin-only-warn": "^1.1.0",
13+
"eslint-config-turbo": "^2.1.1",
1614
"typescript": "^5.5.4"
1715
},
1816
"publishConfig": {},
19-
"sideEffects": false
17+
"sideEffects": false,
18+
"dependencies": {
19+
"@eslint/js": "^9.9.1",
20+
"@types/eslint__js": "^8.42.3",
21+
"typescript-eslint": "^8.3.0"
22+
}
2023
}

packages/config-vitest/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"devDependencies": {
1616
"@jimp/config-typescript": "workspace:*",
1717
"@jimp/test-utils": "workspace:*",
18-
"eslint": "^8.57.0",
18+
"eslint": "^9.9.1",
1919
"typescript": "^5.5.4",
2020
"vitest": "^2.0.5"
2121
},

packages/core/.eslintrc.cjs

-5
This file was deleted.

packages/core/eslint.config.mjs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import shared from "@jimp/config-eslint/base.js";
2+
export default [
3+
...shared,
4+
{
5+
rules: {
6+
"@typescript-eslint/no-explicit-any": "off",
7+
},
8+
},
9+
];

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@types/file-type": "^10.9.1",
3131
"@types/mime": "^3.0.4",
3232
"@types/node": "^18.19.48",
33-
"eslint": "^8.57.0",
33+
"eslint": "^9.9.1",
3434
"tshy": "^3.0.2",
3535
"typescript": "^5.5.4",
3636
"vitest": "^2.0.5"

packages/core/src/index.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export interface JimpPlugin {
9090
}
9191

9292
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
93-
k: infer I,
93+
k: infer I
9494
) => void
9595
? I
9696
: never;
@@ -272,8 +272,8 @@ export function createJimp<
272272
if (Array.isArray(bitmap.data)) {
273273
data = Buffer.concat(
274274
bitmap.data.map((hex) =>
275-
Buffer.from(hex.toString(16).padStart(8, "0"), "hex"),
276-
),
275+
Buffer.from(hex.toString(16).padStart(8, "0"), "hex")
276+
)
277277
);
278278
}
279279

@@ -316,7 +316,7 @@ export function createJimp<
316316
}
317317

318318
const image = new CustomJimp(
319-
await format.decode(actualBuffer),
319+
await format.decode(actualBuffer)
320320
) as InstanceType<typeof CustomJimp> & ExtraMethodMap;
321321

322322
attemptExifRotate(image, actualBuffer);
@@ -386,6 +386,7 @@ export function createJimp<
386386
let outputImage: Jimp;
387387

388388
if (format.hasAlpha) {
389+
// eslint-disable-next-line @typescript-eslint/no-this-alias
389390
outputImage = this;
390391
} else {
391392
outputImage = new CustomJimp({
@@ -456,7 +457,7 @@ export function createJimp<
456457
const mimeType = mime.getType(path);
457458
await writeFile(
458459
path,
459-
await this.getBuffer(mimeType as SupportedMimeTypes, options),
460+
await this.getBuffer(mimeType as SupportedMimeTypes, options)
460461
);
461462
}
462463

@@ -657,7 +658,7 @@ export function createJimp<
657658
mode?: BlendMode;
658659
opacitySource?: number;
659660
opacityDest?: number;
660-
} = {},
661+
} = {}
661662
) {
662663
return composite(this, src, x, y, options);
663664
}
@@ -687,14 +688,14 @@ export function createJimp<
687688
y: number,
688689
w: number,
689690
h: number,
690-
cb: (x: number, y: number, idx: number) => any,
691+
cb: (x: number, y: number, idx: number) => any
691692
): this;
692693
scan(
693694
x: number | ((x: number, y: number, idx: number) => any),
694695
y?: number,
695696
w?: number,
696697
h?: number,
697-
f?: (x: number, y: number, idx: number) => any,
698+
f?: (x: number, y: number, idx: number) => any
698699
): this {
699700
return scan(this, x as any, y as any, w as any, h as any, f as any);
700701
}

packages/core/src/utils/composite.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Edge, JimpClass } from "@jimp/types";
22

33
import { BlendMode } from "./constants.js";
44
import * as compositeModes from "./composite-modes.js";
5-
import { limit255, scan } from "@jimp/utils";
5+
import { limit255 } from "@jimp/utils";
66

77
export function composite<I extends JimpClass>(
88
baseImage: I,
@@ -13,7 +13,7 @@ export function composite<I extends JimpClass>(
1313
mode?: BlendMode;
1414
opacitySource?: number;
1515
opacityDest?: number;
16-
} = {},
16+
} = {}
1717
) {
1818
if (!(src instanceof baseImage.constructor)) {
1919
throw new Error("The source must be a Jimp image");
@@ -23,11 +23,8 @@ export function composite<I extends JimpClass>(
2323
throw new Error("x and y must be numbers");
2424
}
2525

26-
let {
27-
mode = BlendMode.SRC_OVER,
28-
opacitySource = 1.0,
29-
opacityDest = 1.0,
30-
} = options;
26+
const { mode = BlendMode.SRC_OVER } = options;
27+
let { opacitySource = 1.0, opacityDest = 1.0 } = options;
3128

3229
if (
3330
typeof opacitySource !== "number" ||
@@ -41,7 +38,6 @@ export function composite<I extends JimpClass>(
4138
opacityDest = 1.0;
4239
}
4340

44-
// eslint-disable-next-line import/namespace
4541
const blendmode = compositeModes[mode];
4642

4743
// round input
@@ -76,7 +72,7 @@ export function composite<I extends JimpClass>(
7672
b: baseImage.bitmap.data[dstIdx + 2]! / 255,
7773
a: baseImage.bitmap.data[dstIdx + 3]! / 255,
7874
},
79-
opacitySource,
75+
opacitySource
8076
);
8177

8278
baseImage.bitmap.data[dstIdx + 0] = limit255(blended.r * 255);

packages/core/src/utils/image-bitmap.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import EXIFParser, { ExifData } from "exif-parser";
22
import { JimpClass } from "@jimp/types";
33

4-
const EXIF_TAGS = {
5-
ORIENTATION: 0x0112, // decimal: 274
6-
IMAGE_WIDTH: 0x0100, // decimal: 256
7-
IMAGE_HEIGHT: 0x0101, // decimal: 257
8-
};
9-
104
/**
115
* Obtains image orientation from EXIF metadata.
126
*
@@ -95,7 +89,7 @@ function transformBitmap<I extends JimpClass>(
9589
img: I,
9690
width: number,
9791
height: number,
98-
transformation: (x: number, y: number) => readonly [number, number],
92+
transformation: (x: number, y: number) => readonly [number, number]
9993
) {
10094
// Underscore-prefixed values are related to the source bitmap
10195
// Their counterparts with no prefix are related to the target bitmap
@@ -120,7 +114,7 @@ function transformBitmap<I extends JimpClass>(
120114
img.bitmap.width = width;
121115
img.bitmap.height = height;
122116

123-
// @ts-ignore
117+
// @ts-expect-error Accessing private property
124118
img._exif.tags.Orientation = 1;
125119
}
126120

@@ -146,14 +140,14 @@ function exifRotate<I extends JimpClass>(img: I) {
146140

147141
export async function attemptExifRotate<I extends JimpClass>(
148142
image: I,
149-
buffer: Buffer,
143+
buffer: Buffer
150144
) {
151145
try {
152146
(image as unknown as { _exif: ExifData })._exif =
153147
EXIFParser.create(buffer).parse();
154148

155149
exifRotate(image); // EXIF data
156150
} catch (error) {
157-
/* meh */
151+
console.error(error);
158152
}
159153
}

packages/diff/.eslintrc.cjs

-5
This file was deleted.

packages/diff/eslint.config.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import shared from "@jimp/config-eslint/base.js";
2+
export default [...shared];

packages/diff/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@jimp/core": "workspace:*",
2727
"@jimp/test-utils": "workspace:*",
2828
"@types/pixelmatch": "^5.2.6",
29-
"eslint": "^8.57.0",
29+
"eslint": "^9.9.1",
3030
"tshy": "^3.0.2",
3131
"typescript": "^5.5.4",
3232
"vitest": "^2.0.5"

packages/diff/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export function diff<I extends JimpClass>(img1: I, img2: I, threshold = 0.1) {
4848
throw new Error("threshold must be a number between 0 and 1");
4949
}
5050

51+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5152
const diff = new (img1 as any).constructor({
5253
width: bmp1.width,
5354
height: bmp1.height,
@@ -60,7 +61,7 @@ export function diff<I extends JimpClass>(img1: I, img2: I, threshold = 0.1) {
6061
diff.bitmap.data,
6162
diff.bitmap.width,
6263
diff.bitmap.height,
63-
{ threshold },
64+
{ threshold }
6465
);
6566

6667
return {

packages/docs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@jimp/plugin-print": "workspace:*",
2121
"@types/react": "^18.3.5",
2222
"astro": "^4.15.1",
23-
"eslint": "^8.57.0",
23+
"eslint": "^9.9.1",
2424
"jimp": "workspace:*",
2525
"react": "^18.3.1",
2626
"react-dom": "^18.3.1",

packages/file-ops/.eslintrc.cjs

-5
This file was deleted.

packages/file-ops/eslint.config.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import shared from "@jimp/config-eslint/base.js";
2+
export default [...shared];

packages/file-ops/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@jimp/config-eslint": "workspace:*",
1818
"@jimp/config-typescript": "workspace:*",
1919
"@types/node": "^18.19.48",
20-
"eslint": "^8.57.0",
20+
"eslint": "^9.9.1",
2121
"tshy": "^3.0.2",
2222
"typescript": "^5.5.4",
2323
"vitest": "^2.0.5"

packages/jimp/.eslintrc.cjs

-5
This file was deleted.

0 commit comments

Comments
 (0)