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

chore: use Biome for linting #10862

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion benchmark/packages/timer/src/index.ts
Expand Up @@ -27,7 +27,6 @@ export default function createIntegration(): AstroIntegration {
setAdapter(getAdapter());

if (config.output === 'static') {
// eslint-disable-next-line no-console
console.warn(`[@benchmark/timer] \`output: "server"\` is required to use this adapter.`);
}
},
Expand Down
1 change: 0 additions & 1 deletion benchmark/packages/timer/src/preview.ts
Expand Up @@ -9,7 +9,6 @@ const preview: CreatePreviewServer = async function ({ serverEntrypoint, host, p
server.listen(port, host);
enableDestroy(server);

// eslint-disable-next-line no-console
console.log(`Preview server listening on http://${host}:${port}`);

// Resolves once the server is closed
Expand Down
242 changes: 227 additions & 15 deletions biome.json
@@ -1,13 +1,19 @@
{
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json",
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json",
"files": {
"ignore": [
"vendor",
"**/dist/**",
"**/smoke/**",
"**/fixtures/**",
"**/vendor/**",
"**/.vercel/**"
"**/.vercel/**",
"**/*.d.ts",
"packages/**/*.min.js",
"packages/astro/vendor/vite/",
"examples/",
"scripts/",
".changeset/"
],
"include": ["test/**", "e2e/**", "packages/**"]
},
Expand All @@ -24,25 +30,231 @@
"*.astro"
]
},
"organizeImports": {
"enabled": true
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"complexity": {
"noBannedTypes": "error",
"noUselessTypeConstraint": "error",
"useLiteralKeys": "off",
"useOptionalChain": "error"
},
"correctness": {
"noPrecisionLoss": "error",
"noUnusedVariables": "error"
},
"style": {
"noInferrableTypes": "error",
"noNamespace": "error",
"useAsConstAssertion": "error",
"useBlockStatements": "off",
"useConsistentArrayType": "error",
"useConst": "off",
"useForOf": "error",
"useShorthandFunctionType": "error"
},
"suspicious": {
"noEmptyBlockStatements": "off",
"noExplicitAny": "off",
"noExtraNonNullAssertion": "error",
"noMisleadingInstantiator": "error",
"noUnsafeDeclarationMerging": "error",
"useAwait": "off",
"useNamespaceKeyword": "error"
}
}
},
"linter": { "enabled": false },
"javascript": {
"formatter": {
"trailingComma": "es5",
"quoteStyle": "single",
"semicolons": "always"
}
"semicolons": "always",
"quoteStyle": "single"
},
"globals": []
},
"json": {
"parser": {
"allowComments": true,
"allowTrailingCommas": true
"parser": { "allowComments": true, "allowTrailingCommas": true },
"formatter": { "indentStyle": "space", "trailingCommas": "none" }
},
"overrides": [
{
"include": ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"],
"linter": {
"rules": {
"correctness": {
"noConstAssign": "off",
"noGlobalObjectCalls": "off",
"noInvalidConstructorSuper": "off",
"noInvalidNewBuiltin": "off",
"noNewSymbol": "off",
"noSetterReturn": "off",
"noUnreachable": "off",
"noUnreachableSuper": "off"
},
"style": {
"noArguments": "error",
"noVar": "error",
"useConst": "error",
"useNodejsImportProtocol": "error"
},
"suspicious": {
"noDuplicateClassMembers": "off",
"noDuplicateObjectKeys": "off",
"noDuplicateParameters": "off",
"noFunctionAssign": "off",
"noImportAssign": "off",
"noRedeclare": "off",
"noUnsafeNegation": "off",
"useGetterReturn": "off"
}
}
}
},
"formatter": {
"indentStyle": "space",
"trailingCommas": "none"
{
"include": ["*.astro"],
"linter": {
"rules": {
"correctness": {
"noUnusedVariables": "off"
}
}
}
},
{
"include": ["*.test.js"],
"linter": {
"rules": {
"suspicious": {
"noFocusedTests": "error"
},
"style": {
"useNodeAssertStrict": "warn"
}
}
}
},
{
"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"
}
}
}
},
{
"include": ["packages/astro/src/runtime/**/*.ts"],
"linter": {
"rules": {
"nursery": {
"noRestrictedImports": {
"level": "error",
"options": {
"paths": {
"node:assert": "The use of node modules is forbidden here.",
"node:assert/strict": "The use of node modules is forbidden here.",
"node:async_hooks": "The use of node modules is forbidden here.",
"node:buffer": "The use of node modules is forbidden here.",
"node:child_process": "The use of node modules is forbidden here.",
"node:cluster": "The use of node modules is forbidden here.",
"node:console": "The use of node modules is forbidden here.",
"node:constants": "The use of node modules is forbidden here.",
"node:crypto": "The use of node modules is forbidden here.",
"node:dgram": "The use of node modules is forbidden here.",
"node:diagnostics_channel": "The use of node modules is forbidden here.",
"node:dns": "The use of node modules is forbidden here.",
"node:dns/promises": "The use of node modules is forbidden here.",
"node:domain": "The use of node modules is forbidden here.",
"node:events": "The use of node modules is forbidden here.",
"node:fs": "The use of node modules is forbidden here.",
"node:fs/promises": "The use of node modules is forbidden here.",
"node:http": "The use of node modules is forbidden here.",
"node:http2": "The use of node modules is forbidden here.",
"node:https": "The use of node modules is forbidden here.",
"node:inspector": "The use of node modules is forbidden here.",
"node:inspector/promises": "The use of node modules is forbidden here.",
"node:module": "The use of node modules is forbidden here.",
"node:net": "The use of node modules is forbidden here.",
"node:os": "The use of node modules is forbidden here.",
"node:path": "The use of node modules is forbidden here.",
"node:path/posix": "The use of node modules is forbidden here.",
"node:path/win32": "The use of node modules is forbidden here.",
"node:perf_hooks": "The use of node modules is forbidden here.",
"node:process": "The use of node modules is forbidden here.",
"node:punycode": "The use of node modules is forbidden here.",
"node:querystring": "The use of node modules is forbidden here.",
"node:readline": "The use of node modules is forbidden here.",
"node:readline/promises": "The use of node modules is forbidden here.",
"node:repl": "The use of node modules is forbidden here.",
"node:stream": "The use of node modules is forbidden here.",
"node:stream/consumers": "The use of node modules is forbidden here.",
"node:stream/promises": "The use of node modules is forbidden here.",
"node:stream/web": "The use of node modules is forbidden here.",
"node:string_decoder": "The use of node modules is forbidden here.",
"node:sys": "The use of node modules is forbidden here.",
"node:timers": "The use of node modules is forbidden here.",
"node:timers/promises": "The use of node modules is forbidden here.",
"node:tls": "The use of node modules is forbidden here.",
"node:trace_events": "The use of node modules is forbidden here.",
"node:tty": "The use of node modules is forbidden here.",
"node:url": "The use of node modules is forbidden here.",
"node:util": "The use of node modules is forbidden here.",
"node:util/types": "The use of node modules is forbidden here.",
"node:v8": "The use of node modules is forbidden here.",
"node:vm": "The use of node modules is forbidden here.",
"node:wasi": "The use of node modules is forbidden here.",
"node:worker_threads": "The use of node modules is forbidden here.",
"node:zlib": "The use of node modules is forbidden here."
}
}
}
}
}
}
},
{
"include": ["packages/astro/src/runtime/client/**/*.ts"],
"javascript": { "globals": ["browser"] }
},
{ "include": ["packages/integrations/**/*.ts"], "linter": { "rules": {} } },
{
"include": ["benchmark/**/*.js"],
"linter": { "rules": { "correctness": { "noUnusedVariables": "off" } } }
},
{ "include": ["packages/db/**/cli/**/*.ts"], "linter": { "rules": {} } },
{
"include": ["packages/astro/src/core/errors/errors-data.ts"],
"linter": { "rules": {} }
},
{
"include": ["packages/db/src/runtime/**/*.ts"],
"linter": { "rules": {} }
}
}
]
}
67 changes: 5 additions & 62 deletions eslint.config.js
Expand Up @@ -6,8 +6,6 @@ import { FlatCompat } from '@eslint/eslintrc';
import tseslint from 'typescript-eslint';

// plugins
import prettierEslint from 'eslint-plugin-prettier';
import noOnlyTestsEslint from 'eslint-plugin-no-only-tests';
import regexpEslint from 'eslint-plugin-regexp';
const typescriptEslint = tseslint.plugin;

Expand Down Expand Up @@ -43,9 +41,8 @@ export default [
},

...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
// ...tseslint.configs.stylisticTypeChecked,
// mimic ESLintRC-style extends
...compat.extends('prettier'),
...compat.extends('plugin:regexp/recommended'),
{
languageOptions: {
Expand All @@ -57,25 +54,12 @@ export default [
},
plugins: {
'@typescript-eslint': typescriptEslint,
prettier: prettierEslint,
'no-only-tests': noOnlyTestsEslint,
regexp: regexpEslint,
},
rules: {
// These off/configured-differently-by-default rules fit well for us
'@typescript-eslint/switch-exhaustiveness-check': 'error',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'no-only-tests/no-only-tests': 'error',
'@typescript-eslint/no-shadow': 'error',
'no-console': 'warn',

// Todo: do we want these?
'@typescript-eslint/array-type': 'off',
Expand Down Expand Up @@ -105,6 +89,10 @@ export default [
'@typescript-eslint/sort-type-constituents': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-types': 'off',
'no-console': 'off',
'@typescript-eslint/no-unused-vars': "off",
'@typescript-eslint/no-namespace': "off",

// Enforce separate type imports for type-only imports to avoid bundling unneeded code
'@typescript-eslint/consistent-type-imports': [
Expand All @@ -124,20 +112,6 @@ export default [
'regexp/use-ignore-case': 'off',
},
},

{
// Ensure Node builtins aren't included in Astro's server runtime
files: ['packages/astro/src/runtime/**/*.ts'],
rules: {
'no-restricted-imports': [
'error',
{
paths: [...builtinModules],
patterns: ['node:*'],
},
],
},
},
{
files: ['packages/astro/src/runtime/client/**/*.ts'],
languageOptions: {
Expand All @@ -146,37 +120,6 @@ export default [
},
},
},
{
files: ['packages/**/test/*.js', 'packages/**/*.js'],
languageOptions: {
globals: {
mocha: true,
globalThis: false, // false means read-only
},
},
rules: {
'no-console': 'off',
},
},
{
files: ['packages/integrations/**/*.ts'],
rules: {
'no-console': ['error', { allow: ['warn', 'error', 'info', 'debug'] }],
},
},
{
files: ['benchmark/**/*.js'],
rules: {
'@typescript-eslint/no-unused-vars': 'off',
'no-console': 'off',
},
},
{
files: ['packages/db/**/cli/**/*.ts'],
rules: {
'no-console': 'off',
},
},
{
files: ['packages/astro/src/core/errors/errors-data.ts'],
rules: {
Expand Down