0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

fix: cleanup warnings (#1986)

* fix: lint warnings

* fix: test
This commit is contained in:
Juan Picado 2020-10-27 10:18:59 +01:00
parent 3a93da454f
commit e83e500b80
19 changed files with 80 additions and 72 deletions

View file

@ -43,22 +43,21 @@
"jest/no-test-callback": 0,
"jest/expect-expect": 0,
"jest/no-try-expect": 0,
"jest/no-identical-title": 1,
"keyword-spacing": "off",
"no-tabs": "off",
"no-useless-escape": "off",
"padded-blocks": "off",
"require-jsdoc": "off",
"valid-jsdoc": "off",
"import/order": ["warn"],
"eol-last": "warn",
"no-irregular-whitespace": "warn",
"no-mixed-spaces-and-tabs": ["warn", "smart-tabs"],
"no-trailing-spaces": "warn",
"import/order": ["error"],
"eol-last": "error",
"no-irregular-whitespace": "error",
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
"no-trailing-spaces": "error",
"camelcase": "off",
"guard-for-in": "error",
"new-cap": "error",
"max-len": ["warn", 100],
"max-len": ["error", 100],
"no-console": ["error", { "allow": ["warn"] }],
"no-constant-condition": "error",
"no-debugger": "error",
@ -68,14 +67,12 @@
"no-new-require": "error",
"no-undef": "error",
"no-unreachable": "error",
"no-unused-vars": ["warn", { "vars": "all", "args": "none" }],
"no-var": "error",
"one-var": "error",
"prefer-rest-params": "warn",
"prefer-spread": "warn",
"prefer-rest-params": "error",
"prefer-spread": "error",
"handle-callback-err": 0,
"prefer-const": 0,
"prefer-promise-reject-errors": 1,
"@typescript-eslint/camelcase": 0,
"@typescript-eslint/ban-ts-ignore": 0,
"@typescript-eslint/no-var-requires": 0,
@ -83,13 +80,21 @@
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-this-alias": 0,
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/array-type": ["warn"],
"@typescript-eslint/array-type": ["error"],
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/indent": 0,
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/ban-types": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
// rules to fix
"no-unused-vars": ["warn", { "vars": "all", "args": "none" }],
"jest/no-identical-title": ["warn"],
"prefer-promise-reject-errors": ["warn"],
"jest/no-disabled-tests": ["warn"],
"jest/no-commented-out-tests": ["warn"],
"@typescript-eslint/prefer-optional-chain": ["warn"],
"@typescript-eslint/explicit-member-accessibility": ["warn"],
"@typescript-eslint/prefer-optional-chain": ["warn"]
"@typescript-eslint/no-unused-vars": ["warn"]
}
}

View file

@ -216,7 +216,6 @@ export function publishPackage(storage: IStorageHandler, config: Config, auth: I
/**
* npm-registry-client 0.3+ embeds tarball into the json upload
* https://github.com/isaacs/npm-registry-client/commit/e9fbeb8b67f249394f735c74ef11fe4720d46ca0
* issue https://github.com/rlidwka/sinopia/issues/31, dealing with it here:
*/

View file

@ -171,16 +171,6 @@ describe('formatter', () => {
expect(printMessage(log, prettyfierOptions)).toMatchSnapshot();
});
// test('should handle undefined object', () => {
// const log = {
// level: 15,
// something: 'foo',
// msg: 'custom - @{something} - @{missingParam}'
// };
//
// expect(printMessage(undefined, undefined, undefined)).toMatchSnapshot();
// });
test('should display a resource request', () => {
const log = {
level: 30,

View file

@ -63,6 +63,7 @@ class ActiveDirectoryPlugin implements IPluginAuth<ActiveDirectoryConfig> {
);
if (matchingGroups.length <= 0) {
// eslint-disable-next-line max-len
const notMemberMessage = `AD - User ${user} is not member of group(s): ${requestedGroups.join(
', '
)}`;

View file

@ -8,7 +8,7 @@ import {
} from '@verdaccio/types';
import { getConflict, getForbidden, getNotFound, getUnauthorized } from '@verdaccio/commons-api';
import { VerdaccioMemoryConfig, Users, UserMemory } from './types/index';
import { VerdaccioMemoryConfig, Users, UserMemory } from './types';
export default class Memory implements IPluginAuth<VerdaccioMemoryConfig> {
public _logger: Logger;
@ -91,10 +91,7 @@ export default class Memory implements IPluginAuth<VerdaccioMemoryConfig> {
}
public allow_access(user: RemoteUser, pkg: PackageAccess, cb: Callback): void {
if (
(pkg.access && pkg.access.includes('$all')) ||
(pkg.access && pkg.access.includes('$anonymous'))
) {
if (pkg?.access?.includes('$all') || pkg?.access?.includes('$anonymous')) {
this._logger.debug(
{ user: user.name },
'[VerdaccioMemory] user: @{user} has been granted access'
@ -109,10 +106,7 @@ export default class Memory implements IPluginAuth<VerdaccioMemoryConfig> {
return cb(err);
}
if (
(pkg.access && pkg.access.includes(user.name)) ||
(pkg.access && pkg.access.includes('$authenticated'))
) {
if (pkg?.access?.includes(user.name) || pkg?.access?.includes('$authenticated')) {
this._logger.debug(
{ user: user.name },
'[VerdaccioMemory] user: @{user} has been granted access'
@ -130,10 +124,7 @@ export default class Memory implements IPluginAuth<VerdaccioMemoryConfig> {
}
public allow_publish(user: RemoteUser, pkg: PackageAccess, cb: Callback): void {
if (
(pkg.publish && pkg.publish.includes('$all')) ||
(pkg.publish && pkg.publish.includes('$anonymous'))
) {
if (pkg?.publish?.includes('$all') || pkg?.publish?.includes('$anonymous')) {
this._logger.debug(
{ user: user.name },
'[VerdaccioMemory] user: @{user} has been granted to publish'
@ -148,10 +139,7 @@ export default class Memory implements IPluginAuth<VerdaccioMemoryConfig> {
return cb(err);
}
if (
(pkg.publish && pkg.publish.includes(user.name)) ||
(pkg.publish && pkg.publish.includes('$authenticated'))
) {
if (pkg?.publish?.includes(user.name) || pkg?.publish?.includes('$authenticated')) {
return cb(null, true);
}

View file

@ -61,7 +61,7 @@ describe('Memory', function () {
describe('replace user', function () {
beforeAll(function (done) {
auth.adduser('test', 'secret', function (_err) {
auth.adduser('test', 'secret', function () {
done();
});
});
@ -80,7 +80,7 @@ describe('Memory', function () {
describe('#allow_access', function () {
beforeEach(function (done) {
auth.adduser('test', 'secret', function (_err, _user) {
auth.adduser('test', 'secret', function () {
done();
});
});
@ -136,7 +136,7 @@ describe('Memory', function () {
describe('#allow_publish', function () {
beforeEach(function (done) {
auth.adduser('test', 'secret', function (_err, _user) {
auth.adduser('test', 'secret', function () {
done();
});
});
@ -198,7 +198,7 @@ describe('Memory', function () {
config: {} as VerdaccioMemoryConfig,
logger,
});
auth.adduser('test', 'secret', function (_err, _user) {
auth.adduser('test', 'secret', function () {
done();
});
});
@ -222,7 +222,7 @@ describe('Memory', function () {
describe('#authenticate', function () {
beforeEach(function (done) {
auth.adduser('test', 'secret', function (_err, _user) {
auth.adduser('test', 'secret', function () {
done();
});
});

View file

@ -283,7 +283,8 @@ export default class S3PackageManager implements ILocalPackageManager {
Key: `${this.packagePath}/${name}`,
};
// NOTE: I'm using listObjectVersions so I don't have to download the full object with getObject.
// NOTE: I'm using listObjectVersions so I don't have to download the
// full object with getObject.
// Preferably, I'd use getObjectMetadata or getDetails when it's available in the node sdk
// TODO: convert to headObject
this.s3.headObject(
@ -321,7 +322,8 @@ export default class S3PackageManager implements ILocalPackageManager {
const error: HttpError = convertS3Error(err);
this.logger.error(
{ error: error.message },
's3: [S3PackageManager writeTarball managedUpload send] emit error @{error}'
`s3: [S3PackageManager writeTarball managedUpload send]
emit error @{error}`
);
uploadStream.emit('error', error);
@ -369,7 +371,8 @@ export default class S3PackageManager implements ILocalPackageManager {
} else {
this.logger.trace(
{ name },
's3: [S3PackageManager writeTarball uploadStream] streamEnded false emit end @{name}'
`s3: [S3PackageManager writeTarball uploadStream] streamEnded
false emit end @{name}`
);
uploadStream.on('end', onEnd);
}
@ -391,7 +394,8 @@ export default class S3PackageManager implements ILocalPackageManager {
} finally {
this.logger.debug(
{ name, baseS3Params },
's3: [S3PackageManager writeTarball uploadStream abort] s3.deleteObject @{name}/@baseS3Params'
`s3: [S3PackageManager writeTarball uploadStream abort]
s3.deleteObject @{name}/@baseS3Params`
);
this.s3.deleteObject(baseS3Params);

View file

@ -36,7 +36,8 @@ const json: Package = {
},
dist: {
integrity:
'sha512-6gHiERpiDgtb3hjqpQH5/i7zRmvYi9pmCjQf2ZMy3QEa9wVk9RgdZaPWUt7ZOnWUPFjcr9cmE6dUBf+XoPoH4g==',
'sha512-6gHiERpiDgtb3hjqpQH5/i7zRmvYi9pmCjQ' +
'f2ZMy3QEa9wVk9RgdZaPWUt7ZOnWUPFjcr9cmE6dUBf+XoPoH4g==',
shasum: '2c03764f651a9f016ca0b7620421457b619151b9',
tarball: 'http://localhost:5555/@scope/pk1-test/-/@scope/pk1-test-1.0.6.tgz',
},
@ -47,7 +48,21 @@ const json: Package = {
'@scope/pk1-test-1.0.6.tgz': {
content_type: 'application/octet-stream',
data:
'H4sIAAAAAAAAE+2W32vbMBDH85y/QnjQp9qxLEeBMsbGlocNBmN7bFdQ5WuqxJaEpGQdo//79KPeQsnIw5KUDX/9IOvurLuz/DHSjK/YAiY6jcXSKjk6sMqypHWNdtmD6hlBI0wqQmo8nVbVqMR4OsNoVB66kF1aW8eML+Vv10m9oF/jP6IfY4QyyTrILlD2eqkcm+gVzpdrJrPz4NuAsULJ4MZFWdBkbcByI7R79CRjx0ScCdnAvf+SkjUFWu8IubzBgXUhDPidQlfZ3BhlLpBUKDiQ1cDFrYDmKkNnZwjuhUM4808+xNVW8P2bMk1Y7vJrtLC1u1MmLPjBF40+Cc4ahV6GDmI/DWygVRpMwVX3KtXUCg7Sxp7ff3nbt6TBFy65gK1iffsN41yoEHtdFbOiisWMH8bPvXUH0SP3k+KG3UBr+DFy7OGfEJr4x5iWVeS/pLQe+D+FIv/agIWI6GX66kFuIhT+1gDjrp/4d7WAvAwEJPh0u14IufWkM0zaW2W6nLfM2lybgJ4LTJ0/jWiAK8OcMjt8MW3OlfQppcuhhQ6k+2OgkK2Q8DssFPi/IHpU9fz3/+xj5NjDf8QFE39VmE4JDfzPCBn4P4X6/f88f/Pu47zomiPk2Lv/dOv8h+P/34/D/p9CL+Kp67mrGDRo0KBBp9ZPsETQegASAAA=',
'H4sIAAAAAAAAE+2W32vbMBDH85y/QnjQp9qxLEeBMsbGlo' +
'cNBmN7bFdQ5WuqxJaEpGQdo//79KPeQsnIw5KUDX/9IOvur' +
'Luz/DHSjK/YAiY6jcXSKjk6sMqypHWNdtmD6hlBI0wqQmo8n' +
'VbVqMR4OsNoVB66kF1aW8eML+Vv10m9oF/jP6IfY4QyyTrI' +
'LlD2eqkcm+gVzpdrJrPz4NuAsULJ4MZFWdBkbcByI7R79CR' +
'jx0ScCdnAvf+SkjUFWu8IubzBgXUhDPidQlfZ3BhlLpBUK' +
'DiQ1cDFrYDmKkNnZwjuhUM4808+xNVW8P2bMk1Y7vJrtLC' +
'1u1MmLPjBF40+Cc4ahV6GDmI/DWygVRpMwVX3KtXUCg7S' +
'xp7ff3nbt6TBFy65gK1iffsN41yoEHtdFbOiisWMH8bPvX' +
'UH0SP3k+KG3UBr+DFy7OGfEJr4x5iWVeS/pLQe+D+FIv/a' +
'gIWI6GX66kFuIhT+1gDjrp/4d7WAvAwEJPh0u14IufWkM0' +
'zaW2W6nLfM2lybgJ4LTJ0/jWiAK8OcMjt8MW3OlfQppcuhh' +
'Q6k+2OgkK2Q8DssFPi/IHpU9fz3/+xj5NjDf8QFE39VmE4' +
'JDfzPCBn4P4X6/f88f/Pu47zomiPk2Lv/dOv8h+P/34/D/' +
'p9CL+Kp67mrGDRo0KBBp9ZPsETQegASAAA=',
length: 512,
},
},

View file

@ -43,7 +43,8 @@ describe.skip('Local Database', () => {
reject(err);
return;
}
expect(data.IsTruncated).toBe(false); // none of the tests we do should create this much data
// none of the tests we do should create this much data
expect(data.IsTruncated).toBe(false);
// remove the stuff that changes from the results
expect(
data.Contents.map(({ Key, Size }) => ({

View file

@ -38,7 +38,8 @@ describe.skip('S3 package manager', () => {
reject(err);
return;
}
expect(data.IsTruncated).toBe(false); // none of the tests we do should create this much data
// none of the tests we do should create this much data
expect(data.IsTruncated).toBe(false);
// remove the stuff that changes from the results
expect(
data.Contents.map(({ Key, Size }) => ({

View file

@ -109,7 +109,7 @@ describe('S3PackageManager with mocked s3', function () {
});
});
test('new package is uploaded to custom storage prefix as specified on package section in config', (done) => {
test('new package is uploaded to custom storage prefix', (done) => {
expect.assertions(2);
const config: S3Config = {
bucket: 'test-bucket',
@ -340,7 +340,7 @@ describe('S3PackageManager with mocked s3', function () {
getMatchedPackagesSpec: jest.fn(() => null) as PackageAccess,
} as S3Config;
mockGetObject.mockImplementation((params) => {
mockGetObject.mockImplementation(() => {
return {
on: jest.fn(() => ({
createReadStream: jest.fn(() => ({
@ -371,7 +371,7 @@ describe('S3PackageManager with mocked s3', function () {
})) as PackageAccess,
} as S3Config;
mockGetObject.mockImplementation((params) => {
mockGetObject.mockImplementation(() => {
return {
on: jest.fn(() => ({
createReadStream: jest.fn(() => ({

View file

@ -63,7 +63,8 @@ class GoogleCloudDatabase implements IPluginStorage<VerdaccioConfigGoogleStorage
if (keyFileName) {
GOOGLE_OPTIONS.keyFilename = keyFileName;
this.logger.warn(
'Using credentials in a file might be un-secure and is only recommended for local development'
`Using credentials in a file might be un-secure
and is only recommended for local development`
);
}
@ -179,7 +180,8 @@ class GoogleCloudDatabase implements IPluginStorage<VerdaccioConfigGoogleStorage
// const deletedItems: any = [];
// const sanityCheck = (deletedItems: any): null | Error => {
// if (typeof deletedItems === 'undefined' || deletedItems.length === 0 || deletedItems[0][0].indexUpdates === 0) {
// if (typeof deletedItems === 'undefined' || deletedItems.length === 0
// || deletedItems[0][0].indexUpdates === 0) {
// return getNotFound('trying to remove a package that does not exist');
// } else if (deletedItems[0][0].indexUpdates > 0) {
// return null;

View file

@ -48,7 +48,8 @@ export default class StorageHelper implements IStorageHelper {
return result;
}
// public async updateEntity(key: string, excludeFromIndexes: any, data: any): Promise<CommitResult> {
// public async updateEntity(key: string, excludeFromIndexes: any, data: any):
// Promise<CommitResult> {
// const entity = {
// key,
// excludeFromIndexes,
@ -83,7 +84,8 @@ export default class StorageHelper implements IStorageHelper {
* An entity has one or more named properties, each of which can have one or more values.
* Entities of the same kind do not need to have the same properties,
* and an entity's values for a given property do not all need to be of the same data type.
* (If necessary, an application can establish and enforce such restrictions in its own data model.)
* (If necessary, an application can establish and enforce such
* restrictions in its own data model.)
* https://cloud.google.com/datastore/docs/concepts/entities
* @param key
*/

View file

@ -204,9 +204,12 @@ class GoogleCloudStorageHandler implements IPackageStorageManager {
await file.save(this._convertToString(metadata), {
validation: this.config.validation || defaultValidation,
/**
* When resumable is `undefined` - it will default to `true`as per GC Storage documentation:
* `Resumable uploads are automatically enabled and must be shut off explicitly by setting options.resumable to false`
* @see https://cloud.google.com/nodejs/docs/reference/storage/2.5.x/File#createWriteStream
* When resumable is `undefined` - it will default to `true`as
* per GC Storage documentation:
* `Resumable uploads are automatically enabled and must be shut
* off explicitly by setting options.resumable to false`
* @see
* https://cloud.google.com/nodejs/docs/reference/storage/2.5.x/File#createWriteStream
*/
resumable: this.config.resumable,
});

View file

@ -86,9 +86,7 @@ class MemoryHandler implements IPackageStorageManager {
public savePackage(name: string, value: Package, cb: CallbackAction): void {
try {
const json: string = stringifyPackage(value);
this.data[name] = json;
this.data[name] = stringifyPackage(value);
return cb(null);
} catch (err) {
return cb(getInternalError(err.message));
@ -160,7 +158,7 @@ class MemoryHandler implements IPackageStorageManager {
try {
const readStream = fs.createReadStream(pathName);
const contentLength: number = (fs.data[name] && fs.data[name].length) || 0;
const contentLength: number = fs?.data[name]?.length || 0;
readTarballStream.emit('content-length', contentLength);
readTarballStream.emit('open');
readStream.pipe(readTarballStream);

View file

@ -90,7 +90,6 @@ class ProxyStorage implements IProxy {
public upname: string;
// FIXME: proxy can be boolean or object, something smells here
// @ts-ignore
// any due this https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#operands-for-delete-must-be-optional
public proxy: any;
// @ts-ignore
public last_request_time: number | null;

View file

@ -38,6 +38,7 @@ const generateTokenCLI = async (app, token, payload): Promise<any> => {
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
.end(function (err, resp) {
if (err) {
// eslint-disable-next-line prefer-promise-reject-errors
return reject([err, resp]);
}
resolve([err, resp]);
@ -54,6 +55,7 @@ const deleteTokenCLI = async (app, token, tokenToDelete): Promise<any> => {
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
.end(function (err, resp) {
if (err) {
// eslint-disable-next-line prefer-promise-reject-errors
return reject([err, resp]);
}
resolve([err, resp]);

View file

@ -90,7 +90,6 @@ export function getLatestReadme(pkg: Package): string {
// FIXME: type any due this
export function cleanUpReadme(version: any): Version {
if (isNil(version) === false) {
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#operands-for-delete-must-be-optional
delete version.readme;
}

View file

@ -1,7 +1,6 @@
/* eslint-disable prefer-promise-reject-errors */
import { fork } from 'child_process';
export function prepareEnvironment(rootFolder: string, folderName: string) {}
export function spawnRegistry(verdaccioPath: string, args: string[], childOptions) {
return new Promise((resolve, reject) => {
let _childOptions = { silent: true, ...childOptions };