Skip to content

Commit

Permalink
fix(eslint): '@typescript-eslint/explicit-function-return-… (#4872)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice authored and rarkins committed Nov 26, 2019
1 parent d210191 commit f0d4995
Show file tree
Hide file tree
Showing 44 changed files with 771 additions and 587 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Expand Up @@ -25,6 +25,8 @@ module.exports = {
'prefer-template': 'off',
'no-underscore-dangle': 0,

'@typescript-eslint/explicit-function-return-type': 'error',

// TODO: fix lint
'@typescript-eslint/camelcase': 'off', // disabled until ??
'@typescript-eslint/no-explicit-any': 0,
Expand Down
28 changes: 20 additions & 8 deletions lib/datasource/docker/index.ts
Expand Up @@ -9,16 +9,22 @@ import { logger } from '../../logger';
import got from '../../util/got';
import * as hostRules from '../../util/host-rules';
import { PkgReleaseConfig, ReleaseResult } from '../common';
import { GotResponse } from '../../platform';

// TODO: add got typings when available
// TODO: replace www-authenticate with https://www.npmjs.com/package/auth-header ?

const ecrRegex = /\d+\.dkr\.ecr\.([-a-z0-9]+)\.amazonaws\.com/;

export interface RegistryRepository {
registry: string;
repository: string;
}

export function getRegistryRepository(
lookupName: string,
registryUrls: string[]
) {
): RegistryRepository {
let registry: string;
const split = lookupName.split('/');
if (split.length > 1 && (split[0].includes('.') || split[0].includes(':'))) {
Expand Down Expand Up @@ -48,7 +54,10 @@ export function getRegistryRepository(
};
}

function getECRAuthToken(region: string, opts: hostRules.HostRule) {
function getECRAuthToken(
region: string,
opts: hostRules.HostRule
): Promise<string | null> {
const config = { region, accessKeyId: undefined, secretAccessKey: undefined };
if (opts.username && opts.password) {
config.accessKeyId = opts.username;
Expand Down Expand Up @@ -171,22 +180,22 @@ async function getAuthHeaders(
}
}

function digestFromManifestStr(str: hasha.HashaInput) {
function digestFromManifestStr(str: hasha.HashaInput): string {
return 'sha256:' + hasha(str, { algorithm: 'sha256' });
}

function extractDigestFromResponse(manifestResponse) {
function extractDigestFromResponse(manifestResponse: GotResponse): string {
if (manifestResponse.headers['docker-content-digest'] === undefined) {
return digestFromManifestStr(manifestResponse.body);
}
return manifestResponse.headers['docker-content-digest'];
return manifestResponse.headers['docker-content-digest'] as string;
}

async function getManifestResponse(
registry: string,
repository: string,
tag: string
) {
): Promise<GotResponse> {
logger.debug(`getManifestResponse(${registry}, ${repository}, ${tag})`);
try {
const headers = await getAuthHeaders(registry, repository);
Expand Down Expand Up @@ -408,12 +417,15 @@ async function getTags(
}
}

export function getConfigResponse(url: string, headers: OutgoingHttpHeaders) {
export function getConfigResponse(
url: string,
headers: OutgoingHttpHeaders
): Promise<GotResponse> {
return got(url, {
headers,
hooks: {
beforeRedirect: [
(options: any) => {
(options: any): void => {
if (
options.search &&
options.search.indexOf('X-Amz-Algorithm') !== -1
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/github/index.ts
Expand Up @@ -66,7 +66,7 @@ export async function getPreset(
}

const cacheNamespace = 'datasource-github';
function getCacheKey(repo: string, type: string) {
function getCacheKey(repo: string, type: string): string {
return `${repo}:${type}`;
}

Expand Down
10 changes: 8 additions & 2 deletions lib/datasource/gitlab/index.ts
Expand Up @@ -7,7 +7,9 @@ const glGot = api.get;

const GitLabApiUrl = 'https://gitlab.com/api/v4/projects';

async function getDefaultBranchName(urlEncodedPkgName: string) {
async function getDefaultBranchName(
urlEncodedPkgName: string
): Promise<string> {
const branchesUrl = `${GitLabApiUrl}/${urlEncodedPkgName}/repository/branches`;
type GlBranch = {
default: boolean;
Expand Down Expand Up @@ -61,7 +63,11 @@ export async function getPreset(
}

const cacheNamespace = 'datasource-gitlab';
function getCacheKey(depHost: string, repo: string, lookupType: string) {
function getCacheKey(
depHost: string,
repo: string,
lookupType: string
): string {
const type = lookupType || 'tags';
return `${depHost}:${repo}:${type}`;
}
Expand Down
12 changes: 8 additions & 4 deletions lib/datasource/index.ts
Expand Up @@ -74,7 +74,9 @@ async function fetchReleases(
return dep;
}

function getRawReleases(config: PkgReleaseConfig): Promise<ReleaseResult> {
function getRawReleases(
config: PkgReleaseConfig
): Promise<ReleaseResult | null> {
const cacheKey =
cacheNamespace +
config.datasource +
Expand All @@ -88,7 +90,9 @@ function getRawReleases(config: PkgReleaseConfig): Promise<ReleaseResult> {
return global.repoCache[cacheKey];
}

export async function getPkgReleases(config: PkgReleaseConfig) {
export async function getPkgReleases(
config: PkgReleaseConfig
): Promise<ReleaseResult | null> {
const res = await getRawReleases({
...config,
lookupName: config.lookupName || config.depName,
Expand All @@ -101,7 +105,7 @@ export async function getPkgReleases(config: PkgReleaseConfig) {
// Filter by version scheme
const version = versioning.get(versionScheme);
// Return a sorted list of valid Versions
function sortReleases(release1: Release, release2: Release) {
function sortReleases(release1: Release, release2: Release): number {
return version.sortVersions(release1.version, release2.version);
}
if (res.releases) {
Expand All @@ -112,7 +116,7 @@ export async function getPkgReleases(config: PkgReleaseConfig) {
return res;
}

export function supportsDigests(config: DigestConfig) {
export function supportsDigests(config: DigestConfig): boolean {
return !!datasources[config.datasource].getDigest;
}

Expand Down
14 changes: 7 additions & 7 deletions lib/datasource/maven/util.ts
Expand Up @@ -2,33 +2,33 @@ import url from 'url';
import got from '../../util/got';
import { logger } from '../../logger';

function isMavenCentral(pkgUrl: url.URL | string) {
function isMavenCentral(pkgUrl: url.URL | string): boolean {
return (
(typeof pkgUrl === 'string' ? pkgUrl : pkgUrl.host) === 'central.maven.org'
);
}

function isTemporalError(err: { code: string; statusCode: number }) {
function isTemporalError(err: { code: string; statusCode: number }): boolean {
return (
err.code === 'ECONNRESET' ||
err.statusCode === 429 ||
(err.statusCode >= 500 && err.statusCode < 600)
);
}

function isHostError(err: { code: string }) {
function isHostError(err: { code: string }): boolean {
return err.code === 'ETIMEDOUT';
}

function isNotFoundError(err: { code: string; statusCode: number }) {
function isNotFoundError(err: { code: string; statusCode: number }): boolean {
return err.code === 'ENOTFOUND' || err.statusCode === 404;
}

function isPermissionsIssue(err: { statusCode: number }) {
function isPermissionsIssue(err: { statusCode: number }): boolean {
return err.statusCode === 401 || err.statusCode === 403;
}

function isConnectionError(err: { code: string }) {
function isConnectionError(err: { code: string }): boolean {
return err.code === 'ECONNREFUSED';
}

Expand All @@ -42,7 +42,7 @@ export async function downloadHttpProtocol(
hostType,
hooks: {
beforeRedirect: [
(options: any) => {
(options: any): void => {
if (
options.search &&
options.search.indexOf('X-Amz-Algorithm') !== -1
Expand Down
4 changes: 2 additions & 2 deletions lib/datasource/metadata.ts
Expand Up @@ -67,7 +67,7 @@ export function addMetaData(
dep?: ReleaseResult,
datasource?: string,
lookupName?: string
) {
): void {
if (!dep) {
return;
}
Expand All @@ -86,7 +86,7 @@ export function addMetaData(
/**
* @param {string} url
*/
const massageGithubUrl = url => {
const massageGithubUrl = (url: string): string => {
return url
.replace('http:', 'https:')
.replace('www.github.com', 'github.com')
Expand Down
4 changes: 2 additions & 2 deletions lib/datasource/npm/get.ts
Expand Up @@ -15,12 +15,12 @@ import { Release, ReleaseResult } from '../common';

let memcache = {};

export function resetMemCache() {
export function resetMemCache(): void {
logger.debug('resetMemCache()');
memcache = {};
}

export function resetCache() {
export function resetCache(): void {
resetMemCache();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/npm/npmrc.ts
Expand Up @@ -27,7 +27,7 @@ function envReplace(value: any, env = process.env): any {
});
}

export function setNpmrc(input?: string) {
export function setNpmrc(input?: string): void {
if (input) {
if (input === npmrcRaw) {
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/nuget/v2.ts
Expand Up @@ -4,7 +4,7 @@ import { logger } from '../../logger';
import got from '../../util/got';
import { ReleaseResult } from '../common';

function getPkgProp(pkgInfo: XmlElement, propName: string) {
function getPkgProp(pkgInfo: XmlElement, propName: string): string {
return pkgInfo.childNamed('m:properties').childNamed(`d:${propName}`).val;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/nuget/v3.ts
Expand Up @@ -9,7 +9,7 @@ import { ReleaseResult } from '../common';
const defaultNugetFeed = 'https://api.nuget.org/v3/index.json';
const cacheNamespace = 'datasource-nuget';

export function getDefaultFeed() {
export function getDefaultFeed(): string {
return defaultNugetFeed;
}

Expand Down
12 changes: 7 additions & 5 deletions lib/datasource/packagist/index.ts
Expand Up @@ -6,12 +6,12 @@ import parse from 'github-url-from-git';
import pAll from 'p-all';
import { logger } from '../../logger';

import got from '../../util/got';
import got, { GotJSONOptions } from '../../util/got';
import * as hostRules from '../../util/host-rules';
import { PkgReleaseConfig, ReleaseResult } from '../common';

function getHostOpts(url: string) {
const opts: any = {
function getHostOpts(url: string): GotJSONOptions {
const opts: GotJSONOptions = {
json: true,
};
const { username, password } = hostRules.find({ hostType: 'packagist', url });
Expand Down Expand Up @@ -173,7 +173,9 @@ async function getAllPackages(regUrl: string): Promise<AllPackages | null> {
const { packages, providersUrl, files, includesFiles } = registryMeta;
const providerPackages: Record<string, string> = {};
if (files) {
const queue = files.map(file => () => getPackagistFile(regUrl, file));
const queue = files.map(file => (): Promise<PackagistFile> =>
getPackagistFile(regUrl, file)
);
const resolvedFiles = await pAll(queue, { concurrency: 5 });
for (const res of resolvedFiles) {
for (const [name, val] of Object.entries(res.providers)) {
Expand Down Expand Up @@ -204,7 +206,7 @@ async function getAllPackages(regUrl: string): Promise<AllPackages | null> {
return allPackages;
}

async function packagistOrgLookup(name: string) {
async function packagistOrgLookup(name: string): Promise<ReleaseResult> {
const cacheNamespace = 'datasource-packagist-org';
const cachedResult = await renovateCache.get<ReleaseResult>(
cacheNamespace,
Expand Down
4 changes: 2 additions & 2 deletions lib/datasource/pypi/index.ts
Expand Up @@ -6,14 +6,14 @@ import { matches } from '../../versioning/pep440';
import got from '../../util/got';
import { PkgReleaseConfig, ReleaseResult } from '../common';

function normalizeName(input: string) {
function normalizeName(input: string): string {
return input.toLowerCase().replace(/(-|\.)/g, '_');
}

function compatibleVersions(
releases: Record<string, { requires_python?: boolean }[]>,
compatibility: Record<string, string>
) {
): string[] {
const versions = Object.keys(releases);
if (!(compatibility && compatibility.python)) {
return versions;
Expand Down
8 changes: 4 additions & 4 deletions lib/datasource/rubygems/get-rubygems-org.ts
Expand Up @@ -6,7 +6,7 @@ let lastSync = new Date('2000-01-01');
let packageReleases: Record<string, string[]> = Object.create(null); // Because we might need a "constructor" key
let contentLength = 0;

async function updateRubyGemsVersions() {
async function updateRubyGemsVersions(): Promise<void> {
const url = 'https://rubygems.org/versions';
const options = {
headers: {
Expand All @@ -30,7 +30,7 @@ async function updateRubyGemsVersions() {
return;
}

function processLine(line: string) {
function processLine(line: string): void {
let split: string[];
let pkg: string;
let versions: string;
Expand Down Expand Up @@ -68,14 +68,14 @@ async function updateRubyGemsVersions() {
lastSync = new Date();
}

function isDataStale() {
function isDataStale(): boolean {
const minutesElapsed = Math.floor(
(new Date().getTime() - lastSync.getTime()) / (60 * 1000)
);
return minutesElapsed >= 5;
}

async function syncVersions() {
async function syncVersions(): Promise<void> {
if (isDataStale()) {
global.updateRubyGemsVersions =
global.updateRubyGemsVersions || updateRubyGemsVersions();
Expand Down
7 changes: 4 additions & 3 deletions lib/datasource/rubygems/get.ts
@@ -1,3 +1,4 @@
import { OutgoingHttpHeaders } from 'http';
import { logger } from '../../logger';
import got from '../../util/got';
import { maskToken } from '../../util/mask';
Expand All @@ -9,7 +10,7 @@ const INFO_PATH = '/api/v1/gems';
const VERSIONS_PATH = '/api/v1/versions';

// istanbul ignore next
const processError = ({ err, ...rest }) => {
const processError = ({ err, ...rest }): null => {
const { statusCode, headers = {} } = err;
const data = {
...rest,
Expand All @@ -33,11 +34,11 @@ const processError = ({ err, ...rest }) => {
return null;
};

const getHeaders = () => {
const getHeaders = (): OutgoingHttpHeaders => {
return { hostType: 'rubygems' };
};

const fetch = async ({ dependency, registry, path }) => {
const fetch = async ({ dependency, registry, path }): Promise<any> => {
const json = true;

const retry = { retries: retriable() };
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/rubygems/retriable.ts
Expand Up @@ -38,7 +38,7 @@ export type HTTPError = InstanceType<got.GotInstance['HTTPError']>;
export default (numberOfRetries = NUMBER_OF_RETRIES): got.RetryFunction => (
_?: number,
err?: Partial<HTTPError>
) => {
): number => {
if (numberOfRetries === 0) {
return 0;
}
Expand Down

0 comments on commit f0d4995

Please sign in to comment.