diff --git a/lib/manager/gradle/shallow/types.ts b/lib/manager/gradle/shallow/types.ts index f9eeeed2511ad6d7ffd622d4e623f760559c0fe1..ff1bcd5aa6e537ae78e008a6f8bd0a592fa2c574 100644 --- a/lib/manager/gradle/shallow/types.ts +++ b/lib/manager/gradle/shallow/types.ts @@ -47,7 +47,7 @@ export type SyntaxHandlerOutput = { export interface SyntaxMatchConfig { matchers: SyntaxMatcher[]; - handler: (MatcherHandlerInput) => SyntaxHandlerOutput; + handler: (_: SyntaxHandlerInput) => SyntaxHandlerOutput; } export interface MatchConfig { diff --git a/lib/util/http/legacy.ts b/lib/util/http/legacy.ts index 62d4b3c5949d961a21da348c703dd9bdf6c0ad01..037d14848197e59be7799f8416c588dfb303774b 100644 --- a/lib/util/http/legacy.ts +++ b/lib/util/http/legacy.ts @@ -35,8 +35,9 @@ Object.defineProperty(HttpError.prototype, 'url', { Object.defineProperty(HttpError.prototype, 'host', { get: function url(this: HttpError) { - const { host } = parseUrl(this.response?.url) ?? {}; - return host; + const urlStr = this.response?.url; + const url = urlStr ? parseUrl(urlStr) : null; + return url?.host; }, }); diff --git a/lib/versioning/maven/compare.spec.ts b/lib/versioning/maven/compare.spec.ts index 3af2aca6a14a52778355a284ec092f2cb2f2d818..ffc36fbee066a72819a072fd2156c36c014e2b0d 100644 --- a/lib/versioning/maven/compare.spec.ts +++ b/lib/versioning/maven/compare.spec.ts @@ -123,6 +123,7 @@ describe('versioning/maven/compare', () => { ${'[1.3,1.2]'} ${'[1,[2,3],4]'} ${'[,1.0]'} + ${'[,1.0],[,1.0]'} `('filters out incorrect range: $input', ({ input }) => { const range = parseRange(input); expect(range).toBeNull(); diff --git a/lib/versioning/maven/compare.ts b/lib/versioning/maven/compare.ts index 619ae62ce240a8ee456e9e6b69e82a33f764c22b..3d641f8f55939b844b5db52bc106ca220702ffb8 100644 --- a/lib/versioning/maven/compare.ts +++ b/lib/versioning/maven/compare.ts @@ -25,7 +25,10 @@ export interface QualifierToken extends BaseToken { export type Token = NumberToken | QualifierToken; -function iterateChars(str: string, cb: (p: string, n: string) => void): void { +function iterateChars( + str: string, + cb: (p: string | null, n: string | null) => void +): void { let prev = null; let next = null; for (let i = 0; i < str.length; i += 1) { @@ -173,7 +176,7 @@ export enum QualifierTypes { SP, } -export function qualifierType(token: Token): number { +export function qualifierType(token: Token): number | null { const val = token.val; if (val === 'alpha' || (token.isTransition && val === 'a')) { return QualifierTypes.Alpha; @@ -274,8 +277,8 @@ function compare(left: string, right: string): number { return 0; } -function isVersion(version: string): boolean { - if (!version) { +function isVersion(version: unknown): version is string { + if (!version || typeof version !== 'string') { return false; } if (!regEx(/^[a-z0-9.-]+$/i).test(version)) { @@ -297,7 +300,7 @@ function isVersion(version: string): boolean { const INCLUDING_POINT = 'INCLUDING_POINT'; const EXCLUDING_POINT = 'EXCLUDING_POINT'; -function parseRange(rangeStr: string): Range[] { +function parseRange(rangeStr: string): Range[] | null { function emptyInterval(): Range { return { leftType: null, @@ -310,17 +313,17 @@ function parseRange(rangeStr: string): Range[] { } const commaSplit = rangeStr.split(','); - let result: Range[] = []; + let ranges: Range[] | null = []; let interval = emptyInterval(); commaSplit.forEach((subStr) => { - if (!result) { + if (!ranges) { return; } if (interval.leftType === null) { if (regEx(/^\[.*]$/).test(subStr)) { const ver = subStr.slice(1, -1); - result.push({ + ranges.push({ leftType: INCLUDING_POINT, leftValue: ver, leftBracket: '[', @@ -340,43 +343,46 @@ function parseRange(rangeStr: string): Range[] { interval.leftValue = ver; interval.leftBracket = subStr[0]; } else { - result = null; + ranges = null; } } else if (subStr.endsWith(']')) { const ver = subStr.slice(0, -1); interval.rightType = INCLUDING_POINT; interval.rightValue = ver; interval.rightBracket = ']'; - result.push(interval); + ranges.push(interval); interval = emptyInterval(); } else if (subStr.endsWith(')') || subStr.endsWith('[')) { const ver = subStr.slice(0, -1); interval.rightType = EXCLUDING_POINT; interval.rightValue = ver; interval.rightBracket = subStr.endsWith(')') ? ')' : '['; - result.push(interval); + ranges.push(interval); interval = emptyInterval(); } else { - result = null; + ranges = null; } }); if (interval.leftType) { return null; } // something like '[1,2],[3' - if (!result || !result.length) { + if (!ranges || !ranges.length) { return null; } - const lastIdx = result.length - 1; - let prevValue: string = null; - return result.reduce((acc, range, idx) => { + const lastIdx = ranges.length - 1; + let prevValue: string | null = null; + const result: Range[] = []; + for (let idx = 0; idx < ranges.length; idx += 1) { + const range = ranges[idx]; const { leftType, leftValue, rightType, rightValue } = range; if (idx === 0 && leftValue === '') { if (leftType === EXCLUDING_POINT && isVersion(rightValue)) { prevValue = rightValue; - return [...acc, { ...range, leftValue: null }]; + result.push({ ...range, leftValue: null }); + continue; } return null; } @@ -385,7 +391,8 @@ function parseRange(rangeStr: string): Range[] { if (prevValue && compare(prevValue, leftValue) === 1) { return null; } - return [...acc, { ...range, rightValue: null }]; + result.push({ ...range, rightValue: null }); + continue; } return null; } @@ -397,10 +404,12 @@ function parseRange(rangeStr: string): Range[] { return null; } prevValue = rightValue; - return [...acc, range]; + result.push(range); + continue; } return null; - }, [] as Range[]); + } + return result; } function isValid(str: string): boolean { @@ -411,20 +420,20 @@ function isValid(str: string): boolean { } export interface Range { - leftType: typeof INCLUDING_POINT | typeof EXCLUDING_POINT; - leftValue: string; - leftBracket: string; - rightType: typeof INCLUDING_POINT | typeof EXCLUDING_POINT; - rightValue: string; - rightBracket: string; + leftType: typeof INCLUDING_POINT | typeof EXCLUDING_POINT | null; + leftValue: string | null; + leftBracket: string | null; + rightType: typeof INCLUDING_POINT | typeof EXCLUDING_POINT | null; + rightValue: string | null; + rightBracket: string | null; } -function rangeToStr(fullRange: Range[]): string | null { +function rangeToStr(fullRange: Range[] | null): string | null { if (fullRange === null) { return null; } - const valToStr = (val: string): string => (val === null ? '' : val); + const valToStr = (val: string | null): string => (val === null ? '' : val); if (fullRange.length === 1) { const { leftBracket, rightBracket, leftValue, rightValue } = fullRange[0]; diff --git a/lib/versioning/maven/index.ts b/lib/versioning/maven/index.ts index 589ecfc7af56bb0f3f94acf79850e281fc7e6738..f4c8301c1345dfd2b9cdc53459513c55f459e018 100644 --- a/lib/versioning/maven/index.ts +++ b/lib/versioning/maven/index.ts @@ -105,7 +105,7 @@ const getPatch = (version: string): number | null => { const isGreaterThan = (a: string, b: string): boolean => compare(a, b) === 1; -const isStable = (version: string): boolean | null => { +const isStable = (version: string): boolean => { if (isVersion(version)) { const tokens = tokenize(version); for (const token of tokens) { @@ -118,12 +118,15 @@ const isStable = (version: string): boolean | null => { } return true; } - return null; + return false; }; // istanbul ignore next -const getSatisfyingVersion = (versions: string[], range: string): string => - versions.reduce((result, version) => { +const getSatisfyingVersion = ( + versions: string[], + range: string +): string | null => + versions.reduce((result: string | null, version) => { if (matches(version, range)) { if (!result) { return version; @@ -139,11 +142,11 @@ function getNewValue({ currentValue, rangeStrategy, newVersion, -}: NewValueConfig): string | null { +}: NewValueConfig): string { if (isVersion(currentValue) || rangeStrategy === 'pin') { return newVersion; } - return autoExtendMavenRange(currentValue, newVersion); + return autoExtendMavenRange(currentValue, newVersion) ?? currentValue; } export { isValid }; diff --git a/tsconfig.strict.json b/tsconfig.strict.json index 8fd3ec0ec6a3c550d0c7d3124ba2ccad02cd3864..f2c9059d43a16d157c605fd909c37489c510e0a8 100644 --- a/tsconfig.strict.json +++ b/tsconfig.strict.json @@ -14,6 +14,7 @@ "lib/data-files.generated.ts", "lib/datasource/**/common.ts", "lib/datasource/**/types.ts", + "lib/datasource/gitlab-tags/util.ts", "lib/globals.d.ts", "lib/logger/**/*.ts", "lib/manager/**/common.ts", @@ -23,7 +24,7 @@ "lib/platform/utils/pr-body.ts", "lib/proxy.ts", "lib/types/**/*.ts", - "lib/util/cache/*.ts", + "lib/util/cache/**/*.ts", "lib/util/clone.ts", "lib/util/date.ts", "lib/util/exec", @@ -33,9 +34,11 @@ "lib/util/host-rules.ts", "lib/util/html.ts", "lib/util/http/hooks.ts", + "lib/util/http/legacy.ts", "lib/util/http/types.ts", "lib/util/index.ts", "lib/util/json-writer/indentation-type.ts", + "lib/util/markdown.ts", "lib/util/mask.spec.ts", "lib/util/mask.ts", "lib/util/object.ts", @@ -44,14 +47,16 @@ "lib/util/sanitize.ts", "lib/util/split.ts", "lib/util/url.ts", - "lib/versioning/swift/*.ts", - "lib/versioning/ubuntu/*.ts", - "lib/versioning/semver/*.ts", - "lib/versioning/semver-coerced/*.ts", + "lib/versioning/maven/**/*.ts", + "lib/versioning/semver-coerced/**/*.ts", + "lib/versioning/semver/**/*.ts", + "lib/versioning/swift/**/*.ts", + "lib/versioning/ubuntu/**/*.ts", "lib/workers/pr/changelog/hbs-template.ts", "lib/workers/pr/changelog/types.ts", "lib/workers/repository/init/types.ts", "lib/workers/repository/model/commit-message.ts", + "test/exec-util.ts", "test/graphql-snapshot.ts", "test/http-mock.ts", "test/json-schema.ts", @@ -67,8 +72,7 @@ "lib/datasource/go/types.ts", "lib/datasource/helm/common.ts", "lib/logger/err-serializer.spec.ts", - "lib/manager/gradle/shallow/types.ts", - "lib/util/cache/*.spec.ts", + "lib/util/cache/**/*.spec.ts", "lib/util/exec/buildpack.spec.ts", "lib/util/exec/buildpack.ts", "lib/util/exec/docker/index.spec.ts",