Skip to content

Commit 37c8035

Browse files
authored
Installed AirBnB linter and ran --fix for trivial issues (#48)
* Installed AirBnB linter and ran --fix for trivial issues Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Changed package-lock, added script to auto lint Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Added prettier config Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Added linter, changed github workflow, and linted Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Updated script to remove unnecessary npx, updated fix script to run prettier write. Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Fixed commments Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Changed contributing.md Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com>
1 parent a86e3de commit 37c8035

File tree

20 files changed

+4616
-710
lines changed

20 files changed

+4616
-710
lines changed

.eslintrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"extends": ["airbnb-base", "airbnb-typescript/base", "prettier"],
3+
"parserOptions": {
4+
"project": "./tsconfig.json"
5+
},
6+
"overrides": [
7+
{
8+
"files": ["*.js", "*.ts"],
9+
"rules": {
10+
"class-methods-use-this": "off",
11+
"no-underscore-dangle": "off",
12+
"consistent-return": "off",
13+
"no-param-reassign": "off",
14+
"no-bitwise": "off",
15+
"@typescript-eslint/no-throw-literal": "off"
16+
}
17+
}
18+
]
19+
}

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ jobs:
2727
- name: Check code style
2828
run: |
2929
npm ci
30-
npm run prettier:check
30+
npm run prettier
31+
npm run lint
3132
3233
test:
3334
runs-on: ubuntu-latest

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ node_modules
55
.nyc_output
66
coverage_e2e
77
coverage_unit
8-
8+
*.code-workspace
99
dist
10+
*.DS_Store

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,18 @@ npm run e2e
100100
Code style:
101101

102102
```bash
103-
npm run prettier:check
103+
npm run prettier
104104
npm run prettier:fix
105+
npm run lint
106+
npm run lint:fix
105107
```
106108

107109
## Pull Request Process
108110

109111
1. Update the [CHANGELOG](CHANGELOG.md) with details of your changes, if applicable.
110112
2. Add any appropriate tests.
111113
3. Make your code or other changes.
112-
4. Follow code style: `npm run prettier:fix`
114+
4. Follow code style: `npm run prettier:fix; npm run lint:fix`
113115
5. Review guidelines such as
114116
[How to write the perfect pull request][github-perfect-pr], thanks!
115117

lib/DBSQLClient.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import thrift from 'thrift';
22

3+
import { EventEmitter } from 'events';
34
import TCLIService from '../thrift/TCLIService';
45
import TCLIService_types, { TOpenSessionReq } from '../thrift/TCLIService_types';
56
import IDBSQLClient, { IDBSQLConnectionOptions } from './contracts/IDBSQLClient';
@@ -12,18 +13,22 @@ import IAuthentication from './connection/contracts/IAuthentication';
1213
import NoSaslAuthentication from './connection/auth/NoSaslAuthentication';
1314
import HttpConnection from './connection/connections/HttpConnection';
1415
import IConnectionOptions from './connection/contracts/IConnectionOptions';
15-
import { EventEmitter } from 'events';
1616
import StatusFactory from './factory/StatusFactory';
1717
import HiveDriverError from './errors/HiveDriverError';
1818
import { buildUserAgentString, definedOrError } from './utils';
1919
import PlainHttpAuthentication from './connection/auth/PlainHttpAuthentication';
2020

2121
export default class DBSQLClient extends EventEmitter implements IDBSQLClient {
2222
private client: TCLIService.Client | null;
23+
2324
private connection: IThriftConnection | null;
25+
2426
private statusFactory: StatusFactory;
27+
2528
private connectionProvider: IConnectionProvider;
29+
2630
private authProvider: IAuthentication;
31+
2732
private thrift = thrift;
2833

2934
constructor() {

lib/DBSQLOperation/getResult.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import JsonResult from '../result/JsonResult';
66
function getHandler(schema: TTableSchema | null, data: Array<TRowSet>): IOperationResult {
77
if (schema === null) {
88
return new NullResult();
9-
} else {
10-
return new JsonResult(schema, data);
119
}
10+
return new JsonResult(schema, data);
1211
}
1312

1413
export default function getResult(schema: TTableSchema | null, data: Array<TRowSet>) {

lib/DBSQLOperation/index.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,21 @@ import getResult from './getResult';
2020

2121
export default class DBSQLOperation implements IOperation {
2222
private driver: HiveDriver;
23+
2324
private operationHandle: TOperationHandle;
25+
2426
private schema: TTableSchema | null = null;
27+
2528
private data: Array<TRowSet> = [];
29+
2630
private statusFactory = new StatusFactory();
2731

2832
private fetchType: number = 0;
2933

3034
private _hasMoreRows: boolean = false;
35+
3136
private state: number = TOperationState.INITIALIZED_STATE;
37+
3238
private hasResultSet: boolean = false;
3339

3440
constructor(driver: HiveDriver, operationHandle: TOperationHandle) {
@@ -65,15 +71,14 @@ export default class DBSQLOperation implements IOperation {
6571
return this.firstFetch(chunkSize);
6672
})
6773
.then((response) => this.processFetchResponse(response));
68-
} else {
69-
return this.nextFetch(chunkSize).then((response) => this.processFetchResponse(response));
7074
}
75+
return this.nextFetch(chunkSize).then((response) => this.processFetchResponse(response));
7176
}
7277

7378
async fetchAll(options?: IFetchOptions): Promise<Array<object>> {
74-
let data: Array<object> = [];
79+
const data: Array<object> = [];
7580
do {
76-
let chunk = await this.fetchChunk(options);
81+
const chunk = await this.fetchChunk(options); // eslint-disable-line no-await-in-loop
7782
if (chunk) {
7883
data.push(...chunk);
7984
}
@@ -88,8 +93,8 @@ export default class DBSQLOperation implements IOperation {
8893

8994
await waitUntilReady(this, options.progress, options.callback);
9095

91-
return await this.fetch(options.maxRows).then(() => {
92-
let data = getResult(this.getSchema(), this.getData());
96+
return this.fetch(options.maxRows).then(() => {
97+
const data = getResult(this.getSchema(), this.getData());
9398
this.flush();
9499
return Promise.resolve(data);
95100
});
@@ -128,9 +133,7 @@ export default class DBSQLOperation implements IOperation {
128133
.cancelOperation({
129134
operationHandle: this.operationHandle,
130135
})
131-
.then((response) => {
132-
return this.statusFactory.create(response.status);
133-
});
136+
.then((response) => this.statusFactory.create(response.status));
134137
}
135138

136139
/**
@@ -142,9 +145,7 @@ export default class DBSQLOperation implements IOperation {
142145
.closeOperation({
143146
operationHandle: this.operationHandle,
144147
})
145-
.then((response) => {
146-
return this.statusFactory.create(response.status);
147-
});
148+
.then((response) => this.statusFactory.create(response.status));
148149
}
149150

150151
finished(): boolean {

lib/DBSQLOperation/waitUntilReady.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ async function isReady(
77
progress?: boolean,
88
callback?: OperationStatusCallback,
99
): Promise<boolean> {
10-
let response = await operation.status(Boolean(progress));
10+
const response = await operation.status(Boolean(progress));
1111

1212
if (callback) {
1313
await Promise.resolve(callback(response));
@@ -46,7 +46,6 @@ export default async function waitUntilReady(
4646
}
4747
if (await isReady(operation, progress, callback)) {
4848
return;
49-
} else {
50-
return waitUntilReady(operation, progress, callback);
5149
}
50+
return waitUntilReady(operation, progress, callback);
5251
}

lib/DBSQLSession.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import { definedOrError } from './utils';
1818

1919
export default class DBSQLSession implements IDBSQLSession {
2020
private driver: HiveDriver;
21+
2122
private sessionHandle: TSessionHandle;
23+
2224
private statusFactory: StatusFactory;
2325

2426
constructor(driver: HiveDriver, sessionHandle: TSessionHandle) {
@@ -234,9 +236,7 @@ export default class DBSQLSession implements IDBSQLSession {
234236
.closeSession({
235237
sessionHandle: this.sessionHandle,
236238
})
237-
.then((response) => {
238-
return this.statusFactory.create(response.status);
239-
});
239+
.then((response) => this.statusFactory.create(response.status));
240240
}
241241

242242
private createOperation(handle: TOperationHandle): IOperation {

lib/connection/auth/PlainHttpAuthentication.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ type HttpAuthOptions = AuthOptions & {
88

99
export default class PlainHttpAuthentication implements IAuthentication {
1010
private username: string;
11+
1112
private password: string;
13+
1214
private headers: object;
1315

1416
constructor(options: HttpAuthOptions) {
@@ -27,6 +29,6 @@ export default class PlainHttpAuthentication implements IAuthentication {
2729
}
2830

2931
private getToken(username: string, password: string): string {
30-
return 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64');
32+
return `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`;
3133
}
3234
}

0 commit comments

Comments
 (0)