Skip to content

Commit

Permalink
Refactor to use biome over ESLint and prettier (#1304)
Browse files Browse the repository at this point in the history
* refactor: use biome formatting and check fix

* refactor: remove eslint disabled rules

* refactor: apply unsafe rules

* refactor: refactor to comply with biome rules

* fix: make biome default formatter

* refactor: last biome fixes

* test: adjust assertion

* test: adjust more tests to not skip them

* refactor: use codecov action

* fix: remove matrix

* chore: fix lockfile

* Create famous-hotels-accept.md
  • Loading branch information
tdeekens authored Nov 27, 2024
1 parent e5900d6 commit 4ad33f6
Show file tree
Hide file tree
Showing 54 changed files with 492 additions and 1,426 deletions.
8 changes: 8 additions & 0 deletions .changeset/famous-hotels-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@promster/apollo": patch
"@promster/express": patch
"@promster/fastify": patch
"@promster/hapi": patch
---

Refactor to use biome over ESLint and prettier
6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

56 changes: 0 additions & 56 deletions .eslintrc.cjs

This file was deleted.

21 changes: 9 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ jobs:
install:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x, 22.x]

steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -26,27 +22,28 @@ jobs:
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
node-version-file: '.nvmrc'
cache: pnpm

- name: Install
run: pnpm install

- name: Lint
run: pnpm lint
run: pnpm biome check

- name: Spell check
uses: streetsidesoftware/cspell-action@main
with:
files: '**/*.{md,ts}'
files: "**/*.{md,ts}"

- name: Build
run: pnpm build

- name: Test
if: startsWith(matrix.node-version , '22')
run: pnpm test:ci

- name: Test (with coverage)
if: startsWith(matrix.node-version, '20')
run: pnpm test:ci:coverage

- uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
5 changes: 0 additions & 5 deletions .jestrc.lint.json

This file was deleted.

2 changes: 1 addition & 1 deletion .mise.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[tools]
node = "22.8"
node = "22"
4 changes: 0 additions & 4 deletions .prettierignore

This file was deleted.

4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

20 changes: 15 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"workbench.colorCustomizations": {
"tab.unfocusedActiveBorder": "#fff0"
},
"gitdoc.enabled": false
}
"workbench.colorCustomizations": {
"tab.unfocusedActiveBorder": "#fff0"
},
"gitdoc.enabled": false,
"editor.defaultFormatter": "biomejs.biome",
"editor.codeActionsOnSave": {
"quickfix.biome": "explicit"
},
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
92 changes: 92 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"vcs": {
"clientKind": "git",
"enabled": true,
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": true
},
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 80,
"ignore": [
"**/package.json",
"**/dist/**",
"**/.changeset",
"**/CHANGELOG.md",
"**/pnpm-lock.yaml",
"**/pnpm-workspace.yaml"
]
},
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"performance": {
"noAccumulatingSpread": "off"
},
"complexity": {
"noVoid": "error"
},
"correctness": {
"noUndeclaredVariables": "error",
"noUnreachableSuper": "error",
"noUnusedVariables": "error",
"useArrayLiterals": "error",
"useExhaustiveDependencies": "warn"
},
"style": {
"noNegationElse": "error",
"noRestrictedGlobals": {
"level": "error",
"options": { "deniedGlobals": ["event", "atob", "btoa"] }
},
"useBlockStatements": "error",
"useCollapsedElseIf": "error",
"useConsistentArrayType": {
"level": "error",
"options": { "syntax": "shorthand" }
},
"useForOf": "error",
"useFragmentSyntax": "error",
"useShorthandAssign": "error"
},
"suspicious": {
"noEmptyBlockStatements": "error",
"noSkippedTests": "warn",
"noExplicitAny": "off"
}
},
"ignore": ["**/node_modules/", "**/coverage/", "**/dist/"]
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "es5",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSpacing": true,
"quoteStyle": "single"
},
"globals": [
"it",
"describe",
"expect",
"jest",
"before",
"beforeAll",
"beforeEach",
"after",
"afterAll",
"afterEach"
]
}
}
1 change: 0 additions & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
module.exports = {
extends: ['@commitlint/config-conventional'],
parserPreset: {
Expand Down
2 changes: 1 addition & 1 deletion demo/apollo.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function launchServer() {
await server.listen().then(({ url }) => {
console.log(`🚀 Apollo Server ready at ${url}`);

console.log(`Prometheus metrics available on http://localhost:8080`);
console.log('Prometheus metrics available on http://localhost:8080');

signalIsUp();
});
Expand Down
4 changes: 2 additions & 2 deletions demo/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function launchServer() {
detectKubernetes: false,
});

app.get('/', (req, res) => {
app.get('/', (_req, res) => {
res.send('I am the server!');
});

Expand All @@ -25,7 +25,7 @@ async function launchServer() {
signalIsUp();
});

console.log(`Prometheus metrics available on http://localhost:8080`);
console.log('Prometheus metrics available on http://localhost:8080');
}

launchServer().catch(console.log);
5 changes: 0 additions & 5 deletions jest-runner-eslint.config.js

This file was deleted.

5 changes: 3 additions & 2 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
'packages/**/*.{ts,js}': ['npm run fix:eslint', 'npm run format:js'],
'*.md': ['npm run format:md'],
'*': [
'biome check', // Format, sort imports, lint, and apply safe fixes
],
};
30 changes: 8 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
"auth": "npm_config_registry=https://registry.npmjs.org npm whoami",
"build:watch": "preconstruct watch",
"build": "preconstruct build",
"changeset:version-and-format": "changeset version && prettier --write --parser json '**/package.json' && pnpm install --no-frozen-lockfile",
"changeset:version-and-format": "changeset version && pnpm format '**/package.json' && pnpm install --no-frozen-lockfile",
"changeset": "changeset",
"clean": "manypkg exec rm -rf build dist tsconfig.tsbuildinfo ts-build-cache",
"develop": "jest --projects .jestrc.*.json --watch",
"fix:eslint": "eslint --fix --format=node_modules/eslint-formatter-pretty",
"format:js": "prettier --write '**/packages/**/*.{js,ts}'",
"format:md": "prettier --parser markdown --write '*.md'",
"format:yaml": "prettier --parser yaml --write '*.yaml'",
"format": "npm run format:md && npm run format:js && npm run format:yaml",
"lint": "jest --config .jestrc.lint.json",
"develop": "jest --projects .jestrc.test.json --watch",
"biome:check": "biome check --write",
"biome:fix": "biome lint --write",
"format": "biome format --write",
"lint": "biome lint",
"prerelease": "cross-env NODE_ENV=production pnpm auth && pnpm build",
"release": "changeset publish",
"setup": "husky install && preconstruct dev && manypkg check && check-node-version --package --print",
"test:ci:coverage": "cross-env NODE_ENV=test npm test -- --no-watchman --coverage && codecov",
"test:ci:coverage": "cross-env NODE_ENV=test npm test -- --no-watchman --coverage",
"test:ci": "cross-env NODE_ENV=test npm test -- --no-watchman",
"test:coverage": "cross-env NODE_ENV=test npm test -- --coverage",
"test:watch": "cross-env NODE_ENV=test npm test -- --watch",
Expand Down Expand Up @@ -51,9 +49,9 @@
"packageManager": "pnpm@9.12.2",
"dependencies": {
"@babel/core": "7.25.2",
"@babel/eslint-parser": "7.25.1",
"@babel/preset-env": "7.25.4",
"@babel/preset-typescript": "7.24.7",
"@biomejs/biome": "1.9.4",
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.8",
"@commitlint/cli": "19.5.0",
Expand All @@ -63,24 +61,12 @@
"@tsconfig/node18": "18.2.4",
"@types/node": "20.16.13",
"@types/semver": "7.5.8",
"@typescript-eslint/eslint-plugin": "7.7.1",
"@typescript-eslint/parser": "7.7.1",
"check-node-version": "4.2.1",
"codecov": "3.8.3",
"cross-env": "7.0.3",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-config-xo": "0.44.0",
"eslint-config-xo-typescript": "4.0.0",
"eslint-formatter-pretty": "5.0.0",
"eslint-plugin-jest": "28.3.0",
"eslint-plugin-prettier": "5.1.3",
"husky": "9.0.11",
"jest": "29.7.0",
"jest-runner-eslint": "2.2.0",
"jest-watch-typeahead": "2.2.2",
"lint-staged": "15.2.10",
"prettier": "3.2.5",
"rimraf": "5.0.10",
"ts-jest": "29.1.5",
"typescript": "5.6.2"
Expand Down
18 changes: 9 additions & 9 deletions packages/apollo/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {
type TPromsterOptions,
createPlugin,
signalIsUp,
signalIsNotUp,
} from './plugin';
import {
getSummary,
getContentType,
Prometheus,
defaultRegister,
defaultNormalizers,
defaultRegister,
getContentType,
getSummary,
timing,
} from '@promster/metrics';
import {
type TPromsterOptions,
createPlugin,
signalIsNotUp,
signalIsUp,
} from './plugin';

export {
type TPromsterOptions,
Expand Down
Loading

0 comments on commit 4ad33f6

Please sign in to comment.