chore(lint): optimize linting (#4041)

This commit is contained in:
Michael Kriese 2019-07-10 10:41:12 +02:00 committed by Rhys Arkins
parent bb5baaad3f
commit 3ef1c95a66
21 changed files with 80 additions and 114 deletions

View file

@ -3,33 +3,24 @@ module.exports = {
node: true,
},
extends: [
'airbnb-base',
'plugin:promise/recommended',
'plugin:@typescript-eslint/recommended',
'airbnb-typescript/base',
'prettier',
'prettier/@typescript-eslint',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 9,
project: './tsconfig.json',
},
plugins: ['import', 'promise', '@typescript-eslint'],
rules: {
'import/no-unresolved': 0, // only required for js, see overrides
'require-await': 'error',
'no-use-before-define': 0,
'no-restricted-syntax': 0,
'no-await-in-loop': 0,
'prefer-destructuring': 'off',
'prefer-template': 'off',
'promise/always-return': 'error',
'promise/no-return-wrap': 'error',
'promise/param-names': 'error',
'promise/catch-or-return': 'error',
'promise/no-native': 'off',
'promise/no-nesting': 'warn',
'promise/no-promise-in-callback': 'warn',
'promise/no-callback-in-promise': 'warn',
'promise/avoid-new': 'warn',
'no-underscore-dangle': 0,
// TODO: fix lint
@ -38,25 +29,19 @@ module.exports = {
'@typescript-eslint/no-use-before-define': 'off', // disable until all files converted to typescript
'@typescript-eslint/explicit-member-accessibility': 0,
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/interface-name-prefix': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-non-null-assertion': 0,
},
overrides: [
{
files: ['*.spec.js', '*.spec.ts'],
// TODO: should be removed in near future, uses around ~50% lint time
files: ['*.js'],
rules: {
'global-require': 0,
'prefer-promise-reject-errors': 0,
'import/no-unresolved': [
'error',
{ commonjs: true, caseSensitive: true },
],
},
},
],
settings: {
'import/resolver': {
node: {
paths: ['lib'],
extensions: ['.js', '.ts'],
},
},
},
};

1
.gitignore vendored
View file

@ -11,3 +11,4 @@
*.pyc
renovate-0.0.0-semantic-release.tgz
/e2e/node_modules
.eslintcache

View file

@ -3,7 +3,6 @@
"javascript",
{ "language": "typescript", "autoFix": true }
],
"eslint.options": { "configFile": ".eslintrc.js" },
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},

View file

@ -1,13 +1,13 @@
import URL from 'url';
import { GotJSONOptions } from 'got';
import got from '../../util/got';
import { IGotApi, IGotApiOptions } from '../common';
import { GotApi, GotApiOptions } from '../common';
let baseUrl: string;
function get(path: string, options: IGotApiOptions & GotJSONOptions) {
function get(path: string, options: GotApiOptions & GotJSONOptions) {
const url = URL.resolve(baseUrl, path);
const opts: IGotApiOptions & GotJSONOptions = {
const opts: GotApiOptions & GotJSONOptions = {
hostType: 'bitbucket-server',
json: true,
...options,
@ -21,7 +21,7 @@ function get(path: string, options: IGotApiOptions & GotJSONOptions) {
const helpers = ['get', 'post', 'put', 'patch', 'head', 'delete'];
export const api: IGotApi = {} as any;
export const api: GotApi = {} as any;
for (const x of helpers) {
(api as any)[x] = (url: string, opts: any) =>

View file

@ -1,7 +1,7 @@
import url from 'url';
import delay from 'delay';
import api from './bb-got-wrapper';
import { api } from './bb-got-wrapper';
import * as utils from './utils';
import * as hostRules from '../../util/host-rules';
import GitStorage from '../git/storage';

View file

@ -1,6 +1,6 @@
// SEE for the reference https://github.com/renovatebot/renovate/blob/c3e9e572b225085448d94aa121c7ec81c14d3955/lib/platform/bitbucket/utils.js
import url from 'url';
import api from './bb-got-wrapper';
import { api } from './bb-got-wrapper';
// https://docs.atlassian.com/bitbucket-server/rest/6.0.0/bitbucket-rest.html#idp250
const prStateMapping: any = {

View file

@ -1,9 +1,9 @@
import { GotJSONOptions } from 'got';
import got from '../../util/got';
import { IGotApi, IGotApiOptions } from '../common';
import { GotApi, GotApiOptions } from '../common';
async function get(path: string, options: IGotApiOptions & GotJSONOptions) {
const opts: IGotApiOptions & GotJSONOptions = {
async function get(path: string, options: GotApiOptions & GotJSONOptions) {
const opts: GotApiOptions & GotJSONOptions = {
json: true,
hostType: 'bitbucket',
baseUrl: 'https://api.bitbucket.org/',
@ -15,7 +15,7 @@ async function get(path: string, options: IGotApiOptions & GotJSONOptions) {
const helpers = ['get', 'post', 'put', 'patch', 'head', 'delete'];
export const api: IGotApi = {} as any;
export const api: GotApi = {} as any;
for (const x of helpers) {
(api as any)[x] = (url: string, opts: any) =>

View file

@ -1,5 +1,5 @@
import parseDiff from 'parse-diff';
import api from './bb-got-wrapper';
import { api } from './bb-got-wrapper';
import * as utils from './utils';
import * as hostRules from '../../util/host-rules';
import GitStorage from '../git/storage';

View file

@ -1,5 +1,5 @@
import url from 'url';
import api from './bb-got-wrapper';
import { api } from './bb-got-wrapper';
export function repoInfoTransformer(repoInfoBody: any) {
return {

View file

@ -1,35 +1,35 @@
import got from 'got';
export interface IGotApiOptions {
export interface GotApiOptions {
useCache?: boolean;
hostType?: string;
body?: any;
}
export interface IGotApi<TOptions extends object = any> {
export interface GotApi<TOptions extends object = any> {
get<T extends object = any>(
url: string,
options?: IGotApiOptions & TOptions
options?: GotApiOptions & TOptions
): Promise<got.Response<T>>;
post<T extends object = any>(
url: string,
options?: IGotApiOptions & TOptions
options?: GotApiOptions & TOptions
): Promise<got.Response<T>>;
put<T extends object = any>(
url: string,
options?: IGotApiOptions & TOptions
options?: GotApiOptions & TOptions
): Promise<got.Response<T>>;
patch<T extends object = any>(
url: string,
options?: IGotApiOptions & TOptions
options?: GotApiOptions & TOptions
): Promise<got.Response<T>>;
head<T extends object = any>(
url: string,
options?: IGotApiOptions & TOptions
options?: GotApiOptions & TOptions
): Promise<got.Response<T>>;
delete<T extends object = any>(
url: string,
options?: IGotApiOptions & TOptions
options?: GotApiOptions & TOptions
): Promise<got.Response<T>>;
reset(): void;

View file

@ -9,14 +9,14 @@ declare module 'fs-extra' {
export function exists(pathLike: string): Promise<boolean>;
}
interface IStorageConfig {
interface StorageConfig {
localDir: string;
baseBranch?: string;
url: string;
gitPrivateKey?: string;
}
interface ILocalConfig extends IStorageConfig {
interface LocalConfig extends StorageConfig {
baseBranch: string;
baseBranchSha: string;
branchExists: { [branch: string]: boolean };
@ -24,7 +24,7 @@ interface ILocalConfig extends IStorageConfig {
}
export class Storage {
private _config: ILocalConfig = {} as any;
private _config: LocalConfig = {} as any;
private _git: Git.SimpleGit | undefined;
@ -50,10 +50,10 @@ export class Storage {
}
}
async initRepo(args: IStorageConfig) {
async initRepo(args: StorageConfig) {
this.cleanRepo();
// eslint-disable-next-line no-multi-assign
const config: ILocalConfig = (this._config = { ...args } as any);
const config: LocalConfig = (this._config = { ...args } as any);
// eslint-disable-next-line no-multi-assign
const cwd = (this._cwd = config.localDir);
this._config.branchExists = {};

View file

@ -1,6 +1,6 @@
import parseLinkHeader from 'parse-link-header';
import { IGotApi } from '../common';
import { GotApi } from '../common';
import got from '../../util/got';
const hostType = 'gitlab';
@ -45,15 +45,15 @@ async function get(path: string, options: any) {
const helpers = ['get', 'post', 'put', 'patch', 'head', 'delete'];
interface IGlGotApi
extends IGotApi<{
interface GlGotApi
extends GotApi<{
paginate?: boolean;
token?: string;
}> {
setBaseUrl(url: string): void;
}
export const api: IGlGotApi = {} as any;
export const api: GlGotApi = {} as any;
for (const x of helpers) {
(api as any)[x] = (url: string, opts: any) =>

View file

@ -1,7 +1,7 @@
import URL from 'url';
import is from '@sindresorhus/is';
import api from './gl-got-wrapper';
import { api } from './gl-got-wrapper';
import * as hostRules from '../../util/host-rules';
import GitStorage from '../git/storage';
import { PlatformConfig } from '../common';

10
lib/types.d.ts vendored
View file

@ -1,6 +1,6 @@
declare namespace Renovate {
// TODO: refactor logger
interface ILogger {
interface Logger {
trace(...args: any[]): void;
debug(...args: any[]): void;
info(...args: any[]): void;
@ -11,14 +11,10 @@ declare namespace Renovate {
setMeta(obj: any): void;
}
interface IDict<T> {
[key: string]: T;
}
}
// eslint-disable-next-line no-var, vars-on-top
declare var logger: Renovate.ILogger;
declare var logger: Renovate.Logger;
declare interface Error {
validationError?: string;
@ -28,6 +24,6 @@ declare interface Error {
declare namespace NodeJS {
interface Global {
gitAuthor?: { name: string; email: string };
logger: Renovate.ILogger;
logger: Renovate.Logger;
}
}

View file

@ -172,7 +172,7 @@
"copyfiles": "2.1.0",
"cross-env": "5.2.0",
"eslint": "5.16.0",
"eslint-config-airbnb-base": "13.2.0",
"eslint-config-airbnb-typescript": "4.0.0",
"eslint-config-prettier": "4.3.0",
"eslint-plugin-import": "2.18.0",
"eslint-plugin-promise": "4.2.1",

View file

@ -1,6 +1,6 @@
import responses from './_fixtures/responses';
import { IGotApi } from '../../../lib/platform/common';
import Storage from '../../../lib/platform/git/storage';
import { GotApi } from '../../../lib/platform/common';
import { Storage } from '../../../lib/platform/git/storage';
type BbsApi = typeof import('../../../lib/platform/bitbucket-server');
@ -8,7 +8,7 @@ describe('platform/bitbucket-server', () => {
Object.entries(responses).forEach(([scenarioName, mockResponses]) => {
describe(scenarioName, () => {
let bitbucket: typeof import('../../../lib/platform/bitbucket-server');
let api: jest.Mocked<IGotApi>;
let api: jest.Mocked<GotApi>;
let hostRules: jest.Mocked<typeof import('../../../lib/util/host-rules')>;
let GitStorage: jest.Mock<Storage> & {
getUrl: jest.MockInstance<any, any>;

View file

@ -1,7 +1,7 @@
import { IGotApi } from '../../../lib/platform/common';
import { GotApi } from '../../../lib/platform/common';
describe('platform/gl-got-wrapper', () => {
let api: IGotApi;
let api: GotApi;
let got: jest.Mock<typeof import('got')>;
let hostRules: typeof import('../../../lib/util/host-rules');
beforeEach(() => {

View file

@ -1,10 +1,10 @@
import URL from 'url';
import responses from './_fixtures/responses';
import { IGotApi } from '../../../lib/platform/common';
import { GotApi } from '../../../lib/platform/common';
describe('platform/bitbucket', () => {
let bitbucket: typeof import('../../../lib/platform/bitbucket');
let api: jest.Mocked<IGotApi>;
let api: jest.Mocked<GotApi>;
let hostRules: jest.Mocked<typeof import('../../../lib/util/host-rules')>;
let GitStorage: jest.Mocked<
import('../../../lib/platform/git/storage').Storage

View file

@ -1,10 +1,10 @@
import * as utils from '../../../lib/platform/bitbucket/utils';
import { IGotApi } from '../../../lib/platform/common';
import { GotApi } from '../../../lib/platform/common';
jest.mock('../../../lib/platform/bitbucket/bb-got-wrapper');
const api: jest.Mocked<
IGotApi
GotApi
> = require('../../../lib/platform/bitbucket/bb-got-wrapper').api;
const range = (count: number) => [...Array(count).keys()];

View file

@ -1,5 +1,5 @@
import got from '../../../lib/util/got';
import api from '../../../lib/platform/gitlab/gl-got-wrapper';
import { api } from '../../../lib/platform/gitlab/gl-got-wrapper';
import * as hostRules from '../../../lib/util/host-rules';
jest.mock('../../../lib/util/got');

View file

@ -2701,7 +2701,7 @@ debug@^3.1.0, debug@^3.2.6:
dependencies:
ms "^2.1.1"
debuglog@*, debuglog@^1.0.1:
debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
@ -3106,7 +3106,7 @@ escodegen@1.x.x, escodegen@^1.9.1:
optionalDependencies:
source-map "~0.6.1"
eslint-config-airbnb-base@13.2.0:
eslint-config-airbnb-base@^13.1.0, eslint-config-airbnb-base@^13.2.0:
version "13.2.0"
resolved "https://registry.yarnpkg.com/eslint-config-airbnb-base/-/eslint-config-airbnb-base-13.2.0.tgz#f6ea81459ff4dec2dda200c35f1d8f7419d57943"
integrity sha512-1mg/7eoB4AUeB0X1c/ho4vb2gYkNH8Trr/EgCT/aGmKhhG+F6vF5s8+iRBlWAzFIAphxIdp3YfEKgEl0f9Xg+w==
@ -3115,6 +3115,23 @@ eslint-config-airbnb-base@13.2.0:
object.assign "^4.1.0"
object.entries "^1.1.0"
eslint-config-airbnb-typescript@4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/eslint-config-airbnb-typescript/-/eslint-config-airbnb-typescript-4.0.0.tgz#98d20bfd0cb18f4a4c7c309e48ad2adc3c3ab4de"
integrity sha512-eB/eLUE9JT7F7/HDYhIL3iBOER7fi+k6A2F24CZ5E+kJizEnvrfXMerBrAVP+8gEzQCRGAsJFed/7GYlhDkomw==
dependencies:
eslint-config-airbnb "^17.1.0"
eslint-config-airbnb-base "^13.1.0"
eslint-config-airbnb@^17.1.0:
version "17.1.1"
resolved "https://registry.yarnpkg.com/eslint-config-airbnb/-/eslint-config-airbnb-17.1.1.tgz#2272e0b86bb1e2b138cdf88d07a3b6f4cda3d626"
integrity sha512-xCu//8a/aWqagKljt+1/qAM62BYZeNq04HmdevG5yUGWpja0I/xhqd6GdLRch5oetEGFiJAnvtGuTEAese53Qg==
dependencies:
eslint-config-airbnb-base "^13.2.0"
object.assign "^4.1.0"
object.entries "^1.1.0"
eslint-config-prettier@4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-4.3.0.tgz#c55c1fcac8ce4518aeb77906984e134d9eb5a4f0"
@ -4261,7 +4278,7 @@ import-local@^2.0.0:
pkg-dir "^3.0.0"
resolve-cwd "^2.0.0"
imurmurhash@*, imurmurhash@^0.1.4:
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
@ -5442,7 +5459,7 @@ libnpm@^2.0.1:
read-package-json "^2.0.13"
stringify-package "^1.0.0"
libnpmaccess@*, libnpmaccess@^3.0.1:
libnpmaccess@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/libnpmaccess/-/libnpmaccess-3.0.1.tgz#5b3a9de621f293d425191aa2e779102f84167fa8"
integrity sha512-RlZ7PNarCBt+XbnP7R6PoVgOq9t+kou5rvhaInoNibhPO7eMlRfS0B8yjatgn2yaHIwWNyoJDolC/6Lc5L/IQA==
@ -5471,7 +5488,7 @@ libnpmhook@^5.0.2:
get-stream "^4.0.0"
npm-registry-fetch "^3.8.0"
libnpmorg@*, libnpmorg@^1.0.0:
libnpmorg@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/libnpmorg/-/libnpmorg-1.0.0.tgz#979b868c48ba28c5820e3bb9d9e73c883c16a232"
integrity sha512-o+4eVJBoDGMgRwh2lJY0a8pRV2c/tQM/SxlqXezjcAg26Qe9jigYVs+Xk0vvlYDWCDhP0g74J8UwWeAgsB7gGw==
@ -5496,7 +5513,7 @@ libnpmpublish@^1.1.0:
semver "^5.5.1"
ssri "^6.0.1"
libnpmsearch@*, libnpmsearch@^2.0.0:
libnpmsearch@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/libnpmsearch/-/libnpmsearch-2.0.1.tgz#eccc73a8fbf267d765d18082b85daa2512501f96"
integrity sha512-K0yXyut9MHHCAH+DOiglQCpmBKPZXSUu76+BE2maSEfQN15OwNaA/Aiioe9lRFlVFOr7WcuJCY+VSl+gLi9NTA==
@ -5505,7 +5522,7 @@ libnpmsearch@*, libnpmsearch@^2.0.0:
get-stream "^4.0.0"
npm-registry-fetch "^3.8.0"
libnpmteam@*, libnpmteam@^1.0.1:
libnpmteam@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/libnpmteam/-/libnpmteam-1.0.1.tgz#ff704b1b6c06ea674b3b1101ac3e305f5114f213"
integrity sha512-gDdrflKFCX7TNwOMX1snWojCoDE5LoRWcfOC0C/fqF7mBq8Uz9zWAX4B2RllYETNO7pBupBaSyBDkTAC15cAMg==
@ -5608,11 +5625,6 @@ lockfile@^1.0.4:
dependencies:
signal-exit "^3.0.2"
lodash._baseindexof@*:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=
lodash._baseuniq@~4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
@ -5621,33 +5633,11 @@ lodash._baseuniq@~4.6.0:
lodash._createset "~4.0.0"
lodash._root "~3.0.0"
lodash._bindcallback@*:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=
lodash._cacheindexof@*:
version "3.0.2"
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=
lodash._createcache@*:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
dependencies:
lodash._getnative "^3.0.0"
lodash._createset@~4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=
lodash._getnative@*, lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=
lodash._reinterpolate@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
@ -5688,11 +5678,6 @@ lodash.isstring@^4.0.1:
resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451"
integrity sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=
lodash.restparam@*:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=
lodash.set@^4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
@ -6557,7 +6542,7 @@ npm-pick-manifest@^2.2.3:
npm-package-arg "^6.0.0"
semver "^5.4.1"
npm-profile@*, npm-profile@^4.0.1:
npm-profile@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/npm-profile/-/npm-profile-4.0.1.tgz#d350f7a5e6b60691c7168fbb8392c3603583f5aa"
integrity sha512-NQ1I/1Q7YRtHZXkcuU1/IyHeLy6pd+ScKg4+DQHdfsm769TGq6HPrkbuNJVJS4zwE+0mvvmeULzQdWn2L2EsVA==
@ -7831,7 +7816,7 @@ readable-stream@~1.0.31:
isarray "0.0.1"
string_decoder "~0.10.x"
readdir-scoped-modules@*, readdir-scoped-modules@^1.0.0, readdir-scoped-modules@^1.1.0:
readdir-scoped-modules@^1.0.0, readdir-scoped-modules@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/readdir-scoped-modules/-/readdir-scoped-modules-1.1.0.tgz#8d45407b4f870a0dcaebc0e28670d18e74514309"
integrity sha512-asaikDeqAQg7JifRsZn1NJZXo9E+VwlyCfbkZhwyISinqk5zNS6266HS5kah6P0SaQKGF6SkNnZVHUzHFYxYDw==