From cc146bc7d4c7d46950d4b43dcc051bc9eb058bdb Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Thu, 5 Nov 2020 16:58:36 +0200 Subject: [PATCH] resources: use named groups in RegExp (#2840) --- resources/build-npm.js | 4 ++-- resources/gen-changelog.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/build-npm.js b/resources/build-npm.js index 8a2b68ab87..b2cd83aade 100644 --- a/resources/build-npm.js +++ b/resources/build-npm.js @@ -59,12 +59,12 @@ function buildPackageJSON() { delete packageJSON.engines_on_npm; const { version } = packageJSON; - const versionMatch = /^\d+\.\d+\.\d+-?(.*)?$/.exec(version); + const versionMatch = /^\d+\.\d+\.\d+-?(?.*)?$/.exec(version); if (!versionMatch) { throw new Error('Version does not match semver spec: ' + version); } - const [, preReleaseTag] = versionMatch; + const { preReleaseTag } = versionMatch.groups; if (preReleaseTag != null) { const [tag] = preReleaseTag.split('.'); diff --git a/resources/gen-changelog.js b/resources/gen-changelog.js index 7449c1790c..48a3cf366a 100644 --- a/resources/gen-changelog.js +++ b/resources/gen-changelog.js @@ -47,14 +47,14 @@ if (!packageJSON.repository || typeof packageJSON.repository.url !== 'string') { process.exit(1); } -const repoURLMatch = /https:\/\/github.com\/([^/]+)\/([^/]+).git/.exec( +const repoURLMatch = /https:\/\/github.com\/(?[^/]+)\/(?[^/]+).git/.exec( packageJSON.repository.url, ); if (repoURLMatch == null) { console.error('Cannot extract organization and repo name from repo URL!'); process.exit(1); } -const [, githubOrg, githubRepo] = repoURLMatch; +const { githubOrg, githubRepo } = repoURLMatch.groups; getChangeLog() .then((changelog) => process.stdout.write(changelog)) @@ -275,9 +275,9 @@ function commitsInfoToPRs(commits) { (pr) => pr.repository.nameWithOwner === `${githubOrg}/${githubRepo}`, ); if (associatedPRs.length === 0) { - const match = / \(#([0-9]+)\)$/m.exec(commit.message); + const match = / \(#(?[0-9]+)\)$/m.exec(commit.message); if (match) { - prs[parseInt(match[1], 10)] = true; + prs[parseInt(match.groups.prNumber, 10)] = true; continue; } throw new Error(