Skip to content

Commit

Permalink
fix: fixed lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
priscilawebdev committed Oct 7, 2019
1 parent 55b925d commit c80e915
Show file tree
Hide file tree
Showing 8 changed files with 1,068 additions and 87 deletions.
3 changes: 2 additions & 1 deletion core/commons-api/test/errors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

import {
getNotFound,
VerdaccioError,
Expand All @@ -11,7 +13,6 @@ import {
getServiceUnavailable,
getCode,
} from '../src/index';
import _ from 'lodash';

describe('testing errors', () => {
test('should qualify as an native error', () => {
Expand Down
105 changes: 59 additions & 46 deletions core/file-locking/src/__tests__/lock.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';
import fs from 'fs';
import { lockFile, unlockFile, readFile } from '../index';
import path from "path";
import fs from "fs";

import { lockFile, unlockFile, readFile } from "../index";

interface Error {
message: string;
Expand All @@ -17,97 +18,109 @@ const removeTempFile = (filename: string): void => {
});
};

describe('testing locking', () => {
test('file should be found to be locked', done => {
lockFile(getFilePath('package.json'), (error: Error) => {
describe("testing locking", () => {
test("file should be found to be locked", done => {
lockFile(getFilePath("package.json"), (error: Error) => {
expect(error).toBeNull();
removeTempFile('package.json.lock');
removeTempFile("package.json.lock");
done();
});
});

test('file should fail to be found to be locked', done => {
lockFile(getFilePath('package.fail.json'), (error: Error) => {
expect(error.message).toMatch(/ENOENT: no such file or directory, stat '(.*)package.fail.json'/);
test("file should fail to be found to be locked", done => {
lockFile(getFilePath("package.fail.json"), (error: Error) => {
expect(error.message).toMatch(
/ENOENT: no such file or directory, stat '(.*)package.fail.json'/
);
done();
});
});

test('file should to be found to be unLock', done => {
unlockFile(getFilePath('package.json.lock'), (error: Error) => {
test("file should to be found to be unLock", done => {
unlockFile(getFilePath("package.json.lock"), (error: Error) => {
expect(error).toBeNull();
done();
});
});

test('read file with no options should to be found to be read it as string', done => {
readFile(getFilePath('package.json'), (error: Error, data: any) => {
test("read file with no options should to be found to be read it as string", done => {
readFile(getFilePath("package.json"), (error: Error, data: any) => {
expect(error).toBeNull();
expect(data).toMatchSnapshot();
done();
});
});

test('read file with no options should to be found to be read it as object', done => {
test("read file with no options should to be found to be read it as object", done => {
const options = {
parse: true,
parse: true
};
readFile(getFilePath('package.json'), options, (error: Error, data: any) => {
expect(error).toBeNull();
expect(data).toMatchSnapshot();
done();
});
readFile(
getFilePath("package.json"),
options,
(error: Error, data: any) => {
expect(error).toBeNull();
expect(data).toMatchSnapshot();
done();
}
);
});

test('read file with options (parse) should to be not found to be read it', done => {
test("read file with options (parse) should to be not found to be read it", done => {
const options = {
parse: true,
parse: true
};
readFile(getFilePath('package.fail.json'), options, (error: Error) => {
expect(error.message).toMatch(/ENOENT: no such file or directory, open '(.*)package.fail.json'/);
readFile(getFilePath("package.fail.json"), options, (error: Error) => {
expect(error.message).toMatch(
/ENOENT: no such file or directory, open '(.*)package.fail.json'/
);
done();
});
});

test('read file with options should to be found to be read it and fails to be parsed', done => {
test("read file with options should to be found to be read it and fails to be parsed", done => {
const options = {
parse: true,
parse: true
};
const errorMessage =
process.platform === 'win32'
? 'Unexpected token } in JSON at position 47'
: 'Unexpected token } in JSON at position 44';
readFile(getFilePath('wrong.package.json'), options, (error: Error) => {
process.platform === "win32"
? "Unexpected token } in JSON at position 47"
: "Unexpected token } in JSON at position 44";
readFile(getFilePath("wrong.package.json"), options, (error: Error) => {
expect(error.message).toEqual(errorMessage);
done();
});
});

test('read file with options (parse, lock) should to be found to be read it as object', done => {
test("read file with options (parse, lock) should to be found to be read it as object", done => {
const options = {
parse: true,
lock: true,
lock: true
};
readFile(getFilePath('package2.json'), options, (error: Error, data: any) => {
expect(error).toBeNull();
expect(data).toMatchSnapshot();
removeTempFile('package2.json.lock');
done();
});
readFile(
getFilePath("package2.json"),
options,
(error: Error, data: any) => {
expect(error).toBeNull();
expect(data).toMatchSnapshot();
removeTempFile("package2.json.lock");
done();
}
);
});

test('read file with options (parse, lock) should to be found to be read it and fails to be parsed', done => {
test("read file with options (parse, lock) should to be found to be read it and fails to be parsed", done => {
const options = {
parse: true,
lock: true,
lock: true
};
const errorMessage =
process.platform === 'win32'
? 'Unexpected token } in JSON at position 47'
: 'Unexpected token } in JSON at position 44';
readFile(getFilePath('wrong.package.json'), options, (error: Error) => {
process.platform === "win32"
? "Unexpected token } in JSON at position 47"
: "Unexpected token } in JSON at position 44";
readFile(getFilePath("wrong.package.json"), options, (error: Error) => {
expect(error.message).toEqual(errorMessage);
removeTempFile('wrong.package.json.lock');
removeTempFile("wrong.package.json.lock");
done();
});
});
Expand Down
21 changes: 13 additions & 8 deletions core/file-locking/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import locker from 'lockfile';
import fs from 'fs';
import path from 'path';
import { Callback } from '@verdaccio/types';
import locker from "lockfile";
import fs from "fs";
import path from "path";

import { Callback } from "@verdaccio/types";

// locks a file by creating a lock file
const lockFile = function(name: string, callback: Callback): void {
Expand Down Expand Up @@ -48,7 +49,7 @@ const lockFile = function(name: string, callback: Callback): void {
// number of times to attempt to create a lock
retries: 100,
// time (ms) between tries
retryWait: 100,
retryWait: 100
};
const lockFileName = `${name}.lock`;
locker.lock(lockFileName, lockOpts, () => {
Expand Down Expand Up @@ -92,8 +93,12 @@ const unlockFile = function(name: string, next: Callback): void {
* @param {*} options
* @param {*} callback
*/
function readFile(name: string, options: any = {}, callback: any = (): void => {}): void {
if (typeof options === 'function') {
function readFile(
name: string,
options: any = {},
callback: any = (): void => {}
): void {
if (typeof options === "function") {
callback = options;
options = {};
}
Expand All @@ -118,7 +123,7 @@ function readFile(name: string, options: any = {}, callback: any = (): void => {

const read = function(): Promise<any> {
return new Promise<any>((resolve, reject): void => {
fs.readFile(name, 'utf8', function(err, contents) {
fs.readFile(name, "utf8", function(err, contents) {
if (err) {
return reject(err);
}
Expand Down
3 changes: 2 additions & 1 deletion core/readme/tests/readme.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import parseReadme from '../src';
import fs from 'fs';
import path from 'path';

import parseReadme from '../src';

function readReadme(project: string, fileName = 'readme.md'): Promise<string> {
return new Promise((resolve, reject): void => {
fs.readFile(path.join(__dirname, 'partials', project, fileName), 'utf8', (err, data) => {
Expand Down
2 changes: 1 addition & 1 deletion plugins/audit/src/audit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import request from 'request';
import express, { Request, Response } from 'express';

import { Logger, IPluginMiddleware, IBasicAuth, PluginOptions } from '@verdaccio/types';

import { ConfigAudit } from './types';

export default class ProxyAudit implements IPluginMiddleware<ConfigAudit> {
Expand Down
4 changes: 2 additions & 2 deletions plugins/audit/tests/audit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ProxyAudit, { ConfigAudit } from '../src/index';

import { Logger } from '@verdaccio/types';

import ProxyAudit, { ConfigAudit } from '../src/index';

const config: ConfigAudit = {
enabled: true,
} as ConfigAudit;
Expand Down
2 changes: 1 addition & 1 deletion tools/eslint-config/rules/import.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
extends: ['plugin:import/typescript'],
extends: ['plugin:import/errors', 'plugin:import/warnings', 'plugin:import/typescript'],
rules: {
'import/order': ['error', { 'newlines-between': 'always' }],
},
Expand Down
Loading

0 comments on commit c80e915

Please sign in to comment.