Skip to content

Commit aa9f6fb

Browse files
authored
cherry-pick(#29669): chore: strengthen linting (#29674)
1 parent f5899c1 commit aa9f6fb

File tree

21 files changed

+105
-58
lines changed

21 files changed

+105
-58
lines changed

.eslintrc-with-ts-config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
extends: "./.eslintrc.js",
3+
parserOptions: {
4+
ecmaVersion: 9,
5+
sourceType: "module",
6+
project: "./tsconfig.json",
7+
},
8+
rules: {
9+
"@typescript-eslint/no-base-to-string": "error",
10+
"@typescript-eslint/no-unnecessary-boolean-literal-compare": 2,
11+
},
12+
parserOptions: {
13+
project: "./tsconfig.json"
14+
},
15+
};

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module.exports = {
44
parserOptions: {
55
ecmaVersion: 9,
66
sourceType: "module",
7-
project: "./tsconfig.json",
87
},
98
extends: [
109
"plugin:react-hooks/recommended"
@@ -49,6 +48,7 @@ module.exports = {
4948
"arrow-parens": [2, "as-needed"],
5049
"prefer-const": 2,
5150
"quote-props": [2, "consistent"],
51+
"nonblock-statement-body-position": [2, "below"],
5252

5353
// anti-patterns
5454
"no-var": 2,

docs/src/service-workers-experimental-network-events-js.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,12 @@ self.addEventListener('fetch', event => {
137137
(async () => {
138138
// 1. Try to first serve directly from caches
139139
const response = await caches.match(event.request);
140-
if (response) return response;
140+
if (response)
141+
return response;
141142

142143
// 2. Re-write request for /foo to /bar
143-
if (event.request.url.endsWith('foo')) return fetch('./bar');
144+
if (event.request.url.endsWith('foo'))
145+
return fetch('./bar');
144146

145147
// 3. Prevent tracker.js from being retrieved, and returns a placeholder response
146148
if (event.request.url.endsWith('tracker.js')) {

packages/.eslintrc-with-ts-config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
extends: "../.eslintrc-with-ts-config.js",
2+
extends: "../../.eslintrc-with-ts-config.js",
33
};

packages/playwright-core/src/client/browserContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ export async function prepareBrowserContextParams(options: BrowserContextOptions
526526
function toAcceptDownloadsProtocol(acceptDownloads?: boolean) {
527527
if (acceptDownloads === undefined)
528528
return undefined;
529-
if (acceptDownloads === true)
529+
if (acceptDownloads)
530530
return 'accept';
531531
return 'deny';
532532
}

packages/playwright-core/src/server/chromium/crBrowser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,8 @@ export class CRBrowserContext extends BrowserContext {
594594
targetId = (page._delegate as CRPage)._targetId;
595595
} else if (page instanceof Frame) {
596596
const session = (page._page._delegate as CRPage)._sessions.get(page._id);
597-
if (!session) throw new Error(`This frame does not have a separate CDP session, it is a part of the parent frame's session`);
597+
if (!session)
598+
throw new Error(`This frame does not have a separate CDP session, it is a part of the parent frame's session`);
598599
targetId = session._targetId;
599600
} else {
600601
throw new Error('page: expected Page or Frame');

packages/playwright-core/src/server/injected/vueSelectorEngine.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,18 @@ function buildComponentsTreeVue3(instance: VueVNode): ComponentNode {
8686
// @see https://github.com/vuejs/devtools/blob/e7132f3392b975e39e1d9a23cf30456c270099c2/packages/app-backend-vue3/src/components/util.ts#L29
8787
function getInstanceName(instance: VueVNode): string {
8888
const name = getComponentTypeName(instance.type || {});
89-
if (name) return name;
90-
if (instance.root === instance) return 'Root';
91-
for (const key in instance.parent?.type?.components)
92-
if (instance.parent?.type.components[key] === instance.type) return saveComponentName(instance, key);
93-
for (const key in instance.appContext?.components)
94-
if (instance.appContext.components[key] === instance.type) return saveComponentName(instance, key);
89+
if (name)
90+
return name;
91+
if (instance.root === instance)
92+
return 'Root';
93+
for (const key in instance.parent?.type?.components) {
94+
if (instance.parent?.type.components[key] === instance.type)
95+
return saveComponentName(instance, key);
96+
}
97+
for (const key in instance.appContext?.components) {
98+
if (instance.appContext.components[key] === instance.type)
99+
return saveComponentName(instance, key);
100+
}
95101
return 'Anonymous Component';
96102
}
97103

@@ -132,7 +138,8 @@ function buildComponentsTreeVue3(instance: VueVNode): ComponentNode {
132138

133139
// @see https://github.com/vuejs/devtools/blob/e7132f3392b975e39e1d9a23cf30456c270099c2/packages/app-backend-vue3/src/components/el.ts#L15
134140
function getFragmentRootElements(vnode: any): Element[] {
135-
if (!vnode.children) return [];
141+
if (!vnode.children)
142+
return [];
136143

137144
const list = [];
138145

packages/playwright-core/src/utils/isomorphic/cssTokenizer.ts

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ function preprocess(str: string): number[] {
4848
if (code === 0xd && str.charCodeAt(i + 1) === 0xa) {
4949
code = 0xa; i++;
5050
}
51-
if (code === 0xd || code === 0xc) code = 0xa;
52-
if (code === 0x0) code = 0xfffd;
51+
if (code === 0xd || code === 0xc)
52+
code = 0xa;
53+
if (code === 0x0)
54+
code = 0xfffd;
5355
if (between(code, 0xd800, 0xdbff) && between(str.charCodeAt(i + 1), 0xdc00, 0xdfff)) {
5456
// Decode a surrogate pair into an astral codepoint.
5557
const lead = code - 0xd800;
@@ -63,7 +65,8 @@ function preprocess(str: string): number[] {
6365
}
6466

6567
function stringFromCode(code: number) {
66-
if (code <= 0xffff) return String.fromCharCode(code);
68+
if (code <= 0xffff)
69+
return String.fromCharCode(code);
6770
// Otherwise, encode astral char as surrogate pair.
6871
code -= Math.pow(2, 16);
6972
const lead = Math.floor(code / Math.pow(2, 10)) + 0xd800;
@@ -107,8 +110,10 @@ export function tokenize(str1: string): CSSTokenInterface[] {
107110
num = 1;
108111
i += num;
109112
code = codepoint(i);
110-
if (newline(code)) incrLineno();
111-
else column += num;
113+
if (newline(code))
114+
incrLineno();
115+
else
116+
column += num;
112117
// console.log('Consume '+i+' '+String.fromCharCode(code) + ' 0x' + code.toString(16));
113118
return true;
114119
};
@@ -125,7 +130,8 @@ export function tokenize(str1: string): CSSTokenInterface[] {
125130
return true;
126131
};
127132
const eof = function(codepoint?: number): boolean {
128-
if (codepoint === undefined) codepoint = code;
133+
if (codepoint === undefined)
134+
codepoint = code;
129135
return codepoint === -1;
130136
};
131137
const donothing = function() { };
@@ -138,12 +144,14 @@ export function tokenize(str1: string): CSSTokenInterface[] {
138144
consumeComments();
139145
consume();
140146
if (whitespace(code)) {
141-
while (whitespace(next())) consume();
147+
while (whitespace(next()))
148+
consume();
142149
return new WhitespaceToken();
143150
} else if (code === 0x22) {return consumeAStringToken();} else if (code === 0x23) {
144151
if (namechar(next()) || areAValidEscape(next(1), next(2))) {
145152
const token = new HashToken('');
146-
if (wouldStartAnIdentifier(next(1), next(2), next(3))) token.type = 'id';
153+
if (wouldStartAnIdentifier(next(1), next(2), next(3)))
154+
token.type = 'id';
147155
token.value = consumeAName();
148156
return token;
149157
} else {
@@ -288,7 +296,8 @@ export function tokenize(str1: string): CSSTokenInterface[] {
288296
const str = consumeAName();
289297
if (str.toLowerCase() === 'url' && next() === 0x28) {
290298
consume();
291-
while (whitespace(next(1)) && whitespace(next(2))) consume();
299+
while (whitespace(next(1)) && whitespace(next(2)))
300+
consume();
292301
if (next() === 0x22 || next() === 0x27)
293302
return new FunctionToken(str);
294303
else if (whitespace(next()) && (next(2) === 0x22 || next(2) === 0x27))
@@ -305,7 +314,8 @@ export function tokenize(str1: string): CSSTokenInterface[] {
305314
};
306315

307316
const consumeAStringToken = function(endingCodePoint?: number): CSSParserToken {
308-
if (endingCodePoint === undefined) endingCodePoint = code;
317+
if (endingCodePoint === undefined)
318+
endingCodePoint = code;
309319
let string = '';
310320
while (consume()) {
311321
if (code === endingCodePoint || eof()) {
@@ -331,13 +341,16 @@ export function tokenize(str1: string): CSSTokenInterface[] {
331341

332342
const consumeAURLToken = function(): CSSTokenInterface {
333343
const token = new URLToken('');
334-
while (whitespace(next())) consume();
335-
if (eof(next())) return token;
344+
while (whitespace(next()))
345+
consume();
346+
if (eof(next()))
347+
return token;
336348
while (consume()) {
337349
if (code === 0x29 || eof()) {
338350
return token;
339351
} else if (whitespace(code)) {
340-
while (whitespace(next())) consume();
352+
while (whitespace(next()))
353+
consume();
341354
if (next() === 0x29 || eof(next())) {
342355
consume();
343356
return token;
@@ -379,9 +392,11 @@ export function tokenize(str1: string): CSSTokenInterface[] {
379392
break;
380393
}
381394
}
382-
if (whitespace(next())) consume();
395+
if (whitespace(next()))
396+
consume();
383397
let value = parseInt(digits.map(function(x) { return String.fromCharCode(x); }).join(''), 16);
384-
if (value > maximumallowedcodepoint) value = 0xfffd;
398+
if (value > maximumallowedcodepoint)
399+
value = 0xfffd;
385400
return value;
386401
} else if (eof()) {
387402
return 0xfffd;
@@ -391,8 +406,10 @@ export function tokenize(str1: string): CSSTokenInterface[] {
391406
};
392407

393408
const areAValidEscape = function(c1: number, c2: number) {
394-
if (c1 !== 0x5c) return false;
395-
if (newline(c2)) return false;
409+
if (c1 !== 0x5c)
410+
return false;
411+
if (newline(c2))
412+
return false;
396413
return true;
397414
};
398415
const startsWithAValidEscape = function() {
@@ -416,11 +433,14 @@ export function tokenize(str1: string): CSSTokenInterface[] {
416433

417434
const wouldStartANumber = function(c1: number, c2: number, c3: number) {
418435
if (c1 === 0x2b || c1 === 0x2d) {
419-
if (digit(c2)) return true;
420-
if (c2 === 0x2e && digit(c3)) return true;
436+
if (digit(c2))
437+
return true;
438+
if (c2 === 0x2e && digit(c3))
439+
return true;
421440
return false;
422441
} else if (c1 === 0x2e) {
423-
if (digit(c2)) return true;
442+
if (digit(c2))
443+
return true;
424444
return false;
425445
} else if (digit(c1)) {
426446
return true;
@@ -519,7 +539,8 @@ export function tokenize(str1: string): CSSTokenInterface[] {
519539
while (!eof(next())) {
520540
tokens.push(consumeAToken());
521541
iterationCount++;
522-
if (iterationCount > str.length * 2) throw new Error("I'm infinite-looping!");
542+
if (iterationCount > str.length * 2)
543+
throw new Error("I'm infinite-looping!");
523544
}
524545
return tokens;
525546
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
extends: "../.eslintrc-with-ts-config.js",
2+
extends: "../../.eslintrc-with-ts-config.js",
33
};

0 commit comments

Comments
 (0)