From d3b5e5696f33e0397bc4fad808c576ef02a20e94 Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Tue, 5 May 2020 13:12:39 -0700 Subject: [PATCH] style(dev-infra): enforce format on newly included files (#36940) Historically files to be formatted were added to a listing (via matchers) to be included in formatting. Instead, this change begins efforts to instead include all files in format enforcement, relying instead on an opt out methodology. PR Close #36940 --- .circleci/trigger-webhook.js | 28 +++++++------- scripts/browserstack/start_tunnel.js | 13 ++----- scripts/build/dev-infra-builder.js | 4 +- scripts/build/package-builder.js | 14 +++++-- scripts/ci/payload-size.js | 14 ++++--- scripts/github/utils/github_closes.js | 2 +- scripts/github/utils/json_extract.js | 8 ++-- scripts/github/utils/json_extract_test.js | 46 ++++++++++++----------- scripts/puppeteer-chrome-versions.js | 26 ++++++------- scripts/webdriver-manager-update.js | 9 +++-- tools/gulp-tasks/cldr/extract.js | 7 ++-- 11 files changed, 88 insertions(+), 83 deletions(-) mode change 100755 => 100644 scripts/github/utils/github_closes.js mode change 100755 => 100644 scripts/webdriver-manager-update.js diff --git a/.circleci/trigger-webhook.js b/.circleci/trigger-webhook.js index 77860186bc..88c1b700dc 100644 --- a/.circleci/trigger-webhook.js +++ b/.circleci/trigger-webhook.js @@ -60,14 +60,15 @@ if (require.resolve === module) { // Helpers function _main(args) { - triggerWebhook(...args). - then(({statusCode, responseText}) => (200 <= statusCode && statusCode < 400) ? - console.log(`Status: ${statusCode}\n${responseText}`) : - Promise.reject(new Error(`Request failed (status: ${statusCode}): ${responseText}`))). - catch(err => { - console.error(err); - process.exit(1); - }); + triggerWebhook(...args) + .then( + ({statusCode, responseText}) => (200 <= statusCode && statusCode < 400) ? + console.log(`Status: ${statusCode}\n${responseText}`) : + Promise.reject(new Error(`Request failed (status: ${statusCode}): ${responseText}`))) + .catch(err => { + console.error(err); + process.exit(1); + }); } function postJson(url, data) { @@ -77,15 +78,12 @@ function postJson(url, data) { const statusCode = res.statusCode || -1; let responseText = ''; - res. - on('error', reject). - on('data', d => responseText += d). - on('end', () => resolve({statusCode, responseText})); + res.on('error', reject) + .on('data', d => responseText += d) + .on('end', () => resolve({statusCode, responseText})); }; - request(url, opts, onResponse). - on('error', reject). - end(JSON.stringify(data)); + request(url, opts, onResponse).on('error', reject).end(JSON.stringify(data)); }); } diff --git a/scripts/browserstack/start_tunnel.js b/scripts/browserstack/start_tunnel.js index 6d184692b3..64c1c8105d 100644 --- a/scripts/browserstack/start_tunnel.js +++ b/scripts/browserstack/start_tunnel.js @@ -24,18 +24,11 @@ var hosts = []; PORTS.forEach(function(port) { fakeServers.push(http.createServer(function() {}).listen(port)); - hosts.push({ - name: HOSTNAME, - port: port, - sslFlag: 0 - }); + hosts.push({name: HOSTNAME, port: port, sslFlag: 0}); }); -var tunnel = new BrowserStackTunnel({ - key: ACCESS_KEY, - localIdentifier: TUNNEL_IDENTIFIER, - hosts: hosts -}); +var tunnel = + new BrowserStackTunnel({key: ACCESS_KEY, localIdentifier: TUNNEL_IDENTIFIER, hosts: hosts}); console.info('Starting tunnel on ports', PORTS.join(', ')); tunnel.start(function(error) { diff --git a/scripts/build/dev-infra-builder.js b/scripts/build/dev-infra-builder.js index cfcdde72cf..625f8aaacf 100644 --- a/scripts/build/dev-infra-builder.js +++ b/scripts/build/dev-infra-builder.js @@ -33,6 +33,4 @@ function buildDevInfraPackage() { console.info(''); } -module.exports = { - buildDevInfraPackage -}; +module.exports = {buildDevInfraPackage}; diff --git a/scripts/build/package-builder.js b/scripts/build/package-builder.js index 66325ab4f1..ab518e627f 100644 --- a/scripts/build/package-builder.js +++ b/scripts/build/package-builder.js @@ -47,7 +47,12 @@ const bazelBin = exec(`${bazelCmd} info bazel-bin`, true); const scriptPath = relative(baseDir, require.main.filename); module.exports = { - baseDir, bazelBin, bazelCmd, buildTargetPackages, exec, scriptPath, + baseDir, + bazelBin, + bazelCmd, + buildTargetPackages, + exec, + scriptPath, }; /** @@ -68,12 +73,13 @@ function buildTargetPackages(destPath, enableIvy, description) { // List of targets to build, e.g. core, common, compiler, etc. Note that we want to also remove // all carriage return (`\r`) characters form the query output, because otherwise the carriage // return is part of the bazel target name and bazel will complain. - const getTargetsCmd = - `${bazelCmd} query --output=label "attr('tags', '\\[.*release-with-framework.*\\]', //packages/...) intersect kind('ng_package|pkg_npm', //packages/...)"`; + const getTargetsCmd = `${ + bazelCmd} query --output=label "attr('tags', '\\[.*release-with-framework.*\\]', //packages/...) intersect kind('ng_package|pkg_npm', //packages/...)"`; const targets = exec(getTargetsCmd, true).split(/\r?\n/); // Use `--config=release` so that snapshot builds get published with embedded version info. - exec(`${bazelCmd} build --config=release --config=${enableIvy ? 'ivy' : 'view-engine'} ${targets.join(' ')}`); + exec(`${bazelCmd} build --config=release --config=${enableIvy ? 'ivy' : 'view-engine'} ${ + targets.join(' ')}`); // Create the output directory. const absDestPath = resolve(baseDir, destPath); diff --git a/scripts/ci/payload-size.js b/scripts/ci/payload-size.js index 04bda126b3..19c9114a52 100644 --- a/scripts/ci/payload-size.js +++ b/scripts/ci/payload-size.js @@ -50,11 +50,14 @@ for (const compressionType in limitSizes) { const operator = actualSize > expectedSize ? 'exceeded' : 'fell below'; failureMessages.push( - `FAIL: Commit ${commit} ${compressionType} ${filename} ${operator} expected size by 500 bytes or >1% ` + - `(expected: ${expectedSize}, actual: ${actualSize}).`); + `FAIL: Commit ${commit} ${compressionType} ${filename} ${ + operator} expected size by 500 bytes or >1% ` + + `(expected: ${expectedSize}, actual: ${actualSize}).`); } else { - successMessages.push(`SUCCESS: Commit ${commit} ${compressionType} ${filename} did NOT cross size threshold of 500 bytes or >1% ` + - `(expected: ${expectedSize}, actual: ${actualSize}).`); + successMessages.push( + `SUCCESS: Commit ${commit} ${compressionType} ${ + filename} did NOT cross size threshold of 500 bytes or >1% ` + + `(expected: ${expectedSize}, actual: ${actualSize}).`); } } } @@ -65,7 +68,8 @@ for (const compressionType in limitSizes) { successMessages.concat(failureMessages).forEach(message => console.error(message)); if (failed) { - console.info(`If this is a desired change, please update the size limits in file '${limitFile}'.`); + console.info( + `If this is a desired change, please update the size limits in file '${limitFile}'.`); process.exit(1); } else { console.info(`Payload size check passed. All diffs are less than 1% or 500 bytes.`); diff --git a/scripts/github/utils/github_closes.js b/scripts/github/utils/github_closes.js old mode 100755 new mode 100644 index f1851794a8..77b0f7d610 --- a/scripts/github/utils/github_closes.js +++ b/scripts/github/utils/github_closes.js @@ -28,7 +28,7 @@ if (require.main === module) { function rewriteMsg(msg, prNo) { var lines = msg.split(/\n/); - lines[0] += ' (#' + prNo +')'; + lines[0] += ' (#' + prNo + ')'; lines.push('PR Close #' + prNo); return lines.join('\n'); } diff --git a/scripts/github/utils/json_extract.js b/scripts/github/utils/json_extract.js index 7a86ecfa61..045ca91954 100644 --- a/scripts/github/utils/json_extract.js +++ b/scripts/github/utils/json_extract.js @@ -34,14 +34,14 @@ function extractPaths(obj, paths) { paths.forEach(function(exp) { var objs = obj instanceof Array ? [].concat(obj) : [obj]; exp.split('.').forEach(function(name) { - for(var i = 0; i < objs.length; i++) { + for (var i = 0; i < objs.length; i++) { var o = objs[i]; if (o instanceof Array) { // Expand and do over - objs = objs.slice(0, i).concat(o).concat(objs.slice(i+1, objs.length)); + objs = objs.slice(0, i).concat(o).concat(objs.slice(i + 1, objs.length)); i--; } else { - name.split("=").forEach(function(name, index) { + name.split('=').forEach(function(name, index) { if (index == 0) { objs[i] = o = o[name]; } else if (name.charAt(0) == '^') { @@ -54,7 +54,7 @@ function extractPaths(obj, paths) { } } }); - lines.push(objs.join("|")); + lines.push(objs.join('|')); }); return lines; } diff --git a/scripts/github/utils/json_extract_test.js b/scripts/github/utils/json_extract_test.js index 1afd40b26b..e15684f534 100644 --- a/scripts/github/utils/json_extract_test.js +++ b/scripts/github/utils/json_extract_test.js @@ -8,40 +8,42 @@ * found in the LICENSE file at https://angular.io/license */ -var assert = require("assert"); +var assert = require('assert'); var extractPaths = require('./json_extract').extractPaths; var SAMPLE_LABELS = [ { - "id": 149476251, - "url": "https://api.github.com/repos/angular/angular/labels/cla:%20yes", - "name": "cla: yes", - "color": "009800", - "default": false + 'id': 149476251, + 'url': 'https://api.github.com/repos/angular/angular/labels/cla:%20yes', + 'name': 'cla: yes', + 'color': '009800', + 'default': false }, { - "id": 533874619, - "url": "https://api.github.com/repos/angular/angular/labels/comp:%20aio", - "name": "comp: aio", - "color": "c7def8", - "default": false + 'id': 533874619, + 'url': 'https://api.github.com/repos/angular/angular/labels/comp:%20aio', + 'name': 'comp: aio', + 'color': 'c7def8', + 'default': false }, { - "id": 133556520, - "url": "https://api.github.com/repos/angular/angular/labels/PR%20action:%20merge", - "name": "PR action: merge", - "color": "99ff66", - "default": false + 'id': 133556520, + 'url': 'https://api.github.com/repos/angular/angular/labels/PR%20action:%20merge', + 'name': 'PR action: merge', + 'color': '99ff66', + 'default': false }, { - "id": 655699838, - "url": "https://api.github.com/repos/angular/angular/labels/PR%20target:%20master%20&%20patch", - "name": "PR target: master & patch", - "color": "5319e7", - "default": false + 'id': 655699838, + 'url': 'https://api.github.com/repos/angular/angular/labels/PR%20target:%20master%20&%20patch', + 'name': 'PR target: master & patch', + 'color': '5319e7', + 'default': false } ]; assert.deepEqual(extractPaths({head: {label: 'value1'}}, ['head.label']), ['value1']); -assert.deepEqual(extractPaths(SAMPLE_LABELS, ['name']), ['cla: yes|comp: aio|PR action: merge|PR target: master & patch']); +assert.deepEqual( + extractPaths(SAMPLE_LABELS, ['name']), + ['cla: yes|comp: aio|PR action: merge|PR target: master & patch']); assert.deepEqual(extractPaths(SAMPLE_LABELS, ['name=^PR target:']), ['PR target: master & patch']); diff --git a/scripts/puppeteer-chrome-versions.js b/scripts/puppeteer-chrome-versions.js index 91231d0e60..9918ebc13f 100644 --- a/scripts/puppeteer-chrome-versions.js +++ b/scripts/puppeteer-chrome-versions.js @@ -13,17 +13,17 @@ // "chromium_revision": "722234" but this does not map easily to the Chrome version // so we use this mapping here instead. module.exports = { - "3.3.0": "83.0.4103.0", - "3.2.0": "83.0.4103.0", - "3.1.0": "83.0.4103.0", - "3.0.0": "81.0.4044.0", - "2.1.1": "80.0.3987.0", - "2.1.0": "80.0.3987.0", - "2.0.0": "79.0.3942.0", - "1.20.0": "78.0.3882.0", - "1.19.0": "77.0.3803.0", - "1.17.0": "76.0.3803.0", - "1.15.0": "75.0.3765.0", - "1.13.0": "74.0.3723.0", - "1.12.2": "73.0.3679.0", + '3.3.0': '83.0.4103.0', + '3.2.0': '83.0.4103.0', + '3.1.0': '83.0.4103.0', + '3.0.0': '81.0.4044.0', + '2.1.1': '80.0.3987.0', + '2.1.0': '80.0.3987.0', + '2.0.0': '79.0.3942.0', + '1.20.0': '78.0.3882.0', + '1.19.0': '77.0.3803.0', + '1.17.0': '76.0.3803.0', + '1.15.0': '75.0.3765.0', + '1.13.0': '74.0.3723.0', + '1.12.2': '73.0.3679.0', }; diff --git a/scripts/webdriver-manager-update.js b/scripts/webdriver-manager-update.js old mode 100755 new mode 100644 index e57e7556ea..384e69c107 --- a/scripts/webdriver-manager-update.js +++ b/scripts/webdriver-manager-update.js @@ -16,7 +16,8 @@ const spawnSync = require('child_process').spawnSync; const version = chromeVersionMap[puppeteerVersion]; if (!version) { - console.error(`[webdriver-manager-update.js] Error: Could not find Chrome version for Puppeteer version '${puppeteerVersion}' in Chrome/Puppeteer version map. Please update /scripts/puppeteer-chrome-versions.js.`); + console.error(`[webdriver-manager-update.js] Error: Could not find Chrome version for Puppeteer version '${ + puppeteerVersion}' in Chrome/Puppeteer version map. Please update /scripts/puppeteer-chrome-versions.js.`); process.exit(1); } @@ -33,10 +34,12 @@ const args = [ const result = spawnSync('yarn', args, {shell: true, stdio: 'inherit'}); if (result.error) { - console.error(`[webdriver-manager-update.js] Call to 'yarn ${args.join(' ')}' failed with error code ${result.error.code}`); + console.error(`[webdriver-manager-update.js] Call to 'yarn ${ + args.join(' ')}' failed with error code ${result.error.code}`); process.exit(result.status); } if (result.status) { - console.error(`[webdriver-manager-update.js] Call to 'yarn ${args.join(' ')}' failed with error code ${result.status}`); + console.error(`[webdriver-manager-update.js] Call to 'yarn ${ + args.join(' ')}' failed with error code ${result.status}`); process.exit(result.status); } diff --git a/tools/gulp-tasks/cldr/extract.js b/tools/gulp-tasks/cldr/extract.js index b9955d09b0..73caa43c6c 100644 --- a/tools/gulp-tasks/cldr/extract.js +++ b/tools/gulp-tasks/cldr/extract.js @@ -91,13 +91,13 @@ module.exports = (gulp, done) => { `${RELATIVE_I18N_GLOBAL_FOLDER}/${locale}.js`, generateGlobalLocale( locale, locale === 'en' ? new cldrJs('en') : localeData, baseCurrencies)); - }); console.log(`${LOCALES.length} locale files generated.`); console.log(`All i18n cldr files have been generated, formatting files..."`); shelljs.exec( - `yarn clang-format -i ${I18N_DATA_FOLDER}/**/*.ts ${I18N_DATA_FOLDER}/*.ts ${I18N_FOLDER}/currencies.ts ${I18N_CORE_FOLDER}/locale_en.ts ${I18N_GLOBAL_FOLDER}/*.js`, + `yarn clang-format -i ${I18N_DATA_FOLDER}/**/*.ts ${I18N_DATA_FOLDER}/*.ts ${ + I18N_FOLDER}/currencies.ts ${I18N_CORE_FOLDER}/locale_en.ts ${I18N_GLOBAL_FOLDER}/*.js`, {silent: true}); done(); }; @@ -278,7 +278,8 @@ function generateCurrenciesFile() { export type CurrenciesSymbols = [string] | [string | undefined, string]; /** @internal */ -export const CURRENCIES_EN: {[code: string]: CurrenciesSymbols | [string | undefined, string | undefined, number]} = ${stringify(baseCurrencies, true)}; +export const CURRENCIES_EN: {[code: string]: CurrenciesSymbols | [string | undefined, string | undefined, number]} = ${ + stringify(baseCurrencies, true)}; `; }