Skip to content

Commit 7a631d1

Browse files
committed
More rules
1 parent 7a01c60 commit 7a631d1

14 files changed

+223
-42
lines changed

.eslintrc.json

Lines changed: 184 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,195 @@
44
"plugins": ["@typescript-eslint", "prettier"],
55
"extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "prettier"],
66
"rules": {
7-
"max-len": "off",
8-
"sort-imports": [
9-
"off",
10-
{
11-
"allowSeparatedGroups": true
12-
}
13-
],
14-
"sort-keys": "off",
157
"no-useless-catch": "off", //TODO- Remove the unnecessary try-catch lines used and enable no-useless-catch rule.
16-
"no-constant-condition": "off",
17-
"no-empty-interface": "off",
188
"prefer-rest-params": "off",
9+
"no-constant-condition": "off",
10+
// @typescript-eslint rules
1911
"@typescript-eslint/no-empty-interface": "off",
2012
"@typescript-eslint/ban-types": "off",
21-
"no-mixed-spaces-and-tabs": "off",
22-
"@typescript-eslint/no-unused-vars": "off",
13+
"@typescript-eslint/no-unused-vars": "error",
2314
"@typescript-eslint/no-explicit-any": "off",
2415
"@typescript-eslint/explicit-module-boundary-types": "off",
25-
"prettier/prettier": "error"
16+
"prettier/prettier": "error",
17+
"@typescript-eslint/no-var-requires": "error",
18+
"@typescript-eslint/no-non-null-assertion": "error",
19+
"@typescript-eslint/naming-convention": [
20+
"error",
21+
{
22+
"selector": "typeLike",
23+
"format": ["PascalCase"],
24+
"filter": {
25+
"regex": "^(__String|[A-Za-z]+_[A-Za-z]+)$",
26+
"match": false
27+
}
28+
},
29+
{
30+
"selector": "interface",
31+
"format": ["PascalCase"],
32+
"custom": {
33+
"regex": "^I[A-Z]",
34+
"match": false
35+
},
36+
"filter": {
37+
"regex": "^I(Arguments|TextWriter|O([A-Z][a-z]+[A-Za-z]*)?)$",
38+
"match": false
39+
}
40+
},
41+
{
42+
"selector": "variable",
43+
"format": ["camelCase", "PascalCase", "UPPER_CASE"],
44+
"leadingUnderscore": "allow",
45+
"filter": {
46+
"regex": "^(_{1,2}filename|_{1,2}dirname|_+|[A-Za-z]+_[A-Za-z]+)$",
47+
"match": false
48+
}
49+
},
50+
{
51+
"selector": "function",
52+
"format": ["camelCase", "PascalCase"],
53+
"leadingUnderscore": "allow",
54+
"filter": {
55+
"regex": "^[A-Za-z]+_[A-Za-z]+$",
56+
"match": false
57+
}
58+
},
59+
{
60+
"selector": "parameter",
61+
"format": ["camelCase"],
62+
"leadingUnderscore": "allow",
63+
"filter": {
64+
"regex": "^(_+|[A-Za-z]+_[A-Z][a-z]+)$",
65+
"match": false
66+
}
67+
},
68+
{
69+
"selector": "method",
70+
"format": ["camelCase", "PascalCase"],
71+
"leadingUnderscore": "allow",
72+
"filter": {
73+
"regex": "^[A-Za-z]+_[A-Za-z]+$",
74+
"match": false
75+
}
76+
},
77+
{
78+
"selector": "memberLike",
79+
"format": ["camelCase"],
80+
"leadingUnderscore": "allow",
81+
"filter": {
82+
"regex": "^[A-Za-z]+_[A-Za-z]+$",
83+
"match": false
84+
}
85+
},
86+
{
87+
"selector": "enumMember",
88+
"format": ["camelCase", "PascalCase"],
89+
"leadingUnderscore": "allow",
90+
"filter": {
91+
"regex": "^[A-Za-z]+_[A-Za-z]+$",
92+
"match": false
93+
}
94+
},
95+
{
96+
"selector": "property",
97+
"format": null
98+
}
99+
],
100+
"@typescript-eslint/semi": "error",
101+
"@typescript-eslint/no-use-before-define": "off",
102+
"@typescript-eslint/prefer-for-of": "error",
103+
"@typescript-eslint/prefer-function-type": "error",
104+
"@typescript-eslint/prefer-namespace-keyword": "error",
105+
"@typescript-eslint/quotes": [
106+
"error",
107+
"double",
108+
{
109+
"avoidEscape": true,
110+
"allowTemplateLiterals": true
111+
}
112+
],
113+
"@typescript-eslint/space-within-parens": ["off", "never"],
114+
"@typescript-eslint/triple-slash-reference": "error",
115+
"@typescript-eslint/type-annotation-spacing": "error",
116+
"@typescript-eslint/unified-signatures": "error",
117+
"@typescript-eslint/adjacent-overload-signatures": "error",
118+
"@typescript-eslint/array-type": "error",
119+
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
120+
"@typescript-eslint/no-inferrable-types": "error",
121+
"@typescript-eslint/no-misused-new": "error",
122+
"@typescript-eslint/no-this-alias": "error",
123+
"no-unused-expressions": "off",
124+
"@typescript-eslint/no-unused-expressions": [
125+
"error",
126+
{
127+
"allowTernary": true
128+
}
129+
],
130+
"@typescript-eslint/space-before-function-paren": [
131+
"error",
132+
{
133+
"asyncArrow": "always",
134+
"anonymous": "never",
135+
"named": "never"
136+
}
137+
],
138+
"@typescript-eslint/consistent-type-assertions": "error",
139+
"@typescript-eslint/explicit-member-accessibility": [
140+
"off",
141+
{
142+
"accessibility": "explicit"
143+
}
144+
],
145+
"@typescript-eslint/indent": "off",
146+
"@typescript-eslint/interface-name-prefix": "off",
147+
"@typescript-eslint/member-delimiter-style": [
148+
"off",
149+
{
150+
"multiline": {
151+
"delimiter": "none",
152+
"requireLast": true
153+
},
154+
"singleline": {
155+
"delimiter": "semi",
156+
"requireLast": false
157+
}
158+
}
159+
],
160+
"@typescript-eslint/member-ordering": "off",
161+
"@typescript-eslint/no-empty-function": "error",
162+
"@typescript-eslint/no-namespace": "off",
163+
"@typescript-eslint/no-parameter-properties": "off",
164+
// eslint
165+
// eslint
166+
"brace-style": "off",
167+
"constructor-super": "error",
168+
"curly": ["error", "multi-line"],
169+
"dot-notation": "off",
170+
"eqeqeq": "error",
171+
"new-parens": "error",
172+
"no-caller": "error",
173+
"no-duplicate-case": "error",
174+
"no-duplicate-imports": "error",
175+
"no-empty": "error",
176+
"no-eval": "error",
177+
"no-extra-bind": "error",
178+
"no-fallthrough": "error",
179+
"no-new-func": "off",
180+
"no-new-wrappers": "error",
181+
"no-return-await": "error",
182+
"no-sparse-arrays": "error",
183+
"no-template-curly-in-string": "error",
184+
"no-throw-literal": "error",
185+
"no-trailing-spaces": "error",
186+
"no-undef-init": "error",
187+
"no-unsafe-finally": "error",
188+
"no-unused-labels": "error",
189+
"no-var": "error",
190+
"object-shorthand": "error",
191+
"prefer-const": "error",
192+
"prefer-object-spread": "error",
193+
"quote-props": "off",
194+
"space-in-parens": "error",
195+
"unicode-bom": ["error", "never"],
196+
"use-isnan": "error"
26197
}
27198
}

spec/content/BatchRequestContent.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ describe("BatchRequestContent.ts", () => {
7171
const createFolderDuplicate1 = getCreateFolderRequestCopy();
7272
createFolderDuplicate1.id = "";
7373
try {
74+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
7475
const batchReq = new BatchRequestContent([createFolderDuplicate1]);
7576
throw new Error("Something wrong with the empty id check");
7677
} catch (error) {
@@ -87,6 +88,7 @@ describe("BatchRequestContent.ts", () => {
8788
requests.push(req);
8889
}
8990
try {
91+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
9092
const batchReq = new BatchRequestContent(requests);
9193
throw new Error("Something wrong with the limiting requests");
9294
} catch (error) {
@@ -296,6 +298,7 @@ describe("BatchRequestContent.ts", () => {
296298
it("Should return error for empty requests", async () => {
297299
const batchReq = new BatchRequestContent();
298300
try {
301+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
299302
const content = await batchReq.getContent();
300303
throw new Error("Something wrong with the empty requests validation");
301304
} catch (error) {
@@ -354,6 +357,7 @@ describe("BatchRequestContent.ts", () => {
354357
},
355358
]);
356359
try {
360+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
357361
const content = await batchReq.getContent();
358362
throw new Error("Something wrong with the header checking");
359363
} catch (error) {

spec/core/Client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe("Client.ts", () => {
2626
authProvider: dummyAuthProvider,
2727
middleware: dummyHTTPHandler,
2828
};
29+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2930
const client: Client = Client.initWithMiddleware(options);
3031
throw new Error("Something wrong with the ambiguity check");
3132
} catch (error) {
@@ -39,7 +40,7 @@ describe("Client.ts", () => {
3940
};
4041
const client: Client = Client.initWithMiddleware(options);
4142
assert.isTrue(client instanceof Client);
42-
assert.isDefined(client["httpClient"]);
43+
assert.isDefined(["httpClient"]);
4344
});
4445

4546
it("Should return client instance for a custom middleware chain", () => {

spec/core/GraphResponseHandler.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,7 @@ describe("GraphResponseHandler.ts", () => {
5151
"Content-Type": "application/json",
5252
},
5353
};
54-
const status200Image = {
55-
status: 200,
56-
stautsText: "OK",
57-
headers: {
58-
"Content-Type": "image/jpeg",
59-
},
60-
};
54+
6155
const status200Unknown = {
6256
status: 200,
6357
statusText: "OK",
@@ -82,6 +76,12 @@ describe("GraphResponseHandler.ts", () => {
8276
assert.isUndefined(responseValue);
8377
});
8478

79+
it("Should return internal server error (500 response)", async () => {
80+
const response = new Response(undefined, status500);
81+
const responseValue = await GraphResponseHandler["convertResponse"](response);
82+
assert.isUndefined(responseValue);
83+
});
84+
8585
it("Should return empty text value for empty response", async () => {
8686
const response = new Response(undefined, status202);
8787
const responseValue = await GraphResponseHandler["convertResponse"](response);

spec/middleware/RedirectHandler.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,6 @@ describe("RedirectHandler.ts", () => {
226226

227227
it("Should drop body and change method to get for SEE_OTHER status code", async () => {
228228
const options = new RedirectHandlerOptions();
229-
const cxt: Context = {
230-
request: "/me",
231-
options: {
232-
method: "POST",
233-
body: "dummy body",
234-
},
235-
};
236229
dummyHTTPHandler.setResponses([
237230
new Response("", {
238231
status: 303,

spec/middleware/RedirectHandlerOptions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe("RedirectHandlerOptions.ts", () => {
2626

2727
it("Should throw error for setting max redirects more than allowed", () => {
2828
try {
29+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2930
const options = new RedirectHandlerOptions(100);
3031
throw new Error("Something wrong with the max redirects value redirection");
3132
} catch (error) {
@@ -34,6 +35,7 @@ describe("RedirectHandlerOptions.ts", () => {
3435
});
3536
it("Should throw error for setting max redirects to negative", () => {
3637
try {
38+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3739
const options = new RedirectHandlerOptions(-10);
3840
throw new Error("Something wrong with the max redirects value redirection");
3941
} catch (error) {
@@ -44,7 +46,7 @@ describe("RedirectHandlerOptions.ts", () => {
4446
it("Should initialize instance with default options", () => {
4547
const options = new RedirectHandlerOptions();
4648
assert.equal(options.maxRedirects, RedirectHandlerOptions["DEFAULT_MAX_REDIRECTS"]);
47-
assert.equal(options.shouldRedirect, RedirectHandlerOptions["DEFAULT_SHOULD_RETRY"]);
49+
assert.equal(options.shouldRedirect, RedirectHandlerOptions["defaultShouldRetry"]);
4850
});
4951
});
5052
});

spec/middleware/RetryHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ describe("RetryHandler.ts", function() {
224224
it("Should successfully retry and return ok response", async () => {
225225
const opts = new RetryHandlerOptions(1);
226226
dummyHTTPHandler.setResponses([new Response(null, { status: 429 }), new Response(null, { status: 429 }), new Response("ok", { status: 200 })]);
227-
await handler["executeWithRetry"](cxt, 0, options);
227+
await handler["executeWithRetry"](cxt, 0, opts);
228228
assert.equal(cxt.response.status, 200);
229229
});
230230

spec/middleware/RetryHandlerOptions.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ describe("RetryHandlerOptions.ts", () => {
1616
const options = new RetryHandlerOptions();
1717
assert.equal(options["delay"], RetryHandlerOptions["DEFAULT_DELAY"]);
1818
assert.equal(options["maxRetries"], RetryHandlerOptions["DEFAULT_MAX_RETRIES"]);
19-
assert.equal(options["shouldRetry"], RetryHandlerOptions["DEFAULT_SHOULD_RETRY"]);
19+
assert.equal(options["shouldRetry"], RetryHandlerOptions["defaultShouldRetry"]);
2020
} catch (error) {
2121
throw error;
2222
}
2323
});
2424

2525
it("Should throw error for both delay and maxRetries are higher than the limit", () => {
2626
try {
27+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2728
const options = new RetryHandlerOptions(1000, 1000);
2829
throw new Error("Something wrong with the delay and maxRetries max limit validation");
2930
} catch (error) {
@@ -33,6 +34,7 @@ describe("RetryHandlerOptions.ts", () => {
3334

3435
it("Should throw error for delay is higher than the limit", () => {
3536
try {
37+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3638
const options = new RetryHandlerOptions(1000, 2);
3739
throw new Error("Something wrong with the delay max limit validation");
3840
} catch (error) {
@@ -42,6 +44,7 @@ describe("RetryHandlerOptions.ts", () => {
4244

4345
it("Should throw error for maxRetries is higher than the limit", () => {
4446
try {
47+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4548
const options = new RetryHandlerOptions(1, 2000);
4649
throw new Error("Something wrong with the maxRetries max limit validation");
4750
} catch (error) {
@@ -51,6 +54,7 @@ describe("RetryHandlerOptions.ts", () => {
5154

5255
it("Should throw error for both delay and maxRetries are negative", () => {
5356
try {
57+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
5458
const options = new RetryHandlerOptions(-1, -100);
5559
throw new Error("Something wrong with the delay and maxRetries max limit validation");
5660
} catch (error) {
@@ -60,6 +64,7 @@ describe("RetryHandlerOptions.ts", () => {
6064

6165
it("Should throw error for delay is negative", () => {
6266
try {
67+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6368
const options = new RetryHandlerOptions(-5, 2);
6469
throw new Error("Something wrong with the delay max limit validation");
6570
} catch (error) {
@@ -69,6 +74,7 @@ describe("RetryHandlerOptions.ts", () => {
6974

7075
it("Should throw error for maxRetries is negative", () => {
7176
try {
77+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
7278
const options = new RetryHandlerOptions(1, -10);
7379
throw new Error("Something wrong with the maxRetries max limit validation");
7480
} catch (error) {
@@ -80,6 +86,7 @@ describe("RetryHandlerOptions.ts", () => {
8086
try {
8187
const delay = 1;
8288
const maxRetries = 3;
89+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8390
const shouldRetry: ShouldRetry = (d, a, req, o, res) => {
8491
return false;
8592
};

0 commit comments

Comments
 (0)