Skip to content

Commit

Permalink
refactor(nodejs): use biomejs instead of eslint & prettier (lancedb#1304
Browse files Browse the repository at this point in the history
)

I've been noticing a lot of friction with the current toolchain for
'/nodejs'. Particularly with the usage of eslint and prettier.

[Biome](https://biomejs.dev/) is an all in one formatter & linter that
replaces the need for two different ones that can potentially clash with
one another.

I've been using it in the
[nodejs-polars](https://github.com/pola-rs/nodejs-polars) repo for quite
some time & have found it much more pleasant to work with.

---

One other small change included in this PR:

use [ts-jest](https://www.npmjs.com/package/ts-jest) so we can run our
tests without having to rebuild typescript code first
  • Loading branch information
universalmind303 authored May 14, 2024
1 parent bc582bb commit 055efdc
Show file tree
Hide file tree
Showing 24 changed files with 8,195 additions and 7,974 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ jobs:
cargo fmt --all -- --check
cargo clippy --all --all-features -- -D warnings
npm ci
npm run lint
npm run chkformat
npm run lint-ci
linux:
name: Linux (NodeJS ${{ matrix.node-version }})
timeout-minutes: 30
Expand Down
9 changes: 6 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ repos:
rev: v0.2.2
hooks:
- id: ruff
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
- repo: local
hooks:
- id: prettier
- id: local-biome-check
name: biome check
entry: npx biome check
language: system
types: [text]
files: "nodejs/.*"
exclude: nodejs/lancedb/native.d.ts|nodejs/dist/.*
3 changes: 0 additions & 3 deletions nodejs/.eslintignore

This file was deleted.

1 change: 0 additions & 1 deletion nodejs/.prettierignore

This file was deleted.

19 changes: 5 additions & 14 deletions nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,20 @@ npm run test

### Running lint / format

LanceDb uses eslint for linting. VSCode does not need any plugins to use eslint. However, it
may need some additional configuration. Make sure that eslint.experimental.useFlatConfig is
set to true. Also, if your vscode root folder is the repo root then you will need to set
the eslint.workingDirectories to ["nodejs"]. To manually lint your code you can run:
LanceDb uses [biome](https://biomejs.dev/) for linting and formatting. if you are using VSCode you will need to install the official [Biome](https://marketplace.visualstudio.com/items?itemName=biomejs.biome) extension.
To manually lint your code you can run:

```sh
npm run lint
```

LanceDb uses prettier for formatting. If you are using VSCode you will need to install the
"Prettier - Code formatter" extension. You should then configure it to be the default formatter
for typescript and you should enable format on save. To manually check your code's format you
can run:
to automatically fix all fixable issues:

```sh
npm run chkformat
npm run lint-fix
```

If you need to manually format your code you can run:

```sh
npx prettier --write .
```
If you do not have your workspace root set to the `nodejs` directory, unfortunately the extension will not work. You can still run the linting and formatting commands manually.

### Generating docs

Expand Down
44 changes: 22 additions & 22 deletions nodejs/__test__/arrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,47 @@
// limitations under the License.

import {
convertToTable,
fromTableToBuffer,
makeArrowTable,
makeEmptyTable,
} from "../dist/arrow";
import {
Binary,
Bool,
DataType,
Dictionary,
Field,
FixedSizeList,
Float,
Float16,
Float32,
Float64,
Int32,
tableFromIPC,
Int64,
List,
MetadataVersion,
Precision,
Schema,
Float64,
Struct,
type Table,
Binary,
Bool,
Utf8,
Struct,
List,
DataType,
Dictionary,
Int64,
Float,
Precision,
MetadataVersion,
tableFromIPC,
} from "apache-arrow";
import {
Dictionary as OldDictionary,
Field as OldField,
FixedSizeList as OldFixedSizeList,
Float32 as OldFloat32,
Int32 as OldInt32,
Struct as OldStruct,
Schema as OldSchema,
Struct as OldStruct,
TimestampNanosecond as OldTimestampNanosecond,
Utf8 as OldUtf8,
} from "apache-arrow-old";
import { type EmbeddingFunction } from "../dist/embedding/embedding_function";
import {
convertToTable,
fromTableToBuffer,
makeArrowTable,
makeEmptyTable,
} from "../lancedb/arrow";
import { type EmbeddingFunction } from "../lancedb/embedding/embedding_function";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: skip
function sampleRecords(): Array<Record<string, any>> {
return [
{
Expand Down Expand Up @@ -438,7 +438,7 @@ describe("when using two versions of arrow", function () {
new OldField("ts_no_tz", new OldTimestampNanosecond(null)),
]),
),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: skip
]) as any;
schema.metadataVersion = MetadataVersion.V5;
const table = makeArrowTable([], { schema });
Expand Down
6 changes: 4 additions & 2 deletions nodejs/__test__/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

import * as tmp from "tmp";

import { Connection, connect } from "../dist/index.js";
import { Connection, connect } from "../lancedb";

describe("when connecting", () => {
let tmpDir: tmp.DirResult;
beforeEach(() => (tmpDir = tmp.dirSync({ unsafeCleanup: true })));
beforeEach(() => {
tmpDir = tmp.dirSync({ unsafeCleanup: true });
});
afterEach(() => tmpDir.removeCallback());

it("should connect", async () => {
Expand Down
21 changes: 14 additions & 7 deletions nodejs/__test__/s3_integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

/* eslint-disable @typescript-eslint/naming-convention */

import { connect } from "../dist";
import {
CreateKeyCommand,
KMSClient,
ScheduleKeyDeletionCommand,
} from "@aws-sdk/client-kms";
import {
CreateBucketCommand,
DeleteBucketCommand,
Expand All @@ -23,11 +27,7 @@ import {
ListObjectsV2Command,
S3Client,
} from "@aws-sdk/client-s3";
import {
CreateKeyCommand,
ScheduleKeyDeletionCommand,
KMSClient,
} from "@aws-sdk/client-kms";
import { connect } from "../lancedb";

// Skip these tests unless the S3_TEST environment variable is set
const maybeDescribe = process.env.S3_TEST ? describe : describe.skip;
Expand Down Expand Up @@ -63,9 +63,10 @@ class S3Bucket {
// Delete the bucket if it already exists
try {
await this.deleteBucket(client, name);
} catch (e) {
} catch {
// It's fine if the bucket doesn't exist
}
// biome-ignore lint/style/useNamingConvention: we dont control s3's api
await client.send(new CreateBucketCommand({ Bucket: name }));
return new S3Bucket(name);
}
Expand All @@ -78,27 +79,32 @@ class S3Bucket {
static async deleteBucket(client: S3Client, name: string) {
// Must delete all objects before we can delete the bucket
const objects = await client.send(
// biome-ignore lint/style/useNamingConvention: we dont control s3's api
new ListObjectsV2Command({ Bucket: name }),
);
if (objects.Contents) {
for (const object of objects.Contents) {
await client.send(
// biome-ignore lint/style/useNamingConvention: we dont control s3's api
new DeleteObjectCommand({ Bucket: name, Key: object.Key }),
);
}
}

// biome-ignore lint/style/useNamingConvention: we dont control s3's api
await client.send(new DeleteBucketCommand({ Bucket: name }));
}

public async assertAllEncrypted(path: string, keyId: string) {
const client = S3Bucket.s3Client();
const objects = await client.send(
// biome-ignore lint/style/useNamingConvention: we dont control s3's api
new ListObjectsV2Command({ Bucket: this.name, Prefix: path }),
);
if (objects.Contents) {
for (const object of objects.Contents) {
const metadata = await client.send(
// biome-ignore lint/style/useNamingConvention: we dont control s3's api
new HeadObjectCommand({ Bucket: this.name, Key: object.Key }),
);
expect(metadata.ServerSideEncryption).toBe("aws:kms");
Expand Down Expand Up @@ -137,6 +143,7 @@ class KmsKey {

public async delete() {
const client = KmsKey.kmsClient();
// biome-ignore lint/style/useNamingConvention: we dont control s3's api
await client.send(new ScheduleKeyDeletionCommand({ KeyId: this.keyId }));
}
}
Expand Down
12 changes: 6 additions & 6 deletions nodejs/__test__/table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ import * as fs from "fs";
import * as path from "path";
import * as tmp from "tmp";

import { Table, connect } from "../dist";
import {
Schema,
Field,
FixedSizeList,
Float32,
Float64,
Int32,
FixedSizeList,
Int64,
Float64,
Schema,
} from "apache-arrow";
import { makeArrowTable } from "../dist/arrow";
import { Index } from "../dist/indices";
import { Table, connect } from "../lancedb";
import { makeArrowTable } from "../lancedb/arrow";
import { Index } from "../lancedb/indices";

describe("Given a table", () => {
let tmpDir: tmp.DirResult;
Expand Down
Loading

0 comments on commit 055efdc

Please sign in to comment.