Skip to content

Commit

Permalink
Modernize linting and formatting stack
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyluiz committed Dec 12, 2024
1 parent de7668b commit b41b880
Show file tree
Hide file tree
Showing 13 changed files with 1,098 additions and 113 deletions.
13 changes: 0 additions & 13 deletions .eslintignore

This file was deleted.

33 changes: 0 additions & 33 deletions .eslintrc.json

This file was deleted.

26 changes: 6 additions & 20 deletions .github/workflows/push-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ name: Push Checks
on: [push, pull_request]

jobs:
test-ubuntu:
lint-and-format:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 15.x, 14.x]
node-version: [20.x, 18.x]

steps:
- uses: actions/checkout@v1
Expand All @@ -18,25 +18,11 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: npm install & test
run: |
npm ci
npm test
corepack enable
yarn install
yarn lint
yarn ts:check
env:
CI: true
- name: Codecov Action
uses: codecov/codecov-action@v1

lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: npm lint:check
run: |
npm ci
npm run lint:check
env:
CI: true
13 changes: 0 additions & 13 deletions .prettierignore

This file was deleted.

46 changes: 46 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import js from "@eslint/js";
import typescript from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import prettier from "eslint-config-prettier";

export default [
js.configs.recommended,
{
files: ["**/*.ts", "**/*.tsx"],
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
project: "./tsconfig.json",
},
globals: {
console: true,
Buffer: true,
setTimeout: true,
},
},
plugins: {
"@typescript-eslint": typescript,
},
rules: {
...typescript.configs.recommended.rules,
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^_" },
],
},
},
{
ignores: [
"node_modules/**",
"dist/**",
"coverage/**",
"*.js",
"*.cjs",
"*.mjs",
],
},
prettier,
];
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"typings": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"lint": "tslint -p tsconfig.json",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write .",
"ts:check": "tsc --noEmit",
"prepublishOnly": "yarn build",
"benchmark": "yarn build && yarn node dist/benchmark/index.js",
"benchmark:ws:server": "yarn build && yarn node dist/benchmark/ws/simple/server.js",
Expand All @@ -18,11 +21,17 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@eslint/js": "latest",
"@faker-js/faker": "^9.2.0",
"@types/node": "^22.9.0",
"@types/ws": "^8",
"@typescript-eslint/eslint-plugin": "latest",
"@typescript-eslint/parser": "latest",
"cbor-x": "^1.6.0",
"eslint": "latest",
"eslint-config-prettier": "latest",
"msgpackr": "^1.11.2",
"prettier": "^3.4.2",
"sializer": "0",
"tinybench": "^3.0.6",
"ts-proto": "^2.4.2",
Expand Down
6 changes: 3 additions & 3 deletions src/ascii.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const asciiToUint8Array = (
str: string,
strLength: number,
buffer: Uint8Array,
offset: number
offset: number,
) => {
for (let i = 0; i < strLength; i++) {
buffer[offset + i] = str.charCodeAt(i);
Expand All @@ -19,14 +19,14 @@ const fns = new Array(66).fill(0).map((_, i) => {
"buf",
"length",
"offset",
`return String.fromCharCode(${codes});`
`return String.fromCharCode(${codes});`,
);
});

export const uint8ArrayToAscii = (
buffer: Uint8Array,
byteLength: number,
offset: number
offset: number,
) => {
return fns[byteLength](buffer, byteLength, offset);
};
78 changes: 60 additions & 18 deletions src/benchmark/tests/generated/user.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/benchmark/tests/sia.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { fiveThousandUsers } from "./common.js";
import { Sia } from "../../index.js";
import assert from "assert";
import { fiveThousandUsers } from "./common.js";

const sia = new Sia();

Expand Down
12 changes: 7 additions & 5 deletions src/benchmark/ws/heavy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const bench = new Bench({ name: "RPC", time: 10 * 1000 });
const makeRpcCall = async (
ws: WebSocket,
ondata: (data: Buffer) => void,
payload: Uint8Array
payload: Uint8Array,
) =>
new Promise((resolve) => {
ws.send(payload, { binary: true });
Expand All @@ -76,29 +76,31 @@ const makeRpcCall = async (
bench
.add(
"JSON",
async () => await makeRpcCall(clients.json, callbacks.json, payloads.json())
async () =>
await makeRpcCall(clients.json, callbacks.json, payloads.json()),
)
.addEventListener("complete", () => clients.json.close());

bench
.add(
"Sia",
async () => await makeRpcCall(clients.sia, callbacks.sia, payloads.sia())
async () => await makeRpcCall(clients.sia, callbacks.sia, payloads.sia()),
)
.addEventListener("complete", () => clients.sia.close());

bench
.add(
"CBOR",
async () => await makeRpcCall(clients.cbor, callbacks.cbor, payloads.cbor())
async () =>
await makeRpcCall(clients.cbor, callbacks.cbor, payloads.cbor()),
)
.addEventListener("complete", () => clients.cbor.close());

bench
.add(
"MsgPack",
async () =>
await makeRpcCall(clients.msgpack, callbacks.msgpack, payloads.msgpack())
await makeRpcCall(clients.msgpack, callbacks.msgpack, payloads.msgpack()),
)
.addEventListener("complete", () => clients.msgpack.close());

Expand Down
Loading

0 comments on commit b41b880

Please sign in to comment.