Skip to content

Commit ab3704a

Browse files
committed
chore(lint): prefer 'unknown' to 'any', fix lint warnings
Explicitly enable `any` usage in typescript in: - `dev-packages`, since those are largely integration and E2E tests. (This is done with the addition of a `dev-packages/.eslintrc.js` file.) - `packages/*/test/`, since those are all tests. (This is done with a rule override added to the root `.eslintrc.js` file.) - Several one-off allowances, generally for vendored types from third party sources, and cases involving method overwriting that TypeScript can't follow. (These are done with file/line overrides, explicit `as` casting, and adding type inference to the `isInstanceOf` method.) In other places (ie, in exported production code paths), replace `any` with `unknown`, and upgrade the `@typescript/no-explicit-any` lint rule to an error. This silences a lot of eslint warnings that were habitually ignored, and encourages us to not opt out of strict type safety in our exported code.
1 parent 6fd995e commit ab3704a

File tree

48 files changed

+90
-41
lines changed

Some content is hidden

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

48 files changed

+90
-41
lines changed

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ module.exports = {
2323
'types/**',
2424
'scripts/*.js',
2525
],
26+
rules: {
27+
'@typescript-eslint/no-explicit-any': 'error',
28+
},
2629
reportUnusedDisableDirectives: true,
2730
overrides: [
2831
{
@@ -36,6 +39,9 @@ module.exports = {
3639
parserOptions: {
3740
project: ['tsconfig.test.json'],
3841
},
42+
rules: {
43+
'@typescript-eslint/no-explicit-any': 'off',
44+
},
3945
},
4046
{
4147
files: ['scripts/**/*.ts'],

dev-packages/.eslintrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
extends: ['../.eslintrc.js'],
3+
rules: {
4+
// tests often have just cause to do evil
5+
'@typescript-eslint/no-explicit-any': 'off',
6+
},
7+
};

dev-packages/browser-integration-tests/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
node: true,
55
},
66
// todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project
7-
extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'],
7+
extends: ['../.eslintrc.js', 'plugin:regexp/recommended'],
88
plugins: ['regexp'],
99
ignorePatterns: [
1010
'suites/**/subject.js',

dev-packages/bundler-tests/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
extends: ['../../.eslintrc.js'],
2+
extends: ['../.eslintrc.js'],
33
parserOptions: {
44
sourceType: 'module',
55
},

dev-packages/clear-cache-gh-action/.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
// todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project
3-
extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'],
3+
extends: ['../.eslintrc.js', 'plugin:regexp/recommended'],
44
plugins: ['regexp'],
55
parserOptions: {
66
sourceType: 'module',

dev-packages/cloudflare-integration-tests/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
node: true,
44
},
55
// todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project
6-
extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'],
6+
extends: ['../.eslintrc.js', 'plugin:regexp/recommended'],
77
plugins: ['regexp'],
88
overrides: [
99
{

dev-packages/cloudflare-integration-tests/suites/tracing/google-genai/mocks.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { GoogleGenAIChat, GoogleGenAIClient, GoogleGenAIResponse } from '@s
33
export class MockGoogleGenAI implements GoogleGenAIClient {
44
public models: {
55
generateContent: (...args: unknown[]) => Promise<GoogleGenAIResponse>;
6-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
76
generateContentStream: (...args: unknown[]) => Promise<AsyncGenerator<GoogleGenAIResponse, any, unknown>>;
87
};
98
public chats: {

dev-packages/e2e-tests/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
node: true,
44
},
55
// todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project
6-
extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'],
6+
extends: ['../.eslintrc.js', 'plugin:regexp/recommended'],
77
plugins: ['regexp'],
88
ignorePatterns: ['test-applications/**', 'tmp/**'],
99
parserOptions: {

dev-packages/external-contributor-gh-action/.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
// todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project
3-
extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'],
3+
extends: ['../.eslintrc.js', 'plugin:regexp/recommended'],
44
plugins: ['regexp'],
55
parserOptions: {
66
sourceType: 'module',

dev-packages/node-core-integration-tests/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
node: true,
44
},
55
// todo: remove regexp plugin from here once we add it to base.js eslint config for the whole project
6-
extends: ['../../.eslintrc.js', 'plugin:regexp/recommended'],
6+
extends: ['../.eslintrc.js', 'plugin:regexp/recommended'],
77
plugins: ['regexp'],
88
overrides: [
99
{

0 commit comments

Comments
 (0)