Skip to content

Commit dc62446

Browse files
josephperrottdylhunn
authored andcommitted
refactor: migrate tools to prettier formatting (angular#53947)
Migrate formatting to prettier for tools directory from clang-format PR Close angular#53947
1 parent 4ca81b0 commit dc62446

28 files changed

+706
-560
lines changed

.ng-dev/format.mts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import {FormatConfig} from '@angular/ng-dev';
55
*/
66
export const format: FormatConfig = {
77
'prettier': {
8-
'matchers': ['**/*.{yaml,yml}'],
8+
'matchers': [
9+
'**/*.{yaml,yml}',
10+
'tools/**/*.{js,ts}',
11+
],
912
},
1013
'clang-format': {
1114
'matchers': [
@@ -31,6 +34,9 @@ export const format: FormatConfig = {
3134
'!packages/common/src/i18n/currencies.ts',
3235
// Temporarily disable formatting for adev
3336
'!adev/**',
37+
38+
// Migrated to prettier
39+
'!tools/**/*.{js,ts}',
3440
],
3541
},
3642
'buildifier': true,

tools/circular_dependency_test/madge-resolve.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ class BazelRunfileResolutionPlugin {
2222
// Update the request to refer to the runfile resolved file path.
2323
resolver.doResolve('resolve', {...request, request: resolvedPath}, null, callback, true);
2424
return;
25-
} catch {
26-
}
25+
} catch {}
2726
// If the file could not be resolved through Bazel's runfile resolution, proceed
2827
// with the default module resolvers.
2928
callback();
@@ -34,5 +33,5 @@ class BazelRunfileResolutionPlugin {
3433
// Configures a plugin which ensures that Madge can properly resolve specified
3534
// dependencies through their configured module names.
3635
module.exports = {
37-
resolve: {plugins: [new BazelRunfileResolutionPlugin()]}
36+
resolve: {plugins: [new BazelRunfileResolutionPlugin()]},
3837
};

tools/contributing-stats/get-data.ts

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ const REPOS = ['angular', 'components', 'angular-cli'];
3434
/**
3535
* Handle flags for the script.
3636
*/
37-
const args = yargs.option('use-created', {type: 'boolean'})
38-
.option('since', {type: 'string', demandOption: true})
39-
.strictOptions()
40-
.argv;
37+
const args = yargs
38+
.option('use-created', {type: 'boolean'})
39+
.option('since', {type: 'string', demandOption: true})
40+
.strictOptions().argv;
4141

4242
/**
4343
* Authenticated instance of Github GraphQl API service, relies on a
@@ -48,7 +48,7 @@ const graphql = unauthenticatedGraphql.defaults({
4848
// TODO(josephperrott): Remove reference to TOKEN environment variable as part of larger
4949
// effort to migrate to expecting tokens via GITHUB_ACCESS_TOKEN environment variables.
5050
authorization: `token ${process.env['TOKEN'] || process.env['GITHUB_ACCESS_TOKEN']}`,
51-
}
51+
},
5252
});
5353

5454
/**
@@ -57,27 +57,32 @@ const graphql = unauthenticatedGraphql.defaults({
5757
async function getAllOrgMembers() {
5858
// The GraphQL query object to get a page of members of an organization.
5959
const MEMBERS_QUERY = params(
60-
{
61-
$first: 'Int', // How many entries to get with each request
62-
$after: 'String', // The cursor to start the page at
63-
$owner: 'String!', // The organization to query for
64-
},
65-
{
66-
organization: params({login: '$owner'}, {
60+
{
61+
$first: 'Int', // How many entries to get with each request
62+
$after: 'String', // The cursor to start the page at
63+
$owner: 'String!', // The organization to query for
64+
},
65+
{
66+
organization: params(
67+
{login: '$owner'},
68+
{
6769
membersWithRole: params(
68-
{
69-
first: '$first',
70-
after: '$after',
70+
{
71+
first: '$first',
72+
after: '$after',
73+
},
74+
{
75+
nodes: [{login: types.string}],
76+
pageInfo: {
77+
hasNextPage: types.boolean,
78+
endCursor: types.string,
7179
},
72-
{
73-
nodes: [{login: types.string}],
74-
pageInfo: {
75-
hasNextPage: types.boolean,
76-
endCursor: types.string,
77-
},
78-
}),
79-
})
80-
});
80+
},
81+
),
82+
},
83+
),
84+
},
85+
);
8186
const query = graphqlQuery('members', MEMBERS_QUERY);
8287

8388
/**
@@ -103,10 +108,11 @@ async function getAllOrgMembers() {
103108

104109
while (hasNextPage) {
105110
const {query, params} = queryBuilder(100, cursor);
106-
const results = await graphql(query.toString(), params) as typeof MEMBERS_QUERY;
111+
const results = (await graphql(query.toString(), params)) as typeof MEMBERS_QUERY;
107112

108-
results.organization.membersWithRole.nodes.forEach(
109-
(node: {login: string}) => members.push(node.login));
113+
results.organization.membersWithRole.nodes.forEach((node: {login: string}) =>
114+
members.push(node.login),
115+
);
110116
hasNextPage = results.organization.membersWithRole.pageInfo.hasNextPage;
111117
cursor = results.organization.membersWithRole.pageInfo.endCursor;
112118
}
@@ -121,7 +127,7 @@ async function getAllOrgMembers() {
121127
function buildQueryAndParams(username: string, date: string) {
122128
// Whether the updated or created timestamp should be used.
123129
const updatedOrCreated = args['use-created'] ? 'created' : 'updated';
124-
let dataQueries: {[key: string]: {query: string, label: string}} = {};
130+
let dataQueries: {[key: string]: {query: string; label: string}} = {};
125131
// Add queries and params for all values queried for each repo.
126132
for (let repo of REPOS) {
127133
dataQueries = {
@@ -131,8 +137,7 @@ function buildQueryAndParams(username: string, date: string) {
131137
label: `${ORG}/${repo} Issue Authored`,
132138
},
133139
[`${repo.replace(/[\/\-]/g, '_')}_issues_involved`]: {
134-
query: `repo:${ORG}/${repo} is:issue -author:${username} involves:${username} ${
135-
updatedOrCreated}:>${date}`,
140+
query: `repo:${ORG}/${repo} is:issue -author:${username} involves:${username} ${updatedOrCreated}:>${date}`,
136141
label: `${ORG}/${repo} Issue Involved`,
137142
},
138143
[`${repo.replace(/[\/\-]/g, '_')}_pr_author`]: {
@@ -144,13 +149,11 @@ function buildQueryAndParams(username: string, date: string) {
144149
label: `${ORG}/${repo} PR Involved`,
145150
},
146151
[`${repo.replace(/[\/\-]/g, '_')}_pr_reviewed`]: {
147-
query: `repo:${ORG}/${repo} is:pr -author:${username} reviewed-by:${username} ${
148-
updatedOrCreated}:>${date}`,
152+
query: `repo:${ORG}/${repo} is:pr -author:${username} reviewed-by:${username} ${updatedOrCreated}:>${date}`,
149153
label: `${ORG}/${repo} PR Reviewed`,
150154
},
151155
[`${repo.replace(/[\/\-]/g, '_')}_pr_commented`]: {
152-
query: `repo:${ORG}/${repo} is:pr -author:${username} commenter:${username} ${
153-
updatedOrCreated}:>${date}`,
156+
query: `repo:${ORG}/${repo} is:pr -author:${username} commenter:${username} ${updatedOrCreated}:>${date}`,
154157
label: `${ORG}/${repo} PR Commented`,
155158
},
156159
};
@@ -163,8 +166,7 @@ function buildQueryAndParams(username: string, date: string) {
163166
label: `${ORG} org Issue Authored`,
164167
},
165168
[`${ORG}_org_issues_involved`]: {
166-
query: `org:${ORG} is:issue -author:${username} involves:${username} ${updatedOrCreated}:>${
167-
date}`,
169+
query: `org:${ORG} is:issue -author:${username} involves:${username} ${updatedOrCreated}:>${date}`,
168170
label: `${ORG} org Issue Involved`,
169171
},
170172
[`${ORG}_org_pr_author`]: {
@@ -176,13 +178,11 @@ function buildQueryAndParams(username: string, date: string) {
176178
label: `${ORG} org PR Involved`,
177179
},
178180
[`${ORG}_org_pr_reviewed`]: {
179-
query: `org:${ORG} is:pr -author:${username} reviewed-by:${username} ${updatedOrCreated}:>${
180-
date}`,
181+
query: `org:${ORG} is:pr -author:${username} reviewed-by:${username} ${updatedOrCreated}:>${date}`,
181182
label: `${ORG} org PR Reviewed`,
182183
},
183184
[`${ORG}_org_pr_commented`]: {
184-
query:
185-
`org:${ORG} is:pr -author:${username} commenter:${username} ${updatedOrCreated}:>${date}`,
185+
query: `org:${ORG} is:pr -author:${username} commenter:${username} ${updatedOrCreated}:>${date}`,
186186
label: `${ORG} org PR Commented`,
187187
},
188188
};
@@ -191,7 +191,7 @@ function buildQueryAndParams(username: string, date: string) {
191191
* Gets the labels for each requested value to be used as headers.
192192
*/
193193
function getLabels(pairs: typeof dataQueries) {
194-
return Object.values(pairs).map(val => val.label);
194+
return Object.values(pairs).map((val) => val.label);
195195
}
196196

197197
/**
@@ -201,13 +201,14 @@ function buildQueryAndParams(username: string, date: string) {
201201
const output: {[key: string]: {}} = {};
202202
Object.entries(pairs).map(([key, val]) => {
203203
output[alias(key, 'search')] = params(
204-
{
205-
query: `"${val.query}"`,
206-
type: 'ISSUE',
207-
},
208-
{
209-
issueCount: types.number,
210-
});
204+
{
205+
query: `"${val.query}"`,
206+
type: 'ISSUE',
207+
},
208+
{
209+
issueCount: types.number,
210+
},
211+
);
211212
});
212213
return output;
213214
}
@@ -229,7 +230,7 @@ async function run(date: string) {
229230

230231
for (const username of allOrgMembers) {
231232
const results = await graphql(buildQueryAndParams(username, date).query.toString());
232-
const values = Object.values(results).map(result => `${result.issueCount}`);
233+
const values = Object.values(results).map((result) => `${result.issueCount}`);
233234
console.info([username, ...values].join(','));
234235
}
235236
} catch (error) {

tools/gulp-tasks/changelog-zonejs.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@ module.exports = (gulp) => () => {
1313
// the tag of zone.js will start with `zone.js-`, such as `zone.js-0.10.0`
1414
// we will remove the first 8 (zone.js-) chars to get the real version.
1515
const version = tag.replace(/^zone\.js-/, '');
16-
return gulp.src('packages/zone.js/CHANGELOG.md')
17-
.pipe(conventionalChangelog(
18-
{
19-
preset: 'angular',
20-
},
21-
{linkCompare: true, previousTag: ptag, currentTag: tag, version: version}, {
22-
// Ignore commits that have a different scope than `zone.js`.
23-
extendedRegexp: true,
24-
grep: '^[^(]+\\(zone\\.js\\)',
25-
from: ptag,
26-
to: 'HEAD',
27-
}))
28-
.pipe(gulp.dest('./packages/zone.js/'));
16+
return gulp
17+
.src('packages/zone.js/CHANGELOG.md')
18+
.pipe(
19+
conventionalChangelog(
20+
{
21+
preset: 'angular',
22+
},
23+
{linkCompare: true, previousTag: ptag, currentTag: tag, version: version},
24+
{
25+
// Ignore commits that have a different scope than `zone.js`.
26+
extendedRegexp: true,
27+
grep: '^[^(]+\\(zone\\.js\\)',
28+
from: ptag,
29+
to: 'HEAD',
30+
},
31+
),
32+
)
33+
.pipe(gulp.dest('./packages/zone.js/'));
2934
};

tools/manual_api_docs/generate_block_api_json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function main() {
1515
const rawParamLines = readFileSync(paramFilePath, {encoding: 'utf8'}).split('\n');
1616
const [srcs, outputFileExecRootRelativePath] = rawParamLines;
1717

18-
const entries: DocEntry[] = srcs.split(',').map(sourceFilePath => {
18+
const entries: DocEntry[] = srcs.split(',').map((sourceFilePath) => {
1919
const fileContent = readFileSync(sourceFilePath, {encoding: 'utf8'});
2020

2121
return {

tools/manual_api_docs/generate_element_api_json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function main() {
1515
const rawParamLines = readFileSync(paramFilePath, {encoding: 'utf8'}).split('\n');
1616
const [srcs, outputFileExecRootRelativePath] = rawParamLines;
1717

18-
const entries: DocEntry[] = srcs.split(',').map(sourceFilePath => {
18+
const entries: DocEntry[] = srcs.split(',').map((sourceFilePath) => {
1919
const fileContent = readFileSync(sourceFilePath, {encoding: 'utf8'});
2020

2121
return {

tools/postinstall-patches.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ try {
1515
// This can be fixed using the --preserve-symlinks-main flag which
1616
// is introduced in node 10.2.0
1717
console.warn(
18-
`Running postinstall-patches.js script in an external repository requires --preserve-symlinks-main node flag introduced in node 10.2.0. ` +
19-
`Current node version is ${process.version}. Node called with '${process.argv.join(' ')}'.`);
18+
`Running postinstall-patches.js script in an external repository requires --preserve-symlinks-main node flag introduced in node 10.2.0. ` +
19+
`Current node version is ${process.version}. Node called with '${process.argv.join(' ')}'.`,
20+
);
2021
process.exit(0);
2122
}
2223

tools/saucelabs-daemon/background-service/cli.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ if (!parallelExecutions) {
4343

4444
// Start the daemon and launch the given browser
4545
const daemon = new SaucelabsDaemon(
46-
username,
47-
accessKey,
48-
process.env['CIRCLE_BUILD_NUM']!,
49-
Object.values(customLaunchers) as Browser[],
50-
parallelExecutions,
51-
sauceConnect,
52-
{tunnelIdentifier},
46+
username,
47+
accessKey,
48+
process.env['CIRCLE_BUILD_NUM']!,
49+
Object.values(customLaunchers) as Browser[],
50+
parallelExecutions,
51+
sauceConnect,
52+
{tunnelIdentifier},
5353
);
5454

5555
if (args.includes('--connect')) {

tools/saucelabs-daemon/background-service/ipc.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99
import {createServer, Server, Socket} from 'net';
1010

1111
import {IPC_PORT} from '../ipc-defaults';
12-
import {BackgroundServiceReceiveMessages, InternalErrorMessage, NoAvailableBrowserMessage} from '../ipc-messages';
12+
import {
13+
BackgroundServiceReceiveMessages,
14+
InternalErrorMessage,
15+
NoAvailableBrowserMessage,
16+
} from '../ipc-messages';
1317

1418
import {SaucelabsDaemon} from './saucelabs-daemon';
1519

@@ -27,30 +31,30 @@ export class IpcServer {
2731

2832
constructor(private _service: SaucelabsDaemon) {
2933
this._server = createServer(this._connectionHandler.bind(this));
30-
this._server.listen(
31-
IPC_PORT, () => console.info(`Daemon IPC server listening (pid ${process.pid}).`));
34+
this._server.listen(IPC_PORT, () =>
35+
console.info(`Daemon IPC server listening (pid ${process.pid}).`),
36+
);
3237
}
3338

3439
private _connectionHandler(socket: Socket) {
3540
const socketId = nextSocketId++;
3641
this._connections.set(socketId, socket);
37-
socket.on('data', b => {
42+
socket.on('data', (b) => {
3843
this._processMessage(
39-
socket,
40-
socketId,
41-
JSON.parse(b.toString()) as BackgroundServiceReceiveMessages,
42-
)
43-
.catch((err) => {
44-
console.error(err);
45-
this._sendInternalError(socket, err.toString());
46-
});
44+
socket,
45+
socketId,
46+
JSON.parse(b.toString()) as BackgroundServiceReceiveMessages,
47+
).catch((err) => {
48+
console.error(err);
49+
this._sendInternalError(socket, err.toString());
50+
});
4751
});
4852
}
4953

5054
private async _processMessage(
51-
socket: Socket,
52-
socketId: number,
53-
message: BackgroundServiceReceiveMessages,
55+
socket: Socket,
56+
socketId: number,
57+
message: BackgroundServiceReceiveMessages,
5458
) {
5559
switch (message.type) {
5660
case 'start-test':

0 commit comments

Comments
 (0)