Skip to content

Commit 92abe57

Browse files
authored
Tighten ESLint rules and apply them (#188)
1 parent 054ebef commit 92abe57

File tree

88 files changed

+515
-428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+515
-428
lines changed

.eslintrc.json

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,39 @@
55
"ecmaVersion": 6,
66
"sourceType": "module"
77
},
8-
"plugins": ["@typescript-eslint"],
8+
"plugins": ["@typescript-eslint", "no-only-tests"],
9+
"extends": [
10+
"prettier",
11+
"eslint:recommended",
12+
"plugin:@typescript-eslint/recommended"
13+
],
914
"rules": {
1015
"@typescript-eslint/naming-convention": "warn",
1116
"curly": "warn",
1217
"eqeqeq": "warn",
13-
"no-throw-literal": "warn",
14-
"semi": "off"
18+
"@typescript-eslint/no-non-null-assertion": "off",
19+
"@typescript-eslint/no-explicit-any": "off",
20+
"no-constant-condition": ["error", {"checkLoops": false}],
21+
"no-empty": "off",
22+
"@typescript-eslint/no-empty-function": "off",
23+
"semi": "off",
24+
"no-console": "error",
25+
"no-only-tests/no-only-tests": "error"
1526
},
16-
"ignorePatterns": ["out", "dist", "**/*.d.ts"],
17-
"extends": ["prettier"]
27+
"overrides": [
28+
{
29+
"files": "**/*.test.ts",
30+
"rules": {
31+
"no-console": "off"
32+
}
33+
},
34+
{
35+
"files": "**/apis/*/*.ts",
36+
"rules": {
37+
"@typescript-eslint/no-unused-vars": "off",
38+
"@typescript-eslint/no-empty-interface": "off"
39+
}
40+
}
41+
],
42+
"ignorePatterns": ["out", "dist", "**/*.d.ts"]
1843
}

SCRIPT.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
1. configure plugin
2+
2. delete repo
3+
3. STUCK!!!!
4+
5+
full sync does not clean the cache!
6+
I can't fix a broken state by doing a full sync!
7+
8+
track changes to gitignore
9+
10+
file watcher for .databricks is not working
11+
12+
---
13+
14+
https://docs.databricks.com/dev-tools/ide-how-to.html
15+
16+
We hear from a lot of customers that they want to use their favourite IDE to develop for Databricks.
17+
Today I want to share with you what we have been working on to make this easier.
18+
19+
A few months ago we released a demo project together with docs on IDE best practices with Datab-00ricks.
20+
21+
We showed how to use dbx to develop locally using and IDE and then use dbx from the command line to run code on a Databricks cluster.
22+
23+
While this worked well, it still had a few limitations:
24+
25+
1. It wasn't integrated with the IDE. You had to context switch between the IDE, the command line, and the Databricks UI
26+
2. Using dbx for the edit-run cycle is rather slow
27+
28+
We have been working on a new feature that addresses these limitations.
29+
30+
We are happy to announce that we have released a VSCode extension for Databricks that allows you to run on Databricks code directly from your IDE.
31+
32+
This means that you can now develop locally using your IDE and run code directly on a Databricks cluster without having to context switch between the IDE, the command line, and the Databricks UI.
33+
34+
Let me show you how to use it.
35+
36+
Here I have the demo project from the previous documentation article open in VSCode.
37+
38+
Fisrt I have configured the IDE to connect to a Databricks workspace.
39+
40+
1. I selected an interactive cluster for running my code on
41+
2. I created an empty repo for syncing my code to
42+
2.1 creat an empty repo
43+
44+
Let's start the sync process. Sync runs in the background and watches the file system.
45+
Running code always happens on the cluster.
46+
47+
You can see the original notebook that was the starting point for the demo project.
48+
We have taken this notebook and
49+
50+
1. Converted it to a python script
51+
2. Factored out business logic into a separate file
52+
3. Added unit tests for the business logic
53+
54+
> open notebook in VSCode
55+
> show raw python script
56+
> show refactored python script
57+
> show library code
58+
> show unit tests
59+
> run unit tests - still locally
60+
> run refactored code on cluster
61+
> make code change
62+
> which country do we filter by?
63+
> goto def
64+
> change code to NLD
65+
> we can also run code as workflow
66+
> let's run the original notebook

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"conventional-changelog-cli": "^2.2.2",
3737
"eslint": "^8.26.0",
3838
"eslint-config-prettier": "^8.5.0",
39+
"eslint-plugin-no-only-tests": "^3.1.0",
3940
"ts-mockito": "^2.6.1",
4041
"typescript": "^4.8.4"
4142
}

packages/databricks-sdk-js/src/Redactor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class Redactor {
2828
}
2929
//make a copy of the object
3030
obj = Object.assign({}, obj);
31-
for (let key in obj) {
31+
for (const key in obj) {
3232
if (dropFields.includes(key)) {
3333
delete obj[key];
3434
} else if (

packages/databricks-sdk-js/src/api-client.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import ".";
33
import assert from "node:assert";
44
import {ApiClient} from "./api-client";
55

6+
// eslint-disable-next-line @typescript-eslint/no-var-requires
67
const sdkVersion = require("../package.json").version;
78

89
describe(__filename, () => {
@@ -11,7 +12,7 @@ describe(__filename, () => {
1112
});
1213

1314
it("should create proper user agent", () => {
14-
let ua = new ApiClient("unit", "3.4.5").userAgent();
15+
const ua = new ApiClient("unit", "3.4.5").userAgent();
1516
assert.equal(
1617
ua,
1718
`unit/3.4.5 databricks-sdk-js/${sdkVersion} nodejs/${process.version.slice(

packages/databricks-sdk-js/src/api-client.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import {TextDecoder} from "node:util";
44
import {fromDefaultChain} from "./auth/fromChain";
55
import {fetch} from "./fetch";
66
import {ExposedLoggers, Utils, withLogContext} from "./logging";
7-
import {context, Context} from "./context";
7+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8+
import {context} from "./context";
9+
import {Context} from "./context";
810

11+
// eslint-disable-next-line @typescript-eslint/no-var-requires
912
const sdkVersion = require("../package.json").version;
1013

1114
type HttpMethod = "POST" | "GET" | "DELETE" | "PATCH" | "PUT";
@@ -63,7 +66,7 @@ export class ApiClient {
6366
}
6467

6568
userAgent(): string {
66-
let pairs = [
69+
const pairs = [
6770
`${this.product}/${this.productVersion}`,
6871
`databricks-sdk-js/${sdkVersion}`,
6972
`nodejs/${process.version.slice(1)}`,
@@ -80,7 +83,7 @@ export class ApiClient {
8083
method: HttpMethod,
8184
payload?: any,
8285
@context context?: Context
83-
): Promise<Object> {
86+
): Promise<Record<string, unknown>> {
8487
const credentials = await this.credentialProvider();
8588
const headers = {
8689
"Authorization": `Bearer ${credentials.token}`,
@@ -89,10 +92,10 @@ export class ApiClient {
8992
};
9093

9194
// create a copy of the URL, so that we can modify it
92-
let url = new URL(credentials.host.toString());
95+
const url = new URL(credentials.host.toString());
9396
url.pathname = path;
9497

95-
let options: any = {
98+
const options: any = {
9699
method,
97100
headers,
98101
agent: this.agent,
@@ -136,8 +139,8 @@ export class ApiClient {
136139
);
137140
}
138141

139-
let responseBody = await response.arrayBuffer();
140-
let responseText = new TextDecoder().decode(responseBody);
142+
const responseBody = await response.arrayBuffer();
143+
const responseText = new TextDecoder().decode(responseBody);
141144

142145
// TODO proper error handling
143146
if (!response.ok) {
@@ -160,7 +163,7 @@ export class ApiClient {
160163
}
161164

162165
if ("error_code" in response) {
163-
let message =
166+
const message =
164167
response.message || `HTTP error ${response.error_code}`;
165168
throw logAndReturnError(
166169
url,

packages/databricks-sdk-js/src/apis/clusters/api.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export class ClustersService {
9494
options = options || {};
9595
options.onProgress =
9696
options.onProgress || (async (newPollResponse) => {});
97-
let {timeout, onProgress} = options;
98-
let cancellationToken = context?.cancellationToken;
97+
const {timeout, onProgress} = options;
98+
const cancellationToken = context?.cancellationToken;
9999

100100
const createClusterResponse = await this.create(createCluster, context);
101101

@@ -179,8 +179,8 @@ export class ClustersService {
179179
options = options || {};
180180
options.onProgress =
181181
options.onProgress || (async (newPollResponse) => {});
182-
let {timeout, onProgress} = options;
183-
let cancellationToken = context?.cancellationToken;
182+
const {timeout, onProgress} = options;
183+
const cancellationToken = context?.cancellationToken;
184184

185185
await this.delete(deleteCluster, context);
186186

@@ -273,8 +273,8 @@ export class ClustersService {
273273
options = options || {};
274274
options.onProgress =
275275
options.onProgress || (async (newPollResponse) => {});
276-
let {timeout, onProgress} = options;
277-
let cancellationToken = context?.cancellationToken;
276+
const {timeout, onProgress} = options;
277+
const cancellationToken = context?.cancellationToken;
278278

279279
await this.edit(editCluster, context);
280280

@@ -378,8 +378,8 @@ export class ClustersService {
378378
options = options || {};
379379
options.onProgress =
380380
options.onProgress || (async (newPollResponse) => {});
381-
let {timeout, onProgress} = options;
382-
let cancellationToken = context?.cancellationToken;
381+
const {timeout, onProgress} = options;
382+
const cancellationToken = context?.cancellationToken;
383383

384384
const clusterInfo = await this.get(getRequest, context);
385385

@@ -572,8 +572,8 @@ export class ClustersService {
572572
options = options || {};
573573
options.onProgress =
574574
options.onProgress || (async (newPollResponse) => {});
575-
let {timeout, onProgress} = options;
576-
let cancellationToken = context?.cancellationToken;
575+
const {timeout, onProgress} = options;
576+
const cancellationToken = context?.cancellationToken;
577577

578578
await this.resize(resizeCluster, context);
579579

@@ -655,8 +655,8 @@ export class ClustersService {
655655
options = options || {};
656656
options.onProgress =
657657
options.onProgress || (async (newPollResponse) => {});
658-
let {timeout, onProgress} = options;
659-
let cancellationToken = context?.cancellationToken;
658+
const {timeout, onProgress} = options;
659+
const cancellationToken = context?.cancellationToken;
660660

661661
await this.restart(restartCluster, context);
662662

@@ -765,8 +765,8 @@ export class ClustersService {
765765
options = options || {};
766766
options.onProgress =
767767
options.onProgress || (async (newPollResponse) => {});
768-
let {timeout, onProgress} = options;
769-
let cancellationToken = context?.cancellationToken;
768+
const {timeout, onProgress} = options;
769+
const cancellationToken = context?.cancellationToken;
770770

771771
await this.start(startCluster, context);
772772

packages/databricks-sdk-js/src/apis/commands/api.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ export class CommandExecutionService {
6262
options = options || {};
6363
options.onProgress =
6464
options.onProgress || (async (newPollResponse) => {});
65-
let {timeout, onProgress} = options;
66-
let cancellationToken = context?.cancellationToken;
65+
const {timeout, onProgress} = options;
66+
const cancellationToken = context?.cancellationToken;
6767

6868
await this.cancel(cancelCommand, context);
6969

@@ -188,8 +188,8 @@ export class CommandExecutionService {
188188
options = options || {};
189189
options.onProgress =
190190
options.onProgress || (async (newPollResponse) => {});
191-
let {timeout, onProgress} = options;
192-
let cancellationToken = context?.cancellationToken;
191+
const {timeout, onProgress} = options;
192+
const cancellationToken = context?.cancellationToken;
193193

194194
const created = await this.create(createContext, context);
195195

@@ -296,8 +296,8 @@ export class CommandExecutionService {
296296
options = options || {};
297297
options.onProgress =
298298
options.onProgress || (async (newPollResponse) => {});
299-
let {timeout, onProgress} = options;
300-
let cancellationToken = context?.cancellationToken;
299+
const {timeout, onProgress} = options;
300+
const cancellationToken = context?.cancellationToken;
301301

302302
const created = await this.execute(command, context);
303303

packages/databricks-sdk-js/src/apis/commands/commands.integ.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ describe(__filename, function () {
1515
});
1616

1717
it("should execute python with low level API", async () => {
18-
let commandsApi = new CommandExecutionService(integSetup.client);
18+
const commandsApi = new CommandExecutionService(integSetup.client);
1919

20-
let context = await commandsApi.createAndWait({
20+
const context = await commandsApi.createAndWait({
2121
clusterId: integSetup.cluster.id,
2222
language: "python",
2323
});
2424
//console.log("Execution context", context);
2525

26-
let status = await commandsApi.executeAndWait({
26+
const status = await commandsApi.executeAndWait({
2727
clusterId: integSetup.cluster.id,
2828
contextId: context.id,
2929
language: "python",

packages/databricks-sdk-js/src/apis/jobs/api.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ export class JobsService {
8383
options = options || {};
8484
options.onProgress =
8585
options.onProgress || (async (newPollResponse) => {});
86-
let {timeout, onProgress} = options;
87-
let cancellationToken = context?.cancellationToken;
86+
const {timeout, onProgress} = options;
87+
const cancellationToken = context?.cancellationToken;
8888

8989
await this.cancelRun(cancelRun, context);
9090

@@ -261,8 +261,8 @@ export class JobsService {
261261
options = options || {};
262262
options.onProgress =
263263
options.onProgress || (async (newPollResponse) => {});
264-
let {timeout, onProgress} = options;
265-
let cancellationToken = context?.cancellationToken;
264+
const {timeout, onProgress} = options;
265+
const cancellationToken = context?.cancellationToken;
266266

267267
const run = await this.getRun(getRunRequest, context);
268268

@@ -412,8 +412,8 @@ export class JobsService {
412412
options = options || {};
413413
options.onProgress =
414414
options.onProgress || (async (newPollResponse) => {});
415-
let {timeout, onProgress} = options;
416-
let cancellationToken = context?.cancellationToken;
415+
const {timeout, onProgress} = options;
416+
const cancellationToken = context?.cancellationToken;
417417

418418
await this.repairRun(repairRun, context);
419419

@@ -515,8 +515,8 @@ export class JobsService {
515515
options = options || {};
516516
options.onProgress =
517517
options.onProgress || (async (newPollResponse) => {});
518-
let {timeout, onProgress} = options;
519-
let cancellationToken = context?.cancellationToken;
518+
const {timeout, onProgress} = options;
519+
const cancellationToken = context?.cancellationToken;
520520

521521
const runNowResponse = await this.runNow(runNow, context);
522522

@@ -601,8 +601,8 @@ export class JobsService {
601601
options = options || {};
602602
options.onProgress =
603603
options.onProgress || (async (newPollResponse) => {});
604-
let {timeout, onProgress} = options;
605-
let cancellationToken = context?.cancellationToken;
604+
const {timeout, onProgress} = options;
605+
const cancellationToken = context?.cancellationToken;
606606

607607
const submitRunResponse = await this.submit(submitRun, context);
608608

0 commit comments

Comments
 (0)