Skip to content

Commit 948920d

Browse files
authored
Adding tslint (#129)
* added tslint * updated documentation rules for tslint
1 parent 4aec30a commit 948920d

File tree

5 files changed

+67
-27
lines changed

5 files changed

+67
-27
lines changed

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"nicolasparada.innerhtml",
66
"bierner.lit-html",
77
"esbenp.prettier-vscode",
8-
"rebornix.project-snippets"
8+
"rebornix.project-snippets",
9+
"ms-vscode.vscode-typescript-tslint-plugin"
910
]
1011
}

.vscode/settings.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"editor.formatOnSave": true,
3-
"editor.defaultFormatter": "esbenp.prettier-vscode",
4-
"vetur.format.enable": false
5-
}
2+
"editor.formatOnSave": true,
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"editor.codeActionsOnSave": {
5+
"source.fixAll.tslint": true
6+
}
7+
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"build:esm": "tsc",
3838
"build:watch": "tsc --watch",
3939
"build:bundle": "npm run copy:loader && npm run copy:wc && npm run sass && rollup -c",
40+
"lint": "tslint -c tslint.json 'src/**/*.ts'",
4041
"copy:loader": "cpx src/bundle/mgt-loader.js dist/bundle",
4142
"copy:wc": "cpx node_modules/@webcomponents/webcomponentsjs/bundles/**/* dist/bundle/wc/bundles && cpx node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js dist/bundle/wc",
4243
"test": "jest",
@@ -90,6 +91,8 @@
9091
"sass": "^1.17.3",
9192
"shx": "^0.3.2",
9293
"ts-jest": "^24.0.1",
94+
"tslint": "^5.18.0",
95+
"tslint-config-prettier": "^1.18.0",
9396
"typescript": "^3.4.4",
9497
"whatwg-fetch": "^3.0.0"
9598
},

src/providers/TeamsProvider.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
*/
77

88
import { AuthenticationProviderOptions } from '@microsoft/microsoft-graph-client/lib/es/IAuthenticationProviderOptions';
9-
import { MsalProvider } from './MsalProvider';
10-
import { LoginType, ProviderState } from './IProvider';
119
import { Configuration, UserAgentApplication } from 'msal';
10+
import { LoginType, ProviderState } from './IProvider';
11+
import { MsalProvider } from './MsalProvider';
1212

1313
declare var microsoftTeams: any;
1414

@@ -20,43 +20,35 @@ export interface TeamsConfig {
2020
}
2121

2222
export class TeamsProvider extends MsalProvider {
23-
scopes: string[];
24-
private _authPopupUrl: string;
25-
private _accessToken: string;
26-
public static microsoftTeamsLib;
27-
28-
private _sessionStorageTokenKey = 'mgt-teamsprovider-accesstoken';
29-
private static _sessionStorageClientIdKey = 'msg-teamsprovider-clientId';
30-
3123
private set accessToken(value: string) {
3224
this._accessToken = value;
33-
sessionStorage.setItem(this._sessionStorageTokenKey, value);
25+
sessionStorage.setItem(TeamsProvider._sessionStorageTokenKey, value);
3426
this.setState(value ? ProviderState.SignedIn : ProviderState.SignedOut);
3527
}
3628

3729
private get accessToken() {
3830
return this._accessToken;
3931
}
4032

41-
static async isAvailable() {
33+
public static async isAvailable() {
4234
return !!(TeamsProvider.microsoftTeamsLib || microsoftTeams);
4335
}
4436

45-
static handleAuth() {
37+
public static handleAuth() {
4638
if (!this.isAvailable) {
4739
console.error('Make sure you have referenced the Microsoft Teams sdk before using the TeamsProvider');
4840
return;
4941
}
5042

5143
// we are in popup world now - authenticate and handle it
5244

53-
var url = new URL(window.location.href);
45+
const url = new URL(window.location.href);
5446

5547
let clientId = sessionStorage.getItem(this._sessionStorageClientIdKey);
5648

5749
if (UserAgentApplication.prototype.isCallback(window.location.hash)) {
5850
new MsalProvider({
59-
clientId: clientId
51+
clientId
6052
});
6153
return;
6254
}
@@ -76,8 +68,8 @@ export class TeamsProvider extends MsalProvider {
7668
return;
7769
}
7870

79-
let provider = new MsalProvider({
80-
clientId: clientId // need to add scopes
71+
const provider = new MsalProvider({
72+
clientId // need to add scopes
8173
});
8274

8375
const handleProviderState = async () => {
@@ -87,7 +79,7 @@ export class TeamsProvider extends MsalProvider {
8779
provider.login();
8880
} else if (provider.state === ProviderState.SignedIn) {
8981
try {
90-
let accessToken = await provider.getAccessTokenForScopes(...provider.scopes);
82+
const accessToken = await provider.getAccessTokenForScopes(...provider.scopes);
9183
teams.authentication.notifySuccess(accessToken);
9284
} catch (e) {
9385
teams.authentication.notifyFailure(e);
@@ -99,6 +91,16 @@ export class TeamsProvider extends MsalProvider {
9991
handleProviderState();
10092
}
10193

94+
private static _sessionStorageClientIdKey = 'msg-teamsprovider-clientId';
95+
private static _sessionStorageTokenKey = 'mgt-teamsprovider-accesstoken';
96+
97+
public static microsoftTeamsLib;
98+
99+
private _authPopupUrl: string;
100+
private _accessToken: string;
101+
102+
public scopes: string[];
103+
102104
constructor(config: TeamsConfig) {
103105
super({
104106
clientId: config.clientId,
@@ -115,16 +117,16 @@ export class TeamsProvider extends MsalProvider {
115117

116118
this._authPopupUrl = config.authPopupUrl;
117119
teams.initialize();
118-
this.accessToken = sessionStorage.getItem(this._sessionStorageTokenKey);
120+
this.accessToken = sessionStorage.getItem(TeamsProvider._sessionStorageTokenKey);
119121
}
120122

121-
async login(): Promise<void> {
123+
public async login(): Promise<void> {
122124
this.setState(ProviderState.Loading);
123125
const teams = TeamsProvider.microsoftTeamsLib || microsoftTeams;
124126

125127
return new Promise((resolve, reject) => {
126128
teams.getContext(context => {
127-
let url = new URL(this._authPopupUrl, new URL(window.location.href));
129+
const url = new URL(this._authPopupUrl, new URL(window.location.href));
128130
url.searchParams.append('clientId', this.clientId);
129131

130132
teams.authentication.authenticate({
@@ -142,7 +144,7 @@ export class TeamsProvider extends MsalProvider {
142144
});
143145
}
144146

145-
async getAccessToken(options: AuthenticationProviderOptions): Promise<string> {
147+
public async getAccessToken(options: AuthenticationProviderOptions): Promise<string> {
146148
return this.accessToken;
147149
}
148150
}

tslint.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"defaultSeverity": "error",
3+
"extends": ["tslint:recommended", "tslint-config-prettier"],
4+
"jsRules": {},
5+
"rules": {
6+
"quotemark": [true, "single", "avoid-escape", "avoid-template"],
7+
"interface-name": false,
8+
"completed-docs": [
9+
true,
10+
{
11+
"methods": {
12+
"privacies": ["public", "protected"]
13+
},
14+
"properties": {
15+
"privacies": ["public", "protected"]
16+
},
17+
"classes": true,
18+
"enums": true,
19+
"enum-members": true,
20+
"functions": true,
21+
"interfaces": true,
22+
"namespaces": true,
23+
"types": true,
24+
"variables": true
25+
}
26+
],
27+
"variable-name": {
28+
"options": ["allow-leading-underscore"]
29+
}
30+
},
31+
"rulesDirectory": []
32+
}

0 commit comments

Comments
 (0)