Skip to content

Commit

Permalink
upgrade eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie committed Sep 2, 2024
1 parent f192e7d commit 2e3071e
Show file tree
Hide file tree
Showing 117 changed files with 501 additions and 630 deletions.
10 changes: 9 additions & 1 deletion .ncurc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{
"reject": ["pixelmatch", "mime", "@types/mime", "file-typ"]
"reject": [
// These deps are esm only
"pixelmatch",
"mime",
"@types/mime",
"file-type",
// We support node 18 and above
"@types/node"
]
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"release": "pnpm build && auto shipit",
"generate-package": "turbo gen package",
"generate-plugin": "turbo gen plugin"
"generate-plugin": "turbo gen plugin",
"check-updates": "ncu --packageFile '{,*/**/}package.json'"
},
"devDependencies": {
"@auto-it/all-contributors": "^11.2.1",
Expand All @@ -28,6 +29,7 @@
"@jimp/config-typescript": "workspace:*",
"@turbo/gen": "^2.1.1",
"auto": "^11.2.1",
"npm-check-updates": "^17.1.1",
"prettier": "^3.3.3",
"turbo": "^2.1.1"
}
Expand Down
64 changes: 24 additions & 40 deletions packages/config-eslint/base.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
const { resolve } = require("node:path");
import js from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier";
import turboPlugin from "eslint-plugin-turbo";
import tseslint from "typescript-eslint";

const project = resolve(process.cwd(), "tsconfig.json");

/** @type {import("eslint").Linter.Config} */
module.exports = {
extends: [
"eslint:recommended",
"prettier",
"eslint-config-turbo",
"plugin:@typescript-eslint/recommended",
],
plugins: ["only-warn"],
globals: {
React: true,
JSX: true,
},
env: {
node: true,
export default [
js.configs.recommended,
eslintConfigPrettier,
...tseslint.configs.recommended,
{
ignores: [
// Ignore dotfiles
".*.js",
"node_modules/",
"dist/",
"**/browser.js",
],
},
settings: {
"import/resolver": {
typescript: {
project,
},
{
name: "eslint-config-turbo (recreated flat)",
plugins: {
turbo: { rules: turboPlugin.rules },
},
},
parser: "@typescript-eslint/parser",
parserOptions: {
project,
},
ignorePatterns: [
// Ignore dotfiles
".*.js",
"node_modules/",
"dist/",
"**/browser.js",
],
overrides: [
{
files: ["*.js?(x)", "*.ts?(x)"],
rules: {
"turbo/no-undeclared-env-vars": "error",
},
],
};
},
];
13 changes: 8 additions & 5 deletions packages/config-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
"license": "MIT",
"private": true,
"main": "base.js",
"type": "module",
"scripts": {
"clean": "rm -rf node_modules .tshy .tshy-build dist .turbo"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-turbo": "^1.12.5",
"eslint-plugin-only-warn": "^1.1.0",
"eslint-config-turbo": "^2.1.1",
"typescript": "^5.5.4"
},
"publishConfig": {},
"sideEffects": false
"sideEffects": false,
"dependencies": {
"@eslint/js": "^9.9.1",
"@types/eslint__js": "^8.42.3",
"typescript-eslint": "^8.3.0"
}
}
2 changes: 1 addition & 1 deletion packages/config-vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"devDependencies": {
"@jimp/config-typescript": "workspace:*",
"@jimp/test-utils": "workspace:*",
"eslint": "^8.57.0",
"eslint": "^9.9.1",
"typescript": "^5.5.4",
"vitest": "^2.0.5"
},
Expand Down
5 changes: 0 additions & 5 deletions packages/core/.eslintrc.cjs

This file was deleted.

9 changes: 9 additions & 0 deletions packages/core/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import shared from "@jimp/config-eslint/base.js";
export default [
...shared,
{
rules: {
"@typescript-eslint/no-explicit-any": "off",
},
},
];
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@types/file-type": "^10.9.1",
"@types/mime": "^3.0.4",
"@types/node": "^18.19.48",
"eslint": "^8.57.0",
"eslint": "^9.9.1",
"tshy": "^3.0.2",
"typescript": "^5.5.4",
"vitest": "^2.0.5"
Expand Down
17 changes: 9 additions & 8 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface JimpPlugin {
}

type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
k: infer I,
k: infer I
) => void
? I
: never;
Expand Down Expand Up @@ -272,8 +272,8 @@ export function createJimp<
if (Array.isArray(bitmap.data)) {
data = Buffer.concat(
bitmap.data.map((hex) =>
Buffer.from(hex.toString(16).padStart(8, "0"), "hex"),
),
Buffer.from(hex.toString(16).padStart(8, "0"), "hex")
)
);
}

Expand Down Expand Up @@ -316,7 +316,7 @@ export function createJimp<
}

const image = new CustomJimp(
await format.decode(actualBuffer),
await format.decode(actualBuffer)
) as InstanceType<typeof CustomJimp> & ExtraMethodMap;

attemptExifRotate(image, actualBuffer);
Expand Down Expand Up @@ -386,6 +386,7 @@ export function createJimp<
let outputImage: Jimp;

if (format.hasAlpha) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
outputImage = this;
} else {
outputImage = new CustomJimp({
Expand Down Expand Up @@ -456,7 +457,7 @@ export function createJimp<
const mimeType = mime.getType(path);
await writeFile(
path,
await this.getBuffer(mimeType as SupportedMimeTypes, options),
await this.getBuffer(mimeType as SupportedMimeTypes, options)
);
}

Expand Down Expand Up @@ -657,7 +658,7 @@ export function createJimp<
mode?: BlendMode;
opacitySource?: number;
opacityDest?: number;
} = {},
} = {}
) {
return composite(this, src, x, y, options);
}
Expand Down Expand Up @@ -687,14 +688,14 @@ export function createJimp<
y: number,
w: number,
h: number,
cb: (x: number, y: number, idx: number) => any,
cb: (x: number, y: number, idx: number) => any
): this;
scan(
x: number | ((x: number, y: number, idx: number) => any),
y?: number,
w?: number,
h?: number,
f?: (x: number, y: number, idx: number) => any,
f?: (x: number, y: number, idx: number) => any
): this {
return scan(this, x as any, y as any, w as any, h as any, f as any);
}
Expand Down
14 changes: 5 additions & 9 deletions packages/core/src/utils/composite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Edge, JimpClass } from "@jimp/types";

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

export function composite<I extends JimpClass>(
baseImage: I,
Expand All @@ -13,7 +13,7 @@ export function composite<I extends JimpClass>(
mode?: BlendMode;
opacitySource?: number;
opacityDest?: number;
} = {},
} = {}
) {
if (!(src instanceof baseImage.constructor)) {
throw new Error("The source must be a Jimp image");
Expand All @@ -23,11 +23,8 @@ export function composite<I extends JimpClass>(
throw new Error("x and y must be numbers");
}

let {
mode = BlendMode.SRC_OVER,
opacitySource = 1.0,
opacityDest = 1.0,
} = options;
const { mode = BlendMode.SRC_OVER } = options;
let { opacitySource = 1.0, opacityDest = 1.0 } = options;

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

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

// round input
Expand Down Expand Up @@ -76,7 +72,7 @@ export function composite<I extends JimpClass>(
b: baseImage.bitmap.data[dstIdx + 2]! / 255,
a: baseImage.bitmap.data[dstIdx + 3]! / 255,
},
opacitySource,
opacitySource
);

baseImage.bitmap.data[dstIdx + 0] = limit255(blended.r * 255);
Expand Down
14 changes: 4 additions & 10 deletions packages/core/src/utils/image-bitmap.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import EXIFParser, { ExifData } from "exif-parser";
import { JimpClass } from "@jimp/types";

const EXIF_TAGS = {
ORIENTATION: 0x0112, // decimal: 274
IMAGE_WIDTH: 0x0100, // decimal: 256
IMAGE_HEIGHT: 0x0101, // decimal: 257
};

/**
* Obtains image orientation from EXIF metadata.
*
Expand Down Expand Up @@ -95,7 +89,7 @@ function transformBitmap<I extends JimpClass>(
img: I,
width: number,
height: number,
transformation: (x: number, y: number) => readonly [number, number],
transformation: (x: number, y: number) => readonly [number, number]
) {
// Underscore-prefixed values are related to the source bitmap
// Their counterparts with no prefix are related to the target bitmap
Expand All @@ -120,7 +114,7 @@ function transformBitmap<I extends JimpClass>(
img.bitmap.width = width;
img.bitmap.height = height;

// @ts-ignore
// @ts-expect-error Accessing private property
img._exif.tags.Orientation = 1;
}

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

export async function attemptExifRotate<I extends JimpClass>(
image: I,
buffer: Buffer,
buffer: Buffer
) {
try {
(image as unknown as { _exif: ExifData })._exif =
EXIFParser.create(buffer).parse();

exifRotate(image); // EXIF data
} catch (error) {
/* meh */
console.error(error);
}
}
5 changes: 0 additions & 5 deletions packages/diff/.eslintrc.cjs

This file was deleted.

2 changes: 2 additions & 0 deletions packages/diff/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import shared from "@jimp/config-eslint/base.js";
export default [...shared];
2 changes: 1 addition & 1 deletion packages/diff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@jimp/core": "workspace:*",
"@jimp/test-utils": "workspace:*",
"@types/pixelmatch": "^5.2.6",
"eslint": "^8.57.0",
"eslint": "^9.9.1",
"tshy": "^3.0.2",
"typescript": "^5.5.4",
"vitest": "^2.0.5"
Expand Down
3 changes: 2 additions & 1 deletion packages/diff/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function diff<I extends JimpClass>(img1: I, img2: I, threshold = 0.1) {
throw new Error("threshold must be a number between 0 and 1");
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const diff = new (img1 as any).constructor({
width: bmp1.width,
height: bmp1.height,
Expand All @@ -60,7 +61,7 @@ export function diff<I extends JimpClass>(img1: I, img2: I, threshold = 0.1) {
diff.bitmap.data,
diff.bitmap.width,
diff.bitmap.height,
{ threshold },
{ threshold }
);

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@jimp/plugin-print": "workspace:*",
"@types/react": "^18.3.5",
"astro": "^4.15.1",
"eslint": "^8.57.0",
"eslint": "^9.9.1",
"jimp": "workspace:*",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
5 changes: 0 additions & 5 deletions packages/file-ops/.eslintrc.cjs

This file was deleted.

2 changes: 2 additions & 0 deletions packages/file-ops/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import shared from "@jimp/config-eslint/base.js";
export default [...shared];
2 changes: 1 addition & 1 deletion packages/file-ops/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@jimp/config-eslint": "workspace:*",
"@jimp/config-typescript": "workspace:*",
"@types/node": "^18.19.48",
"eslint": "^8.57.0",
"eslint": "^9.9.1",
"tshy": "^3.0.2",
"typescript": "^5.5.4",
"vitest": "^2.0.5"
Expand Down
5 changes: 0 additions & 5 deletions packages/jimp/.eslintrc.cjs

This file was deleted.

Loading

0 comments on commit 2e3071e

Please sign in to comment.