Skip to content

Commit f303676

Browse files
committed
Wire oxfmt formatting checks
1 parent cf29f17 commit f303676

8 files changed

Lines changed: 54 additions & 38 deletions

File tree

.github/workflows/lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@ jobs:
3232
- name: Install Modules
3333
run: npm ci
3434

35+
- name: Run Format Check
36+
run: npm run format:ci
37+
3538
- name: Run Lint
3639
run: npm run lint:all

oxfmt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from '@node-3d/addon-tools/oxfmt';

oxlint.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import sharedConfig from '@node-3d/addon-tools/oxlint';
2-
3-
export default sharedConfig;
1+
export { default } from '@node-3d/addon-tools/oxlint';

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
"build:ci": "rslib build",
3636
"build:watch": "rslib build --watch",
3737
"lint:ts": "tsgo -p tsconfig.json --noEmit",
38-
"prepare": "npm run build:ci"
38+
"prepare": "npm run build:ci",
39+
"format:ts": "oxfmt -c ./oxfmt.config.ts --no-error-on-unmatched-pattern \"**/*.{js,jsx,ts,tsx}\"",
40+
"format:ci": "oxfmt -c ./oxfmt.config.ts --check --no-error-on-unmatched-pattern \"**/*.{js,jsx,ts,tsx}\""
3941
},
4042
"repository": {
4143
"type": "git",

ts/bmp.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,52 @@ export const createBmpFromPixels = (
1919
const bmpSize = HEADER_SIZE + memSize;
2020
const fakeBmp = Buffer.allocUnsafeSlow(bmpSize);
2121
let pos = 0;
22-
22+
2323
fakeBmp.write('BM', pos, 2, 'ascii');
2424
pos += 2;
25-
25+
2626
fakeBmp.writeUInt32LE(bmpSize, pos);
2727
pos += 4;
28-
28+
2929
pos += 4;
30-
30+
3131
fakeBmp.writeUInt32LE(HEADER_SIZE, pos);
3232
pos += 4;
33-
33+
3434
fakeBmp.writeUInt32LE(DIB_SIZE, pos);
3535
pos += 4;
36-
36+
3737
fakeBmp.writeInt32LE(width, pos);
3838
pos += 4;
39-
39+
4040
fakeBmp.writeInt32LE(height, pos);
4141
pos += 4;
42-
42+
4343
fakeBmp.writeUInt16LE(1, pos);
4444
pos += 2;
45-
45+
4646
fakeBmp.writeUInt16LE(bpp, pos);
4747
pos += 2;
48-
48+
4949
fakeBmp.writeUInt32LE(0, pos);
5050
pos += 4;
51-
51+
5252
fakeBmp.writeUInt32LE(memSize, pos);
5353
pos += 4;
54-
54+
5555
fakeBmp.writeUInt32LE(SOME_BYTES, pos);
5656
pos += 4;
57-
57+
5858
fakeBmp.writeUInt32LE(SOME_BYTES, pos);
5959
pos += 4;
60-
60+
6161
fakeBmp.writeUInt32LE(0, pos);
6262
pos += 4;
63-
63+
6464
fakeBmp.writeUInt32LE(0, pos);
6565
pos += 4;
66-
66+
6767
pixels.copy(fakeBmp, pos);
68-
68+
6969
return fakeBmp;
7070
};

ts/image.test.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ const props = [
2424

2525
const methods = ['on', 'save', 'drawImage'] as const;
2626

27-
const testDataPath = (name: string): string => (
28-
path.resolve(import.meta.dirname, '..', 'examples', 'assets', name)
29-
);
27+
const testDataPath = (name: string): string =>
28+
path.resolve(import.meta.dirname, '..', 'examples', 'assets', name);
3029

3130
const loadImageAsync = async (name: string): Promise<Image> => {
3231
const image = new Image();
@@ -90,7 +89,9 @@ describe('Image', () => {
9089
const image = new Image();
9190

9291
const that = await new Promise((res, rej) => {
93-
image.addEventListener('load', function onLoad(this: Image) { res(this); });
92+
image.addEventListener('load', function onLoad(this: Image) {
93+
res(this);
94+
});
9495
image.addEventListener('error', rej);
9596
image.src = testDataPath('freeimage.jpg');
9697
});
@@ -102,7 +103,9 @@ describe('Image', () => {
102103
const image = await loadImageAsync('freeimage.jpg');
103104

104105
const that = await new Promise((res, rej) => {
105-
image.addEventListener('load', function onLoad(this: Image) { res(this); });
106+
image.addEventListener('load', function onLoad(this: Image) {
107+
res(this);
108+
});
106109
image.addEventListener('error', rej);
107110
});
108111

@@ -113,7 +116,9 @@ describe('Image', () => {
113116
const image = new Image();
114117

115118
const that = await new Promise((res, rej) => {
116-
image.on('load', function onLoad(this: Image) { res(this); });
119+
image.on('load', function onLoad(this: Image) {
120+
res(this);
121+
});
117122
image.on('error', rej);
118123
image.src = testDataPath('freeimage.jpg');
119124
});
@@ -125,7 +130,9 @@ describe('Image', () => {
125130
const image = await loadImageAsync('freeimage.jpg');
126131

127132
const that = await new Promise((res, rej) => {
128-
image.on('load', function onLoad(this: Image) { res(this); });
133+
image.on('load', function onLoad(this: Image) {
134+
res(this);
135+
});
129136
image.on('error', rej);
130137
});
131138

@@ -136,7 +143,9 @@ describe('Image', () => {
136143
const image = new Image();
137144

138145
const that = await new Promise((res, rej) => {
139-
image.once('load', function onLoad(this: Image) { res(this); });
146+
image.once('load', function onLoad(this: Image) {
147+
res(this);
148+
});
140149
image.once('error', rej);
141150
image.src = testDataPath('freeimage.jpg');
142151
});
@@ -148,7 +157,9 @@ describe('Image', () => {
148157
const image = await loadImageAsync('freeimage.jpg');
149158

150159
const that = await new Promise((res, rej) => {
151-
image.once('load', function onLoad(this: Image) { res(this); });
160+
image.once('load', function onLoad(this: Image) {
161+
res(this);
162+
});
152163
image.once('error', rej);
153164
});
154165

ts/image.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ export class Image extends NativeImage {
5656
}
5757

5858
/** Has the underlying native image object been destroyed? */
59-
public declare readonly isDestroyed: boolean;
59+
declare public readonly isDestroyed: boolean;
6060

6161
/** Image width in pixels, or `0` before an image is loaded. */
62-
public declare readonly width: number;
62+
declare public readonly width: number;
6363

6464
/** Image height in pixels, or `0` before an image is loaded. */
65-
public declare readonly height: number;
65+
declare public readonly height: number;
6666

6767
/** Is the image fully loaded? */
6868
public get complete(): boolean {
@@ -143,14 +143,14 @@ export class Image extends NativeImage {
143143
}
144144

145145
/** Save the image to a file. Returns `false` if there is no image to save. */
146-
public declare save: (dest: string) => boolean;
146+
declare public save: (dest: string) => boolean;
147147

148148
/**
149149
* Draw another image onto this one.
150150
*
151151
* The overloads follow the browser canvas `drawImage()` argument forms.
152152
*/
153-
public declare drawImage: {
153+
declare public drawImage: {
154154
(image: Image, dx: number, dy: number): void;
155155
(image: Image, dx: number, dy: number, dWidth: number, dHeight: number): void;
156156
(
@@ -336,9 +336,9 @@ export class Image extends NativeImage {
336336
// Decode data URI payloads before handing bytes to the native decoder.
337337
private loadDataUri(src: string): void {
338338
const [head = '', body = ''] = src.split(',', 2);
339-
const data = head.includes('base64') ?
340-
Buffer.from(body, 'base64') :
341-
Buffer.from(decodeURIComponent(body));
339+
const data = head.includes('base64')
340+
? Buffer.from(body, 'base64')
341+
: Buffer.from(decodeURIComponent(body));
342342

343343
this._load(data);
344344
}

ts/native.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// oxlint-disable typescript/method-signature-style
12
import { createRequire } from 'node:module';
23
import { getBin } from '@node-3d/addon-tools';
34
import '@node-3d/segfault';

0 commit comments

Comments
 (0)