chore: Major linting fixes

This commit is contained in:
Justin 2019-08-22 11:52:28 -04:00
parent 9933620f41
commit 8e5dfc00cd
18 changed files with 127 additions and 100 deletions

37
package-lock.json generated
View File

@ -3525,6 +3525,22 @@
}
}
},
"eslint-plugin-prettier": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-2.7.0.tgz",
"integrity": "sha512-CStQYJgALoQBw3FsBzH0VOVDRnJ/ZimUlpLm226U8qgqYJfPOY/CPK6wyRInMxh73HSKg5wyRwdS4BVYYHwokA==",
"requires": {
"fast-diff": "^1.1.1",
"jest-docblock": "^21.0.0"
},
"dependencies": {
"jest-docblock": {
"version": "21.2.0",
"resolved": "https://registry.npmjs.org/jest-docblock/-/jest-docblock-21.2.0.tgz",
"integrity": "sha512-5IZ7sY9dBAYSV+YjQ0Ovb540Ku7AO9Z5o2Cg789xj167iQuZ2cG+z0f3Uct6WeYLbU6aQiM2pCs7sZ+4dotydw=="
}
}
},
"esprima": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
@ -3779,6 +3795,11 @@
"integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=",
"dev": true
},
"fast-diff": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz",
"integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w=="
},
"fast-glob": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.0.4.tgz",
@ -8380,8 +8401,7 @@
"lines-and-columns": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz",
"integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=",
"dev": true
"integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA="
},
"lint-staged": {
"version": "9.2.3",
@ -15207,8 +15227,7 @@
"tslib": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz",
"integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==",
"dev": true
"integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ=="
},
"tslint": {
"version": "5.19.0",
@ -15315,6 +15334,16 @@
}
}
},
"tslint-plugin-prettier": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/tslint-plugin-prettier/-/tslint-plugin-prettier-2.0.1.tgz",
"integrity": "sha512-4FX9JIx/1rKHIPJNfMb+ooX1gPk5Vg3vNi7+dyFYpLO+O57F4g+b/fo1+W/G0SUOkBLHB/YKScxjX/P+7ZT/Tw==",
"requires": {
"eslint-plugin-prettier": "^2.2.0",
"lines-and-columns": "^1.1.6",
"tslib": "^1.7.1"
}
},
"tsutils": {
"version": "2.29.0",
"resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz",

View File

@ -22,6 +22,7 @@
"ky-universal": "^0.3.0",
"li": "^1.3.0",
"query-string": "^6.8.2",
"tslint-plugin-prettier": "^2.0.1",
"universal-url": "^2.0.0"
},
"devDependencies": {
@ -80,9 +81,9 @@
"build": "tsc && rollup -c",
"commit": "npx git-cz",
"coverage": "codecov",
"lint": "tslint -p . -t stylish",
"lint:doc:fix": "prettier --write './*.json' './*.yml' './*.md'",
"lint:fix": "npm run lint -- --fix",
"lint": "tslint -p . -t stylish && prettier --check './**/*.ts'",
"lint:doc:fix": "prettier --write './*.json' './*.yml' './*.md' './*.js'",
"lint:fix": "prettier --write './**/*.ts' && npm run lint -- --fix",
"prepublishOnly": "npm run build",
"release": "semantic-release",
"test:integration": "jest test/integration -c=jest.config.json --detectOpenHandles",

View File

@ -2,7 +2,7 @@ import ts from 'rollup-plugin-typescript2';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import { terser } from "rollup-plugin-terser";
import { terser } from 'rollup-plugin-terser';
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';
import typescript from 'typescript';
@ -18,14 +18,14 @@ export default [
format: 'umd',
exports: 'named',
globals: {
'li': 'Li',
'humps': 'Humps',
li: 'Li',
humps: 'Humps',
'query-string': 'QueryString',
'randomstring': 'RandomString',
randomstring: 'RandomString',
'ky-universal': 'Ky',
'form-data': 'FormData',
'universal-url':'universal-url'
}
'universal-url': 'universal-url',
},
},
external: [...Object.keys(pkg.dependencies)],
plugins: [
@ -47,12 +47,7 @@ export default [
format: 'cjs',
},
external: [...Object.keys(pkg.dependencies)],
plugins: [
globals(),
builtins(),
ts({ typescript }),
terser(),
],
plugins: [globals(), builtins(), ts({ typescript }), terser()],
},
// ES module (for bundlers) build.
@ -63,9 +58,6 @@ export default [
format: 'es',
},
external: [...Object.keys(pkg.dependencies)],
plugins: [
ts({ typescript }),
terser(),
],
plugins: [ts({ typescript }), terser()],
},
];

View File

@ -69,7 +69,7 @@ methods.forEach(m => {
e.description = output.error || output.message;
}
throw e;
}

View File

@ -41,13 +41,13 @@ export async function get(
// Rescurse through pagination results
if (!query.page && underLimit && pagination.next) {
const { next } = Li.parse(headers.link);
const leaf = service.url.split('/').pop() || ""
const regex = new RegExp(`.+\/api\/v\\d(\/${leaf})?\/`)
const more = await get(service, next.replace(regex, ''), {
const leaf = service.url.split('/').pop() || '';
const regex = new RegExp(`.+\/api\/v\\d(\/${leaf})?\/`);
const more = (await get(service, next.replace(regex, ''), {
maxPages,
sudo,
showPagination: true
}) as PaginationResponse;
showPagination: true,
})) as PaginationResponse;
pagination = more.pagination;
body = [...body, ...more.data];
@ -56,11 +56,7 @@ export async function get(
return (query.page || body.length > 0) && showPagination ? { data: body, pagination } : body;
}
export function stream(
service: BaseService,
endpoint: string,
options: BaseRequestOptions = {},
) {
export function stream(service: BaseService, endpoint: string, options: BaseRequestOptions = {}) {
if (typeof service.requester.stream !== 'function') {
throw new Error('Stream method is not implementated in requester!');
}

View File

@ -88,7 +88,11 @@ class Commits extends BaseService {
mergeRequests(projectId: ProjectId, sha: string, options?: BaseRequestOptions) {
const pId = encodeURIComponent(projectId);
return RequestHelper.get(this, `projects/${pId}/repository/commits/${sha}/merge_requests`, options);
return RequestHelper.get(
this,
`projects/${pId}/repository/commits/${sha}/merge_requests`,
options,
);
}
}

View File

@ -44,7 +44,6 @@ class Groups extends BaseService {
cn,
{ provider, ...options }: Sudo & { provider?: string } = {},
) {
const gId = encodeURIComponent(groupId);
const url = provider ? `${provider}/${cn}` : `${cn}`;

View File

@ -17,7 +17,11 @@ class Labels extends BaseService {
create(projectId: ProjectId, labelName: string, color: string, options?: BaseRequestOptions) {
const pId = encodeURIComponent(projectId);
return RequestHelper.post(this, `projects/${pId}/labels`, { name: labelName, color, ...options });
return RequestHelper.post(this, `projects/${pId}/labels`, {
name: labelName,
color,
...options,
});
}
edit(projectId: ProjectId, labelName: string, options?: BaseRequestOptions) {

View File

@ -37,7 +37,10 @@ class Projects extends BaseService {
return RequestHelper.get(this, `projects/${pId}/events`, options);
}
fork(projectId: ProjectId, { forkedFromId, ...options }: { forkedFromId?: number } & BaseRequestOptions = {}) {
fork(
projectId: ProjectId,
{ forkedFromId, ...options }: { forkedFromId?: number } & BaseRequestOptions = {},
) {
const pId = encodeURIComponent(projectId);
let url = `projects/${pId}/fork`;
@ -133,7 +136,7 @@ class Projects extends BaseService {
return RequestHelper.put(this, `projects/${pId}/push_rule`, options);
}
upload(projectId, content, { metadata, sudo }: { metadata?: UploadMetadata } & Sudo = {}) {
upload(projectId, content, { metadata, sudo }: { metadata?: UploadMetadata } & Sudo = {}) {
const pId = encodeURIComponent(projectId);
const form = new FormData();

View File

@ -11,11 +11,7 @@ import { ResourceId, DiscussionId, NoteId } from '..';
class ResourceDiscussions extends BaseService {
protected resource2Type: string;
constructor(
resourceType: string,
resource2Type: string,
options: BaseServiceOptions,
) {
constructor(resourceType: string, resource2Type: string, options: BaseServiceOptions) {
super({ url: resourceType, ...options });
this.resource2Type = resource2Type;

View File

@ -11,11 +11,7 @@ import { ResourceId, NoteId } from '..';
class ResourceNotes extends BaseService {
protected resource2Type: string;
constructor(
resourceType: string,
resource2Type: string,
options: BaseServiceOptions,
) {
constructor(resourceType: string, resource2Type: string, options: BaseServiceOptions) {
super({ url: resourceType, ...options });
this.resource2Type = resource2Type;

View File

@ -11,7 +11,7 @@ beforeAll(async () => {
describe('ApplicationSettings.all', () => {
let settings;
beforeEach(async () => {
settings = await service.all();
});

View File

@ -53,7 +53,7 @@ describe('Issues.all', () => {
});
it('should return a list filtered to a specfic page', async () => {
const issues1 = await service.all({projectId: project.id, perPage: 1, page: 1 });
const issues1 = await service.all({ projectId: project.id, perPage: 1, page: 1 });
expect(issues1).toBeInstanceOf(Array);
expect(issues1).toHaveLength(1);

View File

@ -31,7 +31,7 @@ describe('Labels.remove', () => {
it('should remove/delete a valid label on a project', async () => {
const label = await service.create(project.id, 'Test Label3', '#FFAABB');
expect(service.remove(project.id, label.name)).resolves.toEqual("");
expect(service.remove(project.id, label.name)).resolves.toEqual('');
});
});
@ -55,14 +55,18 @@ describe('Labels.all', () => {
});
it('should return a list of labels on a project restricted to page 5', async () => {
const labels = await service.all(project.id, { perPage: 5, page: 5});
const labels = await service.all(project.id, { perPage: 5, page: 5 });
expect(labels).toBeInstanceOf(Array);
expect(labels).toHaveLength(5);
});
it('should return a list of labels on a project restricted to page 5 and show the pagination object', async () => {
const { data, pagination } = await service.all(project.id, { perPage: 5, page: 5, showPagination: true});
const { data, pagination } = await service.all(project.id, {
perPage: 5,
page: 5,
showPagination: true,
});
expect(data).toBeInstanceOf(Array);
expect(data).toHaveLength(5);
@ -75,4 +79,4 @@ describe('Labels.all', () => {
totalPages: 11,
});
});
});
});

View File

@ -3,36 +3,36 @@ import { Projects } from '../../../dist';
let service: Projects;
beforeEach(() => {
service = new Projects({
host: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
});
service = new Projects({
host: process.env.GITLAB_URL,
token: process.env.PERSONAL_ACCESS_TOKEN,
});
});
describe('Projects.create', () => {
it('should create a valid project', async () => {
const p = await service.create({ name: 'Project Creation Integration test' });
expect(p).toBeInstanceOf(Object);
expect(p.name).toEqual('Project Creation Integration test');
});
it('should create a valid project', async () => {
const p = await service.create({ name: 'Project Creation Integration test' });
expect(p).toBeInstanceOf(Object);
expect(p.name).toEqual('Project Creation Integration test');
});
});
describe('Projects.upload', () => {
let project: object;
let project: object;
beforeAll(async () => {
project = await service.create({ name: 'Project Upload Integration test' });
});
beforeAll(async () => {
project = await service.create({ name: 'Project Upload Integration test' });
});
it('should upload a text file', async () => {
const content = 'TESTING FILE UPLOAD :D';
const results = await service.upload(project.id, content, {
metadata: {
filename: 'testfile.txt',
contentType: 'text/plain',
},
});
it('should upload a text file', async () => {
const content = 'TESTING FILE UPLOAD :D';
const results = await service.upload(project.id, content, {
metadata: {
filename: 'testfile.txt',
contentType: 'text/plain',
},
});
expect(results).toContainKeys(['alt', 'url', 'markdown']);
});
expect(results).toContainKeys(['alt', 'url', 'markdown']);
});
});

View File

@ -39,41 +39,41 @@ describe('Creation of BaseService instance', () => {
});
test('Camelize option should return simple response with camelized keys', async () => {
const service = new BaseService({ host: 'https://testing.com', token: '1234', camelize: true});
const service = new BaseService({ host: 'https://testing.com', token: '1234', camelize: true });
service.show = jest.fn(() => RequestHelper.get(service, 'test'));
KyRequester.get = jest.fn(() => ({ body: { id: 3, gravatar_enable: true }, headers: {} }));
const results = await service.show();
expect(results).toMatchObject({ id: 3, gravatarEnable: true })
expect(results).toMatchObject({ id: 3, gravatarEnable: true });
});
test('Camelize option should return simple response with camelized keys', async () => {
const service = new BaseService({ host: 'https://testing.com', token: '1234', camelize: true});
const service = new BaseService({ host: 'https://testing.com', token: '1234', camelize: true });
service.show = jest.fn(() => RequestHelper.get(service, 'test'));
KyRequester.get = jest.fn(() => ({
body: [
{ id: 3, gravatar_enable: true },
{ id: 4, gravatar_enable: false },
],
headers: {}
body: [{ id: 3, gravatar_enable: true }, { id: 4, gravatar_enable: false }],
headers: {},
}));
const results = await service.show();
expect(results).toIncludeSameMembers([{ id: 3, gravatarEnable: true }, { id: 4, gravatarEnable: false }])
expect(results).toIncludeSameMembers([
{ id: 3, gravatarEnable: true },
{ id: 4, gravatarEnable: false },
]);
});
test('Camelize option unset should return simple response with default keys', async () => {
const service = new BaseService({ host: 'https://testing.com', token: '1234'});
const service = new BaseService({ host: 'https://testing.com', token: '1234' });
service.show = jest.fn(() => RequestHelper.get(service, 'test'));
KyRequester.get = jest.fn(() => ({ body: { id: 3, gravatar_enable: true }, headers: {} }));
const results = await service.show();
expect(results).toMatchObject({ id: 3, gravatar_enable: true })
expect(results).toMatchObject({ id: 3, gravatar_enable: true });
});
});

View File

@ -11,7 +11,7 @@ const mockedGetBasic = () => ({
},
});
const mockedGetExtended = (url, { query }, limit=30) => {
const mockedGetExtended = (url, { query }, limit = 30) => {
const pages: object[] = [];
const q = url.match(/page=([0-9]+)/);
let page = 1;
@ -21,20 +21,20 @@ const mockedGetExtended = (url, { query }, limit=30) => {
// Only load pages needed for the test
// TODO: modify this to only generate the required response, without the loop
for (let i = 1, a = 1, b = 2; i <= limit && i <= page; i++, a+=2, b+=2) {
for (let i = 1, a = 1, b = 2; i <= limit && i <= page; i++, a += 2, b += 2) {
let next = '';
let prev = '';
let nextPage;
let prevPage;
if ((i+1) <= limit ) {
next = `<https://www.test.com/api/v4/test?page=${i+1}&per_page=2>; rel="next",`;
nextPage = i+1
if (i + 1 <= limit) {
next = `<https://www.test.com/api/v4/test?page=${i + 1}&per_page=2>; rel="next",`;
nextPage = i + 1;
}
if ((i-1) >= 1) {
prev = `<https://www.test.com/api/v4/test?page=${i-1}&per_page=2>; rel="prev",`;
prevPage = i-1
if (i - 1 >= 1) {
prev = `<https://www.test.com/api/v4/test?page=${i - 1}&per_page=2>; rel="prev",`;
prevPage = i - 1;
}
pages.push({
@ -49,7 +49,10 @@ const mockedGetExtended = (url, { query }, limit=30) => {
},
],
headers: {
link: next + prev + `
link:
next +
prev +
`
<https://www.test.com/api/v4/test?page=1&per_page=2>; rel="first",
<https://www.test.com/api/v4/test?page=${limit}&per_page=2>; rel="last"`,
'x-next-page': nextPage,
@ -63,7 +66,7 @@ const mockedGetExtended = (url, { query }, limit=30) => {
}
return pages[page - 1];
}
};
const service = new BaseService({
host: 'https://testing.com',

View File

@ -1,5 +1,5 @@
{
"extends": ["tslint-config-airbnb", "tslint-config-prettier"],
"extends": ["tslint-config-airbnb", "tslint-plugin-prettier", "tslint-config-prettier"],
"rules": {
"variable-name": [true, "ban-keywords", "check-format", "allow-pascal-case"],
"object-shorthand-properties-first": false,