Skip to content

Commit

Permalink
chore: move lint rules to Biome (#12145)
Browse files Browse the repository at this point in the history
* chore: move lint rules to Astro

* better suppression system

* revert

* format code

* address more linting files

* address more linting files
  • Loading branch information
ematipico authored Oct 8, 2024
1 parent 91ecad2 commit 2a1536d
Show file tree
Hide file tree
Showing 87 changed files with 245 additions and 312 deletions.
1 change: 0 additions & 1 deletion benchmark/packages/timer/src/index.ts
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion benchmark/packages/timer/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const preview: CreatePreviewServer = async function ({ serverEntrypoint, host, p
server.listen(port, host);
enableDestroy(server);

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

// Resolves once the server is closed
Expand Down
76 changes: 0 additions & 76 deletions biome.json

This file was deleted.

139 changes: 139 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
"files": {
"ignore": [
"vendor",
"**/dist/**",
"**/smoke/**",
"**/fixtures/**",
"**/vendor/**",
"**/.vercel/**",
],
"include": ["test/**", "e2e/**", "packages/**", "/scripts/**"],
},
"formatter": {
"indentStyle": "tab",
"indentWidth": 2,
"lineWidth": 100,
"ignore": [
"benchmark/projects/",
"benchmark/results/",
".changeset",
"pnpm-lock.yaml",
"*.astro",
],
},
"organizeImports": {
"enabled": true,
},
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"style": {
"useNodejsImportProtocol": "error",
// Enforce separate type imports for type-only imports to avoid bundling unneeded code
"useImportType": "error",
},
"suspicious": {
// This one is specific to catch `console.log`. The rest of logs are permitted
"noConsoleLog": "warn",
},
"correctness": {
"noUnusedVariables": "info",
"noUnusedFunctionParameters": "info",
},
},
},
"javascript": {
"formatter": {
"trailingCommas": "all",
"quoteStyle": "single",
"semicolons": "always",
},
},
"json": {
"parser": {
"allowComments": true,
"allowTrailingCommas": true,
},
"formatter": {
"indentStyle": "space",
"trailingCommas": "none",
},
},
"overrides": [
{
// Workaround to format files like npm does
"include": ["package.json"],
"json": {
"formatter": {
"lineWidth": 1,
},
},
},
{
// We don"t want to have node modules in code that should be runtime agnostic
"include": ["packages/astro/src/runtime/**/*.ts"],
"linter": {
"rules": {
"correctness": {
"noNodejsModules": "error",
},
},
},
},
{
"include": ["*.test.js"],
"linter": {
"rules": {
"suspicious": {
"noFocusedTests": "error",
"noConsole": "off",
},
},
},
},
{
"include": ["*.astro", "client.d.ts"],
"linter": {
"rules": {
"correctness": {
"noUnusedVariables": "off",
},
},
},
},
{
"include": ["packages/integrations/**/*.ts"],
"linter": {
"rules": {
"suspicious": {
"noConsole": {
"level": "error",
"options": {
"allow": ["warn", "error", "info", "debug"],
},
},
},
},
},
},
{
"include": [
"packages/db/**/cli/**/*.ts",
"benchmark/**/*.js",
"packages/astro/src/cli/**/*.ts",
"packages/astro/astro.js",
],
"linter": {
"rules": {
"suspicious": {
"noConsole": "off",
"noConsoleLog": "off",
},
},
},
},
],
}
69 changes: 4 additions & 65 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { builtinModules } from 'node:module';

import tseslint from 'typescript-eslint';

Expand Down Expand Up @@ -51,19 +50,11 @@ export default [
rules: {
// These off/configured-differently-by-default rules fit well for us
'@typescript-eslint/switch-exhaustiveness-check': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'@typescript-eslint/no-shadow': 'error',
'no-console': 'warn',
'no-console': 'off',

// Todo: do we want these?
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/class-literal-property-style': 'off',
Expand Down Expand Up @@ -95,16 +86,8 @@ export default [
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-explicit-any': 'off',

// Enforce separate type imports for type-only imports to avoid bundling unneeded code
'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
fixStyle: 'separate-type-imports',
disallowTypeAnnotations: false,
},
],

// Used by Biome
'@typescript-eslint/consistent-type-imports': 'off',
// These rules enabled by the preset configs don't work well for us
'@typescript-eslint/await-thenable': 'off',
'prefer-const': 'off',
Expand All @@ -115,20 +98,6 @@ export default [
'regexp/prefer-regexp-test': 'warn',
},
},

{
// 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 @@ -137,36 +106,6 @@ export default [
},
},
},
{
files: ['packages/**/test/*.js', 'packages/**/*.js'],
languageOptions: {
globals: {
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"test:e2e:hosts": "turbo run test:hosted",
"benchmark": "astro-benchmark",
"lint": "biome lint && eslint . --report-unused-disable-directives",
"lint:fix": "biome lint --write --unsafe",
"version": "changeset version && node ./scripts/deps/update-example-versions.js && pnpm install --no-frozen-lockfile && pnpm run format",
"preinstall": "npx only-allow pnpm"
},
Expand All @@ -53,7 +54,7 @@
},
"devDependencies": {
"@astrojs/check": "^0.9.4",
"@biomejs/biome": "1.8.3",
"@biomejs/biome": "1.9.3",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.9",
"@types/node": "^18.17.8",
Expand Down
1 change: 0 additions & 1 deletion packages/astro-prism/src/highlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export function runHighlighterWithAstro(lang: string | undefined, code: string)
}

if (lang && !Prism.languages[lang]) {
// eslint-disable-next-line no-console
console.warn(`Unable to load the language: ${lang}`);
}

Expand Down
1 change: 0 additions & 1 deletion packages/astro-prism/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export function addAstro(Prism: typeof import('prismjs')) {
scriptLang = 'typescript';
} else {
scriptLang = 'javascript';
// eslint-disable-next-line no-console
console.warn(
'Prism TypeScript language not loaded, Astro scripts will be treated as JavaScript.',
);
Expand Down
1 change: 0 additions & 1 deletion packages/astro-rss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const rssOptionsValidator = z.object({
.or(globResultValidator)
.transform((items) => {
if (!Array.isArray(items)) {
// eslint-disable-next-line
console.warn(
yellow(
'[RSS] Passing a glob result directly has been deprecated. Please migrate to the `pagesGlobToRssItems()` helper: https://docs.astro.build/en/guides/rss/',
Expand Down
1 change: 0 additions & 1 deletion packages/astro/astro-jsx.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// <reference lib="dom" />
/* eslint @typescript-eslint/no-unused-vars: off */
/**
* Adapted from babel-plugin-react-html-attrs's TypeScript definition from DefinitelyTyped.
* @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/babel-plugin-react-html-attrs/index.d.ts
Expand Down
Loading

0 comments on commit 2a1536d

Please sign in to comment.