fix eslint warnings (#2265)

* chore: reduce warnings

* chore: fix eslint warnings

* fix warning
This commit is contained in:
Juan Picado 2021-06-12 09:25:53 +02:00 committed by GitHub
parent 59ac312c21
commit 15c694156a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 80 additions and 102 deletions

View File

@ -133,7 +133,7 @@
"docker": "docker build -t verdaccio/verdaccio:local . --no-cache",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,yml,yaml,md}\"",
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,yml,yaml,md}\"",
"lint": "eslint --max-warnings 165 \"**/*.{js,jsx,ts,tsx}\"",
"lint": "eslint --max-warnings 48 \"**/*.{js,jsx,ts,tsx}\"",
"test": "pnpm recursive test --filter ./packages",
"test:e2e:cli": "pnpm test --filter ...@verdaccio/e2e-cli",
"test:e2e:ui": "pnpm test --filter ...@verdaccio/e2e-ui",

View File

@ -1,6 +1,4 @@
import _ from 'lodash';
import express, { Express } from 'express';
import express, { Router } from 'express';
import {
match,
validateName,
@ -25,11 +23,7 @@ import profile from './v1/profile';
import token from './v1/token';
import v1Search from './v1/search';
export default function (
config: Config,
auth: IAuth,
storage: IStorageHandler
): Express.Application {
export default function (config: Config, auth: IAuth, storage: IStorageHandler): Router {
/* eslint new-cap:off */
const app = express.Router();
/* eslint new-cap:off */

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
import { Command } from 'clipanion';
export class VersionCommand extends Command {

View File

@ -9,7 +9,6 @@ import {
parseConfigFile,
ROLES,
WEB_TITLE,
getMatchedPackagesSpec,
} from '../src';
import { parseConfigurationFile } from './utils';

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
export default class Config {
constructor() {
this.storage = './test-storage';

View File

@ -1,12 +1,8 @@
/* eslint-disable jest/no-mocks-import */
import fs from 'fs';
import path from 'path';
import { assign } from 'lodash';
import { ILocalData, PluginOptions, Token } from '@verdaccio/types';
import LocalDatabase from '../src/local-database';
import { ILocalFSPackageManager } from '../src/local-fs';
import * as pkgUtils from '../src/pkg-utils';
// FIXME: remove this mocks imports
@ -19,14 +15,11 @@ const optionsPlugin: PluginOptions<{}> = {
};
let locaDatabase: ILocalData<{}>;
let loadPrivatePackages;
describe('Local Database', () => {
beforeEach(() => {
const writeMock = jest.spyOn(fs, 'writeFileSync').mockImplementation();
loadPrivatePackages = jest
.spyOn(pkgUtils, 'loadPrivatePackages')
.mockReturnValue({ list: [], secret: '' });
jest.spyOn(pkgUtils, 'loadPrivatePackages').mockReturnValue({ list: [], secret: '' });
locaDatabase = new LocalDatabase(optionsPlugin.config, optionsPlugin.logger);
(locaDatabase as LocalDatabase).clean();
writeMock.mockClear();

View File

@ -1,9 +1,6 @@
import { URL } from 'url';
import _ from 'lodash';
import buildDebug from 'debug';
import isURLValidator from 'validator/lib/isURL';
import { ConfigYaml } from '@verdaccio/types';
import { HEADERS } from '@verdaccio/commons-api';
const debug = buildDebug('verdaccio:core:url');

View File

@ -8,7 +8,6 @@ import { logger } from '@verdaccio/logger';
import { notifyRequest, NotifyRequestOptions } from './notify-request';
const debug = buildDebug('verdaccio:hooks');
type TemplateMetadata = Package & { publishedPackage: string };
export function compileTemplate(content, metadata) {
// FUTURE: multiple handlers

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`prettyFactory should return a function 1`] = `
exports[`prettyFactory should return a function with options 1`] = `
" trace--- [trace] - foo
"
`;

View File

@ -6,7 +6,7 @@ describe('prettyFactory', () => {
expect(typeof factory['default']({})).toEqual('function');
});
test('should return a function', () => {
test('should return a function with options', () => {
const log = {
level: 10,
foo: 'foo',

View File

@ -2,7 +2,7 @@ import { logger, setup } from '../src';
describe('logger', () => {
test('dsadasd', () => {
const spyOn = jest.spyOn(process.stdout, 'write');
jest.spyOn(process.stdout, 'write');
setup([
{
level: 'info',
@ -10,7 +10,7 @@ describe('logger', () => {
]);
logger.info({ packageName: 'test' }, `publishing or updating a new version for @{packageName}`);
// FIXME: check expect
// expect(spyOn).toHaveBeenCalledTimes(2);
});
});

View File

@ -207,6 +207,8 @@ export function final(
body: FinalBody,
req: $RequestExtend,
res: $ResponseExtend,
// if we remove `next` breaks test
// eslint-disable-next-line @typescript-eslint/no-unused-vars
next: $NextFunctionVer
): void {
if (res.statusCode === HTTP_STATUS.UNAUTHORIZED && !res.getHeader(HEADERS.WWW_AUTH)) {

View File

@ -13,7 +13,6 @@ import {
import { buildToken } from '@verdaccio/utils';
import { generateRandomHexString } from '@verdaccio/utils';
import { Package } from '@verdaccio/types';
import { response } from 'express';
const debug = buildDebug('verdaccio:mock:api');

View File

@ -9,8 +9,3 @@ export interface IServerProcess {
init(binPath: string): Promise<any>;
stop(): void;
}
// eslint-disable-next-line no-unused-vars
declare class PromiseAssert<IRequestPromise> extends Promise<any> {
public constructor(options: any);
}

View File

@ -104,11 +104,12 @@ class GoogleCloudStorageHandler implements IPackageStorageManager {
const file = this.helper.buildFilePath(this.name, fileName);
this.logger.debug({ name: file.name }, 'gcloud: deleting @{name} from storage');
try {
// @ts-ignore
file
// @ts-ignore
.delete()
// FIXME: after upgrade this is broken
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.then((_data: [Response]): void => {
this.logger.debug(
{ name: file.name },

View File

@ -1,13 +1,5 @@
import { getServiceUnavailable } from '@verdaccio/commons-api';
import {
Logger,
Callback,
Config,
IPluginStorage,
Token,
TokenFilter,
PluginOptions,
} from '@verdaccio/types';
import { Logger, Callback, Config, IPluginStorage, Token, PluginOptions } from '@verdaccio/types';
import buildDebug from 'debug';
import MemoryHandler, { DataHandler } from './memory-handler';
@ -108,7 +100,7 @@ class LocalMemory implements IPluginStorage<ConfigMemory> {
return emptyDatabase;
}
public saveToken(token: Token): Promise<void> {
public saveToken(): Promise<void> {
this.logger.warn('[verdaccio/memory][saveToken] save token has not been implemented yet');
return Promise.reject(getServiceUnavailable('method not implemented'));
@ -123,7 +115,7 @@ class LocalMemory implements IPluginStorage<ConfigMemory> {
return Promise.reject(getServiceUnavailable('method not implemented'));
}
public readTokens(filter: TokenFilter): Promise<Token[]> {
public readTokens(): Promise<Token[]> {
this.logger.warn('[verdaccio/memory][readTokens] read tokens has not been implemented yet ');
return Promise.reject(getServiceUnavailable('method not implemented'));

View File

@ -5,9 +5,9 @@ import DialogTitle from 'verdaccio-ui/components/DialogTitle';
import { Theme } from 'verdaccio-ui/design-tokens/theme';
export const Title = styled(DialogTitle)<{ theme?: Theme }>((props) => ({
backgroundColor: props.theme && props.theme.palette.primary.main,
color: props.theme && props.theme.palette.white,
fontSize: props.theme && props.theme.fontSize.lg,
backgroundColor: props.theme?.palette.primary.main,
color: props.theme?.palette.white,
fontSize: props.theme?.fontSize.lg,
}));
export const Content = styled(DialogContent)<{ theme?: Theme }>(({ theme }) => ({

View File

@ -6,7 +6,7 @@ import InputAdornment from 'verdaccio-ui/components/InputAdornment';
import { Theme } from 'verdaccio-ui/design-tokens/theme';
const StyledInputAdornment = styled(InputAdornment)<{ theme?: Theme }>((props) => ({
color: props.theme && props.theme.palette.white,
color: props.theme?.palette.white,
}));
const SearchAdornment: React.FC = () => (

View File

@ -29,15 +29,15 @@ export const LeftSide = styled(RightSide)({
export const MobileNavBar = styled('div')<{ theme?: Theme }>((props) => ({
alignItems: 'center',
display: 'flex',
borderBottom: `1px solid ${props.theme && props.theme.palette.greyLight}`,
borderBottom: `1px solid ${props.theme?.palette.greyLight}`,
padding: '8px',
position: 'relative',
}));
export const InnerMobileNavBar = styled('div')<{ theme?: Theme }>((props) => ({
borderRadius: '4px',
backgroundColor: props.theme && props.theme.palette.greyLight,
color: props.theme && props.theme.palette.white,
backgroundColor: props.theme?.palette.greyLight,
color: props.theme?.palette.white,
width: '100%',
padding: '0 5px',
margin: '0 10px 0 0',

View File

@ -7,7 +7,7 @@ import ListItemText from '../ListItemText';
import Text from '../Text';
export const StyledText = styled(Text)<{ theme?: Theme }>((props) => ({
fontWeight: props.theme && props.theme.fontWeight.bold,
fontWeight: props.theme?.fontWeight.bold,
}));
export const AuthorListItem = styled(ListItem)({

View File

@ -24,7 +24,7 @@ export const StyledTextField = styled(TextField)<{ theme?: Theme }>((props) => (
border: 'none',
},
':after': {
borderColor: props.theme && props.theme.palette.white,
borderColor: props.theme?.palette.white,
},
':hover:before': {
content: 'none',
@ -41,7 +41,7 @@ export const StyledTextField = styled(TextField)<{ theme?: Theme }>((props) => (
},
'& .MuiInputBase-input': {
[`@media screen and (min-width: ${props.theme?.breakPoints.medium}px)`]: {
color: props.theme && props.theme.palette.white,
color: props.theme?.palette.white,
},
},
}));

View File

@ -11,7 +11,7 @@ const resetStyles = makeStyles(({ theme }: { theme?: Theme }) => ({
fontFamily: '"Roboto", Helvetica Neue, Arial, sans-serif',
},
strong: {
fontWeight: theme && theme.fontWeight.semiBold,
fontWeight: theme?.fontWeight.semiBold,
},
'html, body, #root': {
height: '100%',
@ -26,8 +26,8 @@ const resetStyles = makeStyles(({ theme }: { theme?: Theme }) => ({
flex: 1,
height: '100%',
[`@media screen and (min-width: ${theme && theme.breakPoints.container}px)`]: {
maxWidth: theme && theme.breakPoints.container,
[`@media screen and (min-width: ${theme?.breakPoints.container}px)`]: {
maxWidth: theme?.breakPoints.container,
width: '100%',
marginLeft: 'auto',
marginRight: 'auto',

View File

@ -23,7 +23,7 @@ const DependencyBlock: React.FC<DependencyBlockProps> = ({ title, dependencies }
const deps = Object.entries(dependencies);
function handleClick(name: string): void {
enableLoading && enableLoading();
enableLoading?.();
history.push(`/-/web/detail/${name}`);
}

View File

@ -7,7 +7,13 @@ import { DetailContext } from '../context';
import Deprecated from './Deprecated';
import DetailContainerContent from './DetailContainerContent';
import DetailContainerTabs from './DetailContainerTabs';
import { TabPosition } from './tabs';
export enum TabPosition {
README = 'readme',
DEPENDENCIES = 'dependencies',
VERSIONS = 'versions',
UPLINKS = 'uplinks',
}
const DetailContainer: React.FC = () => {
const tabs = Object.values(TabPosition);

View File

@ -3,7 +3,13 @@ import React from 'react';
import loadable from '../../../App/utils/loadable';
import DetailContainerContentReadme from './DetailContainerContentReadme';
import { TabPosition } from './tabs';
export enum TabPosition {
README = 'readme',
DEPENDENCIES = 'dependencies',
VERSIONS = 'versions',
UPLINKS = 'uplinks',
}
const Versions = loadable(() => import(/* webpackChunkName: "Versions" */ './Versions'));
const UpLinks = loadable(() => import(/* webpackChunkName: "UpLinks" */ './UpLinks'));

View File

@ -5,7 +5,7 @@ import Text from 'verdaccio-ui/components/Text';
import { Theme } from 'verdaccio-ui/design-tokens/theme';
export const StyledText = styled(Text)<{ theme?: Theme }>((props) => ({
fontWeight: props.theme && props.theme.fontWeight.bold,
fontWeight: props.theme?.fontWeight.bold,
}));
export const Spacer = styled('div')<{ theme?: Theme }>(({ theme }) => ({

View File

@ -6,7 +6,7 @@ import Text from 'verdaccio-ui/components/Text';
import { Theme } from 'verdaccio-ui/design-tokens/theme';
export const StyledText = styled(Text)<{ theme?: Theme }>((props) => ({
fontWeight: props.theme && props.theme.fontWeight.bold,
fontWeight: props.theme?.fontWeight.bold,
}));
export const Spacer = styled('div')<{ theme?: Theme }>(({ theme }) => ({

View File

@ -1,6 +0,0 @@
export enum TabPosition {
README = 'readme',
DEPENDENCIES = 'dependencies',
VERSIONS = 'versions',
UPLINKS = 'uplinks',
}

View File

@ -11,7 +11,8 @@ import loadable from '../../../App/utils/loadable';
import DetailSidebarFundButton from './DetailSidebarFundButton';
import DetailSidebarTitle from './DetailSidebarTitle';
import Developers, { DeveloperType } from './Developers';
import Developers from './Developers';
import { DeveloperType } from './Developers/DevelopersTitle';
const Engines = loadable(() => import(/* webpackChunkName: "Engines" */ './Engines'));
const Dist = loadable(() => import(/* webpackChunkName: "Dist" */ './Dist'));

View File

@ -5,7 +5,7 @@ import { render, cleanup, fireEvent } from 'verdaccio-ui/utils/test-react-testin
import { DetailContextProvider } from '../../context';
import Developers from './Developers';
import { DeveloperType } from './types';
import { DeveloperType } from './DevelopersTitle';
describe('test Developers', () => {
afterEach(() => {

View File

@ -13,7 +13,11 @@ import { DetailContext } from '../..';
import DevelopersTitle from './DevelopersTitle';
import getUniqueDeveloperValues from './get-unique-developer-values';
import { DeveloperType } from './types';
export enum DeveloperType {
CONTRIBUTORS = 'contributors',
MAINTAINERS = 'maintainers',
}
export const Fab = styled(FloatingActionButton)<{ theme?: Theme }>((props) => ({
backgroundColor: props.theme?.palette.primary.main,

View File

@ -5,7 +5,10 @@ import { useTranslation } from 'react-i18next';
import Text from 'verdaccio-ui/components/Text';
import { Theme } from 'verdaccio-ui/design-tokens/theme';
import { DeveloperType } from './types';
export enum DeveloperType {
CONTRIBUTORS = 'contributors',
MAINTAINERS = 'maintainers',
}
interface Props {
type: DeveloperType;

View File

@ -1,2 +1 @@
export { default } from './Developers';
export { DeveloperType } from './types';

View File

@ -20,12 +20,12 @@ export const Content = styled('div')({
});
export const StyledText = styled(Text)<{ theme?: Theme }>((props) => ({
fontWeight: props.theme && props.theme.fontWeight.bold,
fontWeight: props.theme?.fontWeight.bold,
marginBottom: '10px',
textTransform: 'capitalize',
}));
export const Fab = styled(FloatingActionButton)<{ theme?: Theme }>((props) => ({
backgroundColor: props.theme && props.theme.palette.primary.main,
color: props.theme && props.theme.palette.white,
backgroundColor: props.theme?.palette.primary.main,
color: props.theme?.palette.white,
}));

View File

@ -1,4 +0,0 @@
export enum DeveloperType {
CONTRIBUTORS = 'contributors',
MAINTAINERS = 'maintainers',
}

View File

@ -5,7 +5,7 @@ import Text from 'verdaccio-ui/components/Text';
import { Theme } from 'verdaccio-ui/design-tokens/theme';
export const StyledText = styled(Text)<{ theme?: Theme }>((props) => ({
fontWeight: props.theme && props.theme.fontWeight.bold,
fontWeight: props.theme?.fontWeight.bold,
textTransform: 'capitalize',
}));

View File

@ -17,7 +17,7 @@ import { DetailContext } from '../../context';
import git from './img/git.png';
const StyledText = styled(Text)<{ theme?: Theme }>((props) => ({
fontWeight: props.theme && props.theme.fontWeight.bold,
fontWeight: props.theme?.fontWeight.bold,
textTransform: 'capitalize',
}));

View File

@ -1,6 +1,6 @@
import zlib from 'zlib';
import Stream from 'stream';
import URL, { UrlWithStringQuery } from 'url';
import URL from 'url';
import JSONStream from 'JSONStream';
import _ from 'lodash';
import request from 'request';
@ -480,7 +480,7 @@ class ProxyStorage implements IProxy {
* @param {String} url
* @return {Stream}
*/
fetchTarball(url: string) {
public fetchTarball(url: string) {
const stream = new ReadTarball({});
let current_length = 0;
let expected_length;

View File

@ -3,13 +3,7 @@ import nock from 'nock';
import * as httpMocks from 'node-mocks-http';
import { Config, parseConfigFile } from '@verdaccio/config';
import { ErrorCode } from '@verdaccio/utils';
import {
API_ERROR,
HEADERS,
HEADER_TYPE,
HTTP_STATUS,
VerdaccioError,
} from '@verdaccio/commons-api';
import { API_ERROR, HEADER_TYPE, HTTP_STATUS, VerdaccioError } from '@verdaccio/commons-api';
import { ProxyStorage } from '../src/up-storage';
const getConf = (name) => path.join(__dirname, '/conf', name);

View File

@ -1,6 +1,6 @@
const path = require('path');
const fse = require('fs-extra');
const { staticPath, manifest, manifestFiles } = require('@verdaccio/ui-theme')();
const { staticPath } = require('@verdaccio/ui-theme')();
fse.copySync(staticPath, path.join(__dirname, '../dist/static'));
// eslint-disable-next-line no-console
console.log('theme files copied');

View File

@ -538,7 +538,7 @@ class LocalStorage implements IStorage {
// @ts-ignore
} else if (err.code === STORAGE.NO_SUCH_FILE_ERROR || err.code === HTTP_STATUS.NOT_FOUND) {
// check if package exists to throw an appropriate message
this.getPackageMetadata(name, function (_err: VerdaccioError, _res: Package): void {
this.getPackageMetadata(name, function (_err: VerdaccioError): void {
if (_err) {
uploadStream.emit('error', _err);
} else {
@ -686,7 +686,7 @@ class LocalStorage implements IStorage {
* @param {*} options
* @return {Function}
*/
public search(startKey: string, options: any): IReadTarball {
public search(startKey: string): IReadTarball {
const stream = new ReadTarball({ objectMode: true });
debug('search by %o', startKey);
this._searchEachPackage(

View File

@ -227,8 +227,9 @@ export function mergeUplinkTimeIntoLocal(localMetadata: Package, remoteMetadata:
export function prepareSearchPackage(data: Package, time: unknown): any {
const listVersions: string[] = Object.keys(data.versions);
const versions: string[] = semverSort(listVersions);
const latest: string | undefined =
data[DIST_TAGS] && data[DIST_TAGS].latest ? data[DIST_TAGS].latest : versions.pop();
const latest: string | undefined = data[DIST_TAGS]?.latest
? data[DIST_TAGS].latest
: versions.pop();
if (latest && data.versions[latest]) {
const version: Version = data.versions[latest];

View File

@ -2,7 +2,7 @@ import assert from 'assert';
import Stream from 'stream';
import async, { AsyncResultArrayCallback } from 'async';
import _ from 'lodash';
import e, { Request } from 'express';
import { Request } from 'express';
import buildDebug from 'debug';
import { ProxyStorage } from '@verdaccio/proxy';

View File

@ -23,6 +23,8 @@ module.exports = {
camelcase: 'off',
'guard-for-in': 'error',
'new-cap': 'error',
// disabled in favor of @typescript-eslint/no-unused-vars
'no-unused-vars': 'off',
'max-len': ['error', 100],
'no-console': ['error', { allow: ['warn'] }],
'no-constant-condition': 'error',
@ -54,11 +56,10 @@ module.exports = {
'@typescript-eslint/ban-types': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
// rules to fix
'no-unused-vars': ['warn', { vars: 'all', args: 'none' }],
'prefer-promise-reject-errors': ['warn'],
'@typescript-eslint/prefer-optional-chain': ['warn'],
'@typescript-eslint/explicit-member-accessibility': ['warn'],
'@typescript-eslint/no-unused-vars': ['warn'],
'@typescript-eslint/no-unused-vars': ['error'],
},
};

View File

@ -37,11 +37,11 @@ export default function (server, server2) {
return matchReadme(server2, README_PKG1, README_MESSAGE);
});
test.skip('should fetch not found readme server2 over uplink server1', () => {
test('should fetch not found readme server2 over uplink server1', () => {
return matchReadme(server, README_PKG2, DEFAULT_NO_README);
});
test.skip('should fetch not found readme package on local server1', () => {
test('should fetch not found readme package on local server1', () => {
return matchReadme(server2, README_PKG2, DEFAULT_NO_README);
});
});

View File

@ -6,7 +6,7 @@ import _ from 'lodash';
import { CREDENTIALS } from './registry-launcher';
import smartRequest, { RequestPromise } from './request';
declare class PromiseAssert<RequestPromise> extends Promise<any> {
declare class PromiseAssert extends Promise<any> {
public constructor(options: any);
}