Skip to content

Commit 9249841

Browse files
authored
enable a bunch more linting (#1422)
* A few more cases of avoiding excessive @typescript-eslint/no-explicit-any per file * reenable @typescript-eslint/no-unsafe-* and enable object-shorthand ban "({})" * config updates + use "!" over "as HTMLElement" where possible * build fixes + remove unknown query param "internal_usage_attribution_ids" * reenable noImplicitAny * partially enable eslint TS strictTypeChecked * partially enable stylisticTypeChecked * formatting * enable eqeqeq * enable prefer-arrow-callback * add some output to check-and-fix * disable @typescript-eslint/no-non-null-assertion this codebase uses non-null assertions a lot for document.querySelector() and similar patterns:
1 parent 33c8895 commit 9249841

98 files changed

Lines changed: 769 additions & 570 deletions

File tree

Some content is hidden

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

dist/samples/3d-label-toggle/app/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
// [START maps_3d_label_toggle]
8-
let map;
8+
let map: google.maps.maps3d.Map3DElement;
99
async function init() {
1010
const { Map3DElement } = await google.maps.importLibrary('maps3d');
1111

e2e/samples.spec.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17+
/* eslint-disable @typescript-eslint/no-unsafe-return */
18+
1719
import { test, expect } from '@playwright/test';
18-
import fs from 'fs';
19-
import path from 'path';
20+
import fs from 'node:fs';
21+
import path from 'node:path';
2022
import childProcess, { execSync } from 'child_process';
2123

2224
const samplesDir = path.join(__dirname, '..', 'samples');
@@ -203,7 +205,8 @@ foldersToTest.forEach((sampleFolder) => {
203205

204206
// Wait for Google Maps to load.
205207
await page.waitForFunction(
206-
() => window.google && window.google.maps,
208+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
209+
() => (window as any).google?.maps,
207210
{ timeout: 500 }
208211
);
209212

@@ -214,29 +217,31 @@ foldersToTest.forEach((sampleFolder) => {
214217
// The sample must load the Google Maps API.
215218
const hasGoogleMaps = await page.evaluate(() => {
216219
return (
217-
typeof window.google !== 'undefined' &&
218-
typeof window.google.maps !== 'undefined'
220+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
221+
typeof (window as any).google !== 'undefined' &&
222+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
223+
typeof (window as any).google.maps !== 'undefined'
219224
);
220225
});
221226
expect(hasGoogleMaps).toBeTruthy();
222227

223228
/** const mapElement = await page.locator('#map');
224-
if (await page.locator('#map').isVisible()) {
225-
console.log(`✅ Assertion passed: Map is visible.`);
226-
} else {
227-
console.error(`❌ Assertion failed: Map is not visible.`);
228-
throw new Error('Assertion failed: Map is not visible.');
229-
}*/
229+
if (await page.locator('#map').isVisible()) {
230+
console.log(`✅ Assertion passed: Map is visible.`);
231+
} else {
232+
console.error(`❌ Assertion failed: Map is not visible.`);
233+
throw new Error('Assertion failed: Map is not visible.');
234+
}*/
230235
} finally {
231236
// viteProcess.kill(); // We used to just kill the process. Curious to see about how the other stuff works.
232237
if (viteProcess.pid) {
233238
try {
234239
// Use process.kill for cross-platform compatibility, sending SIGINT
235240
process.kill(viteProcess.pid, 'SIGINT');
236-
} catch (e) {
241+
} catch (error) {
237242
console.warn(
238243
`Failed to kill Vite process for ${sampleFolder} (PID: ${viteProcess.pid}):`,
239-
e.message
244+
error
240245
);
241246
}
242247
}

e2e/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"extends": "../tsconfig.base.json",
33
"compilerOptions": {
4-
"rootDir": "."
4+
"rootDir": ".",
5+
"types": ["node"],
6+
"module": "NodeNext",
7+
"moduleResolution": "NodeNext"
58
},
69
"include": ["./*.ts"]
710
}

e2e/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
// IMPORTANT: Keep this file, it contains things you may need. This file is not
1818

1919
import { Page } from '@playwright/test';
20+
import process from 'node:process';
2021

2122
// from https://github.com/lit/lit.dev/blob/5d79d1e0989e68f8b5905e5271229ffe4c55265c/packages/lit-dev-tests/src/playwright/util.ts
2223

2324
export async function waitForGoogleMapsToLoad(page: Page) {
24-
await page.waitForFunction(() => window.google && window.google.maps);
25+
await page.waitForFunction(
26+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return
27+
() => (window as any).google?.maps
28+
);
2529
await page.waitForTimeout(100);
2630
}
2731

eslint.config.mjs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export default defineConfig([
1414
plugins: { js },
1515
extends: ['js/recommended'],
1616
languageOptions: { globals: { ...globals.browser, ...globals.node } },
17+
linterOptions: {
18+
reportUnusedDisableDirectives: 'error',
19+
},
1720
},
1821
tseslint.configs.recommended,
1922
{
@@ -27,14 +30,18 @@ export default defineConfig([
2730
'prefer-const': 'error',
2831
'spaced-comment': ['error', 'always'],
2932
'no-shadow': 'error',
30-
31-
// temporarily downgraded to warn for historic reasons:
32-
'no-prototype-builtins': 'warn',
33+
'no-prototype-builtins': 'off', // samples show more vanilla patterns
34+
'object-shorthand': ['error', 'always'],
35+
eqeqeq: ['error', 'always', { null: 'ignore' }],
36+
'prefer-arrow-callback': 'error',
3337
},
3438
},
3539
{
3640
files: ['**/*.ts', '**/*.tsx'],
37-
extends: [...tseslint.configs.recommendedTypeChecked],
41+
extends: [
42+
...tseslint.configs.strictTypeChecked,
43+
...tseslint.configs.stylisticTypeChecked,
44+
],
3845
languageOptions: {
3946
parserOptions: {
4047
projectService: true,
@@ -58,12 +65,20 @@ export default defineConfig([
5865
{ allowDeclarations: true, allowDefinitionFiles: true },
5966
],
6067

61-
// temporarily downgraded to warn for historic reasons:
68+
// If something is already "any", then allow member access
6269
'@typescript-eslint/no-unsafe-member-access': 'warn',
63-
'@typescript-eslint/no-unsafe-assignment': 'warn',
64-
'@typescript-eslint/no-unsafe-call': 'warn',
65-
'@typescript-eslint/no-unsafe-return': 'warn',
66-
'@typescript-eslint/no-unsafe-argument': 'warn',
70+
71+
// this codebase uses non-null assertions a lot for document.querySelector() and similar patterns:
72+
'@typescript-eslint/no-non-null-assertion': 'off',
73+
74+
// downgraded to warn for historic reasons:
75+
'@typescript-eslint/restrict-template-expressions': 'warn',
76+
'@typescript-eslint/restrict-plus-operands': 'warn',
77+
'@typescript-eslint/prefer-nullish-coalescing': 'warn',
78+
79+
// buggy. breaks the code:
80+
'@typescript-eslint/non-nullable-type-assertion-style': 'warn',
81+
'@typescript-eslint/no-unnecessary-condition': 'warn',
6782
},
6883
},
6984
{

package-lock.json

Lines changed: 18 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"build-all": "npm run clean && npm run build-all-parallel && npm run generate-index",
77
"build-all-parallel": "bash samples/build-all.sh",
88
"clean": "bash samples/clean.sh",
9-
"generate-index": "bash samples/generate-index.sh"
9+
"generate-index": "bash samples/generate-index.sh",
10+
"check-and-fix": "echo eslint... && npx eslint --fix --quiet && echo prettier... && npx prettier -w --log-level warn . && echo tsc... && find ./ -name tsconfig.json -not -path '*/dist/*' -not -path '*/node_modules/*' -exec echo '{}' \\; -exec npx tsc --noEmit -p '{}' \\;"
1011
},
1112
"workspaces": [
1213
"samples/*"
@@ -19,7 +20,7 @@
1920
"@playwright/test": "^1.59.1",
2021
"@stylistic/eslint-plugin": "^5.10.0",
2122
"@types/google.maps": "^3.64.0",
22-
"@types/node": "^25.6.0",
23+
"@types/node": "^25.6.2",
2324
"eslint": "^10.3.0",
2425
"globals": "^17.6.0",
2526
"prettier": "^3.8.3",

playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import process from 'node:process';
12
import { defineConfig, devices } from '@playwright/test';
23

34
/*

samples/3d-camera-position/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ async function initMap(): Promise<void> {
2121
const fovSlider = document.getElementById('fov') as HTMLInputElement;
2222
const rollSlider = document.getElementById('roll') as HTMLInputElement;
2323

24-
const headingVal = document.getElementById('heading-val') as HTMLElement;
25-
const tiltVal = document.getElementById('tilt-val') as HTMLElement;
26-
const rangeVal = document.getElementById('range-val') as HTMLElement;
27-
const altitudeVal = document.getElementById('altitude-val') as HTMLElement;
28-
const fovVal = document.getElementById('fov-val') as HTMLElement;
29-
const rollVal = document.getElementById('roll-val') as HTMLElement;
30-
const codeElem = document.getElementById('generated-code') as HTMLElement;
24+
const headingVal = document.getElementById('heading-val')!;
25+
const tiltVal = document.getElementById('tilt-val')!;
26+
const rangeVal = document.getElementById('range-val')!;
27+
const altitudeVal = document.getElementById('altitude-val')!;
28+
const fovVal = document.getElementById('fov-val')!;
29+
const rollVal = document.getElementById('roll-val')!;
30+
const codeElem = document.getElementById('generated-code')!;
3131
const copyBtn = document.getElementById('copy-btn') as HTMLButtonElement;
3232

3333
let currentAltitude = 30;
@@ -82,7 +82,7 @@ async function initMap(): Promise<void> {
8282
});
8383

8484
// Listen to slider changes using event delegation.
85-
const panel = document.querySelector('.panel') as HTMLElement;
85+
const panel = document.querySelector('.panel')!;
8686

8787
panel.addEventListener('input', (e) => {
8888
const target = e.target as HTMLInputElement;
@@ -121,7 +121,8 @@ async function initMap(): Promise<void> {
121121
};
122122
}
123123
} else {
124-
map3DElement[prop] = val;
124+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
125+
(map3DElement as any)[prop] = val;
125126
}
126127
updateUI();
127128
});

0 commit comments

Comments
 (0)