Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT1] migrate from prettier+eslint to biome #872

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ab16c72
chore(deps-dev): add @biomejs/biome 1.8.0
trivikr Jun 6, 2024
4c3656b
chore: yarn biome init
trivikr Jun 6, 2024
842df05
chore: remove biome default config
trivikr Jun 6, 2024
0b94cf2
chore: yarn biome migrate prettier
trivikr Jun 6, 2024
efed5d1
chore: use default biome formatter config for semicolons
trivikr Jun 6, 2024
e0dce10
chore: use default biome formatter config for quoteStyle
trivikr Jun 6, 2024
18182ac
fix: biome config for formatter.ignore
trivikr Jun 6, 2024
6910ecc
chore: set biome files.maxSize as 5 MB
trivikr Jun 6, 2024
463e826
chore: remove redundant biome formatter settings
trivikr Jun 6, 2024
bfeadc4
chore(deps-dev): remove prettier
trivikr Jun 6, 2024
df3ffdc
chore: use biome in VSCode settings
trivikr Jun 6, 2024
a87beca
chore: yarn biome migrate eslint --write
trivikr Jun 6, 2024
50bc335
chore: biome format package.json
trivikr Jun 6, 2024
eec239e
chore: move biome formatter.ignore to files.ignore
trivikr Jun 6, 2024
662e7d2
chore: update eslint-ignore with biome-ignore
trivikr Jun 6, 2024
f5c5104
chore: remove @typescript-eslint/ban-ts-comment
trivikr Jun 6, 2024
27c77fc
chore: remove eslint no-fallthrough
trivikr Jun 6, 2024
f39f9a8
chore: biome disable lint/style/useImportType
trivikr Jun 6, 2024
8677e6d
chore: biome disable lint/style/useNodejsImportProtocol
trivikr Jun 6, 2024
3d1cef4
chore: biome disable lint/complexity/noForEach
trivikr Jun 6, 2024
d73b789
chore: biome disable lint/complexity/useFlatMap
trivikr Jun 6, 2024
cf9f8d7
chore: biome disable lint/style/noUnusedTemplateLiteral
trivikr Jun 6, 2024
546b9d4
chore: biome disable lint/style/useTemplate
trivikr Jun 6, 2024
7d43937
chore: biome disable lint/complexity/useOptionalChain
trivikr Jun 6, 2024
83f49e2
chore: biome disable lint/performance/noAccumulatingSpread
trivikr Jun 6, 2024
5bc1c19
chore: use arrow fn in getJsCodeshiftParser callback
trivikr Jun 6, 2024
9f45082
chore: biome-ignore in cli
trivikr Jun 6, 2024
68b1c22
chore: reintroduce try-catch for getJsCodeshiftParser
trivikr Jun 6, 2024
2af2991
chore: remove eslint and replace precommit utils
trivikr Jun 6, 2024
5b4559b
chore: npm lint using biome
trivikr Jun 6, 2024
57373df
chore: biome-ignore in scripts
trivikr Jun 6, 2024
4b2d19c
chore: use biome lint in github action
trivikr Jun 6, 2024
c5d112d
chore: add format command in CI
trivikr Jun 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ jobs:
- uses: actions/checkout@v4
- name: corepack
run: corepack enable
- uses: biomejs/setup-biome@v2
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"
- name: install
run: yarn
- name: lint
run: yarn lint
run: biome lint
- name: format
run: biome format
- name: build
run: yarn build
- name: test
Expand Down
1 change: 0 additions & 1 deletion .prettierignore

This file was deleted.

4 changes: 0 additions & 4 deletions .prettierrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": []
"recommendations": ["biomejs.biome"]
}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"source.fixAll.eslint": "explicit"
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": "biomejs.biome",
"editor.rulers": [80, 120],
"editor.tabSize": 2,
"search.exclude": {
Expand Down
135 changes: 135 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.0/schema.json",
"files": {
"maxSize": 5242880,
"ignore": ["**/__fixtures__/**", "package.json"]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"lineWidth": 100
},
"linter": {
"rules": {
"recommended": true,
"complexity": {
"noBannedTypes": "error",
"noExtraBooleanCast": "error",
"noForEach": "off",
"noMultipleSpacesInRegularExpressionLiterals": "error",
"noUselessCatch": "error",
"noUselessTypeConstraint": "error",
"noWith": "error",
"useFlatMap": "off",
"useOptionalChain": "off"
},
"correctness": {
"noConstAssign": "error",
"noConstantCondition": "error",
"noEmptyCharacterClassInRegex": "error",
"noEmptyPattern": "error",
"noGlobalObjectCalls": "error",
"noInnerDeclarations": "error",
"noInvalidConstructorSuper": "error",
"noNewSymbol": "error",
"noNonoctalDecimalEscape": "error",
"noPrecisionLoss": "error",
"noSelfAssign": "error",
"noSetterReturn": "error",
"noSwitchDeclarations": "error",
"noUndeclaredVariables": "error",
"noUnreachable": "error",
"noUnreachableSuper": "error",
"noUnsafeFinally": "error",
"noUnsafeOptionalChaining": "error",
"noUnusedLabels": "error",
"noUnusedVariables": "error",
"useArrayLiterals": "off",
"useIsNan": "error",
"useValidForDirection": "error",
"useYield": "error"
},
"performance": {
"noAccumulatingSpread": "off"
},
"style": {
"noNamespace": "error",
"noNonNullAssertion": "off",
"noUnusedTemplateLiteral": "off",
"useAsConstAssertion": "error",
"useConsistentArrayType": {
"level": "error",
"options": { "syntax": "shorthand" }
},
"useImportType": "off",
"useNodejsImportProtocol": "off",
"useTemplate": "off"
},
"suspicious": {
"noAsyncPromiseExecutor": "error",
"noCatchAssign": "error",
"noClassAssign": "error",
"noCompareNegZero": "error",
"noControlCharactersInRegex": "error",
"noDebugger": "error",
"noDuplicateCase": "error",
"noDuplicateClassMembers": "error",
"noDuplicateObjectKeys": "error",
"noDuplicateParameters": "error",
"noEmptyBlockStatements": "error",
"noExplicitAny": "error",
"noExtraNonNullAssertion": "error",
"noFallthroughSwitchClause": "error",
"noFunctionAssign": "error",
"noGlobalAssign": "error",
"noImportAssign": "error",
"noMisleadingCharacterClass": "error",
"noMisleadingInstantiator": "error",
"noPrototypeBuiltins": "error",
"noRedeclare": "error",
"noShadowRestrictedNames": "error",
"noUnsafeDeclarationMerging": "error",
"noUnsafeNegation": "error",
"useGetterReturn": "error",
"useValidTypeof": "error"
}
},
"ignore": ["**/__fixtures__"]
},
"javascript": { "formatter": { "trailingCommas": "es5" } },
"overrides": [
{
"include": ["*.ts", "*.tsx", "*.mts", "*.cts"],
"linter": {
"rules": {
"correctness": {
"noConstAssign": "off",
"noGlobalObjectCalls": "off",
"noInvalidConstructorSuper": "off",
"noInvalidNewBuiltin": "off",
"noNewSymbol": "off",
"noSetterReturn": "off",
"noUndeclaredVariables": "off",
"noUnreachable": "off",
"noUnreachableSuper": "off"
},
"style": {
"noArguments": "error",
"noVar": "error",
"useConst": "error"
},
"suspicious": {
"noDuplicateClassMembers": "off",
"noDuplicateObjectKeys": "off",
"noDuplicateParameters": "off",
"noFunctionAssign": "off",
"noImportAssign": "off",
"noRedeclare": "off",
"noUnsafeNegation": "off",
"useGetterReturn": "off"
}
}
}
}
]
}
5 changes: 5 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pre-commit:
commands:
check:
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}"
run: yarn biome check --write --no-errors-on-unmatched --files-ignore-unknown=true {staged_files} && git update-index --again
21 changes: 4 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,22 @@
},
"scripts": {
"build": "tsc",
"lint": "eslint 'src/**/*.ts'",
"prepare": "simple-git-hooks",
"lint": "biome lint",
"prepare": "lefthook install",
"release": "yarn build && changeset publish",
"test": "vitest"
},
"dependencies": {
"jscodeshift": "0.15.2"
},
"devDependencies": {
"@biomejs/biome": "1.8.0",
"@changesets/cli": "^2.27.1",
"@tsconfig/node14": "^14.1.0",
"@types/jscodeshift": "^0.11.11",
"@types/node": "^14.18.33",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"aws-sdk": "2.1597.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-sort-export-all": "^1.4.1",
"lint-staged": "^15.2.2",
"prettier": "3.2.5",
"simple-git-hooks": "^2.11.0",
"lefthook": "^1.6.15",
"tsx": "^4.7.1",
"typescript": "~5.4.2",
"vitest": "~1.6.0"
Expand All @@ -64,13 +58,6 @@
"node": ">=14.0.0"
},
"packageManager": "[email protected]",
"lint-staged": {
"*.ts": [
"eslint --fix",
"prettier --write"
],
"*.{json,md}": "prettier --write"
},
"publishConfig": {
"provenance": true
}
Expand Down
1 change: 1 addition & 0 deletions scripts/generateClientTypesMap/getClientTypesMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const getClientTypesMap = async (clientName: string): Promise<Record<stri
});

const updatedClientTypesMap = getClientTypesMapWithKeysRemovedFromValues(clientTypesMap);
// biome-ignore lint/complexity/useLiteralKeys: script
clientTypesMap["ClientConfiguration"] = `${CLIENT_NAMES_MAP[clientName]}ClientConfig`;

return Object.entries(updatedClientTypesMap)
Expand Down
4 changes: 3 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
// Most of the code from here is from bin/jscodeshift.js
// It's kept that way so that users can reuse jscodeshift options.

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import path from "path";
import Runner from "jscodeshift/dist/Runner";
Expand Down Expand Up @@ -53,6 +52,8 @@ const disclaimerLines = [

const parser = getJsCodeshiftParser();

// biome-ignore lint/style/useSingleVarDeclarator: ignore
// biome-ignore lint/suspicious/noImplicitAnyLet: ignore
let options, positionalArguments;
try {
({ options, positionalArguments } = parser.parse());
Expand Down Expand Up @@ -89,6 +90,7 @@ function run(paths, options) {

if (options.stdin) {
let buffer = "";
// biome-ignore lint/suspicious/noAssignInExpressions: ignore
process.stdin.on("data", (data) => (buffer += data));
process.stdin.on("end", () => run(buffer.split("\n"), options));
} else {
Expand Down
30 changes: 15 additions & 15 deletions src/transforms/v2-to-v3/apis/removePromiseForCallExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ export const removePromiseForCallExpression = (
).object;
break;
}
case "ArrowFunctionExpression":
case "AwaitExpression":
case "CallExpression":
case "ExpressionStatement":
case "ObjectProperty":
case "ReturnStatement":
case "VariableDeclarator": {
const currentCalleeObject = (callExpression.value.callee as MemberExpression)
.object as CallExpression;
if (currentCalleeObject.arguments.length > 0) {
callExpression.value.arguments = currentCalleeObject.arguments;
}
callExpression.value.callee = currentCalleeObject.callee;
break;
}
default: {
emitWarning(
`Removal of .promise() not implemented for parentPath: ${callExpression.parentPath.value.type}\n` +
Expand All @@ -33,21 +48,6 @@ export const removePromiseForCallExpression = (
)
);
callExpression.parentPath.node.comments = comments;
}
// eslint-disable-next-line no-fallthrough
case "ArrowFunctionExpression":
case "AwaitExpression":
case "CallExpression":
case "ExpressionStatement":
case "ObjectProperty":
case "ReturnStatement":
case "VariableDeclarator": {
const currentCalleeObject = (callExpression.value.callee as MemberExpression)
.object as CallExpression;
if (currentCalleeObject.arguments.length > 0) {
callExpression.value.arguments = currentCalleeObject.arguments;
}
callExpression.value.callee = currentCalleeObject.callee;
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ export const getObjectWithUpdatedAwsConfigKeys = (
})
.filter((property) => property !== undefined);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore is Argument is not assignable to parameter
return j.objectExpression(updatedProperties);
};
4 changes: 2 additions & 2 deletions src/transforms/v2-to-v3/transformer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ describe("v2-to-v3", () => {
const output = await transform(input, {
j: jscodeshift,
jscodeshift,
// eslint-disable-next-line @typescript-eslint/no-empty-function
// biome-ignore lint/suspicious/noEmptyBlockStatements: test helper
stats: () => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
// biome-ignore lint/suspicious/noEmptyBlockStatements: test helper
report: () => {},
});

Expand Down
4 changes: 2 additions & 2 deletions src/transforms/v2-to-v3/ts-type/getTypeForString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const getTypeForString = (
const typeArgument = getTypeForString(j, v2ClientLocalName, type);
return j.tsTypeReference.from({
typeName: j.identifier("Array"),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

// @ts-ignore
typeParameters: j.tsTypeParameterInstantiation([typeArgument]),
});
Expand All @@ -42,7 +42,7 @@ export const getTypeForString = (
const typeArgument = getTypeForString(j, v2ClientLocalName, type);
return j.tsTypeReference.from({
typeName: j.identifier("Record"),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

// @ts-ignore
typeParameters: j.tsTypeParameterInstantiation([j.tsStringKeyword(), typeArgument]),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const getMostUsedStringLiteralQuote = (

// Check if the literal value is a string and contains single quotes
if (typeof value === "string") {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Property 'raw' does not exist on type 'Literal'.
const rawValue = path.node.raw || path.node.extra?.raw || "";
if (rawValue.startsWith("'")) {
Expand Down
1 change: 0 additions & 1 deletion src/transforms/v2-to-v3/utils/isTrailingCommaUsed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Collection, JSCodeshift } from "jscodeshift";

export const isTrailingCommaUsed = (j: JSCodeshift, source: Collection<unknown>) => {
for (const node of source.find(j.ObjectExpression).nodes()) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Property 'extra' does not exist on type 'ObjectExpression'.
if (node.extra && node.extra.trailingComma) {
return true;
Expand Down
Loading