Skip to content

Commit 2fea174

Browse files
feat: use typescript-eslint@v6's reworked configs (withastro#7425)
1 parent fc6826f commit 2fea174

File tree

154 files changed

+318
-459
lines changed

Some content is hidden

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

154 files changed

+318
-459
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
**/*.d.ts
2+
packages/**/*.min.js
23
packages/**/dist/**/*
34
packages/**/fixtures/**/*
45
packages/webapi/**/*

.eslintrc.cjs

+43-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,53 @@
11
module.exports = {
2+
extends: [
3+
'plugin:@typescript-eslint/recommended-type-checked',
4+
'plugin:@typescript-eslint/stylistic-type-checked',
5+
'prettier',
6+
],
27
parser: '@typescript-eslint/parser',
3-
extends: ['plugin:@typescript-eslint/recommended', 'prettier'],
8+
parserOptions: {
9+
project: ['./packages/*/tsconfig.json', './tsconfig.eslint.json'],
10+
tsconfigRootDir: __dirname,
11+
},
412
plugins: ['@typescript-eslint', 'prettier', 'no-only-tests'],
513
rules: {
14+
// These off/configured-differently-by-default rules fit well for us
15+
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
16+
'@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }],
17+
'no-only-tests/no-only-tests': 'error',
18+
'@typescript-eslint/no-shadow': ['error'],
19+
'no-console': 'warn',
20+
21+
// Todo: do we want these?
22+
'@typescript-eslint/array-type': 'off',
623
'@typescript-eslint/ban-ts-comment': 'off',
7-
'@typescript-eslint/camelcase': 'off',
8-
'@typescript-eslint/explicit-module-boundary-types': 'off',
24+
'@typescript-eslint/class-literal-property-style': 'off',
25+
'@typescript-eslint/consistent-indexed-object-style': 'off',
26+
'@typescript-eslint/consistent-type-definitions': 'off',
27+
'@typescript-eslint/dot-notation': 'off',
28+
'@typescript-eslint/no-base-to-string': 'off',
29+
'@typescript-eslint/no-confusing-void-expression': 'off',
930
'@typescript-eslint/no-empty-function': 'off',
10-
'@typescript-eslint/no-explicit-any': 'off',
11-
'@typescript-eslint/no-non-null-assertion': 'off',
12-
'@typescript-eslint/no-unused-vars': 'off',
13-
'@typescript-eslint/no-use-before-define': 'off',
14-
'@typescript-eslint/no-var-requires': 'off',
31+
'@typescript-eslint/no-floating-promises': 'off',
32+
'@typescript-eslint/no-misused-promises': 'off',
33+
'@typescript-eslint/no-redundant-type-constituents': 'off',
1534
'@typescript-eslint/no-this-alias': 'off',
16-
'no-console': 'warn',
35+
'@typescript-eslint/no-unsafe-argument': 'off',
36+
'@typescript-eslint/no-unsafe-assignment': 'off',
37+
'@typescript-eslint/no-unsafe-call': 'off',
38+
'@typescript-eslint/no-unsafe-member-access': 'off',
39+
'@typescript-eslint/no-unsafe-return': 'off',
40+
'@typescript-eslint/prefer-nullish-coalescing': 'off',
41+
'@typescript-eslint/prefer-string-starts-ends-with': 'off',
42+
'@typescript-eslint/require-await': 'off',
43+
'@typescript-eslint/restrict-plus-operands': 'off',
44+
'@typescript-eslint/restrict-template-expressions': 'off',
45+
'@typescript-eslint/sort-type-constituents': 'off',
46+
'@typescript-eslint/unbound-method': 'off',
47+
48+
// These rules enabled by the preset configs don't work well for us
49+
'@typescript-eslint/await-thenable': 'off',
1750
'prefer-const': 'off',
18-
'no-shadow': 'off',
19-
'@typescript-eslint/no-shadow': ['error'],
20-
'no-only-tests/no-only-tests': 'error',
2151
},
2252
overrides: [
2353
{
@@ -41,6 +71,7 @@ module.exports = {
4171
{
4272
files: ['benchmark/**/*.js'],
4373
rules: {
74+
'@typescript-eslint/no-unused-vars': 'off',
4475
'no-console': 'off',
4576
},
4677
},

.github/workflows/ci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ env:
3232
jobs:
3333
lint:
3434
name: Lint
35-
timeout-minutes: 3
35+
timeout-minutes: 5
3636
runs-on: ubuntu-latest
3737
steps:
3838
- name: Check out repository
@@ -50,6 +50,9 @@ jobs:
5050
- name: Install dependencies
5151
run: pnpm install
5252

53+
- name: Build (ignoring failures)
54+
run: pnpm run build || true
55+
5356
# Lint autofix cannot run on forks, so just skip those! See https://github.com/wearerequired/lint-action/issues/13
5457
- name: Lint (External)
5558
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.owner.login != github.repository_owner }}

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"test:e2e": "cd packages/astro && pnpm playwright install && pnpm run test:e2e",
2929
"test:e2e:match": "cd packages/astro && pnpm playwright install && pnpm run test:e2e:match",
3030
"benchmark": "astro-benchmark",
31-
"lint": "eslint --cache .",
31+
"lint": "eslint . --report-unused-disable-directives",
3232
"version": "changeset version && node ./scripts/deps/update-example-versions.js && pnpm install --no-frozen-lockfile && pnpm run format",
3333
"preinstall": "npx only-allow pnpm"
3434
},
@@ -78,8 +78,8 @@
7878
"@changesets/changelog-github": "^0.4.8",
7979
"@changesets/cli": "^2.26.1",
8080
"@types/node": "^18.16.18",
81-
"@typescript-eslint/eslint-plugin": "^5.60.0",
82-
"@typescript-eslint/parser": "^5.60.0",
81+
"@typescript-eslint/eslint-plugin": "6.0.0-alpha.158",
82+
"@typescript-eslint/parser": "6.0.0-alpha.158",
8383
"esbuild": "^0.17.19",
8484
"eslint": "^8.43.0",
8585
"eslint-config-prettier": "^8.8.0",

packages/astro/astro.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env node
2-
/* eslint-disable no-console */
32
'use strict';
43

54
// ISOMORPHIC FILE: NO TOP-LEVEL IMPORT/REQUIRE() ALLOWED

packages/astro/e2e/css-sourcemaps.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@playwright/test';
2-
import { getColor, isWindows, testFactory } from './test-utils.js';
2+
import { isWindows, testFactory } from './test-utils.js';
33

44
const test = testFactory({
55
root: './fixtures/css/',

packages/astro/e2e/hydration-race.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ test.describe('Hydration race', () => {
1919
test('Islands inside of slots hydrate', async ({ page, astro }) => {
2020
await page.goto(astro.resolveUrl('/slot'));
2121

22-
const html = await page.content();
23-
2422
const one = page.locator('#one');
2523
await expect(one, 'updated text').toHaveText('Hello One in the client');
2624

packages/astro/e2e/test-utils.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ for (let i = 0; i < testFiles.length; i++) {
1818
}
1919

2020
export function loadFixture(inlineConfig) {
21-
if (!inlineConfig || !inlineConfig.root)
22-
throw new Error("Must provide { root: './fixtures/...' }");
21+
if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }");
2322

2423
// resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath
2524
// without this, the main `loadFixture` helper will resolve relative to `packages/astro/test`

packages/astro/src/assets/image-endpoint.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const get: APIRoute = async ({ request }) => {
3535
const url = new URL(request.url);
3636
const transform = await imageService.parseURL(url, imageServiceConfig);
3737

38-
if (!transform || !transform.src) {
38+
if (!transform?.src) {
3939
throw new Error('Incorrect transform returned by `parseURL`');
4040
}
4141

packages/astro/src/assets/services/squoosh.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const service: LocalImageService = {
3636
async transform(inputBuffer, transformOptions) {
3737
const transform: BaseServiceTransform = transformOptions as BaseServiceTransform;
3838

39-
let format = transform.format!;
39+
let format = transform.format;
4040

4141
const operations: Operation[] = [];
4242

packages/astro/src/assets/services/vendor/squoosh/codecs.ts

-2
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ export const codecs = {
291291
avif: {
292292
name: 'AVIF',
293293
extension: 'avif',
294-
// eslint-disable-next-line no-control-regex
295294
detectors: [/^\x00\x00\x00 ftypavif\x00\x00\x00\x00/],
296295
dec: () =>
297296
instantiateEmscriptenWasm(avifDec as DecodeModuleFactory, avifDecWasm),
@@ -322,7 +321,6 @@ export const codecs = {
322321
oxipng: {
323322
name: 'OxiPNG',
324323
extension: 'png',
325-
// eslint-disable-next-line no-control-regex
326324
detectors: [/^\x89PNG\x0D\x0A\x1A\x0A/],
327325
dec: async () => {
328326
await pngEncDecInit()

packages/astro/src/assets/services/vendor/squoosh/image.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export async function processBuffer(
2929

3030
switch (encoding) {
3131
case 'avif':
32-
return await impl.encodeAvif(imageData, { quality }) as Uint8Array;
32+
return await impl.encodeAvif(imageData, { quality });
3333
case 'jpeg':
3434
case 'jpg':
35-
return await impl.encodeJpeg(imageData, { quality }) as Uint8Array;
35+
return await impl.encodeJpeg(imageData, { quality });
3636
case 'png':
37-
return await impl.encodePng(imageData) as Uint8Array;
37+
return await impl.encodePng(imageData);
3838
case 'webp':
39-
return await impl.encodeWebp(imageData, { quality }) as Uint8Array;
39+
return await impl.encodeWebp(imageData, { quality });
4040
default:
4141
throw Error(`Unsupported encoding format`)
4242
}

packages/astro/src/assets/vendor/image-size/types/jp2.ts

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export const JP2: IImage = {
4949
switch (nextBoxType) {
5050
case BoxTypes.rreq:
5151
// WHAT ARE THESE 4 BYTES?????
52-
// eslint-disable-next-line no-case-declarations
5352
const MAGIC = 4
5453
offset = offset + 4 + MAGIC + calculateRREQLength(buffer.slice(offset + 4))
5554
return parseIHDR(buffer.slice(offset + 8, offset + 24))

packages/astro/src/assets/vendor/image-size/types/pnm.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const handlers: { [type: string]: Handler} = {
1919
let dimensions: string[] = []
2020

2121
while (lines.length > 0) {
22-
const line = lines.shift() as string
22+
const line = lines.shift()!
2323
if (line[0] === '#') {
2424
continue
2525
}
@@ -39,7 +39,7 @@ const handlers: { [type: string]: Handler} = {
3939
pam: (lines) => {
4040
const size: { [key: string]: number } = {}
4141
while (lines.length > 0) {
42-
const line = lines.shift() as string
42+
const line = lines.shift()!
4343
if (line.length > 16 || line.charCodeAt(0) > 128) {
4444
continue
4545
}

packages/astro/src/assets/vendor/image-size/types/svg.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ function parseLength(len: string) {
4141
function parseViewbox(viewbox: string): IAttributes {
4242
const bounds = viewbox.split(' ')
4343
return {
44-
height: parseLength(bounds[3]) as number,
45-
width: parseLength(bounds[2]) as number
44+
height: parseLength(bounds[3])!,
45+
width: parseLength(bounds[2])!
4646
}
4747
}
4848

@@ -51,21 +51,21 @@ function parseAttributes(root: string): IAttributes {
5151
const height = root.match(extractorRegExps.height)
5252
const viewbox = root.match(extractorRegExps.viewbox)
5353
return {
54-
height: height && parseLength(height[2]) as number,
55-
viewbox: viewbox && parseViewbox(viewbox[2]) as IAttributes,
56-
width: width && parseLength(width[2]) as number,
54+
height: height && parseLength(height[2])!,
55+
viewbox: viewbox && parseViewbox(viewbox[2])!,
56+
width: width && parseLength(width[2])!,
5757
}
5858
}
5959

6060
function calculateByDimensions(attrs: IAttributes): ISize {
6161
return {
62-
height: attrs.height as number,
63-
width: attrs.width as number,
62+
height: attrs.height!,
63+
width: attrs.width!,
6464
}
6565
}
6666

6767
function calculateByViewbox(attrs: IAttributes, viewbox: IAttributes): ISize {
68-
const ratio = (viewbox.width as number) / (viewbox.height as number)
68+
const ratio = (viewbox.width!) / (viewbox.height!)
6969
if (attrs.width) {
7070
return {
7171
height: Math.floor(attrs.width / ratio),
@@ -79,8 +79,8 @@ function calculateByViewbox(attrs: IAttributes, viewbox: IAttributes): ISize {
7979
}
8080
}
8181
return {
82-
height: viewbox.height as number,
83-
width: viewbox.width as number,
82+
height: viewbox.height!,
83+
width: viewbox.width!,
8484
}
8585
}
8686

packages/astro/src/assets/vendor/image-size/types/tiff.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function extractTags(buffer: Buffer, isBigEndian: boolean) {
4444
const tags: {[key: number]: number} = {}
4545

4646
let temp: Buffer | undefined = buffer
47-
while (temp && temp.length) {
47+
while (temp?.length) {
4848
const code = readUInt(temp, 16, 0, isBigEndian)
4949
const type = readUInt(temp, 16, 2, isBigEndian)
5050
const length = readUInt(temp, 32, 4, isBigEndian)

packages/astro/src/cli/check/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-console */
21
import {
32
AstroCheck,
43
DiagnosticSeverity,

packages/astro/src/content/error-map.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const errorMap: ZodErrorMap = (baseError, ctx) => {
1414
// raise a single error when `key` does not match:
1515
// > Did not match union.
1616
// > key: Expected `'tutorial' | 'blog'`, received 'foo'
17-
let typeOrLiteralErrByPath: Map<string, TypeOrLiteralErrByPathEntry> = new Map();
17+
let typeOrLiteralErrByPath = new Map<string, TypeOrLiteralErrByPathEntry>();
1818
for (const unionError of baseError.unionErrors.map((e) => e.errors).flat()) {
1919
if (unionError.code === 'invalid_type' || unionError.code === 'invalid_literal') {
2020
const flattenedErrorPath = flattenErrorPath(unionError.path);

packages/astro/src/content/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export function getDataEntryExts(settings: Pick<AstroSettings, 'dataEntryTypes'>
177177
export function getEntryConfigByExtMap<TEntryType extends ContentEntryType | DataEntryType>(
178178
entryTypes: TEntryType[]
179179
): Map<string, TEntryType> {
180-
const map: Map<string, TEntryType> = new Map();
180+
const map = new Map<string, TEntryType>();
181181
for (const entryType of entryTypes) {
182182
for (const ext of entryType.extensions) {
183183
map.set(ext, entryType);
@@ -310,7 +310,7 @@ function getYAMLErrorLine(rawData: string | undefined, objectKey: string) {
310310
return numNewlinesBeforeKey;
311311
}
312312

313-
export function parseFrontmatter(fileContents: string, filePath: string) {
313+
export function parseFrontmatter(fileContents: string) {
314314
try {
315315
// `matter` is empty string on cache results
316316
// clear cache to prevent this

packages/astro/src/core/app/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export class App {
203203
): Promise<Response> {
204204
const url = new URL(request.url);
205205
const pathname = prependForwardSlash(this.removeBase(url.pathname));
206-
const info = this.#routeDataToRouteInfo.get(routeData!)!;
206+
const info = this.#routeDataToRouteInfo.get(routeData)!;
207207
const isCompressHTML = this.#manifest.compressHTML ?? false;
208208
// may be used in the future for handling rel=modulepreload, rel=icon, rel=manifest etc.
209209
const links = new Set<never>();

packages/astro/src/core/app/node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class NodeIncomingMessage extends IncomingMessage {
3434
/**
3535
* The read-only body property of the Request interface contains a ReadableStream with the body contents that have been added to the request.
3636
*/
37-
body?: any | undefined;
37+
body?: unknown;
3838
}
3939

4040
export class NodeApp extends App {

packages/astro/src/core/build/generate.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export function chunkIsPage(
121121
if (output.type !== 'chunk') {
122122
return false;
123123
}
124-
const chunk = output as OutputChunk;
124+
const chunk = output;
125125
if (chunk.facadeModuleId) {
126126
const facadeToEntryId = prependForwardSlash(
127127
rootRelativeFacadeId(chunk.facadeModuleId, settings)
@@ -470,15 +470,7 @@ async function generatePath(
470470
onRequest?: MiddlewareHandler<unknown>
471471
) {
472472
const { settings, logging, origin, routeCache } = opts;
473-
const {
474-
mod,
475-
internals,
476-
linkIds,
477-
scripts: hoistedScripts,
478-
styles: _styles,
479-
pageData,
480-
renderers,
481-
} = gopts;
473+
const { mod, internals, scripts: hoistedScripts, styles: _styles, pageData, renderers } = gopts;
482474

483475
// This adds the page name to the array so it can be shown as part of stats.
484476
if (pageData.route.type === 'page') {

packages/astro/src/core/build/plugins/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export function registerAllPlugins({ internals, options, register }: AstroBuildP
1818
register(pluginAliasResolve(internals));
1919
register(pluginAnalyzer(internals));
2020
register(pluginInternals(internals));
21-
register(pluginRenderers(options, internals));
22-
register(pluginMiddleware(options, internals));
21+
register(pluginRenderers(options));
22+
register(pluginMiddleware(options));
2323
register(pluginPages(options, internals));
2424
register(pluginCSS(options, internals));
25-
register(astroHeadBuildPlugin(options, internals));
25+
register(astroHeadBuildPlugin(internals));
2626
register(pluginPrerender(options, internals));
2727
register(astroConfigBuildPlugin(options, internals));
2828
register(pluginHoistedScripts(options, internals));

packages/astro/src/core/build/plugins/plugin-analyzer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function vitePluginAnalyzer(internals: BuildInternals): VitePlugin {
126126

127127
for (const id of ids) {
128128
const info = this.getModuleInfo(id);
129-
if (!info || !info.meta?.astro) continue;
129+
if (!info?.meta?.astro) continue;
130130

131131
const astro = info.meta.astro as AstroPluginMetadata['astro'];
132132

packages/astro/src/core/build/plugins/plugin-component-entry.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const astroEntryPrefix = '\0astro-entry:';
1010
* entries to re-export only the names the user is using.
1111
*/
1212
export function vitePluginComponentEntry(internals: BuildInternals): VitePlugin {
13-
const componentToExportNames: Map<string, string[]> = new Map();
13+
const componentToExportNames = new Map<string, string[]>();
1414

1515
mergeComponentExportNames(internals.discoveredHydratedComponents);
1616
mergeComponentExportNames(internals.discoveredClientOnlyComponents);

0 commit comments

Comments
 (0)