Skip to content

Commit

Permalink
feat: reconfigure typescript linter / formatter for nodejs (#1042)
Browse files Browse the repository at this point in the history
The eslint rules specify some formatting requirements that are rather
strict and conflict with vscode's default formatter. I was unable to get
auto-formatting to setup correctly. Also, eslint has quite recently
[given up on
formatting](https://eslint.org/blog/2023/10/deprecating-formatting-rules/)
and recommends using a 3rd party formatter.

This PR adds prettier as the formatter. It restores the eslint rules to
their defaults. This does mean we now have the "no explicit any" check
back on. I know that rule is pedantic but it did help me catch a few
corner cases in type testing that weren't covered in the current code.
Leaving in draft as this is dependent on other PRs.
  • Loading branch information
westonpace committed Apr 5, 2024
1 parent 8033a44 commit 785ecfa
Show file tree
Hide file tree
Showing 28 changed files with 1,072 additions and 715 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,6 @@ env:
RUST_BACKTRACE: "1"

jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
working-directory: node
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
- uses: actions/setup-node@v3
with:
node-version: 20
cache: 'npm'
cache-dependency-path: node/package-lock.json
- name: Lint
run: |
npm ci
npm run lint
linux:
name: Linux (Node ${{ matrix.node-version }})
timeout-minutes: 30
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ env:

jobs:
lint:
if: false
name: Lint
runs-on: ubuntu-22.04
defaults:
Expand Down Expand Up @@ -50,6 +49,7 @@ jobs:
cargo clippy --all --all-features -- -D warnings
npm ci
npm run lint
npm run chkformat
linux:
name: Linux (NodeJS ${{ matrix.node-version }})
timeout-minutes: 30
Expand Down
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ repos:
rev: v0.2.2
hooks:
- id: ruff
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
files: "nodejs/.*"
3 changes: 3 additions & 0 deletions nodejs/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/dist/**/*
**/native.js
**/native.d.ts
22 changes: 0 additions & 22 deletions nodejs/.eslintrc.js

This file was deleted.

1 change: 1 addition & 0 deletions nodejs/.prettierignore
29 changes: 27 additions & 2 deletions nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,42 @@

It will replace the NodeJS SDK when it is ready.


## Development

```sh
npm run build
npm t
```

Generating docs
### 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:

```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:

```sh
npm run chkformat
```

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

```sh
npx prettier --write .
```

### Generating docs

```sh
npm run docs

cd ../docs
Expand Down

0 comments on commit 785ecfa

Please sign in to comment.