Skip to content

Commit a4582e5

Browse files
authored
Merge pull request #37 from mt-max/master
Replace tslint with eslint and tsconfig update.
2 parents 691f64c + c3f1659 commit a4582e5

32 files changed

+722
-428
lines changed

.eslintrc-ts.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
extends: [
3+
'./.eslintrc.js',
4+
'plugin:@typescript-eslint/eslint-recommended',
5+
'plugin:@typescript-eslint/recommended',
6+
],
7+
parser: '@typescript-eslint/parser',
8+
plugins: ['@typescript-eslint'],
9+
rules: {
10+
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': 'allow-with-description' }],
11+
},
12+
};

.eslintrc.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
commonjs: true,
5+
es6: true,
6+
node: true,
7+
},
8+
extends: ['eslint:recommended', 'prettier'],
9+
globals: {
10+
Atomics: 'readonly',
11+
SharedArrayBuffer: 'readonly',
12+
},
13+
parserOptions: {
14+
ecmaVersion: 11,
15+
},
16+
plugins: ['prettier'],
17+
ignorePatterns: ['dist'],
18+
rules: {
19+
'prettier/prettier': 'error',
20+
},
21+
};

dist/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module.exports = {
66
setupFilesAfterEnv: ['./scripts/jest/setup.ts'],
77
modulePathIgnorePatterns: [
88
// https://github.com/facebook/jest/issues/2070#issuecomment-431706685
9-
'<rootDir>/.*/__mocks__'
9+
'<rootDir>/.*/__mocks__',
1010
],
1111
globals: {
12-
__VERSION__: packageJSON.version
13-
}
12+
__VERSION__: packageJSON.version,
13+
},
1414
};

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
"createChangelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
1616
"version": "npm run prepareRelease && npm run createChangelog",
1717
"test": "jest --no-cache",
18-
"lint": "tslint --project tsconfig.json",
18+
"lint:js": "eslint '**/*.js'",
19+
"lint:ts": "eslint -c './.eslintrc-ts.js' '**/*.ts'",
20+
"lint": "yarn lint:js; yarn lint:ts",
21+
"lint:fix": "yarn lint:js --fix; yarn lint:ts --fix",
1922
"start:docs": "docsify serve docs"
2023
},
2124
"dependencies": {
@@ -28,23 +31,26 @@
2831
"devDependencies": {
2932
"@commitlint/cli": "^8.2.0",
3033
"@commitlint/config-conventional": "^8.2.0",
31-
"@moneytree/tslint-rules": "^1.0.2",
3234
"@testing-library/jest-dom": "^5.11.0",
3335
"@types/jest": "^24.0.23",
3436
"@types/node-fetch": "^2.5.4",
3537
"@types/qs": "^6.9.0",
36-
"@types/store": "^2.0.2",
3738
"@types/url-safe-base64": "^1.1.0",
3839
"@types/uuid": "^8.0.0",
40+
"@typescript-eslint/eslint-plugin": "^3.0.2",
41+
"@typescript-eslint/parser": "^3.0.2",
3942
"conventional-changelog-cli": "^2.0.28",
4043
"docsify-cli": "^4.4.1",
44+
"eslint": "^7.1.0",
45+
"eslint-config-prettier": "^6.11.0",
46+
"eslint-plugin-prettier": "^3.1.3",
4147
"husky": "^3.1.0",
4248
"jest": "^26.1.0",
4349
"jest-fetch-mock": "^3.0.3",
4450
"node-fetch": "^2.5.0",
51+
"prettier": "^2.0.5",
4552
"ts-jest": "^26.1.1",
4653
"ts-loader": "^6.2.1",
47-
"tslint": "^5.20.1",
4854
"typescript": "^3.7.3",
4955
"webpack": "^4.41.2",
5056
"webpack-cli": "^3.3.10"

prettier.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
trailingComma: 'es5',
3+
tabWidth: 2,
4+
semi: true,
5+
singleQuote: true,
6+
printWidth: 100,
7+
};

src/__tests__/helper.test.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('helper', () => {
2323
backTo: 'backTo',
2424
authAction: 'signup',
2525
showAuthToggle: true,
26-
showRememberMe: true
26+
showRememberMe: true,
2727
},
2828
{}
2929
)
@@ -32,7 +32,7 @@ describe('helper', () => {
3232
backTo: 'backTo',
3333
authAction: 'signup',
3434
showAuthToggle: true,
35-
showRememberMe: true
35+
showRememberMe: true,
3636
});
3737
});
3838

@@ -44,22 +44,22 @@ describe('helper', () => {
4444
backTo: 'backTo',
4545
authAction: 'signup',
4646
showAuthToggle: true,
47-
showRememberMe: true
47+
showRememberMe: true,
4848
},
4949
{
5050
email: 'newEmail',
5151
backTo: 'newBackTo',
5252
authAction: 'login',
5353
showAuthToggle: false,
54-
showRememberMe: false
54+
showRememberMe: false,
5555
}
5656
)
5757
).toMatchObject({
5858
email: 'newEmail',
5959
backTo: 'newBackTo',
6060
authAction: 'login',
6161
showAuthToggle: false,
62-
showRememberMe: false
62+
showRememberMe: false,
6363
});
6464
});
6565

@@ -72,19 +72,19 @@ describe('helper', () => {
7272
authAction: 'signup',
7373
showAuthToggle: true,
7474
showRememberMe: true,
75-
// @ts-ignore
76-
whatIsThis: false
75+
// @ts-ignore: set unsupported key
76+
whatIsThis: false,
7777
},
7878
{
79-
whatIsThis2: false
79+
whatIsThis2: false,
8080
}
8181
)
8282
).toMatchObject({
8383
email: 'email',
8484
backTo: 'backTo',
8585
authAction: 'signup',
8686
showAuthToggle: true,
87-
showRememberMe: true
87+
showRememberMe: true,
8888
});
8989
});
9090

@@ -96,39 +96,34 @@ describe('helper', () => {
9696
backTo: 'backTo',
9797
authAction: 'signup',
9898
showAuthToggle: true,
99-
showRememberMe: true
99+
showRememberMe: true,
100100
},
101101
{
102102
email: 'newEmail',
103103
backTo: 'newBackTo',
104104
authAction: 'login',
105-
showAuthToggle: false
105+
showAuthToggle: false,
106106
},
107107
['email', 'backTo']
108108
)
109109
).toMatchObject({
110110
authAction: 'login',
111111
showAuthToggle: false,
112-
showRememberMe: true
112+
showRememberMe: true,
113113
});
114114
});
115115
});
116116

117117
describe('generateConfigs', () => {
118118
test('with parameter', () => {
119-
// to test hasOwnProperty not including inherit property
120-
const obj = Object.create({ name: 'inherit' });
121-
122119
expect(
123-
generateConfigs(
124-
Object.assign(obj, {
125-
email: 'email',
126-
backTo: 'backTo',
127-
authAction: 'signup',
128-
showAuthToggle: true,
129-
showRememberMe: true
130-
})
131-
)
120+
generateConfigs({
121+
email: 'email',
122+
backTo: 'backTo',
123+
authAction: 'signup',
124+
showAuthToggle: true,
125+
showRememberMe: true,
126+
})
132127
).toBe(
133128
`sdk_platform=js&sdk_version=${packageJson.version}&email=email&back_to=backTo&auth_action=signup&show_auth_toggle=true` +
134129
`&show_remember_me=true`

src/__tests__/index.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('index', () => {
2222
const instance = new MtLinkSdk();
2323

2424
instance.init('clientId', {
25-
redirectUri: 'redirectUri'
25+
redirectUri: 'redirectUri',
2626
});
2727

2828
const options = instance.storedOptions;
@@ -31,7 +31,7 @@ describe('index', () => {
3131
codeVerifier: options.codeVerifier,
3232
mode: options.mode,
3333
redirectUri: options.redirectUri,
34-
state: options.state
34+
state: options.state,
3535
};
3636

3737
const result1 = instance.authorize({ scopes: 'scopes' });
@@ -59,7 +59,7 @@ describe('index', () => {
5959
expect(result6).toBe('test');
6060
expect(exchangeToken).toBeCalledWith(storedOptions, { code: 'code' });
6161

62-
// @ts-ignore
62+
// @ts-ignore: set tokenInfo with invalid type value
6363
mocked(tokenInfo).mockResolvedValueOnce('test');
6464
const result7 = await instance.tokenInfo('test');
6565
expect(result7).toBe('test');
@@ -82,7 +82,7 @@ describe('index', () => {
8282
mtLinkSdk.init('clientId', {
8383
mode: 'local',
8484
state: 'state',
85-
codeVerifier: 'codeVerifier'
85+
codeVerifier: 'codeVerifier',
8686
});
8787

8888
expect(mtLinkSdk.storedOptions.mode).toBe('local');
@@ -92,8 +92,8 @@ describe('index', () => {
9292

9393
test('invalid mode default to production', () => {
9494
mtLinkSdk.init('clientId', {
95-
// @ts-ignore
96-
mode: 'invalid'
95+
// @ts-ignore: set mode to unsupported value
96+
mode: 'invalid',
9797
});
9898

9999
expect(mtLinkSdk.storedOptions.mode).toBe('production');

src/__tests__/server_paths.test.ts renamed to src/__tests__/server-paths.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { MY_ACCOUNT_DOMAINS, VAULT_DOMAINS, LINK_KIT_DOMAINS } from '../server-p
22

33
describe('server_paths', () => {
44
test('MY_ACCOUNT_DOMAINS', () => {
5-
expect(Object.keys(MY_ACCOUNT_DOMAINS)).toMatchObject(['production', 'staging', 'develop', 'local']);
5+
expect(Object.keys(MY_ACCOUNT_DOMAINS)).toMatchObject([
6+
'production',
7+
'staging',
8+
'develop',
9+
'local',
10+
]);
611

712
expect(MY_ACCOUNT_DOMAINS.production).toContain('myaccount');
813
expect(MY_ACCOUNT_DOMAINS.staging).toContain('myaccount');
@@ -24,7 +29,12 @@ describe('server_paths', () => {
2429
});
2530

2631
test('LINK_KIT_DOMAINS', () => {
27-
expect(Object.keys(LINK_KIT_DOMAINS)).toMatchObject(['production', 'staging', 'develop', 'local']);
32+
expect(Object.keys(LINK_KIT_DOMAINS)).toMatchObject([
33+
'production',
34+
'staging',
35+
'develop',
36+
'local',
37+
]);
2838

2939
expect(LINK_KIT_DOMAINS.production).toContain('linkkit');
3040
expect(LINK_KIT_DOMAINS.staging).toContain('linkkit');

src/api/__tests__/authorize.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('api', () => {
5454
country,
5555
scopes,
5656
locale,
57-
cobrandClientId
57+
cobrandClientId,
5858
});
5959

6060
authorize(mtLinkSdk.storedOptions);
@@ -72,7 +72,7 @@ describe('api', () => {
7272
state,
7373
country,
7474
locale,
75-
configs: generateConfigs()
75+
configs: generateConfigs(),
7676
});
7777
const url = `${MY_ACCOUNT_DOMAINS.production}/oauth/authorize?${query}`;
7878
expect(open).toBeCalledWith(url, '_self');
@@ -99,7 +99,7 @@ describe('api', () => {
9999
codeVerifier,
100100
redirectUri,
101101
country,
102-
scopes
102+
scopes,
103103
});
104104

105105
expect(open).toBeCalledTimes(1);
@@ -113,7 +113,7 @@ describe('api', () => {
113113
code_challenge_method: 'S256',
114114
state,
115115
country,
116-
configs: generateConfigs()
116+
configs: generateConfigs(),
117117
});
118118
const url = `${MY_ACCOUNT_DOMAINS.production}/oauth/authorize?${query}`;
119119
expect(open).toBeCalledWith(url, '_self');
@@ -125,7 +125,7 @@ describe('api', () => {
125125

126126
test('without window', () => {
127127
const windowSpy = jest.spyOn(global, 'window', 'get');
128-
// @ts-ignore
128+
// @ts-ignore: mocking window object to undefined
129129
windowSpy.mockImplementation(() => undefined);
130130

131131
expect(() => {

0 commit comments

Comments
 (0)