build: fix EsLint rule and add fixer (#11826)

This commit is contained in:
Nikolay Vitkov 2024-02-05 10:26:37 +01:00 committed by GitHub
parent 197f00547e
commit b2c69fe5bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
38 changed files with 230 additions and 34 deletions

View File

@ -172,8 +172,6 @@ module.exports = {
curly: ['error', 'all'],
// Brackets keep code readable and `return` intentions clear.
'arrow-body-style': ['error', 'always'],
// Error if comments do not adhere to `tsdoc`.
'tsdoc/syntax': 'error',
// Keeps array types simple only when they are simple for readability.
'@typescript-eslint/array-type': ['error', {default: 'array-simple'}],
'no-unused-vars': 'off',
@ -277,5 +275,14 @@ module.exports = {
},
],
},
{
// Applies to only published packages
files: ['packages/**/*.ts'],
rules: {
// Error if comments do not adhere to `tsdoc`.
'tsdoc/syntax': 'error',
},
},
],
};

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
const puppeteer = require('puppeteer');
(async () => {

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
const puppeteer = require('puppeteer');
/**

8
package-lock.json generated
View File

@ -10893,7 +10893,7 @@
"@types/yargs": "17.0.32"
},
"engines": {
"node": ">=18.17.1"
"node": ">=18"
}
},
"packages/browsers/node_modules/cliui": {
@ -10945,7 +10945,7 @@
"@schematics/angular": "^17.0.7"
},
"engines": {
"node": ">=18.17.1"
"node": ">=18"
}
},
"packages/ng-schematics/node_modules/@angular-devkit/architect": {
@ -11382,7 +11382,7 @@
"@types/node": "18.17.15"
},
"engines": {
"node": ">=18.17.1"
"node": ">=18"
}
},
"packages/puppeteer-core": {
@ -11405,7 +11405,7 @@
"rxjs": "7.8.1"
},
"engines": {
"node": ">=18.17.1"
"node": ">=18"
}
},
"packages/puppeteer-core/node_modules/@types/node": {

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import debug from 'debug';
export const mochaHooks = {

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {spawn} from 'child_process';
import {normalize, join} from 'path';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {describe, it} from 'node:test';
import expect from 'expect';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {describe, it} from 'node:test';
import expect from 'expect';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {describe, it} from 'node:test';
import expect from 'expect';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import https from 'https';
import {before, after} from 'node:test';
import {join} from 'path';

View File

@ -0,0 +1,15 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
"extends": ["@microsoft/api-extractor/extends/tsdoc-base.json"],
"tagDefinitions": [
{
"tagName": "@license",
"syntaxKind": "modifier",
"allowMultiple": false
}
],
"supportForTags": {
"@license": true
}
}

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {mkdir, readFile, readdir, writeFile} from 'fs/promises';
import {join} from 'path/posix';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import type {ProtocolMapping} from 'devtools-protocol/types/protocol-mapping.js';
import type {Connection} from '../cdp/Connection.js';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js';
import type ProtocolMapping from 'devtools-protocol/types/protocol-mapping.js';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js';
import {EventEmitter, type EventType} from '../common/EventEmitter.js';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {JSHandle} from '../api/JSHandle.js';
import {debugError} from '../common/util.js';
import {DisposableStack} from '../util/disposable.js';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {source as injectedSource} from '../generated/injected.js';
/**

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
const HIDDEN_VISIBILITY_VALUES = ['hidden', 'collapse'];
/**

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {TimeoutError} from '../common/Errors.js';
/**

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {Deferred} from './Deferred.js';
import {disposeSymbol} from './disposable.js';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
// eslint-disable-next-line no-restricted-imports
import {EventEmitter as NodeEventEmitter} from 'node:events';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {expectNotType, expectType} from 'tsd';
import type {ElementHandle} from 'puppeteer';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {expectNotAssignable, expectNotType, expectType} from 'tsd';
import type {ElementHandle, JSHandle} from 'puppeteer';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {expectType, expectNotType} from 'tsd';
import type {NodeFor} from 'puppeteer';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {expectType} from 'tsd';
import puppeteer, {

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
module.exports = {
rules: {
'no-restricted-imports': [

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
(async () => {
const [, , puppeteerRoot, options] = process.argv;
const browser = await require(puppeteerRoot).launch(JSON.parse(options));

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
(async () => {
const [, , puppeteerRoot, options] = process.argv;
const browser = await require(puppeteerRoot).launch(JSON.parse(options));

View File

@ -1,4 +1,10 @@
#!/usr/bin/env node
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
// @ts-check
'use strict';

View File

@ -11,15 +11,16 @@ const createRule = ESLintUtils.RuleCreator(name => {
return `https://github.com/puppeteer/puppeteer/tree/main/tools/eslint/${name}.ts`;
});
const copyrightPattern = /Copyright ([0-9]{4}) Google Inc\./;
const currentYear = new Date().getFullYear();
// const currentYear = new Date().getFullYear;
// const licenseHeader = `/**
// * @license
// * Copyright ${currentYear} Google Inc.
// * SPDX-License-Identifier: Apache-2.0
// */`;
// Needs to start and end with new line
const licenseHeader = `
/**
* @license
* Copyright ${currentYear} Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
`;
const enforceLicenseRule = createRule<[], 'licenseRule'>({
name: 'check-license',
@ -29,7 +30,7 @@ const enforceLicenseRule = createRule<[], 'licenseRule'>({
description: 'Validate existence of license header',
requiresTypeChecking: false,
},
fixable: undefined, // TODO: change to 'code' once fixer works.
fixable: 'code',
schema: [],
messages: {
licenseRule: 'Add license header.',
@ -39,16 +40,26 @@ const enforceLicenseRule = createRule<[], 'licenseRule'>({
create(context) {
const sourceCode = context.sourceCode;
const comments = sourceCode.getAllComments();
const header =
comments[0]?.type === 'Block' && isHeaderComment(comments[0])
? comments[0]
: null;
function isHeaderComment(comment: TSESTree.Comment) {
if (comment && comment.range[0] >= 0 && comment.range[1] <= 88) {
return true;
} else {
return false;
let insertAfter = [0, 0] as TSESTree.Range;
let header: TSESTree.Comment | null = null;
// Check only the first 2 comments
for (let index = 0; index < 2; index++) {
const comment = comments[index];
if (!comment) {
break;
}
// Shebang comments should be at the top
if (
// Types don't have it debugger showed it...
(comment.type as string) === 'Shebang' ||
(comment.type === 'Line' && comment.value.startsWith('#!'))
) {
insertAfter = comment.range;
continue;
}
if (comment.type === 'Block') {
header = comment;
break;
}
}
@ -56,23 +67,21 @@ const enforceLicenseRule = createRule<[], 'licenseRule'>({
Program(node) {
if (
header &&
header.value.includes('@license') &&
header.value.includes('SPDX-License-Identifier: Apache-2.0') &&
copyrightPattern.test(header.value)
(header.value.includes('@license') ||
header.value.includes('License') ||
header.value.includes('Copyright'))
) {
return;
}
// Add header license
if (!header || !header.value.includes('@license')) {
// const startLoc: [number, number] = [0, 88];
context.report({
node: node,
messageId: 'licenseRule',
// TODO: fix the fixer.
// fix(fixer) {
// return fixer.insertTextBeforeRange(startLoc, licenseHeader);
// },
fix(fixer) {
return fixer.insertTextAfterRange(insertAfter, licenseHeader);
},
});
}
},

View File

@ -7,7 +7,6 @@
"outDir": "./lib",
"declaration": false,
"declarationMap": false,
"sourceMap": false,
"composite": false,
"removeComments": true,
},

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/**
* "Archives" older versions of the website docs to reduce the build time:
*

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
module.exports = {
docs: [

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {DocSearchButton, useDocSearchKeyboardEvents} from '@docsearch/react';
import Head from '@docusaurus/Head';
import Link from '@docusaurus/Link';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import Head from '@docusaurus/Head';
import React from 'react';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
import Head from '@docusaurus/Head';
import Link from '@docusaurus/Link';

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
const url = new URL(window.location.href);
if (url.pathname.endsWith('/') && url.pathname !== '/') {
url.pathname = url.pathname.substring(0, url.pathname.length - 1);

View File

@ -1,3 +1,8 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
self.addEventListener('install', () => {
self.skipWaiting();
});