From 081a23e6fcd54835290eba09ca4be79ffcc4b639 Mon Sep 17 00:00:00 2001 From: IKEDA Sho Date: Fri, 23 Aug 2019 00:42:35 +0900 Subject: [PATCH] chore(manager): add more type annotations (#4344) --- lib/manager/ansible/extract.ts | 4 ++- lib/manager/ansible/update.ts | 2 +- lib/manager/bazel/extract.ts | 13 ++++--- lib/manager/bazel/update.ts | 19 +++++----- lib/manager/buildkite/extract.ts | 2 +- lib/manager/buildkite/update.ts | 5 ++- lib/manager/bundler/artifacts.ts | 4 +-- lib/manager/bundler/extract.ts | 2 +- lib/manager/bundler/range.ts | 4 ++- lib/manager/bundler/update.ts | 2 +- lib/manager/cargo/artifacts.ts | 2 +- lib/manager/cargo/extract.ts | 4 +-- lib/manager/cargo/update.ts | 6 ++-- lib/manager/circleci/extract.ts | 2 +- lib/manager/circleci/update.ts | 2 +- lib/manager/common.ts | 15 +++++--- lib/manager/composer/artifacts.ts | 4 +-- lib/manager/composer/extract.ts | 5 ++- lib/manager/dockerfile/extract.ts | 4 +-- lib/manager/dockerfile/update.ts | 7 ++-- lib/manager/droneci/extract.ts | 2 +- lib/manager/droneci/update.ts | 2 +- lib/manager/github-actions/extract.ts | 2 +- lib/manager/github-actions/update.ts | 2 +- lib/manager/gitlabci-include/extract.ts | 4 +-- lib/manager/gitlabci-include/update.ts | 2 +- lib/manager/gitlabci/extract.ts | 2 +- lib/manager/gitlabci/update.ts | 2 +- lib/manager/gomod/artifacts.ts | 2 +- lib/manager/gomod/extract.ts | 8 +++-- lib/manager/gomod/update.ts | 2 +- lib/manager/gradle-wrapper/extract.ts | 2 +- lib/manager/gradle-wrapper/update.ts | 8 ++--- lib/manager/gradle/build-gradle.ts | 36 +++++++++++-------- lib/manager/gradle/gradle-updates-report.ts | 6 ++-- lib/manager/gradle/index.ts | 5 +-- lib/manager/homebrew/extract.ts | 22 +++++++----- lib/manager/homebrew/update.ts | 24 +++++++++---- lib/manager/homebrew/util.ts | 10 +++--- lib/manager/index.ts | 32 +++++++++-------- lib/manager/kubernetes/extract.ts | 2 +- lib/manager/kubernetes/update.ts | 2 +- lib/manager/leiningen/extract.ts | 6 ++-- lib/manager/meteor/extract.ts | 2 +- lib/manager/meteor/update.ts | 5 ++- lib/manager/npm/extract/index.ts | 2 +- lib/manager/npm/extract/monorepo.ts | 2 +- lib/manager/npm/extract/type.ts | 2 +- lib/manager/npm/update.ts | 8 ++--- lib/manager/nuget/update.ts | 2 +- lib/manager/nvm/update.ts | 5 ++- lib/manager/pip_requirements/extract.ts | 2 +- lib/manager/pip_requirements/update.ts | 2 +- lib/manager/pip_setup/extract.ts | 8 ++--- lib/manager/pipenv/artifacts.ts | 2 +- lib/manager/pipenv/extract.ts | 2 +- lib/manager/pipenv/update.ts | 6 ++-- lib/manager/poetry/artifacts.ts | 2 +- lib/manager/poetry/extract.ts | 2 +- lib/manager/poetry/update.ts | 6 ++-- lib/manager/pub/extract.ts | 2 +- lib/manager/sbt/extract.ts | 7 ++-- lib/manager/swift/extract.ts | 8 ++--- lib/manager/swift/update.ts | 2 +- lib/manager/terraform/extract.ts | 2 +- lib/manager/terraform/update.ts | 2 +- lib/manager/travis/extract.ts | 2 +- lib/manager/travis/update.ts | 2 +- .../travis/__snapshots__/package.spec.ts.snap | 4 +-- test/manager/travis/package.spec.ts | 2 +- 70 files changed, 228 insertions(+), 158 deletions(-) diff --git a/lib/manager/ansible/extract.ts b/lib/manager/ansible/extract.ts index b28748cadb..b7bc8b625b 100644 --- a/lib/manager/ansible/extract.ts +++ b/lib/manager/ansible/extract.ts @@ -2,7 +2,9 @@ import { logger } from '../../logger'; import { getDep } from '../dockerfile/extract'; import { PackageFile, PackageDependency } from '../common'; -export default function extractPackageFile(content: string): PackageFile { +export default function extractPackageFile( + content: string +): PackageFile | null { logger.trace('ansible.extractPackageFile()'); let deps: PackageDependency[] = []; let lineNumber = 0; diff --git a/lib/manager/ansible/update.ts b/lib/manager/ansible/update.ts index ae2781a70b..a24b532877 100644 --- a/lib/manager/ansible/update.ts +++ b/lib/manager/ansible/update.ts @@ -5,7 +5,7 @@ import { Upgrade } from '../common'; export default function updateDependency( fileContent: string, upgrade: Upgrade -) { +): string | null { try { const newFrom = getNewFrom(upgrade); logger.debug(`ansible.updateDependency(): ${newFrom}`); diff --git a/lib/manager/bazel/extract.ts b/lib/manager/bazel/extract.ts index 4269f55a0d..715bef242f 100644 --- a/lib/manager/bazel/extract.ts +++ b/lib/manager/bazel/extract.ts @@ -4,7 +4,12 @@ import { parse as _parse } from 'url'; import { logger } from '../../logger'; import { PackageDependency, PackageFile } from '../common'; -function parseUrl(urlString: string) { +interface UrlParsedResult { + repo: string; + currentValue: string; +} + +function parseUrl(urlString: string): UrlParsedResult | null { // istanbul ignore if if (!urlString) { return null; @@ -29,7 +34,7 @@ function parseUrl(urlString: string) { return null; } -function findBalancedParenIndex(longString: string) { +function findBalancedParenIndex(longString: string): number { /** * Minimalistic string parser with single task -> find last char in def. * It treats [)] as the last char. @@ -63,7 +68,7 @@ function findBalancedParenIndex(longString: string) { }); } -function parseContent(content: string) { +function parseContent(content: string): string[] { return [ 'container_pull', 'http_archive', @@ -86,7 +91,7 @@ function parseContent(content: string) { ); } -export function extractPackageFile(content: string): PackageFile { +export function extractPackageFile(content: string): PackageFile | null { const definitions = parseContent(content); if (!definitions.length) { logger.debug('No matching WORKSPACE definitions found'); diff --git a/lib/manager/bazel/update.ts b/lib/manager/bazel/update.ts index 318d723d81..4a44124b4f 100644 --- a/lib/manager/bazel/update.ts +++ b/lib/manager/bazel/update.ts @@ -7,7 +7,7 @@ function updateWithNewVersion( content: string, currentValue: string, newValue: string -) { +): string { const currentVersion = currentValue.replace(/^v/, ''); const newVersion = newValue.replace(/^v/, ''); let newContent = content; @@ -17,7 +17,7 @@ function updateWithNewVersion( return newContent; } -function extractUrl(flattened: string) { +function extractUrl(flattened: string): string[] | null { const urlMatch = flattened.match(/url="(.*?)"/); if (!urlMatch) { logger.debug('Cannot locate urls in new definition'); @@ -26,7 +26,7 @@ function extractUrl(flattened: string) { return [urlMatch[1]]; } -function extractUrls(content: string) { +function extractUrls(content: string): string[] | null { const flattened = content.replace(/\n/g, '').replace(/\s/g, ''); const urlsMatch = flattened.match(/urls?=\[.*?\]/); if (!urlsMatch) { @@ -40,9 +40,12 @@ function extractUrls(content: string) { return urls; } -async function getHashFromUrl(url: string) { +async function getHashFromUrl(url: string): Promise { const cacheNamespace = 'url-sha256'; - const cachedResult = await renovateCache.get(cacheNamespace, url); + const cachedResult = await renovateCache.get( + cacheNamespace, + url + ); /* istanbul ignore next line */ if (cachedResult) return cachedResult; try { @@ -57,7 +60,7 @@ async function getHashFromUrl(url: string) { } } -async function getHashFromUrls(urls: string[]) { +async function getHashFromUrls(urls: string[]): Promise { const hashes = (await Promise.all( urls.map(url => getHashFromUrl(url)) )).filter(Boolean); @@ -73,14 +76,14 @@ async function getHashFromUrls(urls: string[]) { return distinctHashes[0]; } -function setNewHash(content: string, hash: string) { +function setNewHash(content: string, hash: string): string { return content.replace(/(sha256\s*=\s*)"[^"]+"/, `$1"${hash}"`); } export async function updateDependency( fileContent: string, upgrade: Upgrade -): Promise { +): Promise { try { logger.debug( `bazel.updateDependency(): ${upgrade.newValue || upgrade.newDigest}` diff --git a/lib/manager/buildkite/extract.ts b/lib/manager/buildkite/extract.ts index 3bdcace4d6..7fde4a27d4 100644 --- a/lib/manager/buildkite/extract.ts +++ b/lib/manager/buildkite/extract.ts @@ -4,7 +4,7 @@ import { PackageFile, PackageDependency } from '../common'; export { extractPackageFile }; -function extractPackageFile(content: string): PackageFile { +function extractPackageFile(content: string): PackageFile | null { const deps: PackageDependency[] = []; try { const lines = content.split('\n'); diff --git a/lib/manager/buildkite/update.ts b/lib/manager/buildkite/update.ts index 8e33f5b1f2..14e7da9691 100644 --- a/lib/manager/buildkite/update.ts +++ b/lib/manager/buildkite/update.ts @@ -1,7 +1,10 @@ import { logger } from '../../logger'; import { Upgrade } from '../common'; -export function updateDependency(currentFileContent: string, upgrade: Upgrade) { +export function updateDependency( + currentFileContent: string, + upgrade: Upgrade +): string | null { try { const lineIdx = upgrade.managerData.lineNumber - 1; logger.debug(`buildkite.updateDependency: ${upgrade.newValue}`); diff --git a/lib/manager/bundler/artifacts.ts b/lib/manager/bundler/artifacts.ts index 1dc820f246..dcc325ea38 100644 --- a/lib/manager/bundler/artifacts.ts +++ b/lib/manager/bundler/artifacts.ts @@ -10,7 +10,7 @@ import { matches, sortVersions, } from '../../versioning/ruby'; -import { UpdateArtifactsConfig } from '../common'; +import { UpdateArtifactsConfig, UpdateArtifactsResult } from '../common'; // istanbul ignore next export async function updateArtifacts( @@ -18,7 +18,7 @@ export async function updateArtifacts( updatedDeps: string[], newPackageFileContent: string, config: UpdateArtifactsConfig -) { +): Promise { logger.debug(`bundler.updateArtifacts(${packageFileName})`); // istanbul ignore if if (global.repoCache.bundlerArtifactsError) { diff --git a/lib/manager/bundler/extract.ts b/lib/manager/bundler/extract.ts index ef60fb0ca9..3d5eabea6c 100644 --- a/lib/manager/bundler/extract.ts +++ b/lib/manager/bundler/extract.ts @@ -7,7 +7,7 @@ export { extractPackageFile }; async function extractPackageFile( content: string, fileName?: string -): Promise { +): Promise { const res: PackageFile = { registryUrls: [], deps: [], diff --git a/lib/manager/bundler/range.ts b/lib/manager/bundler/range.ts index 067a55721e..ae7626226f 100644 --- a/lib/manager/bundler/range.ts +++ b/lib/manager/bundler/range.ts @@ -1,3 +1,5 @@ +import { RangeStrategy } from '../../versioning'; + /* * The getRangeStrategy() function is optional and can be removed if not applicable. * It is used when the user configures rangeStrategy=auto. @@ -11,6 +13,6 @@ * */ -export function getRangeStrategy() { +export function getRangeStrategy(): RangeStrategy { return 'replace'; } diff --git a/lib/manager/bundler/update.ts b/lib/manager/bundler/update.ts index 2c0f3a2ebc..eb6784a320 100644 --- a/lib/manager/bundler/update.ts +++ b/lib/manager/bundler/update.ts @@ -10,7 +10,7 @@ import { Upgrade } from '../common'; export function updateDependency( currentFileContent: string, upgrade: Upgrade -): string { +): string | null { try { const delimiter = currentFileContent.split('"').length > diff --git a/lib/manager/cargo/artifacts.ts b/lib/manager/cargo/artifacts.ts index 1509aa56dc..b1adefc87a 100644 --- a/lib/manager/cargo/artifacts.ts +++ b/lib/manager/cargo/artifacts.ts @@ -11,7 +11,7 @@ export async function updateArtifacts( updatedDeps: string[], newPackageFileContent: string, config: UpdateArtifactsConfig -): Promise { +): Promise { await logger.debug(`cargo.updateArtifacts(${packageFileName})`); if (updatedDeps === undefined || updatedDeps.length < 1) { logger.debug('No updated cargo deps - returning null'); diff --git a/lib/manager/cargo/extract.ts b/lib/manager/cargo/extract.ts index 399cee39bc..8e4219e25b 100644 --- a/lib/manager/cargo/extract.ts +++ b/lib/manager/cargo/extract.ts @@ -7,7 +7,7 @@ import { CargoConfig, CargoSection } from './types'; export function extractPackageFile( content: string, fileName: string -): PackageFile { +): PackageFile | null { logger.trace(`cargo.extractPackageFile(${fileName})`); let parsedContent: CargoConfig; try { @@ -55,7 +55,7 @@ function extractFromSection( parsedContent: CargoSection, section: keyof CargoSection, target?: string -) { +): PackageDependency[] { const deps: PackageDependency[] = []; const sectionContent = parsedContent[section]; if (!sectionContent) { diff --git a/lib/manager/cargo/update.ts b/lib/manager/cargo/update.ts index 0c8f116898..11b6d7c977 100644 --- a/lib/manager/cargo/update.ts +++ b/lib/manager/cargo/update.ts @@ -5,7 +5,7 @@ import { Upgrade } from '../common'; import { CargoConfig, CargoSection } from './types'; // Return true if the match string is found at index in content -function matchAt(content: string, index: number, match: string) { +function matchAt(content: string, index: number, match: string): boolean { return content.substring(index, index + match.length) === match; } @@ -15,7 +15,7 @@ function replaceAt( index: number, oldString: string, newString: string -) { +): string { logger.debug(`Replacing ${oldString} with ${newString} at index ${index}`); return ( content.substr(0, index) + @@ -27,7 +27,7 @@ function replaceAt( export function updateDependency( fileContent: string, upgrade: Upgrade<{ nestedVersion?: boolean }> -) { +): string { logger.trace({ config: upgrade }, 'poetry.updateDependency()'); if (!upgrade) { return fileContent; diff --git a/lib/manager/circleci/extract.ts b/lib/manager/circleci/extract.ts index ed12bc590c..07a3600fd9 100644 --- a/lib/manager/circleci/extract.ts +++ b/lib/manager/circleci/extract.ts @@ -2,7 +2,7 @@ import { logger } from '../../logger'; import { getDep } from '../dockerfile/extract'; import { PackageFile, PackageDependency } from '../common'; -export function extractPackageFile(content: string): PackageFile { +export function extractPackageFile(content: string): PackageFile | null { const deps: PackageDependency[] = []; try { const lines = content.split('\n'); diff --git a/lib/manager/circleci/update.ts b/lib/manager/circleci/update.ts index 23b35a5546..b54eae70bb 100644 --- a/lib/manager/circleci/update.ts +++ b/lib/manager/circleci/update.ts @@ -5,7 +5,7 @@ import { Upgrade } from '../common'; export function updateDependency( fileContent: string, upgrade: Upgrade -): string { +): string | null { try { const lines = fileContent.split('\n'); const lineToChange = lines[upgrade.managerData.lineNumber]; diff --git a/lib/manager/common.ts b/lib/manager/common.ts index 9ed94d1035..82760aa0b1 100644 --- a/lib/manager/common.ts +++ b/lib/manager/common.ts @@ -173,15 +173,17 @@ export interface ManagerApi { extractAllPackageFiles?( config: ExtractConfig, files: string[] - ): Result; + ): Result; extractPackageFile?( content: string, packageFile?: string, config?: ExtractConfig - ): Result; + ): Result; - getPackageUpdates(config: PackageUpdateConfig): Result; + getPackageUpdates?( + config: PackageUpdateConfig + ): Result; getRangeStrategy(config: RangeConfig): RangeStrategy; @@ -190,9 +192,12 @@ export interface ManagerApi { updatedDeps: string[], newPackageFileContent: string, config: UpdateArtifactsConfig - ): Result; + ): Result; - updateDependency(fileContent: string, upgrade: Upgrade): Result; + updateDependency( + fileContent: string, + upgrade: Upgrade + ): Result; } // TODO: name and properties used by npm manager diff --git a/lib/manager/composer/artifacts.ts b/lib/manager/composer/artifacts.ts index 87655c6a19..e2487716e3 100644 --- a/lib/manager/composer/artifacts.ts +++ b/lib/manager/composer/artifacts.ts @@ -3,7 +3,7 @@ import URL from 'url'; import fs from 'fs-extra'; import upath from 'upath'; import { exec } from '../../util/exec'; -import { UpdateArtifactsConfig } from '../common'; +import { UpdateArtifactsConfig, UpdateArtifactsResult } from '../common'; import { logger } from '../../logger'; import * as hostRules from '../../util/host-rules'; import { getChildProcessEnv } from '../../util/env'; @@ -13,7 +13,7 @@ export async function updateArtifacts( updatedDeps: string[], newPackageFileContent: string, config: UpdateArtifactsConfig -) { +): Promise { logger.debug(`composer.updateArtifacts(${packageFileName})`); process.env.COMPOSER_CACHE_DIR = process.env.COMPOSER_CACHE_DIR || diff --git a/lib/manager/composer/extract.ts b/lib/manager/composer/extract.ts index 71d76542de..db355343a4 100644 --- a/lib/manager/composer/extract.ts +++ b/lib/manager/composer/extract.ts @@ -81,7 +81,10 @@ function parseRepositories( } } -export async function extractPackageFile(content: string, fileName: string) { +export async function extractPackageFile( + content: string, + fileName: string +): Promise { logger.trace(`composer.extractPackageFile(${fileName})`); let composerJson: ComposerConfig; try { diff --git a/lib/manager/dockerfile/extract.ts b/lib/manager/dockerfile/extract.ts index c032d917d3..6b46dde94d 100644 --- a/lib/manager/dockerfile/extract.ts +++ b/lib/manager/dockerfile/extract.ts @@ -28,7 +28,7 @@ export function splitImageParts(currentFrom: string): PackageDependency { return dep; } -export function getDep(currentFrom: string) { +export function getDep(currentFrom: string): PackageDependency { const dep = splitImageParts(currentFrom); dep.datasource = 'docker'; if ( @@ -41,7 +41,7 @@ export function getDep(currentFrom: string) { return dep; } -export function extractPackageFile(content: string): PackageFile { +export function extractPackageFile(content: string): PackageFile | null { const deps: PackageDependency[] = []; const stageNames: string[] = []; let lineNumber = 0; diff --git a/lib/manager/dockerfile/update.ts b/lib/manager/dockerfile/update.ts index feae2bfa3d..cfab1b29ec 100644 --- a/lib/manager/dockerfile/update.ts +++ b/lib/manager/dockerfile/update.ts @@ -1,7 +1,7 @@ import { logger } from '../../logger'; import { Upgrade } from '../common'; -export function getNewFrom(upgrade: Upgrade) { +export function getNewFrom(upgrade: Upgrade): string { const { depName, newValue, newDigest } = upgrade; let newFrom = depName; if (newValue) { @@ -13,7 +13,10 @@ export function getNewFrom(upgrade: Upgrade) { return newFrom; } -export function updateDependency(fileContent: string, upgrade: Upgrade) { +export function updateDependency( + fileContent: string, + upgrade: Upgrade +): string | null { try { const { lineNumber, fromSuffix } = upgrade.managerData; let { fromPrefix } = upgrade.managerData; diff --git a/lib/manager/droneci/extract.ts b/lib/manager/droneci/extract.ts index 4b54d1262d..775917e65d 100644 --- a/lib/manager/droneci/extract.ts +++ b/lib/manager/droneci/extract.ts @@ -2,7 +2,7 @@ import { logger } from '../../logger'; import { getDep } from '../dockerfile/extract'; import { PackageFile, PackageDependency } from '../common'; -export function extractPackageFile(content: string): PackageFile { +export function extractPackageFile(content: string): PackageFile | null { const deps: PackageDependency[] = []; try { const lines = content.split('\n'); diff --git a/lib/manager/droneci/update.ts b/lib/manager/droneci/update.ts index c9f20f840a..78e8633c1b 100644 --- a/lib/manager/droneci/update.ts +++ b/lib/manager/droneci/update.ts @@ -5,7 +5,7 @@ import { Upgrade } from '../common'; export function updateDependency( fileContent: string, upgrade: Upgrade -): string { +): string | null { try { const lines = fileContent.split('\n'); const lineToChange = lines[upgrade.managerData.lineNumber]; diff --git a/lib/manager/github-actions/extract.ts b/lib/manager/github-actions/extract.ts index b50126c093..68ef79f86a 100644 --- a/lib/manager/github-actions/extract.ts +++ b/lib/manager/github-actions/extract.ts @@ -2,7 +2,7 @@ import { logger } from '../../logger'; import { getDep } from '../dockerfile/extract'; import { PackageFile, PackageDependency } from '../common'; -export function extractPackageFile(content: string): PackageFile { +export function extractPackageFile(content: string): PackageFile | null { logger.debug('github-actions.extractPackageFile()'); const deps: PackageDependency[] = []; let lineNumber = 0; diff --git a/lib/manager/github-actions/update.ts b/lib/manager/github-actions/update.ts index 49e094dac9..806c53a3ac 100644 --- a/lib/manager/github-actions/update.ts +++ b/lib/manager/github-actions/update.ts @@ -5,7 +5,7 @@ import { Upgrade } from '../common'; export function updateDependency( fileContent: string, upgrade: Upgrade -): string { +): string | null { try { const newFrom = getNewFrom(upgrade); logger.debug(`github-actions.updateDependency(): ${newFrom}`); diff --git a/lib/manager/gitlabci-include/extract.ts b/lib/manager/gitlabci-include/extract.ts index 0200c27a06..d625bcc58f 100644 --- a/lib/manager/gitlabci-include/extract.ts +++ b/lib/manager/gitlabci-include/extract.ts @@ -7,7 +7,7 @@ function extractDepFromInclude(includeObj: { file: any; project: string; ref: string; -}) { +}): PackageDependency | null { if (!includeObj.file || !includeObj.project) { return null; } @@ -28,7 +28,7 @@ export function extractPackageFile( content: string, _packageFile: string, config: ExtractConfig -): PackageFile { +): PackageFile | null { const deps: PackageDependency[] = []; try { const doc = yaml.safeLoad(content); diff --git a/lib/manager/gitlabci-include/update.ts b/lib/manager/gitlabci-include/update.ts index 975ed795af..cb116aac36 100644 --- a/lib/manager/gitlabci-include/update.ts +++ b/lib/manager/gitlabci-include/update.ts @@ -5,7 +5,7 @@ import { Upgrade } from '../common'; export function updateDependency( currentFileContent: string, upgrade: Upgrade -): string { +): string | null { try { const { depName, newValue } = upgrade; diff --git a/lib/manager/gitlabci/extract.ts b/lib/manager/gitlabci/extract.ts index 8e489ca12e..5a565623a8 100644 --- a/lib/manager/gitlabci/extract.ts +++ b/lib/manager/gitlabci/extract.ts @@ -2,7 +2,7 @@ import { logger } from '../../logger'; import { getDep } from '../dockerfile/extract'; import { PackageFile, PackageDependency } from '../common'; -export function extractPackageFile(content: string): PackageFile { +export function extractPackageFile(content: string): PackageFile | null { const deps: PackageDependency[] = []; try { const lines = content.split('\n'); diff --git a/lib/manager/gitlabci/update.ts b/lib/manager/gitlabci/update.ts index f00493bff6..ec10db76b9 100644 --- a/lib/manager/gitlabci/update.ts +++ b/lib/manager/gitlabci/update.ts @@ -5,7 +5,7 @@ import { Upgrade } from '../common'; export function updateDependency( currentFileContent: string, upgrade: Upgrade -): string { +): string | null { try { const newFrom = getNewFrom(upgrade); const lines = currentFileContent.split('\n'); diff --git a/lib/manager/gomod/artifacts.ts b/lib/manager/gomod/artifacts.ts index 3eacdbc95c..ba7f7050bc 100644 --- a/lib/manager/gomod/artifacts.ts +++ b/lib/manager/gomod/artifacts.ts @@ -11,7 +11,7 @@ export async function updateArtifacts( _updatedDeps: string[], newGoModContent: string, config: UpdateArtifactsConfig -): Promise { +): Promise { logger.debug(`gomod.updateArtifacts(${goModFileName})`); process.env.GOPATH = process.env.GOPATH || join(config.cacheDir, './others/go'); diff --git a/lib/manager/gomod/extract.ts b/lib/manager/gomod/extract.ts index 965a9a7298..625cd5b4ed 100644 --- a/lib/manager/gomod/extract.ts +++ b/lib/manager/gomod/extract.ts @@ -2,7 +2,11 @@ import { logger } from '../../logger'; import { isVersion } from '../../versioning/semver'; import { PackageDependency, PackageFile } from '../common'; -function getDep(lineNumber: number, match: RegExpMatchArray, type: string) { +function getDep( + lineNumber: number, + match: RegExpMatchArray, + type: string +): PackageDependency { const [, , currentValue] = match; let [, depName] = match; depName = depName.replace(/"/g, ''); @@ -35,7 +39,7 @@ function getDep(lineNumber: number, match: RegExpMatchArray, type: string) { return dep; } -export function extractPackageFile(content: string): PackageFile { +export function extractPackageFile(content: string): PackageFile | null { logger.trace({ content }, 'gomod.extractPackageFile()'); const deps: PackageDependency[] = []; try { diff --git a/lib/manager/gomod/update.ts b/lib/manager/gomod/update.ts index c63dbf3c9d..70534dff0e 100644 --- a/lib/manager/gomod/update.ts +++ b/lib/manager/gomod/update.ts @@ -5,7 +5,7 @@ import { Upgrade } from '../common'; export function updateDependency( currentFileContent: string, upgrade: Upgrade -): string { +): string | null { try { logger.debug(`gomod.updateDependency: ${upgrade.newValue}`); const { depName, depType } = upgrade; diff --git a/lib/manager/gradle-wrapper/extract.ts b/lib/manager/gradle-wrapper/extract.ts index b4ccac285c..190dae4d6c 100644 --- a/lib/manager/gradle-wrapper/extract.ts +++ b/lib/manager/gradle-wrapper/extract.ts @@ -2,7 +2,7 @@ import { coerce } from 'semver'; import { logger } from '../../logger'; import { PackageFile, PackageDependency } from '../common'; -export function extractPackageFile(fileContent: string): PackageFile { +export function extractPackageFile(fileContent: string): PackageFile | null { logger.debug('gradle-wrapper.extractPackageFile()'); const lines = fileContent.split('\n'); diff --git a/lib/manager/gradle-wrapper/update.ts b/lib/manager/gradle-wrapper/update.ts index a20f419b6f..0886e9ede6 100644 --- a/lib/manager/gradle-wrapper/update.ts +++ b/lib/manager/gradle-wrapper/update.ts @@ -5,7 +5,7 @@ import { Upgrade } from '../common'; export async function updateDependency( fileContent: string, upgrade: Upgrade -): Promise { +): Promise { try { logger.debug(upgrade, 'gradle-wrapper.updateDependency()'); const lines = fileContent.split('\n'); @@ -35,14 +35,14 @@ export async function updateDependency( } } -function replaceType(url: string) { +function replaceType(url: string): string { return url.replace('bin', 'all'); } -async function getChecksum(url: string) { +async function getChecksum(url: string): Promise { try { const response = await got(url); - return response.body; + return response.body as string; } catch (err) { if (err.statusCode === 404 || err.code === 'ENOTFOUND') { logger.info('Gradle checksum lookup failure: not found'); diff --git a/lib/manager/gradle/build-gradle.ts b/lib/manager/gradle/build-gradle.ts index 4322fbe793..5c7c03441e 100644 --- a/lib/manager/gradle/build-gradle.ts +++ b/lib/manager/gradle/build-gradle.ts @@ -26,7 +26,7 @@ export function updateGradleVersion( buildGradleContent: string, dependency: GradleDependency, newVersion: string -) { +): string { if (dependency) { const updateFunctions: UpdateFunction[] = [ updateVersionLiterals, @@ -84,7 +84,7 @@ function updateVersionLiterals( dependency: GradleDependency, buildGradleContent: string, newVersion: string -) { +): string | null { const regexes: RegExp[] = [ moduleStringVersionFormatMatch(dependency), groovyPluginStringVersionFormatMatch(dependency), @@ -104,7 +104,7 @@ function updateLocalVariables( dependency: GradleDependency, buildGradleContent: string, newVersion: string -) { +): string | null { const regexes: RegExp[] = [ moduleMapVariableVersionFormatMatch(dependency), moduleStringVariableInterpolationVersionFormatMatch(dependency), @@ -127,7 +127,7 @@ function updateGlobalVariables( dependency: GradleDependency, buildGradleContent: string, newVersion: string -) { +): string | null { const variable = variables[`${dependency.group}:${dependency.name}`]; if (variable) { const regex = variableDefinitionFormatMatch(variable); @@ -146,7 +146,7 @@ function updatePropertyFileGlobalVariables( dependency: GradleDependency, buildGradleContent: string, newVersion: string -) { +): string | null { const variable = variables[`${dependency.group}:${dependency.name}`]; if (variable) { const regex = new RegExp(`(${variable}\\s*=\\s*)(.*)`); @@ -159,25 +159,29 @@ function updatePropertyFileGlobalVariables( } // https://github.com/patrikerdes/gradle-use-latest-versions-plugin/blob/8cf9c3917b8b04ba41038923cab270d2adda3aa6/src/main/groovy/se/patrikerdes/DependencyUpdate.groovy#L27-L29 -function moduleStringVersionFormatMatch(dependency: GradleDependency) { +function moduleStringVersionFormatMatch(dependency: GradleDependency): RegExp { return new RegExp( `(["']${dependency.group}:${dependency.name}:)[^$].*?(([:@].*?)?["'])` ); } -function groovyPluginStringVersionFormatMatch(dependency: GradleDependency) { +function groovyPluginStringVersionFormatMatch( + dependency: GradleDependency +): RegExp { return new RegExp( `(id\\s+["']${dependency.group}["']\\s+version\\s+["'])[^$].*?(["'])` ); } -function kotlinPluginStringVersionFormatMatch(dependency: GradleDependency) { +function kotlinPluginStringVersionFormatMatch( + dependency: GradleDependency +): RegExp { return new RegExp( `(id\\("${dependency.group}"\\)\\s+version\\s+")[^$].*?(")` ); } -function moduleMapVersionFormatMatch(dependency: GradleDependency) { +function moduleMapVersionFormatMatch(dependency: GradleDependency): RegExp { // prettier-ignore return new RegExp( `(group\\s*:\\s*["']${dependency.group}["']\\s*,\\s*` + @@ -188,7 +192,7 @@ function moduleMapVersionFormatMatch(dependency: GradleDependency) { function moduleKotlinNamedArgumentVersionFormatMatch( dependency: GradleDependency -) { +): RegExp { // prettier-ignore return new RegExp( `(group\\s*=\\s*"${dependency.group}"\\s*,\\s*` + @@ -197,7 +201,9 @@ function moduleKotlinNamedArgumentVersionFormatMatch( ); } -function moduleMapVariableVersionFormatMatch(dependency: GradleDependency) { +function moduleMapVariableVersionFormatMatch( + dependency: GradleDependency +): RegExp { // prettier-ignore return new RegExp( `group\\s*:\\s*["']${dependency.group}["']\\s*,\\s*` + @@ -208,7 +214,7 @@ function moduleMapVariableVersionFormatMatch(dependency: GradleDependency) { function moduleKotlinNamedArgumentVariableVersionFormatMatch( dependency: GradleDependency -) { +): RegExp { // prettier-ignore return new RegExp( `group\\s*=\\s*"${dependency.group}"\\s*,\\s*` + @@ -219,7 +225,7 @@ function moduleKotlinNamedArgumentVariableVersionFormatMatch( function moduleStringVariableInterpolationVersionFormatMatch( dependency: GradleDependency -) { +): RegExp { return new RegExp( `["']${dependency.group}:${dependency.name}:\\$([^{].*?)["']` ); @@ -227,12 +233,12 @@ function moduleStringVariableInterpolationVersionFormatMatch( function moduleStringVariableExpressionVersionFormatMatch( dependency: GradleDependency -) { +): RegExp { return new RegExp( `["']${dependency.group}:${dependency.name}:\\$\{([^{].*?)}["']` ); } -function variableDefinitionFormatMatch(variable: string) { +function variableDefinitionFormatMatch(variable: string): RegExp { return new RegExp(`(${variable}\\s*=\\s*?["'])(.*)(["'])`); } diff --git a/lib/manager/gradle/gradle-updates-report.ts b/lib/manager/gradle/gradle-updates-report.ts index f83c8d35d8..3bf70518ff 100644 --- a/lib/manager/gradle/gradle-updates-report.ts +++ b/lib/manager/gradle/gradle-updates-report.ts @@ -67,7 +67,9 @@ gradle.buildFinished { await writeFile(gradleInitFile, content); } -async function extractDependenciesFromUpdatesReport(localDir: string) { +async function extractDependenciesFromUpdatesReport( + localDir: string +): Promise { const gradleProjectConfigurations = await readGradleReport(localDir); const dependencies = gradleProjectConfigurations @@ -111,7 +113,7 @@ function mergeDependenciesWithRepositories( function flatternDependencies( accumulator: GradleDependencyWithRepos[], currentValue: GradleDependencyWithRepos[] -) { +): GradleDependencyWithRepos[] { accumulator.push(...currentValue); return accumulator; } diff --git a/lib/manager/gradle/index.ts b/lib/manager/gradle/index.ts index fd3a572de5..2ff7ebc90e 100644 --- a/lib/manager/gradle/index.ts +++ b/lib/manager/gradle/index.ts @@ -21,7 +21,7 @@ const TIMEOUT_CODE = 143; export async function extractAllPackageFiles( config: ExtractConfig, packageFiles: string[] -): Promise { +): Promise { if ( !packageFiles.some(packageFile => ['build.gradle', 'build.gradle.kts'].includes(packageFile) @@ -117,7 +117,7 @@ async function executeGradle(config: ExtractConfig) { logger.info('Gradle report complete'); } -async function getGradleCommandLine(config: ExtractConfig) { +async function getGradleCommandLine(config: ExtractConfig): Promise { let cmd: string; const gradlewExists = await exists(config.localDir + '/gradlew'); if (config.binarySource === 'docker') { @@ -129,4 +129,5 @@ async function getGradleCommandLine(config: ExtractConfig) { } return cmd + ' ' + GRADLE_DEPENDENCY_REPORT_OPTIONS; } + export const language = 'java'; diff --git a/lib/manager/homebrew/extract.ts b/lib/manager/homebrew/extract.ts index c4c51b0f04..ccc5135107 100644 --- a/lib/manager/homebrew/extract.ts +++ b/lib/manager/homebrew/extract.ts @@ -4,7 +4,7 @@ import { logger } from '../../logger'; import { PackageFile, PackageDependency } from '../common'; // TODO: Maybe check if quotes/double-quotes are balanced -export function extractPackageFile(content: string): PackageFile { +export function extractPackageFile(content: string): PackageFile | null { logger.trace('extractPackageFile()'); /* 1. match "class className < Formula" @@ -57,7 +57,7 @@ export function extractPackageFile(content: string): PackageFile { return { deps }; } -function extractSha256(content: string) { +function extractSha256(content: string): string | null { const sha256RegExp = /(^|\s)sha256(\s)/; let i = content.search(sha256RegExp); if (isSpace(content[i])) { @@ -66,7 +66,7 @@ function extractSha256(content: string) { return parseSha256(i, content); } -function parseSha256(idx: number, content: string) { +function parseSha256(idx: number, content: string): string | null { let i = idx; i += 'sha256'.length; i = skip(i, content, c => { @@ -84,7 +84,7 @@ function parseSha256(idx: number, content: string) { return sha256; } -function extractUrl(content: string) { +function extractUrl(content: string): string | null { const urlRegExp = /(^|\s)url(\s)/; let i = content.search(urlRegExp); // content.search() returns -1 if not found @@ -98,7 +98,13 @@ function extractUrl(content: string) { return parseUrl(i, content); } -export function parseUrlPath(urlStr: string) { +export interface UrlPathParsedResult { + currentValue: string; + ownerName: string; + repoName: string; +} + +export function parseUrlPath(urlStr: string): UrlPathParsedResult | null { if (!urlStr) { return null; } @@ -136,7 +142,7 @@ export function parseUrlPath(urlStr: string) { } } -function parseUrl(idx: number, content: string) { +function parseUrl(idx: number, content: string): string | null { let i = idx; i += 'url'.length; i = skip(i, content, c => { @@ -155,7 +161,7 @@ function parseUrl(idx: number, content: string) { return url; } -function extractClassName(content: string) { +function extractClassName(content: string): string | null { const classRegExp = /(^|\s)class\s/; let i = content.search(classRegExp); if (isSpace(content[i])) { @@ -166,7 +172,7 @@ function extractClassName(content: string) { /* This function parses the "class className < Formula" header and returns the className and index of the character just after the header */ -function parseClassHeader(idx: number, content: string) { +function parseClassHeader(idx: number, content: string): string | null { let i = idx; i += 'class'.length; i = skip(i, content, c => { diff --git a/lib/manager/homebrew/update.ts b/lib/manager/homebrew/update.ts index a228bb5c1e..f9f8009916 100644 --- a/lib/manager/homebrew/update.ts +++ b/lib/manager/homebrew/update.ts @@ -77,7 +77,11 @@ export async function updateDependency( return newContent; } -function updateUrl(content: string, oldUrl: string, newUrl: string) { +function updateUrl( + content: string, + oldUrl: string, + newUrl: string +): string | null { const urlRegExp = /(^|\s)url(\s)/; let i = content.search(urlRegExp); if (i === -1) { @@ -102,7 +106,11 @@ function updateUrl(content: string, oldUrl: string, newUrl: string) { return newContent; } -function getUrlTestContent(content: string, oldUrl: string, newUrl: string) { +function getUrlTestContent( + content: string, + oldUrl: string, + newUrl: string +): string { const urlRegExp = /(^|\s)url(\s)/; const cleanContent = removeComments(content); let j = cleanContent.search(urlRegExp); @@ -118,7 +126,7 @@ function replaceUrl( content: string, oldUrl: string, newUrl: string -) { +): string | null { let i = idx; i += 'url'.length; i = skip(i, content, c => isSpace(c)); @@ -132,7 +140,11 @@ function replaceUrl( return newContent; } -function updateSha256(content: string, oldSha256: string, newSha256: string) { +function updateSha256( + content: string, + oldSha256: string, + newSha256: string +): string | null { const sha256RegExp = /(^|\s)sha256(\s)/; let i = content.search(sha256RegExp); if (i === -1) { @@ -161,7 +173,7 @@ function getSha256TestContent( content: string, oldSha256: string, newSha256: string -) { +): string | null { const sha256RegExp = /(^|\s)sha256(\s)/; const cleanContent = removeComments(content); let j = cleanContent.search(sha256RegExp); @@ -177,7 +189,7 @@ function replaceSha256( content: string, oldSha256: string, newSha256: string -) { +): string | null { let i = idx; i += 'sha256'.length; i = skip(i, content, c => isSpace(c)); diff --git a/lib/manager/homebrew/util.ts b/lib/manager/homebrew/util.ts index 83e3e89e22..54ea340c43 100644 --- a/lib/manager/homebrew/util.ts +++ b/lib/manager/homebrew/util.ts @@ -2,7 +2,7 @@ export function skip( idx: number, content: string, cond: (s: string) => boolean -) { +): number { let i = idx; while (i < content.length) { if (!cond(content[i])) { @@ -13,18 +13,18 @@ export function skip( return i; } -export function isSpace(c: string) { +export function isSpace(c: string): boolean { return /\s/.test(c); } -export function removeComments(content: string) { +export function removeComments(content: string): string { let newContent = removeLineComments(content); newContent = removeMultiLineComments(newContent); return newContent; } // Remove line comments starting with # -function removeLineComments(content: string) { +function removeLineComments(content: string): string { let newContent = ''; let comment = false; for (let i = 0; i < content.length; i += 1) { @@ -45,7 +45,7 @@ function removeLineComments(content: string) { } // Remove multi-line comments enclosed between =begin and =end -function removeMultiLineComments(content: string) { +function removeMultiLineComments(content: string): string { const beginRegExp = /(^|\n)=begin\s/; const endRegExp = /(^|\n)=end\s/; let newContent = content; diff --git a/lib/manager/index.ts b/lib/manager/index.ts index 0467781cff..d6f49eff05 100644 --- a/lib/manager/index.ts +++ b/lib/manager/index.ts @@ -1,9 +1,13 @@ import { - ManagerApi, ExtractConfig, - RangeConfig, + ManagerApi, + PackageFile, PackageUpdateConfig, + RangeConfig, + Result, + PackageUpdateResult, } from './common'; +import { RangeStrategy } from '../versioning'; const managerList = [ 'ansible', @@ -63,25 +67,25 @@ const languageList = [ export const get = (manager: string, name: T) => managers[manager][name]; -export const getLanguageList = () => languageList; -export const getManagerList = () => managerList; +export const getLanguageList = (): string[] => languageList; +export const getManagerList = (): string[] => managerList; export function extractAllPackageFiles( manager: string, config: ExtractConfig, files: string[] -) { - return managers[manager] && get(manager, 'extractAllPackageFiles') - ? get(manager, 'extractAllPackageFiles')(config, files) +): Result { + return managers[manager] && managers[manager].extractAllPackageFiles + ? managers[manager].extractAllPackageFiles(config, files) : null; } export function getPackageUpdates( manager: string, config: PackageUpdateConfig -) { - return managers[manager] && get(manager, 'getPackageUpdates') - ? get(manager, 'getPackageUpdates')(config) +): Result | null { + return managers[manager] && managers[manager].getPackageUpdates + ? managers[manager].getPackageUpdates(config) : null; } @@ -90,13 +94,13 @@ export function extractPackageFile( content: string, fileName?: string, config?: ExtractConfig -) { - return managers[manager] && get(manager, 'extractPackageFile') - ? get(manager, 'extractPackageFile')(content, fileName, config) +): Result { + return managers[manager] && managers[manager].extractPackageFile + ? managers[manager].extractPackageFile(content, fileName, config) : null; } -export function getRangeStrategy(config: RangeConfig) { +export function getRangeStrategy(config: RangeConfig): RangeStrategy { const { manager, rangeStrategy } = config; if (managers[manager].getRangeStrategy) { // Use manager's own function if it exists diff --git a/lib/manager/kubernetes/extract.ts b/lib/manager/kubernetes/extract.ts index 21a7709ff6..9007fa323e 100644 --- a/lib/manager/kubernetes/extract.ts +++ b/lib/manager/kubernetes/extract.ts @@ -2,7 +2,7 @@ import { logger } from '../../logger'; import { getDep } from '../dockerfile/extract'; import { PackageFile, PackageDependency } from '../common'; -export function extractPackageFile(content: string): PackageFile { +export function extractPackageFile(content: string): PackageFile | null { logger.trace('kubernetes.extractPackageFile()'); let deps: PackageDependency[] = []; let lineNumber = 0; diff --git a/lib/manager/kubernetes/update.ts b/lib/manager/kubernetes/update.ts index 56418fab2f..0c16c1a23f 100644 --- a/lib/manager/kubernetes/update.ts +++ b/lib/manager/kubernetes/update.ts @@ -5,7 +5,7 @@ import { Upgrade } from '../common'; export function updateDependency( fileContent: string, upgrade: Upgrade -): string { +): string | null { try { const newFrom = getNewFrom(upgrade); logger.debug(`kubernetes.updateDependency(): ${newFrom}`); diff --git a/lib/manager/leiningen/extract.ts b/lib/manager/leiningen/extract.ts index dc3864a35b..6735329cfa 100644 --- a/lib/manager/leiningen/extract.ts +++ b/lib/manager/leiningen/extract.ts @@ -3,7 +3,7 @@ import { PackageDependency, PackageFile } from '../common'; export const DEFAULT_CLOJARS_REPO = 'https://clojars.org/repo/'; -export function trimAtKey(str: string, kwName: string) { +export function trimAtKey(str: string, kwName: string): string | null { const regex = new RegExp(`:${kwName}(?=\\s)`); const keyOffset = str.search(regex); if (keyOffset < 0) return null; @@ -13,7 +13,7 @@ export function trimAtKey(str: string, kwName: string) { return withSpaces.slice(valueOffset); } -export function expandDepName(name: string) { +export function expandDepName(name: string): string { return name.indexOf('/') === -1 ? `${name}:${name}` : name.replace('/', ':'); } @@ -89,7 +89,7 @@ export function extractFromVectors( return result; } -function extractLeinRepos(content: string) { +function extractLeinRepos(content: string): string[] { const result = [DEFAULT_CLOJARS_REPO, DEFAULT_MAVEN_REPO]; const repoContent = trimAtKey( diff --git a/lib/manager/meteor/extract.ts b/lib/manager/meteor/extract.ts index face708d11..c62f1da4b4 100644 --- a/lib/manager/meteor/extract.ts +++ b/lib/manager/meteor/extract.ts @@ -1,7 +1,7 @@ import { logger } from '../../logger'; import { PackageFile, PackageDependency } from '../common'; -export function extractPackageFile(content: string): PackageFile { +export function extractPackageFile(content: string): PackageFile | null { let deps: PackageDependency[] = []; const npmDepends = content.match(/\nNpm\.depends\({([\s\S]*?)}\);/); if (!npmDepends) { diff --git a/lib/manager/meteor/update.ts b/lib/manager/meteor/update.ts index eb0e6c5b09..c84a535bce 100644 --- a/lib/manager/meteor/update.ts +++ b/lib/manager/meteor/update.ts @@ -1,7 +1,10 @@ import { logger } from '../../logger'; import { Upgrade } from '../common'; -export function updateDependency(fileContent: string, upgrade: Upgrade) { +export function updateDependency( + fileContent: string, + upgrade: Upgrade +): string { const { depName, currentValue, newValue } = upgrade; logger.debug(`meteor.updateDependency(): ${depName} = ${newValue}`); const regexReplace = new RegExp( diff --git a/lib/manager/npm/extract/index.ts b/lib/manager/npm/extract/index.ts index 8e023fc442..116e41b799 100644 --- a/lib/manager/npm/extract/index.ts +++ b/lib/manager/npm/extract/index.ts @@ -44,7 +44,7 @@ export async function extractPackageFile( content: string, fileName: string, config: ExtractConfig -): Promise { +): Promise { logger.trace(`npm.extractPackageFile(${fileName})`); logger.trace({ content }); const deps: PackageDependency[] = []; diff --git a/lib/manager/npm/extract/monorepo.ts b/lib/manager/npm/extract/monorepo.ts index 22834edded..64adb9ebb1 100644 --- a/lib/manager/npm/extract/monorepo.ts +++ b/lib/manager/npm/extract/monorepo.ts @@ -6,7 +6,7 @@ import upath from 'upath'; import { logger } from '../../../logger'; import { PackageFile } from '../../common'; -function matchesAnyPattern(val: string, patterns: string[]) { +function matchesAnyPattern(val: string, patterns: string[]): boolean { const res = patterns.some( pattern => pattern === val + '/' || minimatch(val, pattern, { dot: true }) ); diff --git a/lib/manager/npm/extract/type.ts b/lib/manager/npm/extract/type.ts index addc7d2f33..bf8ded344b 100644 --- a/lib/manager/npm/extract/type.ts +++ b/lib/manager/npm/extract/type.ts @@ -1,6 +1,6 @@ import { NpmPackage } from './common'; -export function mightBeABrowserLibrary(packageJson: NpmPackage) { +export function mightBeABrowserLibrary(packageJson: NpmPackage): boolean { // return true unless we're sure it's not a browser library if (packageJson.private === true) { // it's not published diff --git a/lib/manager/npm/update.ts b/lib/manager/npm/update.ts index f7f5a5efe0..5d9d7de4ab 100644 --- a/lib/manager/npm/update.ts +++ b/lib/manager/npm/update.ts @@ -6,7 +6,7 @@ import { Upgrade } from '../common'; export function updateDependency( fileContent: string, upgrade: Upgrade -): string { +): string | null { const { depType, depName } = upgrade; let { newValue } = upgrade; if (upgrade.currentRawValue) { @@ -137,7 +137,7 @@ export function updateDependency( } // Return true if the match string is found at index in content -function matchAt(content: string, index: number, match: string) { +function matchAt(content: string, index: number, match: string): boolean { return content.substring(index, index + match.length) === match; } @@ -147,7 +147,7 @@ function replaceAt( index: number, oldString: string, newString: string -) { +): string { logger.debug(`Replacing ${oldString} with ${newString} at index ${index}`); return ( content.substr(0, index) + @@ -160,7 +160,7 @@ export function bumpPackageVersion( content: string, currentValue: string, bumpVersion: ReleaseType | string -) { +): string { logger.debug('bumpVersion()'); if (!bumpVersion) { return content; diff --git a/lib/manager/nuget/update.ts b/lib/manager/nuget/update.ts index 6869ded841..b2d437b931 100644 --- a/lib/manager/nuget/update.ts +++ b/lib/manager/nuget/update.ts @@ -4,7 +4,7 @@ import { Upgrade } from '../common'; export function updateDependency( fileContent: string, upgrade: Upgrade -): string { +): string | null { try { logger.debug(`nuget.updateDependency(): ${upgrade.newFrom}`); const lines = fileContent.split('\n'); diff --git a/lib/manager/nvm/update.ts b/lib/manager/nvm/update.ts index cd6d4eefb5..0ad7ac1ada 100644 --- a/lib/manager/nvm/update.ts +++ b/lib/manager/nvm/update.ts @@ -1,7 +1,10 @@ import { logger } from '../../logger'; import { Upgrade } from '../common'; -export function updateDependency(_fileContent: string, upgrade: Upgrade) { +export function updateDependency( + _fileContent: string, + upgrade: Upgrade +): string { logger.debug(`nvm.updateDependency(): ${upgrade.newVersion}`); return `${upgrade.newValue}\n`; } diff --git a/lib/manager/pip_requirements/extract.ts b/lib/manager/pip_requirements/extract.ts index 37efc02163..4d9d302737 100644 --- a/lib/manager/pip_requirements/extract.ts +++ b/lib/manager/pip_requirements/extract.ts @@ -17,7 +17,7 @@ export function extractPackageFile( content: string, _: string, config: ExtractConfig -) { +): PackageFile | null { logger.trace('pip_requirements.extractPackageFile()'); let indexUrl: string; diff --git a/lib/manager/pip_requirements/update.ts b/lib/manager/pip_requirements/update.ts index 34061f6bb9..f8e7263532 100644 --- a/lib/manager/pip_requirements/update.ts +++ b/lib/manager/pip_requirements/update.ts @@ -5,7 +5,7 @@ import { Upgrade } from '../common'; export function updateDependency( fileContent: string, upgrade: Upgrade -): string { +): string | null { try { logger.debug(`pip_requirements.updateDependency(): ${upgrade.newValue}`); const lines = fileContent.split('\n'); diff --git a/lib/manager/pip_setup/extract.ts b/lib/manager/pip_setup/extract.ts index 295216de48..cd427aeeca 100644 --- a/lib/manager/pip_setup/extract.ts +++ b/lib/manager/pip_setup/extract.ts @@ -6,14 +6,14 @@ import { dependencyPattern } from '../pip_requirements/extract'; import { ExtractConfig, PackageFile, PackageDependency } from '../common'; export const pythonVersions = ['python', 'python3', 'python3.7']; -let pythonAlias: string = null; +let pythonAlias: string | null = null; -export function parsePythonVersion(str: string) { +export function parsePythonVersion(str: string): number[] { const arr = str.split(' ')[1].split('.'); return [parseInt(arr[0], 10), parseInt(arr[1], 10)]; } -export async function getPythonAlias() { +export async function getPythonAlias(): Promise { if (pythonAlias) { return pythonAlias; } @@ -89,7 +89,7 @@ export async function extractPackageFile( content: string, packageFile: string, config: ExtractConfig -): Promise { +): Promise { logger.debug('pip_setup.extractPackageFile()'); let setup: PythonSetup; try { diff --git a/lib/manager/pipenv/artifacts.ts b/lib/manager/pipenv/artifacts.ts index f4af20c5f8..dc5980d3ac 100644 --- a/lib/manager/pipenv/artifacts.ts +++ b/lib/manager/pipenv/artifacts.ts @@ -10,7 +10,7 @@ export async function updateArtifacts( _updatedDeps: string[], newPipfileContent: string, config: UpdateArtifactsConfig -): Promise { +): Promise { logger.debug(`pipenv.updateArtifacts(${pipfileName})`); process.env.PIPENV_CACHE_DIR = process.env.PIPENV_CACHE_DIR || join(config.cacheDir, './others/pipenv'); diff --git a/lib/manager/pipenv/extract.ts b/lib/manager/pipenv/extract.ts index 75eaeef9aa..16759d0f55 100644 --- a/lib/manager/pipenv/extract.ts +++ b/lib/manager/pipenv/extract.ts @@ -33,7 +33,7 @@ interface PipRequirement { git?: string; } -export function extractPackageFile(content: string): PackageFile { +export function extractPackageFile(content: string): PackageFile | null { logger.debug('pipenv.extractPackageFile()'); let pipfile: PipFile; diff --git a/lib/manager/pipenv/update.ts b/lib/manager/pipenv/update.ts index b283af298b..b3450a6bee 100644 --- a/lib/manager/pipenv/update.ts +++ b/lib/manager/pipenv/update.ts @@ -4,7 +4,7 @@ import { logger } from '../../logger'; import { Upgrade } from '../common'; // Return true if the match string is found at index in content -function matchAt(content: string, index: number, match: string) { +function matchAt(content: string, index: number, match: string): boolean { return content.substring(index, index + match.length) === match; } @@ -14,7 +14,7 @@ function replaceAt( index: number, oldString: string, newString: string -) { +): string { logger.debug(`Replacing ${oldString} with ${newString} at index ${index}`); return ( content.substr(0, index) + @@ -26,7 +26,7 @@ function replaceAt( export function updateDependency( fileContent: string, upgrade: Upgrade -): string { +): string | null { try { const { depType, depName, newValue, managerData = {} } = upgrade; const { nestedVersion } = managerData; diff --git a/lib/manager/poetry/artifacts.ts b/lib/manager/poetry/artifacts.ts index 7a165c214e..ec20263e89 100644 --- a/lib/manager/poetry/artifacts.ts +++ b/lib/manager/poetry/artifacts.ts @@ -11,7 +11,7 @@ export async function updateArtifacts( updatedDeps: string[], newPackageFileContent: string, config: UpdateArtifactsConfig -): Promise { +): Promise { await logger.debug(`poetry.updateArtifacts(${packageFileName})`); if (updatedDeps === undefined || updatedDeps.length < 1) { logger.debug('No updated poetry deps - returning null'); diff --git a/lib/manager/poetry/extract.ts b/lib/manager/poetry/extract.ts index 478ddad293..6461754b6f 100644 --- a/lib/manager/poetry/extract.ts +++ b/lib/manager/poetry/extract.ts @@ -7,7 +7,7 @@ import { PoetryFile, PoetrySection } from './types'; export function extractPackageFile( content: string, fileName: string -): PackageFile { +): PackageFile | null { logger.trace(`poetry.extractPackageFile(${fileName})`); let pyprojectfile: PoetryFile; try { diff --git a/lib/manager/poetry/update.ts b/lib/manager/poetry/update.ts index b1321b1715..eb2598764c 100644 --- a/lib/manager/poetry/update.ts +++ b/lib/manager/poetry/update.ts @@ -6,7 +6,7 @@ import { PoetryFile } from './types'; // TODO: Maybe factor out common code from pipenv.updateDependency and poetry.updateDependency // Return true if the match string is found at index in content -function matchAt(content: string, index: number, match: string) { +function matchAt(content: string, index: number, match: string): boolean { return content.substring(index, index + match.length) === match; } @@ -16,7 +16,7 @@ function replaceAt( index: number, oldString: string, newString: string -) { +): string { logger.debug(`Replacing ${oldString} with ${newString} at index ${index}`); return ( content.substr(0, index) + @@ -28,7 +28,7 @@ function replaceAt( export function updateDependency( fileContent: string, upgrade: Upgrade<{ nestedVersion?: boolean }> -): string { +): string | null { logger.trace({ config: upgrade }, 'poetry.updateDependency()'); if (!upgrade) { return null; diff --git a/lib/manager/pub/extract.ts b/lib/manager/pub/extract.ts index f2aa0ffb05..0ffdde1f68 100644 --- a/lib/manager/pub/extract.ts +++ b/lib/manager/pub/extract.ts @@ -34,7 +34,7 @@ function getDeps( export function extractPackageFile( content: string, packageFile: string -): PackageFile { +): PackageFile | null { try { const doc = safeLoad(content); const deps = [ diff --git a/lib/manager/sbt/extract.ts b/lib/manager/sbt/extract.ts index 5319390914..05e7a132cb 100644 --- a/lib/manager/sbt/extract.ts +++ b/lib/manager/sbt/extract.ts @@ -52,7 +52,10 @@ interface ParseContext { depType?: string; } -function parseDepExpr(expr: string, ctx: ParseContext) { +function parseDepExpr( + expr: string, + ctx: ParseContext +): PackageDependency | null { const { scalaVersion, fileOffset, variables } = ctx; let { depType } = ctx; @@ -139,7 +142,7 @@ function parseSbtLine( line: string, lineIndex: number, lines: string[] -): PackageFile & ParseOptions { +): (PackageFile & ParseOptions) | null { const { deps, registryUrls, fileOffset, variables } = acc; let { isMultiDeps, scalaVersion } = acc; diff --git a/lib/manager/swift/extract.ts b/lib/manager/swift/extract.ts index c55b10b1d3..80746f4e02 100644 --- a/lib/manager/swift/extract.ts +++ b/lib/manager/swift/extract.ts @@ -47,7 +47,7 @@ const searchLabels = { exactVersion: EXACT_VERSION, }; -function searchKeysForState(state) { +function searchKeysForState(state): string[] { switch (state) { case 'dependencies': return [SPACE, COLON, WILDCARD]; @@ -94,7 +94,7 @@ interface MatchResult { substr: string; } -function getMatch(str: string, state: string): MatchResult { +function getMatch(str: string, state: string): MatchResult | null { const keys = searchKeysForState(state); let result = null; for (let i = 0; i < keys.length; i += 1) { @@ -117,7 +117,7 @@ function getMatch(str: string, state: string): MatchResult { return result; } -function getDepName(url: string) { +function getDepName(url: string): string | null { try { const { host, pathname } = new URL(url); if (host === 'github.com' || host === 'gitlab.com') { @@ -135,7 +135,7 @@ function getDepName(url: string) { export function extractPackageFile( content: string, packageFile: string = null -): PackageFile { +): PackageFile | null { if (!content) return null; const result: PackageFile = { diff --git a/lib/manager/swift/update.ts b/lib/manager/swift/update.ts index 66131fc956..b7725ff06b 100644 --- a/lib/manager/swift/update.ts +++ b/lib/manager/swift/update.ts @@ -6,7 +6,7 @@ const fromParam = /^\s*from\s*:\s*"([^"]+)"\s*$/; export function updateDependency( fileContent: string, upgrade: Upgrade -): string { +): string | null { const { currentValue, newValue, fileReplacePosition } = upgrade; const leftPart = fileContent.slice(0, fileReplacePosition); const rightPart = fileContent.slice(fileReplacePosition); diff --git a/lib/manager/terraform/extract.ts b/lib/manager/terraform/extract.ts index 808a67e9ca..223b1bd622 100644 --- a/lib/manager/terraform/extract.ts +++ b/lib/manager/terraform/extract.ts @@ -2,7 +2,7 @@ import { logger } from '../../logger'; import { isValid, isVersion } from '../../versioning/hashicorp'; import { PackageDependency, PackageFile } from '../common'; -export function extractPackageFile(content: string): PackageFile { +export function extractPackageFile(content: string): PackageFile | null { logger.trace({ content }, 'terraform.extractPackageFile()'); if (!content.includes('module "')) { return null; diff --git a/lib/manager/terraform/update.ts b/lib/manager/terraform/update.ts index f7d08539b3..56edfc743c 100644 --- a/lib/manager/terraform/update.ts +++ b/lib/manager/terraform/update.ts @@ -4,7 +4,7 @@ import { Upgrade } from '../common'; export function updateDependency( currentFileContent: string, upgrade: Upgrade -): string { +): string | null { try { logger.debug(`terraform.updateDependency: ${upgrade.newValue}`); const lines = currentFileContent.split('\n'); diff --git a/lib/manager/travis/extract.ts b/lib/manager/travis/extract.ts index bbcf0f0f67..554ecb7a71 100644 --- a/lib/manager/travis/extract.ts +++ b/lib/manager/travis/extract.ts @@ -3,7 +3,7 @@ import yaml from 'js-yaml'; import { PackageFile, PackageDependency } from '../common'; import { logger } from '../../logger'; -export function extractPackageFile(content: string): PackageFile { +export function extractPackageFile(content: string): PackageFile | null { let doc; try { doc = yaml.safeLoad(content); diff --git a/lib/manager/travis/update.ts b/lib/manager/travis/update.ts index e39c66691d..fb09d1e54d 100644 --- a/lib/manager/travis/update.ts +++ b/lib/manager/travis/update.ts @@ -6,7 +6,7 @@ import { logger } from '../../logger'; export function updateDependency( fileContent: string, upgrade: Upgrade -): string { +): string | null { try { logger.debug(`travis.updateDependency(): ${upgrade.newValue}`); const indent = detectIndent(fileContent).indent || ' '; diff --git a/test/manager/travis/__snapshots__/package.spec.ts.snap b/test/manager/travis/__snapshots__/package.spec.ts.snap index 459fd7e257..86af8e5824 100644 --- a/test/manager/travis/__snapshots__/package.spec.ts.snap +++ b/test/manager/travis/__snapshots__/package.spec.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`lib/manager/node/package getPackageUpdates detects pinning 1`] = ` +exports[`lib/manager/travis/package getPackageUpdates detects pinning 1`] = ` Array [ Object { "isRange": true, @@ -14,7 +14,7 @@ Array [ ] `; -exports[`lib/manager/node/package getPackageUpdates returns result if needing updates 1`] = ` +exports[`lib/manager/travis/package getPackageUpdates returns result if needing updates 1`] = ` Array [ Object { "isRange": true, diff --git a/test/manager/travis/package.spec.ts b/test/manager/travis/package.spec.ts index 7129210bd7..2433b1c059 100644 --- a/test/manager/travis/package.spec.ts +++ b/test/manager/travis/package.spec.ts @@ -7,7 +7,7 @@ const getPkgReleases: any = _getPkgReleases; jest.mock('../../../lib/datasource/github'); -describe('lib/manager/node/package', () => { +describe('lib/manager/travis/package', () => { describe('getPackageUpdates', () => { // TODO: should be `PackageUpdateConfig` let config: any;