diff --git a/.eslintrc b/.eslintrc index 8458b0c7c..a55c2156f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -46,6 +46,7 @@ "@typescript-eslint/no-this-alias": 2, "@typescript-eslint/no-useless-constructor": 2, "@typescript-eslint/no-floating-promises": 2, + "@typescript-eslint/prefer-reduce-type-parameter": 2, "@typescript-eslint/prefer-as-const": 2, "@typescript-eslint/prefer-for-of": 2, "@typescript-eslint/prefer-optional-chain": 2, diff --git a/packages/core/src/changelog.ts b/packages/core/src/changelog.ts index 0b6d67178..e9e5c60b2 100644 --- a/packages/core/src/changelog.ts +++ b/packages/core/src/changelog.ts @@ -369,13 +369,16 @@ export default class Changelog { /** Create a section in the changelog to with all of the changelog notes organized by change type */ private async createLabelSection(split: ICommitSplit, sections: string[]) { - const changelogTitles = this.options.labels.reduce((titles, label) => { - if (label.changelogTitle) { - titles[label.name] = label.changelogTitle; - } + const changelogTitles = this.options.labels.reduce>( + (titles, label) => { + if (label.changelogTitle) { + titles[label.name] = label.changelogTitle; + } - return titles; - }, {} as { [label: string]: string }); + return titles; + }, + {} + ); const labelSections = await Promise.all( Object.entries(split).map(async ([label, labelCommits]) => { @@ -415,12 +418,12 @@ export default class Changelog { }) ); - const mergedSections = labelSections.reduce( + const mergedSections = labelSections.reduce>( (acc, [title, commits]) => ({ ...acc, [title]: [...(acc[title] || []), ...commits], }), - {} as Record + {} ); Object.entries(mergedSections) diff --git a/packages/core/src/git.ts b/packages/core/src/git.ts index 001eef770..254d11e9d 100644 --- a/packages/core/src/git.ts +++ b/packages/core/src/git.ts @@ -346,7 +346,7 @@ export default class Git { subject: commit.rawBody!, files: (commit.files || []).map((file) => path.resolve(file)), })) - .reduce((all, commit) => { + .reduce((all, commit) => { // The -m option will list a commit for each merge parent. This // means two items will have the same hash. We are using -m to get all the changed files // in a merge commit. The following code combines these repeated hashes into @@ -360,7 +360,7 @@ export default class Git { } return all; - }, [] as ICommit[]); + }, []); } catch (error) { console.log(error); const tag = error.match(/ambiguous argument '(\S+)\.\.\S+'/); @@ -855,13 +855,16 @@ export default class Git { ).reverse(); const branchTags = (await this.getTags(`heads/${branch}`)).reverse(); const comparator = options.first ? lt : gt; - const firstGreatestUnique = branchTags.reduce((result, tag) => { - if (!baseTags.includes(tag) && (!result || comparator(tag, result))) { - return tag; - } + const firstGreatestUnique = branchTags.reduce( + (result, tag) => { + if (!baseTags.includes(tag) && (!result || comparator(tag, result))) { + return tag; + } - return result; - }); + return result; + }, + undefined + ); this.logger.verbose.info("Tags found in base branch:", baseTags); this.logger.verbose.info("Tags found in branch:", branchTags); diff --git a/packages/core/src/release.ts b/packages/core/src/release.ts index c6ed47189..8d6677fdd 100644 --- a/packages/core/src/release.ts +++ b/packages/core/src/release.ts @@ -134,14 +134,14 @@ export const defaultLabels: ILabelDefinition[] = [ /** Construct a map of label => semver label */ export const getVersionMap = (labels = defaultLabels) => - labels.reduce((semVer, { releaseType: type, name }) => { + labels.reduce((semVer, { releaseType: type, name }) => { if (type && (isVersionLabel(type) || type === "none")) { const list = semVer.get(type) || []; semVer.set(type, [...list, name]); } return semVer; - }, new Map() as IVersionLabels); + }, new Map()); const readFile = promisify(fs.readFile); const writeFile = promisify(fs.writeFile); @@ -239,9 +239,9 @@ export default class Release { ); const allPrCommitHashes = allPrCommits .filter(Boolean) - .reduce( + .reduce( (all, pr) => [...all, ...pr.map((subCommit) => subCommit.sha)], - [] as string[] + [] ); const uniqueCommits = allCommits.filter( (commit) => diff --git a/packages/core/src/validate-config.ts b/packages/core/src/validate-config.ts index 44b73532e..4a58a5e36 100644 --- a/packages/core/src/validate-config.ts +++ b/packages/core/src/validate-config.ts @@ -77,19 +77,22 @@ function reporter(validation: t.Validation) { }); const otherErrors: string[] = []; - const grouped = errors.reduce((acc, item) => { - if (typeof item === "string") { - otherErrors.push(item); - return acc; - } + const grouped = errors.reduce>( + (acc, item) => { + if (typeof item === "string") { + otherErrors.push(item); + return acc; + } - if (!acc[item.path]) { - acc[item.path] = []; - } + if (!acc[item.path]) { + acc[item.path] = []; + } - acc[item.path].push(item); - return acc; - }, {} as Record); + acc[item.path].push(item); + return acc; + }, + {} + ); const paths = Object.keys(grouped); return [ diff --git a/plugins/all-contributors/src/index.ts b/plugins/all-contributors/src/index.ts index 180e2a864..63c96bba9 100644 --- a/plugins/all-contributors/src/index.ts +++ b/plugins/all-contributors/src/index.ts @@ -209,9 +209,9 @@ export default class AllContributorsPlugin implements IPlugin { return; } - const allContributions = Object.values(extra).reduce( + const allContributions = Object.values(extra).reduce( (all, i) => [...all, ...i], - [] as string[] + [] ); const unknownTypes = allContributions.filter( (contribution) => diff --git a/plugins/npm/src/index.ts b/plugins/npm/src/index.ts index 7b5ed5bcc..7580458c8 100644 --- a/plugins/npm/src/index.ts +++ b/plugins/npm/src/index.ts @@ -143,23 +143,26 @@ export async function getChangedPackages({ export function getMonorepoPackage() { const packages = getPackages(process.cwd()); - return packages.reduce((greatest, subPackage) => { - if (subPackage.package.version) { - if (!greatest.version) { - return subPackage.package; - } + return packages.reduce( + (greatest, subPackage) => { + if (subPackage.package.version) { + if (!greatest.version) { + return subPackage.package; + } - if (subPackage.package.private) { - return greatest; - } + if (subPackage.package.private) { + return greatest; + } - return gt(greatest.version, subPackage.package.version) - ? greatest - : subPackage.package; - } + return gt(greatest.version, subPackage.package.version) + ? greatest + : subPackage.package; + } - return greatest; - }, {} as IPackageJSON); + return greatest; + }, + { name: "initial" } + ); } /** Get all of the packages+version in the lerna monorepo */