Skip to content

Commit 2a1536d

Browse files
authored
chore: move lint rules to Biome (withastro#12145)
* chore: move lint rules to Astro * better suppression system * revert * format code * address more linting files * address more linting files
1 parent 91ecad2 commit 2a1536d

File tree

87 files changed

+245
-312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+245
-312
lines changed

benchmark/packages/timer/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export default function createIntegration(): AstroIntegration {
2727
setAdapter(getAdapter());
2828

2929
if (config.output === 'static') {
30-
// eslint-disable-next-line no-console
3130
console.warn(`[@benchmark/timer] \`output: "server"\` is required to use this adapter.`);
3231
}
3332
},

benchmark/packages/timer/src/preview.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const preview: CreatePreviewServer = async function ({ serverEntrypoint, host, p
99
server.listen(port, host);
1010
enableDestroy(server);
1111

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

1515
// Resolves once the server is closed

biome.json

-76
This file was deleted.

biome.jsonc

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
3+
"files": {
4+
"ignore": [
5+
"vendor",
6+
"**/dist/**",
7+
"**/smoke/**",
8+
"**/fixtures/**",
9+
"**/vendor/**",
10+
"**/.vercel/**",
11+
],
12+
"include": ["test/**", "e2e/**", "packages/**", "/scripts/**"],
13+
},
14+
"formatter": {
15+
"indentStyle": "tab",
16+
"indentWidth": 2,
17+
"lineWidth": 100,
18+
"ignore": [
19+
"benchmark/projects/",
20+
"benchmark/results/",
21+
".changeset",
22+
"pnpm-lock.yaml",
23+
"*.astro",
24+
],
25+
},
26+
"organizeImports": {
27+
"enabled": true,
28+
},
29+
"linter": {
30+
"enabled": true,
31+
"rules": {
32+
"recommended": false,
33+
"style": {
34+
"useNodejsImportProtocol": "error",
35+
// Enforce separate type imports for type-only imports to avoid bundling unneeded code
36+
"useImportType": "error",
37+
},
38+
"suspicious": {
39+
// This one is specific to catch `console.log`. The rest of logs are permitted
40+
"noConsoleLog": "warn",
41+
},
42+
"correctness": {
43+
"noUnusedVariables": "info",
44+
"noUnusedFunctionParameters": "info",
45+
},
46+
},
47+
},
48+
"javascript": {
49+
"formatter": {
50+
"trailingCommas": "all",
51+
"quoteStyle": "single",
52+
"semicolons": "always",
53+
},
54+
},
55+
"json": {
56+
"parser": {
57+
"allowComments": true,
58+
"allowTrailingCommas": true,
59+
},
60+
"formatter": {
61+
"indentStyle": "space",
62+
"trailingCommas": "none",
63+
},
64+
},
65+
"overrides": [
66+
{
67+
// Workaround to format files like npm does
68+
"include": ["package.json"],
69+
"json": {
70+
"formatter": {
71+
"lineWidth": 1,
72+
},
73+
},
74+
},
75+
{
76+
// We don"t want to have node modules in code that should be runtime agnostic
77+
"include": ["packages/astro/src/runtime/**/*.ts"],
78+
"linter": {
79+
"rules": {
80+
"correctness": {
81+
"noNodejsModules": "error",
82+
},
83+
},
84+
},
85+
},
86+
{
87+
"include": ["*.test.js"],
88+
"linter": {
89+
"rules": {
90+
"suspicious": {
91+
"noFocusedTests": "error",
92+
"noConsole": "off",
93+
},
94+
},
95+
},
96+
},
97+
{
98+
"include": ["*.astro", "client.d.ts"],
99+
"linter": {
100+
"rules": {
101+
"correctness": {
102+
"noUnusedVariables": "off",
103+
},
104+
},
105+
},
106+
},
107+
{
108+
"include": ["packages/integrations/**/*.ts"],
109+
"linter": {
110+
"rules": {
111+
"suspicious": {
112+
"noConsole": {
113+
"level": "error",
114+
"options": {
115+
"allow": ["warn", "error", "info", "debug"],
116+
},
117+
},
118+
},
119+
},
120+
},
121+
},
122+
{
123+
"include": [
124+
"packages/db/**/cli/**/*.ts",
125+
"benchmark/**/*.js",
126+
"packages/astro/src/cli/**/*.ts",
127+
"packages/astro/astro.js",
128+
],
129+
"linter": {
130+
"rules": {
131+
"suspicious": {
132+
"noConsole": "off",
133+
"noConsoleLog": "off",
134+
},
135+
},
136+
},
137+
},
138+
],
139+
}

eslint.config.js

+4-65
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from 'node:path';
22
import { fileURLToPath } from 'node:url';
3-
import { builtinModules } from 'node:module';
43

54
import tseslint from 'typescript-eslint';
65

@@ -51,19 +50,11 @@ export default [
5150
rules: {
5251
// These off/configured-differently-by-default rules fit well for us
5352
'@typescript-eslint/switch-exhaustiveness-check': 'error',
54-
'@typescript-eslint/no-unused-vars': [
55-
'error',
56-
{
57-
argsIgnorePattern: '^_',
58-
varsIgnorePattern: '^_',
59-
caughtErrorsIgnorePattern: '^_',
60-
ignoreRestSiblings: true,
61-
},
62-
],
6353
'@typescript-eslint/no-shadow': 'error',
64-
'no-console': 'warn',
54+
'no-console': 'off',
6555

6656
// Todo: do we want these?
57+
'@typescript-eslint/no-unused-vars': 'off',
6758
'@typescript-eslint/array-type': 'off',
6859
'@typescript-eslint/ban-ts-comment': 'off',
6960
'@typescript-eslint/class-literal-property-style': 'off',
@@ -95,16 +86,8 @@ export default [
9586
'@typescript-eslint/unbound-method': 'off',
9687
'@typescript-eslint/no-explicit-any': 'off',
9788

98-
// Enforce separate type imports for type-only imports to avoid bundling unneeded code
99-
'@typescript-eslint/consistent-type-imports': [
100-
'error',
101-
{
102-
prefer: 'type-imports',
103-
fixStyle: 'separate-type-imports',
104-
disallowTypeAnnotations: false,
105-
},
106-
],
107-
89+
// Used by Biome
90+
'@typescript-eslint/consistent-type-imports': 'off',
10891
// These rules enabled by the preset configs don't work well for us
10992
'@typescript-eslint/await-thenable': 'off',
11093
'prefer-const': 'off',
@@ -115,20 +98,6 @@ export default [
11598
'regexp/prefer-regexp-test': 'warn',
11699
},
117100
},
118-
119-
{
120-
// Ensure Node builtins aren't included in Astro's server runtime
121-
files: ['packages/astro/src/runtime/**/*.ts'],
122-
rules: {
123-
'no-restricted-imports': [
124-
'error',
125-
{
126-
paths: [...builtinModules],
127-
patterns: ['node:*'],
128-
},
129-
],
130-
},
131-
},
132101
{
133102
files: ['packages/astro/src/runtime/client/**/*.ts'],
134103
languageOptions: {
@@ -137,36 +106,6 @@ export default [
137106
},
138107
},
139108
},
140-
{
141-
files: ['packages/**/test/*.js', 'packages/**/*.js'],
142-
languageOptions: {
143-
globals: {
144-
globalThis: false, // false means read-only
145-
},
146-
},
147-
rules: {
148-
'no-console': 'off',
149-
},
150-
},
151-
{
152-
files: ['packages/integrations/**/*.ts'],
153-
rules: {
154-
'no-console': ['error', { allow: ['warn', 'error', 'info', 'debug'] }],
155-
},
156-
},
157-
{
158-
files: ['benchmark/**/*.js'],
159-
rules: {
160-
'@typescript-eslint/no-unused-vars': 'off',
161-
'no-console': 'off',
162-
},
163-
},
164-
{
165-
files: ['packages/db/**/cli/**/*.ts'],
166-
rules: {
167-
'no-console': 'off',
168-
},
169-
},
170109
{
171110
files: ['packages/astro/src/core/errors/errors-data.ts'],
172111
rules: {

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"test:e2e:hosts": "turbo run test:hosted",
3737
"benchmark": "astro-benchmark",
3838
"lint": "biome lint && eslint . --report-unused-disable-directives",
39+
"lint:fix": "biome lint --write --unsafe",
3940
"version": "changeset version && node ./scripts/deps/update-example-versions.js && pnpm install --no-frozen-lockfile && pnpm run format",
4041
"preinstall": "npx only-allow pnpm"
4142
},
@@ -53,7 +54,7 @@
5354
},
5455
"devDependencies": {
5556
"@astrojs/check": "^0.9.4",
56-
"@biomejs/biome": "1.8.3",
57+
"@biomejs/biome": "1.9.3",
5758
"@changesets/changelog-github": "^0.5.0",
5859
"@changesets/cli": "^2.27.9",
5960
"@types/node": "^18.17.8",

packages/astro-prism/src/highlighter.ts

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export function runHighlighterWithAstro(lang: string | undefined, code: string)
2626
}
2727

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

packages/astro-prism/src/plugin.ts

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export function addAstro(Prism: typeof import('prismjs')) {
88
scriptLang = 'typescript';
99
} else {
1010
scriptLang = 'javascript';
11-
// eslint-disable-next-line no-console
1211
console.warn(
1312
'Prism TypeScript language not loaded, Astro scripts will be treated as JavaScript.',
1413
);

packages/astro-rss/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ const rssOptionsValidator = z.object({
7070
.or(globResultValidator)
7171
.transform((items) => {
7272
if (!Array.isArray(items)) {
73-
// eslint-disable-next-line
7473
console.warn(
7574
yellow(
7675
'[RSS] Passing a glob result directly has been deprecated. Please migrate to the `pagesGlobToRssItems()` helper: https://docs.astro.build/en/guides/rss/',

packages/astro/astro-jsx.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/// <reference lib="dom" />
2-
/* eslint @typescript-eslint/no-unused-vars: off */
32
/**
43
* Adapted from babel-plugin-react-html-attrs's TypeScript definition from DefinitelyTyped.
54
* @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/babel-plugin-react-html-attrs/index.d.ts

0 commit comments

Comments
 (0)