diff --git a/lib/config/.eslintrc.js b/lib/config/.eslintrc.js new file mode 100644 index 0000000000000000000000000000000000000000..8bcc65cc06d65e68d5207c000f5167759c3b1dcd --- /dev/null +++ b/lib/config/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + rules: { + '@typescript-eslint/explicit-function-return-type': 2, + }, +}; diff --git a/lib/config/cli.ts b/lib/config/cli.ts index 7666b70f7b2d92ecdd572fce087d8f6cfb838f28..bd5153ce3d96b93f8572e5403aa0a84330a7fe79 100644 --- a/lib/config/cli.ts +++ b/lib/config/cli.ts @@ -33,7 +33,7 @@ export function getConfig(input: string[]): RenovateCliConfig { const config: RenovateCliConfig = {}; const coersions = { - boolean: (val: string) => { + boolean: (val: string): boolean => { if (val === 'true' || val === '') return true; if (val === 'false') return false; throw new Error( @@ -42,7 +42,7 @@ export function getConfig(input: string[]): RenovateCliConfig { "'" ); }, - array: (val: string) => { + array: (val: string): string[] => { if (val === '') { return []; } @@ -52,7 +52,7 @@ export function getConfig(input: string[]): RenovateCliConfig { return val.split(',').map(el => el.trim()); } }, - object: (val: string) => { + object: (val: string): any => { if (val === '') { return {}; } @@ -62,7 +62,7 @@ export function getConfig(input: string[]): RenovateCliConfig { throw new Error("Invalid JSON value: '" + val + "'"); } }, - string: (val: string) => val, + string: (val: string): string => val, integer: parseInt, }; diff --git a/lib/config/definitions.ts b/lib/config/definitions.ts index 15886aa93acf3bd69fa7cf6daa9fb5cc6576a30c..ddb37f960a9281a5c781cbfd2d035bbace9fc625 100644 --- a/lib/config/definitions.ts +++ b/lib/config/definitions.ts @@ -2041,6 +2041,6 @@ const options: RenovateOptions[] = [ }, ]; -export function getOptions() { +export function getOptions(): any { return options; } diff --git a/lib/config/env.ts b/lib/config/env.ts index e6250321e76712fcd8b8ee6070bcfaef3fb9ebbf..3000b62904f846d2677a1d648d5bb7a7997d52ab 100644 --- a/lib/config/env.ts +++ b/lib/config/env.ts @@ -18,10 +18,10 @@ export function getConfig(env: NodeJS.ProcessEnv): RenovateConfig { const config: RenovateConfig = { hostRules: [] }; const coersions = { - boolean: (val: string) => val === 'true', - array: (val: string) => val.split(',').map(el => el.trim()), - string: (val: string) => val.replace(/\\n/g, '\n'), - object: (val: string) => JSON.parse(val), + boolean: (val: string): boolean => val === 'true', + array: (val: string): string[] => val.split(',').map(el => el.trim()), + string: (val: string): string => val.replace(/\\n/g, '\n'), + object: (val: string): any => JSON.parse(val), integer: parseInt, }; diff --git a/lib/config/presets.ts b/lib/config/presets.ts index 48062a64108fdf0dabec483908bcfd9d047789a8..d2672521b658bee5018339603d70ab18b7a61b89 100644 --- a/lib/config/presets.ts +++ b/lib/config/presets.ts @@ -18,7 +18,7 @@ const datasources = { export function replaceArgs( obj: string | string[] | object | object[], argMapping: Record<string, any> -) { +): any { if (is.string(obj)) { let returnStr = obj; for (const [arg, argVal] of Object.entries(argMapping)) { diff --git a/lib/logger/__mocks__/index.ts b/lib/logger/__mocks__/index.ts index b303a70ad2212b1584ddffa7da63553a7aeeac09..36b7185649965915db5e4f0d0f2c7dc860ba104e 100644 --- a/lib/logger/__mocks__/index.ts +++ b/lib/logger/__mocks__/index.ts @@ -16,6 +16,6 @@ loggerLevels.forEach(k => { export const setMeta = jest.fn(); export const levels = jest.fn(); export const addStream = jest.fn(); -export const getErrors = () => []; +export const getErrors = (): any[] => []; export { logger }; diff --git a/lib/logger/index.ts b/lib/logger/index.ts index 9b838a1924ea325f6edb60a6ee3f4229b7c1f571..ec499ade79dc4ab1695f5fe379803f95165064f0 100644 --- a/lib/logger/index.ts +++ b/lib/logger/index.ts @@ -98,7 +98,7 @@ loggerLevels.forEach(loggerLevel => { }); // setMeta overrides existing meta -export function setMeta(obj: any) { +export function setMeta(obj: any): void { meta = { ...obj }; } @@ -112,6 +112,6 @@ export function levels(name: string, level: bunyan.LogLevel): void { bunyanLogger.levels(name, level); } -export function getErrors() { +export function getErrors(): any { return errors.getErrors(); } diff --git a/lib/logger/pretty-stdout.ts b/lib/logger/pretty-stdout.ts index 318a528d0bb13177062c0fb745a9078f28247e1f..f4becca043b24487148fcefb90f2f3de8cebe853 100644 --- a/lib/logger/pretty-stdout.ts +++ b/lib/logger/pretty-stdout.ts @@ -35,12 +35,12 @@ const levels: Record<number, string> = { 60: chalk.bgRed('FATAL'), }; -export function indent(str: string, leading = false) { +export function indent(str: string, leading = false): string { const prefix = leading ? ' ' : ''; return prefix + str.split(/\r?\n/).join('\n '); } -export function getMeta(rec: BunyanRecord) { +export function getMeta(rec: BunyanRecord): string { if (!rec) { return ''; } @@ -56,7 +56,7 @@ export function getMeta(rec: BunyanRecord) { return chalk.gray(res); } -export function getDetails(rec: BunyanRecord) { +export function getDetails(rec: BunyanRecord): string { if (!rec) { return ''; } diff --git a/lib/platform/index.ts b/lib/platform/index.ts index 60ccc5d709798b8c051d3ae68f1bf1945d387cb4..7d335490f0bd3e8a5346cec937a2564fcab6abd5 100644 --- a/lib/platform/index.ts +++ b/lib/platform/index.ts @@ -36,7 +36,9 @@ export async function setPlatformApi(name: string): Promise<void> { _platform = await import('./' + name); } -export async function initPlatform(config: RenovateConfig) { +export async function initPlatform( + config: RenovateConfig +): Promise<RenovateConfig> { await setPlatformApi(config.platform); // TODO: types const platformInfo = await platform.initPlatform(config); diff --git a/lib/platform/utils/read-only-issue-body.ts b/lib/platform/utils/read-only-issue-body.ts index 4f9959b62896f11849037a9a5bb021e84b2d9045..56813a3415f55b158e2da51274b8688164ffc2eb 100644 --- a/lib/platform/utils/read-only-issue-body.ts +++ b/lib/platform/utils/read-only-issue-body.ts @@ -1,4 +1,4 @@ -export function readOnlyIssueBody(body: string) { +export function readOnlyIssueBody(body: string): string { return body .replace(' only once you click their checkbox below', '') .replace(' unless you click a checkbox below', '') diff --git a/lib/renovate.ts b/lib/renovate.ts index e44bbd478f94276da997ccdaa19a7f36e4c33497..cd4a70320273b2303eb68cf37fcdea6ba4ad9f08 100644 --- a/lib/renovate.ts +++ b/lib/renovate.ts @@ -5,6 +5,6 @@ import * as globalWorker from './workers/global'; proxy.bootstrap(); -(async () => { +(async (): Promise<void> => { process.exitCode = await globalWorker.start(); })(); diff --git a/lib/util/.eslintrc.js b/lib/util/.eslintrc.js new file mode 100644 index 0000000000000000000000000000000000000000..8bcc65cc06d65e68d5207c000f5167759c3b1dcd --- /dev/null +++ b/lib/util/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + rules: { + '@typescript-eslint/explicit-function-return-type': 2, + }, +}; diff --git a/lib/util/emoji.ts b/lib/util/emoji.ts index d27b3baf450de3110df0048ed2a0f625a74282bc..98bb11857557282d7dac59a6bee48c9d2a6d81c2 100644 --- a/lib/util/emoji.ts +++ b/lib/util/emoji.ts @@ -3,7 +3,7 @@ import { RenovateConfig } from '../config'; let unicodeEmoji = false; -export function setEmojiConfig(_config: RenovateConfig) { +export function setEmojiConfig(_config: RenovateConfig): void { unicodeEmoji = _config.unicodeEmoji; } diff --git a/lib/util/got/stats.ts b/lib/util/got/stats.ts index 9e4826173be9ad006281265ad0c65d3e775935d3..2217781fb2da454f09d1aba1636dbbf5ee24b416 100644 --- a/lib/util/got/stats.ts +++ b/lib/util/got/stats.ts @@ -11,12 +11,12 @@ interface HostStats { let stats: Record<string, number[]> = {}; // istanbul ignore next -export const resetStats = () => { +export const resetStats = (): void => { stats = {}; }; // istanbul ignore next -export const printStats = () => { +export const printStats = (): void => { logger.trace({ stats }, 'Host transfer stats (milliseconds)'); const hostStats: Record<string, HostStats> = {}; for (const [hostname, entries] of Object.entries(stats)) { diff --git a/lib/util/host-rules.ts b/lib/util/host-rules.ts index 09f02a8a1f38eb702f7577b22546c1d0c6088fe5..451f5f8f2029b6c748343407944537924f2d19ad 100644 --- a/lib/util/host-rules.ts +++ b/lib/util/host-rules.ts @@ -18,7 +18,7 @@ export interface HostRule { let hostRules: HostRule[] = []; -export function add(params: HostRule) { +export function add(params: HostRule): void { if (params.domainName && params.hostName) { throw new Error('hostRules cannot contain both a domainName and hostName'); } @@ -47,35 +47,35 @@ export interface HostRuleSearch { url?: string; } -function isEmptyRule(rule: HostRule) { +function isEmptyRule(rule: HostRule): boolean { return !rule.hostType && !rule.domainName && !rule.hostName && !rule.baseUrl; } -function isHostTypeRule(rule: HostRule) { +function isHostTypeRule(rule: HostRule): boolean { return rule.hostType && !rule.domainName && !rule.hostName && !rule.baseUrl; } -function isDomainNameRule(rule: HostRule) { - return !rule.hostType && rule.domainName; +function isDomainNameRule(rule: HostRule): boolean { + return !rule.hostType && !!rule.domainName; } -function isHostNameRule(rule: HostRule) { - return !rule.hostType && rule.hostName; +function isHostNameRule(rule: HostRule): boolean { + return !rule.hostType && !!rule.hostName; } -function isBaseUrlRule(rule: HostRule) { - return !rule.hostType && rule.baseUrl; +function isBaseUrlRule(rule: HostRule): boolean { + return !rule.hostType && !!rule.baseUrl; } -function isMultiRule(rule: HostRule) { - return rule.hostType && (rule.domainName || rule.hostName || rule.baseUrl); +function isMultiRule(rule: HostRule): boolean { + return rule.hostType && !!(rule.domainName || rule.hostName || rule.baseUrl); } -function matchesHostType(rule: HostRule, search: HostRuleSearch) { +function matchesHostType(rule: HostRule, search: HostRuleSearch): boolean { return rule.hostType === search.hostType; } -function matchesDomainName(rule: HostRule, search: HostRuleSearch) { +function matchesDomainName(rule: HostRule, search: HostRuleSearch): boolean { const hostname = search.url && URL.parse(search.url).hostname; return ( search.url && @@ -85,7 +85,7 @@ function matchesDomainName(rule: HostRule, search: HostRuleSearch) { ); } -function matchesHostName(rule: HostRule, search: HostRuleSearch) { +function matchesHostName(rule: HostRule, search: HostRuleSearch): boolean { return ( search.url && rule.hostName && @@ -93,11 +93,11 @@ function matchesHostName(rule: HostRule, search: HostRuleSearch) { ); } -function matchesBaseUrl(rule: HostRule, search: HostRuleSearch) { +function matchesBaseUrl(rule: HostRule, search: HostRuleSearch): boolean { return search.url && rule.baseUrl && search.url.startsWith(rule.baseUrl); } -export function find(search: HostRuleSearch) { +export function find(search: HostRuleSearch): HostRule { if (!(search.hostType || search.url)) { logger.warn({ search }, 'Invalid hostRules search'); return {}; @@ -153,7 +153,7 @@ export function find(search: HostRuleSearch) { return res; } -export function hosts({ hostType }: { hostType: string }) { +export function hosts({ hostType }: { hostType: string }): string[] { return hostRules .filter(rule => rule.hostType === hostType) .map(rule => { @@ -164,7 +164,7 @@ export function hosts({ hostType }: { hostType: string }) { .filter(Boolean); } -export function clear() { +export function clear(): void { hostRules = []; sanitize.clear(); } diff --git a/lib/util/regex.ts b/lib/util/regex.ts index 3094b008a111e4aaa8925b49fc185edcd9f16b1e..41dfce98f1ba292eaa95bf964c1bbefb3da29564 100644 --- a/lib/util/regex.ts +++ b/lib/util/regex.ts @@ -14,7 +14,7 @@ try { RegEx = RegExp; } -export function regEx(pattern: string, flags?: string) { +export function regEx(pattern: string, flags?: string): RegExp { try { return new RegEx(pattern, flags); } catch (err) { diff --git a/lib/util/sanitize.ts b/lib/util/sanitize.ts index 98d6b737c1ea9185e1e986414d055f4a36c0aec9..c1324009793d3c6b41071cd836f8c4257828235b 100644 --- a/lib/util/sanitize.ts +++ b/lib/util/sanitize.ts @@ -1,6 +1,6 @@ const secrets = new Set<string>(); -export function sanitize(input: string) { +export function sanitize(input: string): string { if (!input) return input; let output: string = input; secrets.forEach(secret => { @@ -11,10 +11,10 @@ export function sanitize(input: string) { return output; } -export function add(secret: string) { +export function add(secret: string): void { secrets.add(secret); } -export function clear() { +export function clear(): void { secrets.clear(); } diff --git a/lib/versioning/.eslintrc.js b/lib/versioning/.eslintrc.js new file mode 100644 index 0000000000000000000000000000000000000000..8bcc65cc06d65e68d5207c000f5167759c3b1dcd --- /dev/null +++ b/lib/versioning/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + rules: { + '@typescript-eslint/explicit-function-return-type': 2, + }, +}; diff --git a/lib/versioning/cargo/index.ts b/lib/versioning/cargo/index.ts index a33f78be123834b340f5f84eee6537ccca3224de..50847c56b2b6d87dfd317fe265ec89c6fa67f1bc 100644 --- a/lib/versioning/cargo/index.ts +++ b/lib/versioning/cargo/index.ts @@ -1,9 +1,9 @@ import { api as npm } from '../npm'; import { VersioningApi, RangeStrategy } from '../common'; -const isVersion = (input: string) => npm.isVersion(input); +const isVersion = (input: string): string | boolean => npm.isVersion(input); -function convertToCaret(item: string) { +function convertToCaret(item: string): string { // In Cargo, "1.2.3" doesn't mean exactly 1.2.3, it means >= 1.2.3 < 2.0.0 if (isVersion(item)) { // NOTE: Partial versions like '1.2' don't get converted to '^1.2' @@ -14,17 +14,17 @@ function convertToCaret(item: string) { return item.trim(); } -function cargo2npm(input: string) { +function cargo2npm(input: string): string { let versions = input.split(','); versions = versions.map(convertToCaret); return versions.join(' '); } -function notEmpty(s: string) { +function notEmpty(s: string): boolean { return s !== ''; } -function npm2cargo(input: string) { +function npm2cargo(input: string): string { // Note: this doesn't remove the ^ const res = input .split(' ') @@ -40,21 +40,22 @@ function npm2cargo(input: string) { return res.join(', '); } -const isLessThanRange = (version: string, range: string) => +const isLessThanRange = (version: string, range: string): boolean => npm.isLessThanRange(version, cargo2npm(range)); -export const isValid = (input: string) => npm.isValid(cargo2npm(input)); +export const isValid = (input: string): string | boolean => + npm.isValid(cargo2npm(input)); -const matches = (version: string, range: string) => +const matches = (version: string, range: string): boolean => npm.matches(version, cargo2npm(range)); -const maxSatisfyingVersion = (versions: string[], range: string) => +const maxSatisfyingVersion = (versions: string[], range: string): string => npm.maxSatisfyingVersion(versions, cargo2npm(range)); -const minSatisfyingVersion = (versions: string[], range: string) => +const minSatisfyingVersion = (versions: string[], range: string): string => npm.minSatisfyingVersion(versions, cargo2npm(range)); -const isSingleVersion = (constraint: string) => +const isSingleVersion = (constraint: string): string | boolean => constraint.trim().startsWith('=') && isVersion( constraint @@ -68,7 +69,7 @@ function getNewValue( rangeStrategy: RangeStrategy, fromVersion: string, toVersion: string -) { +): string { if (rangeStrategy === 'pin' || isSingleVersion(currentValue)) { let res = '='; if (currentValue.startsWith('= ')) { diff --git a/lib/versioning/composer/index.ts b/lib/versioning/composer/index.ts index bdbb52de71be4260372785c818829479ed5230e6..c5880f4a91aebb42d4cb8dec01a550fa2f01ba64 100644 --- a/lib/versioning/composer/index.ts +++ b/lib/versioning/composer/index.ts @@ -3,7 +3,7 @@ import { logger } from '../../logger'; import { api as npm } from '../npm'; import { VersioningApi, RangeStrategy } from '../common'; -function padZeroes(input: string) { +function padZeroes(input: string): string { const sections = input.split('.'); while (sections.length < 3) { sections.push('0'); @@ -11,7 +11,7 @@ function padZeroes(input: string) { return sections.join('.'); } -function composer2npm(input: string) { +function composer2npm(input: string): string { if (npm.isVersion(input)) { return input; } @@ -26,43 +26,43 @@ function composer2npm(input: string) { return output; } -const equals = (a: string, b: string) => +const equals = (a: string, b: string): boolean => npm.equals(composer2npm(a), composer2npm(b)); -const getMajor = (version: string) => +const getMajor = (version: string): number => npm.getMajor(coerce(composer2npm(version))); -const getMinor = (version: string) => +const getMinor = (version: string): number => npm.getMinor(coerce(composer2npm(version))); -const getPatch = (version: string) => +const getPatch = (version: string): number => npm.getPatch(coerce(composer2npm(version))); -const isGreaterThan = (a: string, b: string) => +const isGreaterThan = (a: string, b: string): boolean => npm.isGreaterThan(composer2npm(a), composer2npm(b)); -const isLessThanRange = (version: string, range: string) => +const isLessThanRange = (version: string, range: string): boolean => npm.isLessThanRange(composer2npm(version), composer2npm(range)); -const isSingleVersion = (input: string) => +const isSingleVersion = (input: string): string | boolean => input && npm.isSingleVersion(composer2npm(input)); -const isStable = (version: string) => +const isStable = (version: string): boolean => version && npm.isStable(composer2npm(version)); -export const isValid = (input: string) => +export const isValid = (input: string): string | boolean => input && npm.isValid(composer2npm(input)); -export const isVersion = (input: string) => +export const isVersion = (input: string): string | boolean => input && npm.isVersion(composer2npm(input)); -const matches = (version: string, range: string) => +const matches = (version: string, range: string): boolean => npm.matches(composer2npm(version), composer2npm(range)); -const maxSatisfyingVersion = (versions: string[], range: string) => +const maxSatisfyingVersion = (versions: string[], range: string): string => npm.maxSatisfyingVersion(versions.map(composer2npm), composer2npm(range)); -const minSatisfyingVersion = (versions: string[], range: string) => +const minSatisfyingVersion = (versions: string[], range: string): string => npm.minSatisfyingVersion(versions.map(composer2npm), composer2npm(range)); function getNewValue( @@ -70,7 +70,7 @@ function getNewValue( rangeStrategy: RangeStrategy, fromVersion: string, toVersion: string -) { +): string { if (rangeStrategy === 'pin') { return toVersion; } @@ -138,7 +138,7 @@ function getNewValue( return newValue; } -function sortVersions(a: string, b: string) { +function sortVersions(a: string, b: string): number { return npm.sortVersions(composer2npm(a), composer2npm(b)); } diff --git a/lib/versioning/docker/index.ts b/lib/versioning/docker/index.ts index 9f7f4ab4c131f1e256c6b0996f076733431b21f5..00b6f64f089347140009128779e782dc8e8fc724 100644 --- a/lib/versioning/docker/index.ts +++ b/lib/versioning/docker/index.ts @@ -1,7 +1,7 @@ import * as generic from '../loose/generic'; import { VersioningApi } from '../common'; -function parse(version: string) { +function parse(version: string): any { const versionPieces = version.replace(/^v/, '').split('-'); const prefix = versionPieces.shift(); const suffix = versionPieces.join('-'); @@ -12,12 +12,12 @@ function parse(version: string) { return { release, suffix }; } -function valueToVersion(value: string) { +function valueToVersion(value: string): string { // Remove any suffix after '-', e.g. '-alpine' return value ? value.split('-')[0] : value; } -function compare(version1: string, vervion2: string) { +function compare(version1: string, vervion2: string): number { const parsed1 = parse(version1); const parsed2 = parse(vervion2); // istanbul ignore if @@ -43,7 +43,7 @@ function compare(version1: string, vervion2: string) { return parsed2.suffix.localeCompare(parsed1.suffix); } -function isCompatible(version: string, range: string) { +function isCompatible(version: string, range: string): boolean { const parsed1 = parse(version); const parsed2 = parse(range); return ( diff --git a/lib/versioning/hashicorp/index.ts b/lib/versioning/hashicorp/index.ts index 5ed2786188c9e550b8b104cbeea5b64eaba98f24..f29b5ee4b0ac582f553d4768389aff78bf086aa7 100644 --- a/lib/versioning/hashicorp/index.ts +++ b/lib/versioning/hashicorp/index.ts @@ -1,23 +1,24 @@ import { api as npm } from '../npm'; import { VersioningApi, RangeStrategy } from '../common'; -function hashicorp2npm(input: string) { +function hashicorp2npm(input: string): string { // The only case incompatible with semver is a "short" ~>, e.g. ~> 1.2 return input.replace(/~>(\s*\d+\.\d+$)/, '^$1').replace(',', ''); } -const isLessThanRange = (version: string, range: string) => +const isLessThanRange = (version: string, range: string): boolean => npm.isLessThanRange(hashicorp2npm(version), hashicorp2npm(range)); -export const isValid = (input: string) => npm.isValid(hashicorp2npm(input)); +export const isValid = (input: string): string | boolean => + npm.isValid(hashicorp2npm(input)); -const matches = (version: string, range: string) => +const matches = (version: string, range: string): boolean => npm.matches(hashicorp2npm(version), hashicorp2npm(range)); -const maxSatisfyingVersion = (versions: string[], range: string) => +const maxSatisfyingVersion = (versions: string[], range: string): string => npm.maxSatisfyingVersion(versions.map(hashicorp2npm), hashicorp2npm(range)); -const minSatisfyingVersion = (versions: string[], range: string) => +const minSatisfyingVersion = (versions: string[], range: string): string => npm.minSatisfyingVersion(versions.map(hashicorp2npm), hashicorp2npm(range)); function getNewValue( @@ -25,7 +26,7 @@ function getNewValue( rangeStrategy: RangeStrategy, fromVersion: string, toVersion: string -) { +): string { // handle specia. ~> 1.2 case if (currentValue.match(/(~>\s*)\d+\.\d+$/)) { return currentValue.replace( diff --git a/lib/versioning/hex/index.ts b/lib/versioning/hex/index.ts index a6e396fb93331b39c64ba6d1fe77d537c68a843d..4f7b9a20f921903a2e3ae370ec9b0fc66ac33313 100644 --- a/lib/versioning/hex/index.ts +++ b/lib/versioning/hex/index.ts @@ -1,7 +1,7 @@ import { api as npm } from '../npm'; import { VersioningApi, RangeStrategy } from '../common'; -function hex2npm(input: string) { +function hex2npm(input: string): string { return input .replace(/~>\s*(\d+\.\d+)$/, '^$1') .replace(/~>\s*(\d+\.\d+\.\d+)/, '~$1') @@ -10,7 +10,7 @@ function hex2npm(input: string) { .replace(/!=\s*(\d+\.\d+(\.\d+.*)?)/, '>$1 <$1'); } -function npm2hex(input: string) { +function npm2hex(input: string): string { const res = input .split(' ') .map(str => str.trim()) @@ -31,18 +31,19 @@ function npm2hex(input: string) { return output; } -const isLessThanRange = (version: string, range: string) => +const isLessThanRange = (version: string, range: string): boolean => npm.isLessThanRange(hex2npm(version), hex2npm(range)); -const isValid = (input: string) => npm.isValid(hex2npm(input)); +const isValid = (input: string): string | boolean => + npm.isValid(hex2npm(input)); -const matches = (version: string, range: string) => +const matches = (version: string, range: string): boolean => npm.matches(hex2npm(version), hex2npm(range)); -const maxSatisfyingVersion = (versions: string[], range: string) => +const maxSatisfyingVersion = (versions: string[], range: string): string => npm.maxSatisfyingVersion(versions.map(hex2npm), hex2npm(range)); -const minSatisfyingVersion = (versions: string[], range: string) => +const minSatisfyingVersion = (versions: string[], range: string): string => npm.minSatisfyingVersion(versions.map(hex2npm), hex2npm(range)); const getNewValue = ( @@ -50,7 +51,7 @@ const getNewValue = ( rangeStrategy: RangeStrategy, fromVersion: string, toVersion: string -) => { +): string => { let newSemver = npm.getNewValue( hex2npm(currentValue), rangeStrategy, diff --git a/lib/versioning/ivy/index.ts b/lib/versioning/ivy/index.ts index 68d516c88234f3595c33ce7eba485eedde46b88f..7f273001e697c5073c3fc1cc8aa0744572e426c8 100644 --- a/lib/versioning/ivy/index.ts +++ b/lib/versioning/ivy/index.ts @@ -22,14 +22,14 @@ const { sortVersions, } = maven; -function isVersion(str: string) { +function isVersion(str: string): string | boolean { if (!str) { return false; } return isSingleVersion(str) || !!parseDynamicRevision(str); } -function matches(a: string, b: string) { +function matches(a: string, b: string): boolean { if (!a) return false; if (!b) return false; const dynamicRevision = parseDynamicRevision(b); diff --git a/lib/versioning/loose/generic.ts b/lib/versioning/loose/generic.ts index bec102da6293ed2e7fb4c02ca5e505b8f63baf4d..ce5c09d199482c5b1a8ad353fcd2466b2e3de151 100644 --- a/lib/versioning/loose/generic.ts +++ b/lib/versioning/loose/generic.ts @@ -16,34 +16,38 @@ export interface VersionComparator { // parse should return null if version not valid // parse should return an object with property release, an array of version sections major.minor.patch export const parser = (parse: VersionParser): Partial<VersioningApi> => { - function isValid(version: string) { + function isValid(version: string): string { if (!version) { return null; } const parsed = parse(version); return parsed ? version : null; } - function getSection(version: string, index: number) { + function getSection(version: string, index: number): number { const parsed = parse(version); return parsed && parsed.release.length > index ? parsed.release[index] : null; } - function getMajor(version: string) { + function getMajor(version: string): number { return getSection(version, 0); } - function getMinor(version: string) { + function getMinor(version: string): number { return getSection(version, 1); } - function getPatch(version: string) { + function getPatch(version: string): number { return getSection(version, 2); } + function isStable(version: string): boolean { + return !!isValid(version); + } + return { // validation isCompatible: isValid, isSingleVersion: isValid, - isStable: v => !!isValid(v), + isStable, isValid, isVersion: isValid, // digestion of version @@ -58,22 +62,22 @@ export const parser = (parse: VersionParser): Partial<VersioningApi> => { export const comparer = ( compare: VersionComparator ): Partial<VersioningApi> => { - function equals(version: string, other: string) { + function equals(version: string, other: string): boolean { return compare(version, other) === 0; } - function isGreaterThan(version: string, other: string) { + function isGreaterThan(version: string, other: string): boolean { return compare(version, other) > 0; } - function isLessThanRange(version: string, range: string) { + function isLessThanRange(version: string, range: string): boolean { return compare(version, range) < 0; } // we don't not have ranges, so versions has to be equal - function maxSatisfyingVersion(versions: string[], range: string) { + function maxSatisfyingVersion(versions: string[], range: string): string { return versions.find(v => equals(v, range)) || null; } - function minSatisfyingVersion(versions: string[], range: string) { + function minSatisfyingVersion(versions: string[], range: string): string { return versions.find(v => equals(v, range)) || null; } function getNewValue( @@ -81,10 +85,10 @@ export const comparer = ( _rangeStrategy: RangeStrategy, _fromVersion: string, toVersion: string - ) { + ): string { return toVersion; } - function sortVersions(version: string, other: string) { + function sortVersions(version: string, other: string): number { return compare(version, other); } @@ -108,7 +112,7 @@ export const create = ({ }: { parse: VersionParser; compare: VersionComparator; -}) => { +}): any => { let schema: VersioningApi = {} as any; if (parse) { schema = { ...schema, ...parser(parse) }; @@ -122,7 +126,7 @@ export const create = ({ export abstract class GenericVersioningApi< T extends GenericVersion = GenericVersion > implements VersioningApi { - private _getSection(version: string, index: number) { + private _getSection(version: string, index: number): number { const parsed = this._parse(version); return parsed && parsed.release.length > index ? parsed.release[index] diff --git a/lib/versioning/loose/index.ts b/lib/versioning/loose/index.ts index 9c6f53985b74e15e762517d3d25a784297638d00..2f2cf8b0c9103f7e2f38c39669f550eb16718156 100644 --- a/lib/versioning/loose/index.ts +++ b/lib/versioning/loose/index.ts @@ -3,7 +3,7 @@ import { VersioningApi } from '../common'; const pattern = /^v?(\d+(?:\.\d+)*)(.*)$/; -function parse(version: string) { +function parse(version: string): any { const matches = pattern.exec(version); if (!matches) { return null; @@ -16,7 +16,7 @@ function parse(version: string) { return { release, suffix: suffix || '' }; } -function compare(version1: string, vervion2: string) { +function compare(version1: string, vervion2: string): number { const parsed1 = parse(version1); const parsed2 = parse(vervion2); // istanbul ignore if diff --git a/lib/versioning/maven/compare.ts b/lib/versioning/maven/compare.ts index 32af458aa7686a517484fb62e5c2184b98c58e38..af22f91bdabf94f7cce0c7d012558985025ad925 100644 --- a/lib/versioning/maven/compare.ts +++ b/lib/versioning/maven/compare.ts @@ -23,7 +23,7 @@ export interface QualifierToken extends BaseToken { export type Token = NumberToken | QualifierToken; -function iterateChars(str: string, cb: (p: string, n: string) => void) { +function iterateChars(str: string, cb: (p: string, n: string) => void): void { let prev = null; let next = null; for (let i = 0; i < str.length; i += 1) { @@ -34,26 +34,26 @@ function iterateChars(str: string, cb: (p: string, n: string) => void) { cb(prev, null); } -function isDigit(char: string) { +function isDigit(char: string): boolean { return /^\d$/.test(char); } -function isLetter(char: string) { +function isLetter(char: string): boolean { return /^[a-z]$/i.test(char); } -function isTransition(prevChar: string, nextChar: string) { +function isTransition(prevChar: string, nextChar: string): boolean { return ( (isDigit(prevChar) && isLetter(nextChar)) || (isLetter(prevChar) && isDigit(nextChar)) ); } -function iterateTokens(versionStr: string, cb: (token: Token) => void) { +function iterateTokens(versionStr: string, cb: (token: Token) => void): void { let currentPrefix = PREFIX_HYPHEN; let currentVal = ''; - function yieldToken(transition = false) { + function yieldToken(transition = false): void { const val = currentVal || '0'; if (/^\d+$/.test(val)) { cb({ @@ -93,7 +93,7 @@ function iterateTokens(versionStr: string, cb: (token: Token) => void) { }); } -function isNull(token: Token) { +function isNull(token: Token): boolean { const val = token.val; return ( val === 0 || @@ -112,7 +112,7 @@ const zeroToken: NumberToken = { isTransition: false, }; -function tokenize(versionStr: string) { +function tokenize(versionStr: string): Token[] { let buf: Token[] = []; let result: Token[] = []; let leadingZero = true; @@ -147,7 +147,7 @@ function nullFor(token: Token): Token { }; } -function commonOrder(token: Token) { +function commonOrder(token: Token): number { if (token.prefix === PREFIX_DOT && token.type === TYPE_QUALIFIER) { return 0; } @@ -160,7 +160,7 @@ function commonOrder(token: Token) { return 3; } -function qualifierOrder(token: Token) { +function qualifierOrder(token: Token): number { const val = token.val; if (val === 'alpha' || (token.isTransition && val === 'a')) { return 1; @@ -192,7 +192,7 @@ function qualifierOrder(token: Token) { return null; } -function qualifierCmp(left: Token, right: Token) { +function qualifierCmp(left: Token, right: Token): number { const leftOrder = qualifierOrder(left); const rightOrder = qualifierOrder(right); if (leftOrder && rightOrder) { @@ -214,7 +214,7 @@ function qualifierCmp(left: Token, right: Token) { return 1; } -function tokenCmp(left: Token, right: Token) { +function tokenCmp(left: Token, right: Token): number { if (left.prefix === right.prefix) { if (left.type === TYPE_NUMBER && right.type === TYPE_NUMBER) { if (left.val === right.val) { @@ -245,7 +245,7 @@ function tokenCmp(left: Token, right: Token) { return 1; } -function compare(left: string, right: string) { +function compare(left: string, right: string): number { const leftTokens = tokenize(left); const rightTokens = tokenize(right); const length = Math.max(leftTokens.length, rightTokens.length); @@ -258,7 +258,7 @@ function compare(left: string, right: string) { return 0; } -function isVersion(version: string) { +function isVersion(version: string): boolean { if (!version) return false; if (!/^[a-z0-9.-]+$/i.test(version)) return false; if (/^[.-]/.test(version)) return false; @@ -270,7 +270,7 @@ function isVersion(version: string) { const INCLUDING_POINT = 'INCLUDING_POINT'; const EXCLUDING_POINT = 'EXCLUDING_POINT'; -function parseRange(rangeStr: string) { +function parseRange(rangeStr: string): any { function emptyInterval(): Range { return { leftType: null, @@ -367,7 +367,7 @@ function parseRange(rangeStr: string) { ); } -function isValid(str: string) { +function isValid(str: string): boolean { if (!str) { return false; } @@ -386,7 +386,7 @@ export interface Range { function rangeToStr(fullRange: Range[]): string | null { if (fullRange === null) return null; - const valToStr = (val: string) => (val === null ? '' : val); + const valToStr = (val: string): string => (val === null ? '' : val); if (fullRange.length === 1) { const { leftBracket, rightBracket, leftValue, rightValue } = fullRange[0]; @@ -417,7 +417,7 @@ function autoExtendMavenRange( ): string | null { const range = parseRange(currentRepresentation); if (!range) return currentRepresentation; - const isPoint = (vals: Range[]) => { + const isPoint = (vals: Range[]): boolean => { if (vals.length !== 1) return false; const { leftType, leftValue, rightType, rightValue } = vals[0]; return ( @@ -454,7 +454,7 @@ function autoExtendMavenRange( return rangeToStr(range); } -function isSubversion(majorVersion: string, minorVersion: string) { +function isSubversion(majorVersion: string, minorVersion: string): boolean { const majorTokens = tokenize(majorVersion); const minorTokens = tokenize(minorVersion); diff --git a/lib/versioning/maven/index.ts b/lib/versioning/maven/index.ts index 645e22060806e1cc627c1cc7f40da9328e20613e..4cf72ac3ce8a7d0b67cbcf108a607137b597ccde 100644 --- a/lib/versioning/maven/index.ts +++ b/lib/versioning/maven/index.ts @@ -12,14 +12,14 @@ import { } from './compare'; import { RangeStrategy, VersioningApi } from '../common'; -const equals = (a: string, b: string) => compare(a, b) === 0; +const equals = (a: string, b: string): boolean => compare(a, b) === 0; -function matches(a: string, b: string) { +function matches(a: string, b: string): boolean { if (!b) return false; if (isVersion(b)) return equals(a, b); const ranges = parseRange(b); if (!ranges) return false; - return ranges.reduce((result, range) => { + return ranges.reduce((result, range): any => { if (result) return result; const { leftType, leftValue, rightType, rightValue } = range; @@ -83,7 +83,7 @@ const getPatch = (version: string): number | null => { return null; }; -const isGreaterThan = (a: string, b: string) => compare(a, b) === 1; +const isGreaterThan = (a: string, b: string): boolean => compare(a, b) === 1; const isStable = (version: string): boolean | null => { if (isVersion(version)) { diff --git a/lib/versioning/node/index.ts b/lib/versioning/node/index.ts index 6a150c5bbf13ad331b5d20181a229029941cb46c..dcde501adc3a0648e29ee74cf670d33d291887ba 100644 --- a/lib/versioning/node/index.ts +++ b/lib/versioning/node/index.ts @@ -6,7 +6,7 @@ function getNewValue( rangeStrategy: RangeStrategy, fromVersion: string, toVersion: string -) { +): string { const res = npm.getNewValue( currentValue, rangeStrategy, diff --git a/lib/versioning/npm/index.ts b/lib/versioning/npm/index.ts index 7f60432699718b3e9a8e7fe279770480b46611fd..f78579d9f1657ec1c1835fb2c54798ec82a298f8 100644 --- a/lib/versioning/npm/index.ts +++ b/lib/versioning/npm/index.ts @@ -19,10 +19,10 @@ const { } = semver; // If this is left as an alias, inputs like "17.04.0" throw errors -export const isValid = (input: string) => validRange(input); -export const isVersion = (input: string) => valid(input); +export const isValid = (input: string): string => validRange(input); +export const isVersion = (input: string): string => valid(input); -const isSingleVersion = (constraint: string) => +const isSingleVersion = (constraint: string): string => isVersion(constraint) || (constraint.startsWith('=') && isVersion(constraint.substring(1).trim())); diff --git a/lib/versioning/npm/range.ts b/lib/versioning/npm/range.ts index 92a3ef86bfe4f875cded4476b8aa8262ff77b861..56019cec7ee3d4f3310e8f3d4ace45789fc94175 100644 --- a/lib/versioning/npm/range.ts +++ b/lib/versioning/npm/range.ts @@ -16,7 +16,7 @@ export function getNewValue( rangeStrategy: RangeStrategy, fromVersion: string, toVersion: string -) { +): string { if (rangeStrategy === 'pin' || isVersion(currentValue)) { return toVersion; } diff --git a/lib/versioning/nuget/index.ts b/lib/versioning/nuget/index.ts index dcf69691249721afeecbde1d750903c22da51409..66a420fdd3afccd398342bac885b8da63a8bf80b 100644 --- a/lib/versioning/nuget/index.ts +++ b/lib/versioning/nuget/index.ts @@ -3,7 +3,7 @@ import { VersioningApi } from '../common'; const pattern = /^(\d+(?:\.\d+)*)(-[^+]+)?(\+.*)?$/; -function parse(version: string) { +function parse(version: string): any { const matches = pattern.exec(version); if (!matches) { return null; @@ -13,7 +13,7 @@ function parse(version: string) { return { release, suffix: prereleasesuffix || '' }; } -function compare(version1: string, vervion2: string) { +function compare(version1: string, vervion2: string): number { const parsed1 = parse(version1); const parsed2 = parse(vervion2); // istanbul ignore if @@ -43,7 +43,7 @@ function compare(version1: string, vervion2: string) { return suffixComparison; } -function isStable(version: string) { +function isStable(version: string): boolean { const parsed = parse(version); return parsed && parsed.suffix === ''; } diff --git a/lib/versioning/pep440/index.ts b/lib/versioning/pep440/index.ts index 699fe4a48b6fb4a0d20b6786bcd76103196c9124..f0bf0b09f13affdf0595dfcc1466f71d61887caa 100644 --- a/lib/versioning/pep440/index.ts +++ b/lib/versioning/pep440/index.ts @@ -16,7 +16,7 @@ const { eq: equals, } = pep440; -const isStable = (input: string) => { +const isStable = (input: string): boolean => { const version = explain(input); if (!version) { return false; @@ -25,19 +25,19 @@ const isStable = (input: string) => { }; // If this is left as an alias, inputs like "17.04.0" throw errors -export const isValid = (input: string) => validRange(input); +export const isValid = (input: string): string => validRange(input); -const maxSatisfyingVersion = (versions: string[], range: string) => { +const maxSatisfyingVersion = (versions: string[], range: string): string => { const found = filter(versions, range).sort(sortVersions); return found.length === 0 ? null : found[found.length - 1]; }; -const minSatisfyingVersion = (versions: string[], range: string) => { +const minSatisfyingVersion = (versions: string[], range: string): string => { const found = filter(versions, range).sort(sortVersions); return found.length === 0 ? null : found[0]; }; -export const isSingleVersion = (constraint: string) => +export const isSingleVersion = (constraint: string): string => isVersion(constraint) || (constraint.startsWith('==') && isVersion(constraint.substring(2).trim())); diff --git a/lib/versioning/pep440/range.ts b/lib/versioning/pep440/range.ts index 309940718469232ee4615c40a205d5b719736d5f..fafb81b38b99ebbf36d8b030f866bde200433ef0 100644 --- a/lib/versioning/pep440/range.ts +++ b/lib/versioning/pep440/range.ts @@ -8,7 +8,7 @@ function getFutureVersion( baseVersion: string, toVersion: string, step: number -) { +): string { const toRelease: number[] = parseVersion(toVersion).release; const baseRelease: number[] = parseVersion(baseVersion).release; let found = false; @@ -40,7 +40,7 @@ export function getNewValue( rangeStrategy: RangeStrategy, fromVersion: string, toVersion: string -) { +): string { // easy pin if (rangeStrategy === 'pin') { return '==' + toVersion; diff --git a/lib/versioning/poetry/index.ts b/lib/versioning/poetry/index.ts index 6964d671d15276a05e2c31276fe82854e6b97b94..49ec562ff31080d5897dd198e31b7a2a25cbe8f8 100644 --- a/lib/versioning/poetry/index.ts +++ b/lib/versioning/poetry/index.ts @@ -3,14 +3,14 @@ import { major, minor } from 'semver'; import { api as npm } from '../npm'; import { RangeStrategy, VersioningApi } from '../common'; -function notEmpty(s: string) { +function notEmpty(s: string): boolean { return s !== ''; } // This function works like cargo2npm, but it doesn't // add a '^', because poetry treats versions without operators as // exact versions. -function poetry2npm(input: string) { +function poetry2npm(input: string): string { const versions = input .split(',') .map(str => str.trim()) @@ -21,7 +21,7 @@ function poetry2npm(input: string) { // NOTE: This function is copied from cargo versionsing code. // Poetry uses commas (like in cargo) instead of spaces (like in npm) // for AND operation. -function npm2poetry(input: string) { +function npm2poetry(input: string): string { // Note: this doesn't remove the ^ const res = input .split(' ') @@ -37,22 +37,23 @@ function npm2poetry(input: string) { return res.join(', '); } -const isLessThanRange = (version: string, range: string) => +const isLessThanRange = (version: string, range: string): boolean => npm.isLessThanRange(version, poetry2npm(range)); -export const isValid = (input: string) => npm.isValid(poetry2npm(input)); +export const isValid = (input: string): string | boolean => + npm.isValid(poetry2npm(input)); -const isVersion = (input: string) => npm.isVersion(input); -const matches = (version: string, range: string) => +const isVersion = (input: string): string | boolean => npm.isVersion(input); +const matches = (version: string, range: string): boolean => npm.matches(version, poetry2npm(range)); -const maxSatisfyingVersion = (versions: string[], range: string) => +const maxSatisfyingVersion = (versions: string[], range: string): string => npm.maxSatisfyingVersion(versions, poetry2npm(range)); -const minSatisfyingVersion = (versions: string[], range: string) => +const minSatisfyingVersion = (versions: string[], range: string): string => npm.minSatisfyingVersion(versions, poetry2npm(range)); -const isSingleVersion = (constraint: string) => +const isSingleVersion = (constraint: string): string | boolean => (constraint.trim().startsWith('=') && isVersion( constraint @@ -66,7 +67,7 @@ function handleShort( operator: string, currentValue: string, toVersion: string -) { +): string { const toVersionMajor = major(toVersion); const toVersionMinor = minor(toVersion); const split = currentValue.split('.'); @@ -86,7 +87,7 @@ function getNewValue( rangeStrategy: RangeStrategy, fromVersion: string, toVersion: string -) { +): string { if (rangeStrategy === 'replace') { const npmCurrentValue = poetry2npm(currentValue); const parsedRange = parseRange(npmCurrentValue); diff --git a/lib/versioning/regex/index.ts b/lib/versioning/regex/index.ts index 94395785f4ba2412d67fc299f5c82a5069ba19a6..a841467df5c11fa1916aeb5b8c6818fb5bbe76ff 100644 --- a/lib/versioning/regex/index.ts +++ b/lib/versioning/regex/index.ts @@ -113,7 +113,7 @@ export class RegExpVersioningApi extends GenericVersioningApi<RegExpVersion> { ); } - matches(version: string, range: string) { + matches(version: string, range: string): boolean { return satisfies( asSemver(this._parse(version)), asSemver(this._parse(range)) diff --git a/lib/versioning/ruby/index.ts b/lib/versioning/ruby/index.ts index 01c230b26bba6d4013fb13fd9be4552256fe8f5c..8389ef7efac2b6d928cb277321c7310e2b4887e4 100644 --- a/lib/versioning/ruby/index.ts +++ b/lib/versioning/ruby/index.ts @@ -13,17 +13,18 @@ import { parse as parseRange, ltr } from './range'; import { isSingleOperator, isValidOperator } from './operator'; import { pin, bump, replace } from './strategies'; -const equals = (left: string, right: string) => eq(left, right); +const equals = (left: string, right: string): boolean => eq(left, right); -const getMajor = (version: string) => parseVersion(version).major; -const getMinor = (version: string) => parseVersion(version).minor; -const getPatch = (version: string) => parseVersion(version).patch; +const getMajor = (version: string): number => parseVersion(version).major; +const getMinor = (version: string): number => parseVersion(version).minor; +const getPatch = (version: string): number => parseVersion(version).patch; -export const isVersion = (version: string) => !!valid(version); -const isGreaterThan = (left: string, right: string) => gt(left, right); -const isLessThanRange = (version: string, range: string) => ltr(version, range); +export const isVersion = (version: string): boolean => !!valid(version); +const isGreaterThan = (left: string, right: string): boolean => gt(left, right); +const isLessThanRange = (version: string, range: string): boolean => + ltr(version, range); -const isSingleVersion = (range: string) => { +const isSingleVersion = (range: string): boolean => { const { version, operator } = parseRange(range); return operator @@ -31,10 +32,10 @@ const isSingleVersion = (range: string) => { : isVersion(version); }; -const isStable = (version: string) => +const isStable = (version: string): boolean => parseVersion(version).prerelease ? false : isVersion(version); -export const isValid = (input: string) => +export const isValid = (input: string): boolean => input .split(',') .map(piece => piece.trim()) @@ -46,11 +47,11 @@ export const isValid = (input: string) => : isVersion(version); }); -export const matches = (version: string, range: string) => +export const matches = (version: string, range: string): boolean => satisfies(version, range); -const maxSatisfyingVersion = (versions: string[], range: string) => +const maxSatisfyingVersion = (versions: string[], range: string): string => maxSatisfying(versions, range); -const minSatisfyingVersion = (versions: string[], range: string) => +const minSatisfyingVersion = (versions: string[], range: string): string => minSatisfying(versions, range); const getNewValue = ( @@ -58,7 +59,7 @@ const getNewValue = ( rangeStrategy: RangeStrategy, _fromVersion: string, toVersion: string -) => { +): string => { switch (rangeStrategy) { case 'pin': return pin({ to: toVersion }); @@ -73,7 +74,7 @@ const getNewValue = ( } }; -export const sortVersions = (left: string, right: string) => +export const sortVersions = (left: string, right: string): number => gt(left, right) ? 1 : -1; export const api: VersioningApi = { diff --git a/lib/versioning/ruby/operator.ts b/lib/versioning/ruby/operator.ts index 05e32a35e5beb5c1d3dd261bda448e42dc39e22a..7b3b5def09afbe4f980a606ae6cfd022d35cd65a 100644 --- a/lib/versioning/ruby/operator.ts +++ b/lib/versioning/ruby/operator.ts @@ -11,8 +11,9 @@ const PGTE = '~>'; const SINGLE = [EQUAL]; const ALL = [EQUAL, NOT_EQUAL, GT, LT, GTE, LTE, PGTE]; -const isValidOperator = (operator: string) => ALL.includes(operator); -const isSingleOperator = (operator: string) => SINGLE.includes(operator); +const isValidOperator = (operator: string): boolean => ALL.includes(operator); +const isSingleOperator = (operator: string): boolean => + SINGLE.includes(operator); export { EQUAL, diff --git a/lib/versioning/ruby/range.ts b/lib/versioning/ruby/range.ts index e2f161f0e6daf5d020c4e53c0a94c1187c7fea4e..3aaa5e98b00f3842a5b5c1422488d187648c66a5 100644 --- a/lib/versioning/ruby/range.ts +++ b/lib/versioning/ruby/range.ts @@ -27,7 +27,7 @@ interface GemVersion { } type GemRequirement = [string, GemVersion]; -const ltr = (version: string, range: string) => { +const ltr = (version: string, range: string): boolean => { const gemVersion: GemVersion = create(version); const requirements: GemRequirement[] = range.split(',').map(_parse); diff --git a/lib/versioning/ruby/strategies/bump.ts b/lib/versioning/ruby/strategies/bump.ts index 723adedda7f1191db821b6e88e68f1e9a12c24f6..350127831a18d0bf2090241107211c80478847b5 100644 --- a/lib/versioning/ruby/strategies/bump.ts +++ b/lib/versioning/ruby/strategies/bump.ts @@ -4,7 +4,7 @@ import { EQUAL, NOT_EQUAL, GT, LT, GTE, LTE, PGTE } from '../operator'; import { floor, increment, decrement } from '../version'; import { parse as parseRange } from '../range'; -export default ({ range, to }: { range: string; to: string }) => { +export default ({ range, to }: { range: string; to: string }): string => { const ranges = range.split(',').map(parseRange); const results = ranges.map(({ operator, version: ver }) => { switch (operator) { diff --git a/lib/versioning/ruby/strategies/pin.ts b/lib/versioning/ruby/strategies/pin.ts index 279563363617c24ceca21ebb980994a79f2fb440..e7f7a12b60228b457f6087ddcd03e6ac22e60a8b 100644 --- a/lib/versioning/ruby/strategies/pin.ts +++ b/lib/versioning/ruby/strategies/pin.ts @@ -1 +1 @@ -export default ({ to }: { to: string }) => to; +export default ({ to }: { to: string }): string => to; diff --git a/lib/versioning/ruby/strategies/replace.ts b/lib/versioning/ruby/strategies/replace.ts index 927c9a7b1d8aab3cd238837c76b2645255384ccb..0fde62c4b342b36199344dc0a2f92db104d7e8fb 100644 --- a/lib/versioning/ruby/strategies/replace.ts +++ b/lib/versioning/ruby/strategies/replace.ts @@ -1,7 +1,7 @@ import { satisfies } from '@snyk/ruby-semver'; import bump from './bump'; -export default ({ to, range }: { range: string; to: string }) => { +export default ({ to, range }: { range: string; to: string }): string => { if (satisfies(to, range)) { return range; } diff --git a/lib/versioning/ruby/version.ts b/lib/versioning/ruby/version.ts index e46d249b0af6e8fe537295cfc3a76cd5d4de82aa..edad649cefbd3c0b255eac72d4a24a6683b13789 100644 --- a/lib/versioning/ruby/version.ts +++ b/lib/versioning/ruby/version.ts @@ -16,13 +16,13 @@ const parse = (version: string): RubyVersion => ({ prerelease: prerelease(version), }); -const adapt = (left: string, right: string) => +const adapt = (left: string, right: string): string => left .split('.') .slice(0, right.split('.').length) .join('.'); -const floor = (version: string) => +const floor = (version: string): string => [ ...create(version) .release() @@ -32,7 +32,7 @@ const floor = (version: string) => ].join('.'); // istanbul ignore next -const incrementLastSegment = (version: string) => { +const incrementLastSegment = (version: string): string => { const segments = create(version) .release() .getSegments(); @@ -47,14 +47,14 @@ const incrementMajor = ( min: number, ptch: number, pre: string[] -) => (min === 0 || ptch === 0 || pre.length === 0 ? maj + 1 : maj); +): number => (min === 0 || ptch === 0 || pre.length === 0 ? maj + 1 : maj); // istanbul ignore next -const incrementMinor = (min: number, ptch: number, pre: string[]) => +const incrementMinor = (min: number, ptch: number, pre: string[]): number => ptch === 0 || pre.length === 0 ? min + 1 : min; // istanbul ignore next -const incrementPatch = (ptch: number, pre: string[]) => +const incrementPatch = (ptch: number, pre: string[]): number => pre.length === 0 ? ptch + 1 : ptch; // istanbul ignore next diff --git a/lib/versioning/semver/index.ts b/lib/versioning/semver/index.ts index cadf2f520af4aead283d43f34b0a568808e2dd9c..9b068e357867d0ea3bee3cd96a91f206b0930dc1 100644 --- a/lib/versioning/semver/index.ts +++ b/lib/versioning/semver/index.ts @@ -19,7 +19,7 @@ const { } = semver; // If this is left as an alias, inputs like "17.04.0" throw errors -export const isVersion = (input: string) => valid(input); +export const isVersion = (input: string): string => valid(input); export { isVersion as isValid, maxSatisfyingVersion }; @@ -28,7 +28,7 @@ function getNewValue( _rangeStrategy: RangeStrategy, _fromVersion: string, toVersion: string -) { +): string { return toVersion; } diff --git a/lib/versioning/swift/index.ts b/lib/versioning/swift/index.ts index 0f0df3a22646e5a52ee9fdac1e41edb7818174bc..8ec6dcc2f9281cc907c53664dd27727d03f1dd81 100644 --- a/lib/versioning/swift/index.ts +++ b/lib/versioning/swift/index.ts @@ -20,16 +20,16 @@ const { eq: equals, } = semver; -export const isValid = (input: string) => +export const isValid = (input: string): boolean => !!valid(input) || !!validRange(toSemverRange(input)); -export const isVersion = (input: string) => !!valid(input); -const maxSatisfyingVersion = (versions: string[], range: string) => +export const isVersion = (input: string): boolean => !!valid(input); +const maxSatisfyingVersion = (versions: string[], range: string): string => maxSatisfying(versions, toSemverRange(range)); -const minSatisfyingVersion = (versions: string[], range: string) => +const minSatisfyingVersion = (versions: string[], range: string): string => minSatisfying(versions, toSemverRange(range)); -const isLessThanRange = (version: string, range: string) => +const isLessThanRange = (version: string, range: string): boolean => ltr(version, toSemverRange(range)); -const matches = (version: string, range: string) => +const matches = (version: string, range: string): boolean => satisfies(version, toSemverRange(range)); export const api: VersioningApi = { diff --git a/lib/versioning/swift/range.ts b/lib/versioning/swift/range.ts index 9552cf45758f60ab430d309ea6ed548566ffe23b..9bfaa6a4a2ec0f585fc199396d152622527ef7d8 100644 --- a/lib/versioning/swift/range.ts +++ b/lib/versioning/swift/range.ts @@ -6,7 +6,7 @@ const fromRange = /^\s*"([^"]+)"\s*\.\.\.\s*$/; const binaryRange = /^\s*"([^"]+)"\s*(\.\.[.<])\s*"([^"]+)"\s*$/; const toRange = /^\s*(\.\.[.<])\s*"([^"]+)"\s*$/; -function toSemverRange(range: string) { +function toSemverRange(range: string): string { if (fromParam.test(range)) { const [, version] = range.match(fromParam); if (semver.valid(version)) { @@ -39,7 +39,7 @@ function getNewValue( _rangeStrategy: RangeStrategy, _fromVersion: string, toVersion: string -) { +): string { if (fromParam.test(currentValue)) { return toVersion; } diff --git a/lib/workers/branch/schedule.ts b/lib/workers/branch/schedule.ts index c10be4b7dec161dee01967fc7db6ef1ec29487b1..c3ff3f3636ed475ae45d51bf2c9899ad47afe1fc 100644 --- a/lib/workers/branch/schedule.ts +++ b/lib/workers/branch/schedule.ts @@ -65,7 +65,7 @@ export function hasValidSchedule( return [true, '']; } -export function isScheduledNow(config) { +export function isScheduledNow(config): boolean { let configSchedule = config.schedule; logger.debug(`Checking schedule(${configSchedule}, ${config.timezone})`); if ( diff --git a/lib/workers/branch/status-checks.ts b/lib/workers/branch/status-checks.ts index c05704a7882f10d3ee61422a6fc7c77ce677407f..e9dfc6c2b3584254e20a0c1f80802ae08ca35bbe 100644 --- a/lib/workers/branch/status-checks.ts +++ b/lib/workers/branch/status-checks.ts @@ -8,7 +8,7 @@ async function setStatusCheck( context: string, description: string, state: string -) { +): Promise<void> { const existingState = await platform.getBranchStatusCheck( branchName, context @@ -33,7 +33,7 @@ export type StabilityConfig = RenovateConfig & { branchName: string; }; -export async function setStability(config: StabilityConfig) { +export async function setStability(config: StabilityConfig): Promise<void> { if (!config.stabilityStatus) { return; } diff --git a/lib/workers/global/limits.ts b/lib/workers/global/limits.ts index ed2f2cf670d952ffba3bfdd3bba30126422d7525..0cf7d3052da9f32f16f4ebb19a66032b510d02db 100644 --- a/lib/workers/global/limits.ts +++ b/lib/workers/global/limits.ts @@ -4,12 +4,12 @@ const limitsToInit = ['prCommitsPerRunLimit']; const l: Record<string, number> = {}; const v: Record<string, number> = {}; -export function setLimit(name: string, value: number) { +export function setLimit(name: string, value: number): void { logger.debug(`Limits.setLimit l[${name}] = ${value}`); l[name] = value; } -export function init(config: Record<string, any>) { +export function init(config: Record<string, any>): void { logger.debug(`Limits.init enter method`); for (const limit of limitsToInit) { logger.debug(`Limits.init ${limit} processing`); @@ -24,7 +24,7 @@ export function init(config: Record<string, any>) { } } -export function getLimitRemaining(name: string) { +export function getLimitRemaining(name: string): number { let result; if (typeof v[name] !== 'undefined') { result = l[name] - v[name]; @@ -34,7 +34,7 @@ export function getLimitRemaining(name: string) { return result; } -export function incrementLimit(name: string, value = 1) { +export function incrementLimit(name: string, value = 1): void { if (typeof v[name] !== 'undefined') { v[name] += value; } diff --git a/lib/workers/repository/onboarding/branch/check.ts b/lib/workers/repository/onboarding/branch/check.ts index 2e6ee518a2eea87a1785b04bbf28da5347560a48..635643ce3bdce3e9c4f66dc574027a5571882d7b 100644 --- a/lib/workers/repository/onboarding/branch/check.ts +++ b/lib/workers/repository/onboarding/branch/check.ts @@ -36,7 +36,10 @@ const packageJsonConfigExists = async (): Promise<boolean> => { return false; }; -const closedPrExists = () => +// TODO: types +export type Pr = any; + +const closedPrExists = (): Promise<Pr> => platform.findPr(onboardingBranch, onboardingPrTitle, '!open'); export const isOnboarded = async (config: RenovateConfig): Promise<boolean> => { @@ -88,4 +91,5 @@ export const isOnboarded = async (config: RenovateConfig): Promise<boolean> => { throw new Error('disabled'); }; -export const onboardingPrExists = () => platform.getBranchPr(onboardingBranch); +export const onboardingPrExists = (): Promise<boolean> => + platform.getBranchPr(onboardingBranch); diff --git a/lib/workers/repository/process/lookup/index.ts b/lib/workers/repository/process/lookup/index.ts index 6a9539373d1f8f02242c1341ab8632c6423e97cf..32c070a95c73291586a599764fe76a1ee2d2e87f 100644 --- a/lib/workers/repository/process/lookup/index.ts +++ b/lib/workers/repository/process/lookup/index.ts @@ -109,7 +109,7 @@ function getFromVersion( return version.maxSatisfyingVersion(useVersions, currentValue); } -function getBucket(config: LookupUpdateConfig, update: LookupUpdate) { +function getBucket(config: LookupUpdateConfig, update: LookupUpdate): string { const { separateMajorMinor, separateMultipleMajor } = config; const { updateType, newMajor } = update; if (updateType === 'lockfileUpdate') { diff --git a/lib/workers/repository/updates/branchify.ts b/lib/workers/repository/updates/branchify.ts index 15dc93ce9f42d0dacc9c685035050e00a7b54774..28e040750cc5fdbddeaf47c147d2f8ffd9d8eeb2 100644 --- a/lib/workers/repository/updates/branchify.ts +++ b/lib/workers/repository/updates/branchify.ts @@ -25,7 +25,7 @@ function cleanBranchName(branchName: string): string { export function branchifyUpgrades( config: RenovateConfig, packageFiles: Record<string, any[]> -) { +): RenovateConfig { logger.debug('branchifyUpgrades'); const updates = flattenUpdates(config, packageFiles); logger.debug( @@ -43,7 +43,8 @@ export function branchifyUpgrades( update.currentVersion = update.currentValue; update.newVersion = update.newVersion || update.newValue; // massage for handlebars - const upper = (str: string) => str.charAt(0).toUpperCase() + str.substr(1); + const upper = (str: string): string => + str.charAt(0).toUpperCase() + str.substr(1); if (update.updateType) { update[`is${upper(update.updateType)}`] = true; } diff --git a/lib/workers/repository/updates/flatten.ts b/lib/workers/repository/updates/flatten.ts index e8e3694d4352ab50533e5bfe1d34df36b9832c03..83d12cbacf0011dfe88268c2eb12bc4c16e535e1 100644 --- a/lib/workers/repository/updates/flatten.ts +++ b/lib/workers/repository/updates/flatten.ts @@ -17,7 +17,7 @@ function getUpdateTypeRules(packageRules: PackageRule[]): PackageRule[] { export function flattenUpdates( config: RenovateConfig, packageFiles: Record<string, any[]> -) { +): RenovateConfig[] { const updates = []; const updateTypes = [ 'major', diff --git a/lib/workers/repository/updates/generate.ts b/lib/workers/repository/updates/generate.ts index 54b702c57237bb6784cf1417b8cc322c32e52048..175a1ef754be13e06d9dfe571b827c9c186d9d8d 100644 --- a/lib/workers/repository/updates/generate.ts +++ b/lib/workers/repository/updates/generate.ts @@ -3,7 +3,11 @@ import { DateTime } from 'luxon'; import semver from 'semver'; import mdTable from 'markdown-table'; import { logger } from '../../../logger'; -import { mergeChildConfig, ManagerConfig } from '../../../config'; +import { + mergeChildConfig, + ManagerConfig, + RenovateConfig, +} from '../../../config'; import { PackageDependency } from '../../../manager/common'; function ifTypesGroup( @@ -59,7 +63,7 @@ function getTableValues( return null; } -export function generateBranchConfig(branchUpgrades) { +export function generateBranchConfig(branchUpgrades): RenovateConfig { logger.debug(`generateBranchConfig(${branchUpgrades.length})`); logger.trace({ config: branchUpgrades }); let config: any = { diff --git a/test/.eslintrc.js b/test/.eslintrc.js index e75e9d6d4f310f7c0cfa2e23bf7e0834650593a9..d7cc230f0a8d109050049d489125293f11b2a70d 100644 --- a/test/.eslintrc.js +++ b/test/.eslintrc.js @@ -12,5 +12,6 @@ module.exports = { '@typescript-eslint/no-var-requires': 0, '@typescript-eslint/no-object-literal-type-assertion': 0, + '@typescript-eslint/explicit-function-return-type': 0, }, }; diff --git a/test/static-files.spec.ts b/test/static-files.spec.ts index 4237df1a590c0ff69c8847c26cb3ff72ab92796f..72f090a0cbdbd20b98557b95a013abf95c572325 100644 --- a/test/static-files.spec.ts +++ b/test/static-files.spec.ts @@ -4,13 +4,13 @@ const glob = util.promisify(require('glob')); const ignoredExtensions = ['js', 'ts', 'md', 'pyc', 'DS_Store', 'map']; -function filterFiles(files: string[]) { +function filterFiles(files: string[]): string[] { return files.filter(file => ignoredExtensions.every(extension => !file.endsWith(`.${extension}`)) ); } -async function getFiles(dir: string) { +async function getFiles(dir: string): Promise<string[]> { return filterFiles(await glob(`${dir}/**/*`, { dot: true, nodir: true })).map( (file: string) => file.replace(`${dir}/`, '') ); diff --git a/test/website-docs.spec.ts b/test/website-docs.spec.ts index dc27a0268cde00ade8bed1da17806bdbeb27e35c..49fa105e9f5d6a1935ca5095fcb9c18809084ce8 100644 --- a/test/website-docs.spec.ts +++ b/test/website-docs.spec.ts @@ -72,12 +72,14 @@ describe('docs', () => { toContainOption(received, argument) { if (received.includes(argument)) { return { - message: () => `Option "${argument}" should be within definitions`, + message: (): string => + `Option "${argument}" should be within definitions`, pass: true, }; } return { - message: () => `Option "${argument}" doesn't exist within definitions`, + message: (): string => + `Option "${argument}" doesn't exist within definitions`, pass: false, }; },