Skip to content

Commit 205b09c

Browse files
committed
Fix linter issues
1 parent 8b2bba1 commit 205b09c

File tree

9 files changed

+26
-21
lines changed

9 files changed

+26
-21
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.js
2+
*.d.ts
3+
dist
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
{
1+
module.exports = {
22
"extends": ["plugin:@infinum/core", "plugin:@infinum/typescript"],
3-
"overrides": [
4-
{
5-
"files": ["*.ts"]
6-
}
7-
],
83
"parserOptions": {
94
"project": ["./tsconfig.json"]
105
},
116
"parser": "@typescript-eslint/parser"
12-
}
7+
};

example/src/App.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@ const providerUrls: Record<string, string> = {
1010
auth0: 'https://dev-u8csbbr8zashh2k8.us.auth0.com/userinfo',
1111
};
1212

13-
const useSW = localStorage.getItem('useSW') === 'true';
14-
1513
function App() {
16-
const [result, setResult] = useState<null | { data: { name: string; picture: string } }>(null);
14+
const [result, setResult] = useState<null | { data: { name: string; picture: string }, provider: string }>(null);
1715

1816
useEffect(() => {
1917
if (!result) {
20-
getUserData().then(setResult as any, () => null);
18+
getUserData().then(setResult as (data: unknown) => void, () => null);
2119
}
2220
}, []);
2321

2422
const getUserInfo = useCallback(async () => {
25-
// @ts-ignore
26-
const userInfoUrl: string | undefined = providerUrls[result?.provider];
23+
const userInfoUrl: string | null = result && providerUrls[result.provider];
2724

2825
if (userInfoUrl) {
2926
await fetch('/test');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"module": "index.mjs",
77
"scripts": {
88
"build": "tsup --minify && node ./prepare.js",
9-
"lint": "eslint -c ./.eslintrc.json .",
9+
"lint": "eslint .",
1010
"dev": "nodemon -i example -i dist -i node_modules -i test -i 'src/**.test.ts' -e ts,tsx --exec \"npm run build:example\"",
1111
"build:example": "npm run build && cd example && rm -rf node_modules/auth-worker && npm install && npm run build:sw -- --clean=false",
1212
"test": "jest"

src/utils/register.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('utils/register', () => {
2323
{ workerPath: './test-service-worker.js', scope: '/test', debug: true }
2424
);
2525
expect(window.navigator.serviceWorker.register).toHaveBeenCalledWith(
26+
// eslint-disable-next-line max-len
2627
'./test-service-worker.js?config=%7B%22google%22%3A%7B%22clientId%22%3A%22example-client-id%22%2C%22scopes%22%3A%22https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile%22%7D%7D&v=1&debug=1',
2728
{
2829
scope: '/test',
@@ -39,6 +40,7 @@ describe('utils/register', () => {
3940
},
4041
});
4142
expect(window.navigator.serviceWorker.register).toHaveBeenCalledWith(
43+
// eslint-disable-next-line max-len
4244
'./service-worker.js?config=%7B%22google%22%3A%7B%22clientId%22%3A%22example-client-id%22%2C%22scopes%22%3A%22https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile%22%7D%7D&v=1&debug=0',
4345
{
4446
scope: '/',

src/worker/fetch.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('worker/fetch', () => {
6363

6464
(fetch as jest.Mock).mockResolvedValueOnce(
6565
new Response(
66+
// eslint-disable-next-line max-len
6667
'{"access_token": "mockAccessToken", "token_type": "mockTokenType", "refresh_token": "newMockRefreshToken", "expires_in": 1234567890}',
6768
{ status: 200 }
6869
)
@@ -200,6 +201,7 @@ describe('worker/fetch', () => {
200201

201202
(fetch as jest.Mock).mockResolvedValueOnce(
202203
new Response(
204+
// eslint-disable-next-line max-len
203205
'{"access_token": "mockAccessToken", "token_type": "mockTokenType", "refresh_token": "newMockRefreshToken", "expires_in": 1234567890}',
204206
{ status: 200 }
205207
)
@@ -231,6 +233,7 @@ describe('worker/fetch', () => {
231233

232234
(fetch as jest.Mock).mockResolvedValueOnce(
233235
new Response(
236+
// eslint-disable-next-line max-len
234237
'{"access_token": "mockAccessToken", "token_type": "mockTokenType", "refresh_token": "newMockRefreshToken", "expires_in": 1234567890}',
235238
{ status: 200 }
236239
)

src/worker/interceptor.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe('worker/interceptor', () => {
6262

6363
(fetch as jest.Mock).mockResolvedValueOnce(
6464
new Response(
65+
// eslint-disable-next-line max-len
6566
'{"access_token": "mockAccessToken", "token_type": "mockTokenType", "refresh_token": "newMockRefreshToken", "expires_in": 1234567890}',
6667
{ status: 200 }
6768
)
@@ -112,10 +113,10 @@ describe('worker/interceptor', () => {
112113

113114
const location = response.headers.get('location');
114115

115-
expect(location.startsWith('https://example.com/login?client_id=fooClientId&response_type=token&state=')).toBe(
116-
true
117-
);
118-
expect(location.endsWith('&scope=&redirect_uri=https%3A%2F%2Fexample.com%2Ffoobar%2Fcallback%2Ffoo')).toBe(true);
116+
expect(location.startsWith('https://example.com/login?client_id=fooClientId&response_type=token&state='))
117+
.toBe(true);
118+
expect(location.endsWith('&scope=&redirect_uri=https%3A%2F%2Fexample.com%2Ffoobar%2Fcallback%2Ffoo'))
119+
.toBe(true);
119120
expect(response.status).toBe(302);
120121
});
121122

src/worker/operations.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ describe('worker/operations', () => {
2626

2727
(getAuthState as jest.Mock).mockReturnValue(state);
2828

29-
await expect(createSession('', 'mockProvider', '', 'http://example.com')).rejects.toThrow('No config found');
29+
await expect(createSession('', 'mockProvider', '', 'http://example.com'))
30+
.rejects.toThrow('No config found');
3031
});
3132

3233
it('should fail if there is no valid providers', async () => {
@@ -54,7 +55,8 @@ describe('worker/operations', () => {
5455

5556
(getAuthState as jest.Mock).mockReturnValue(state);
5657

57-
await expect(createSession('', 'mockProvider', '123', 'http://example.com')).rejects.toThrow('Invalid state');
58+
await expect(createSession('', 'mockProvider', '123', 'http://example.com'))
59+
.rejects.toThrow('Invalid state');
5860
});
5961

6062
it('should work for token flow', async () => {
@@ -316,6 +318,7 @@ describe('worker/operations', () => {
316318

317319
(fetch as jest.Mock).mockResolvedValueOnce(
318320
new Response(
321+
// eslint-disable-next-line max-len
319322
'{"access_token": "mockAccess", "user": "mockUserInfo", "expiresIn": 321, "tokenType": "Foo", "refreshToken": "mockRefresh"}',
320323
{ status: 200 }
321324
)

src/worker/utils.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ describe('worker/utils', () => {
5656

5757
await mockState;
5858
expect(getAuthState).toHaveBeenCalled();
59-
expect(console.log).toHaveBeenCalledWith(expect.stringMatching(/%cWW\/\w{4}/), expect.any(String), 'Test Log');
59+
expect(console.log)
60+
.toHaveBeenCalledWith(expect.stringMatching(/%cWW\/\w{4}/), expect.any(String), 'Test Log');
6061
});
6162

6263
it('should not log the arguments if debug is disabled in the state', async () => {

0 commit comments

Comments
 (0)