Skip to content

Commit f9c09aa

Browse files
devDeps: bump eslint packages (#147)
* devDeps: bump @typescript-eslint/ packages * devDeps: [email protected]>27.1.5 * devDeps: [email protected]>39.6.2 * devDeps: [email protected]>8.40.0 * devDeps: [email protected]>2.2.8 * bump @types/node * lint:fix * lint: address lint errors after upgrade * Bump @metamask/eslint-config from 10.0.0 to 11.1.0 Bumps [@metamask/eslint-config](https://github.com/MetaMask/eslint-config) from 10.0.0 to 11.1.0. - [Release notes](https://github.com/MetaMask/eslint-config/releases) - [Commits](MetaMask/eslint-config@v10.0.0...v11.1.0) --- updated-dependencies: - dependency-name: "@metamask/eslint-config" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * Bump @metamask/eslint-config-jest from 10.0.0 to 11.1.0 Bumps [@metamask/eslint-config-jest](https://github.com/MetaMask/eslint-config) from 10.0.0 to 11.1.0. - [Release notes](https://github.com/MetaMask/eslint-config/releases) - [Commits](MetaMask/eslint-config@v10.0.0...v11.1.0) --- updated-dependencies: - dependency-name: "@metamask/eslint-config-jest" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * Bump @metamask/eslint-config-nodejs from 10.0.0 to 11.1.0 Bumps [@metamask/eslint-config-nodejs](https://github.com/MetaMask/eslint-config) from 10.0.0 to 11.1.0. - [Release notes](https://github.com/MetaMask/eslint-config/releases) - [Commits](MetaMask/eslint-config@v10.0.0...v11.1.0) --- updated-dependencies: - dependency-name: "@metamask/eslint-config-nodejs" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * Bump @metamask/eslint-config-typescript from 10.0.0 to 11.1.0 Bumps [@metamask/eslint-config-typescript](https://github.com/MetaMask/eslint-config) from 10.0.0 to 11.1.0. - [Release notes](https://github.com/MetaMask/eslint-config/releases) - [Commits](MetaMask/eslint-config@v10.0.0...v11.1.0) --- updated-dependencies: - dependency-name: "@metamask/eslint-config-typescript" dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 839be83 commit f9c09aa

File tree

11 files changed

+287
-679
lines changed

11 files changed

+287
-679
lines changed

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,27 @@
3838
},
3939
"devDependencies": {
4040
"@lavamoat/allow-scripts": "^2.1.0",
41-
"@metamask/eslint-config": "^10.0.0",
42-
"@metamask/eslint-config-jest": "^10.0.0",
43-
"@metamask/eslint-config-nodejs": "^10.0.0",
44-
"@metamask/eslint-config-typescript": "^10.0.0",
41+
"@metamask/eslint-config": "^11.1.0",
42+
"@metamask/eslint-config-jest": "^11.1.0",
43+
"@metamask/eslint-config-nodejs": "^11.1.0",
44+
"@metamask/eslint-config-typescript": "^11.1.0",
4545
"@types/cross-spawn": "^6.0.2",
4646
"@types/diff": "^5.0.0",
4747
"@types/jest": "^26.0.23",
4848
"@types/semver": "^7.3.6",
4949
"@types/yargs": "^16.0.1",
50-
"@typescript-eslint/eslint-plugin": "^5.41.0",
51-
"@typescript-eslint/parser": "^5.41.0",
52-
"eslint": "^8.26.0",
50+
"@typescript-eslint/eslint-plugin": "^5.42.1",
51+
"@typescript-eslint/parser": "^5.42.1",
52+
"eslint": "^8.40.0",
5353
"eslint-config-prettier": "^8.5.0",
5454
"eslint-plugin-import": "^2.26.0",
55-
"eslint-plugin-jest": "^26.8.2",
56-
"eslint-plugin-jsdoc": "^39.3.25",
55+
"eslint-plugin-jest": "^27.1.5",
56+
"eslint-plugin-jsdoc": "^39.6.2",
5757
"eslint-plugin-node": "^11.1.0",
5858
"eslint-plugin-prettier": "^4.2.1",
5959
"jest": "^26.4.2",
6060
"outdent": "^0.8.0",
61-
"prettier": "^2.2.1",
61+
"prettier": "^2.8.8",
6262
"rimraf": "^3.0.2",
6363
"ts-jest": "^26.5.6",
6464
"typescript": "~4.8.4"

src/changelog.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ type AddChangeOptions = {
249249
* formatting, update a changelog, or build one from scratch.
250250
*/
251251
export default class Changelog {
252-
private _releases: ReleaseMetadata[];
252+
readonly #releases: ReleaseMetadata[];
253253

254-
private _changes: ChangelogChanges;
254+
#changes: ChangelogChanges;
255255

256-
private _repoUrl: string;
256+
readonly #repoUrl: string;
257257

258-
private _tagPrefix: string;
258+
readonly #tagPrefix: string;
259259

260260
/**
261261
* Construct an empty changelog.
@@ -271,10 +271,10 @@ export default class Changelog {
271271
repoUrl: string;
272272
tagPrefix?: string;
273273
}) {
274-
this._releases = [];
275-
this._changes = { [unreleased]: {} };
276-
this._repoUrl = repoUrl;
277-
this._tagPrefix = tagPrefix;
274+
this.#releases = [];
275+
this.#changes = { [unreleased]: {} };
276+
this.#repoUrl = repoUrl;
277+
this.#tagPrefix = tagPrefix;
278278
}
279279

280280
/**
@@ -297,16 +297,16 @@ export default class Changelog {
297297
throw new Error('Version required');
298298
} else if (semver.valid(version) === null) {
299299
throw new Error(`Not a valid semver version: '${version}'`);
300-
} else if (this._changes[version]) {
300+
} else if (this.#changes[version]) {
301301
throw new Error(`Release already exists: '${version}'`);
302302
}
303303

304-
this._changes[version] = {};
304+
this.#changes[version] = {};
305305
const newRelease = { version, date, status };
306306
if (addToStart) {
307-
this._releases.unshift(newRelease);
307+
this.#releases.unshift(newRelease);
308308
} else {
309-
this._releases.push(newRelease);
309+
this.#releases.push(newRelease);
310310
}
311311
}
312312

@@ -335,13 +335,13 @@ export default class Changelog {
335335
throw new Error(`Unrecognized category: '${category}'`);
336336
} else if (!description) {
337337
throw new Error('Description required');
338-
} else if (version !== undefined && !this._changes[version]) {
338+
} else if (version !== undefined && !this.#changes[version]) {
339339
throw new Error(`Specified release version does not exist: '${version}'`);
340340
}
341341

342342
const release = version
343-
? this._changes[version]
344-
: this._changes[unreleased];
343+
? this.#changes[version]
344+
: this.#changes[unreleased];
345345

346346
if (!release[category]) {
347347
release[category] = [];
@@ -365,12 +365,12 @@ export default class Changelog {
365365
* @param version - The release version to migrate unreleased changes to.
366366
*/
367367
migrateUnreleasedChangesToRelease(version: Version) {
368-
const releaseChanges = this._changes[version];
368+
const releaseChanges = this.#changes[version];
369369
if (!releaseChanges) {
370370
throw new Error(`Specified release version does not exist: '${version}'`);
371371
}
372372

373-
const unreleasedChanges = this._changes[unreleased];
373+
const unreleasedChanges = this.#changes[unreleased];
374374

375375
for (const category of Object.keys(unreleasedChanges) as ChangeCategory[]) {
376376
if (releaseChanges[category]) {
@@ -382,7 +382,7 @@ export default class Changelog {
382382
releaseChanges[category] = unreleasedChanges[category];
383383
}
384384
}
385-
this._changes[unreleased] = {};
385+
this.#changes[unreleased] = {};
386386
}
387387

388388
/**
@@ -391,7 +391,7 @@ export default class Changelog {
391391
* @returns The metadata for each release.
392392
*/
393393
getReleases() {
394-
return this._releases;
394+
return this.#releases;
395395
}
396396

397397
/**
@@ -429,7 +429,7 @@ export default class Changelog {
429429
* @returns The changes included in the given released.
430430
*/
431431
getReleaseChanges(version: Version) {
432-
return this._changes[version];
432+
return this.#changes[version];
433433
}
434434

435435
/**
@@ -438,7 +438,7 @@ export default class Changelog {
438438
* @returns The changes that have not yet been released.
439439
*/
440440
getUnreleasedChanges() {
441-
return this._changes[unreleased];
441+
return this.#changes[unreleased];
442442
}
443443

444444
/**
@@ -450,12 +450,12 @@ export default class Changelog {
450450
return `${changelogTitle}
451451
${changelogDescription}
452452
453-
${stringifyReleases(this._releases, this._changes)}
453+
${stringifyReleases(this.#releases, this.#changes)}
454454
455455
${stringifyLinkReferenceDefinitions(
456-
this._repoUrl,
457-
this._tagPrefix,
458-
this._releases,
456+
this.#repoUrl,
457+
this.#tagPrefix,
458+
this.#releases,
459459
)}`;
460460
}
461461
}

src/cli.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,21 @@
22

33
import { promises as fs, constants as fsConstants } from 'fs';
44
import path from 'path';
5-
// Intentionally shadowing 'URL' global, which is equivalent
6-
// Can't use global directly because of missing type, see:
7-
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34960
8-
// eslint-disable-next-line @typescript-eslint/no-shadow
9-
import { URL } from 'url';
105
import semver from 'semver';
11-
import yargs from 'yargs/yargs';
126
import type { Argv } from 'yargs';
137
import { hideBin } from 'yargs/helpers';
8+
import yargs from 'yargs/yargs';
149

15-
import { updateChangelog } from './update-changelog';
10+
import { unreleased, Version } from './constants';
1611
import { generateDiff } from './generate-diff';
1712
import { createEmptyChangelog } from './init';
18-
19-
import { unreleased, Version } from './constants';
20-
13+
import { getRepositoryUrl } from './repo';
14+
import { updateChangelog } from './update-changelog';
2115
import {
2216
ChangelogFormattingError,
2317
InvalidChangelogError,
2418
validateChangelog,
2519
} from './validate-changelog';
26-
import { getRepositoryUrl } from './repo';
2720

2821
const updateEpilog = `New commits will be added to the "${unreleased}" section (or \
2922
to the section for the current release if the '--rc' flag is used) in reverse \
@@ -211,7 +204,7 @@ type InitOptions = {
211204
* @param options.tagPrefix - The prefix used in tags before the version number.
212205
*/
213206
async function init({ changelogPath, repoUrl, tagPrefix }: InitOptions) {
214-
const changelogContent = await createEmptyChangelog({ repoUrl, tagPrefix });
207+
const changelogContent = createEmptyChangelog({ repoUrl, tagPrefix });
215208
await saveChangelog(changelogPath, changelogContent);
216209
}
217210

src/generate-diff.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import _outdent from 'outdent';
2+
23
import { generateDiff } from './generate-diff';
34

45
const outdent = _outdent({ trimTrailingNewline: false });

src/parse-changelog.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import _outdent from 'outdent';
2+
23
import { parseChangelog } from './parse-changelog';
34

45
const outdent = _outdent({ trimTrailingNewline: false });

src/parse-changelog.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import semver from 'semver';
2+
23
import Changelog from './changelog';
34
import { ChangeCategory, unreleased } from './constants';
45

src/repo.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable node/no-process-env */
22

33
import path from 'path';
4+
45
import { getRepositoryUrl } from './repo';
56

67
describe('getRepositoryUrl', () => {

src/repo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable node/no-process-env, node/no-sync */
22

3-
import path from 'path';
43
import fs from 'fs';
4+
import path from 'path';
55

66
type PackageJson = {
77
repository:

src/update-changelog.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { strict as assert } from 'assert';
22
import execa from 'execa';
3-
import { parseChangelog } from './parse-changelog';
4-
import { ChangeCategory, Version } from './constants';
3+
54
import type Changelog from './changelog';
5+
import { ChangeCategory, Version } from './constants';
6+
import { parseChangelog } from './parse-changelog';
67

78
/**
89
* Get the most recent tag for a project.
@@ -70,7 +71,7 @@ async function getCommits(commitHashes: string[]) {
7071
if (matchResults) {
7172
// Squash & Merge: the commit subject is parsed as `<description> (#<PR ID>)`
7273
prNumber = matchResults[1];
73-
description = subject.match(/^(.+)\s\(#\d+\)/u)?.[1] || '';
74+
description = subject.match(/^(.+)\s\(#\d+\)/u)?.[1] ?? '';
7475
} else {
7576
// Merge: the PR ID is parsed from the git subject (which is of the form `Merge pull request
7677
// #<PR ID> from <branch>`, and the description is assumed to be the first line of the body.
@@ -125,8 +126,10 @@ function getAllLoggedPrNumbers(changelog: Changelog) {
125126

126127
const prNumbersWithChangelogEntries = [];
127128
for (const description of changeDescriptions) {
128-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
129-
const matchResults = description!.matchAll(/\[#(\d+)\]/gu);
129+
if (!description) {
130+
continue;
131+
}
132+
const matchResults = description.matchAll(/\[#(\d+)\]/gu);
130133
const prNumbers = Array.from(matchResults, (result) => result[1]);
131134
prNumbersWithChangelogEntries.push(...prNumbers);
132135
}
@@ -209,7 +212,7 @@ export async function updateChangelog({
209212

210213
if (
211214
isReleaseCandidate &&
212-
mostRecentTag === `${tagPrefixes[0]}${currentVersion}`
215+
mostRecentTag === `${tagPrefixes[0]}${currentVersion || ''}`
213216
) {
214217
throw new Error(
215218
`Current version already has tag, which is unexpected for a release candidate.`,

src/validate-changelog.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,8 @@ describe('validateChangelog', () => {
233233
});
234234

235235
it('should throw when a change category is unrecognized', () => {
236-
const changelogWithUnrecognizedChangeCategory = changelogWithReleases.replace(
237-
'### Changed',
238-
'### Updated',
239-
);
236+
const changelogWithUnrecognizedChangeCategory =
237+
changelogWithReleases.replace('### Changed', '### Updated');
240238
expect(() =>
241239
validateChangelog({
242240
changelogContent: changelogWithUnrecognizedChangeCategory,

0 commit comments

Comments
 (0)