Skip to content

Commit 2634383

Browse files
committed
feat: add eslint add fix indent
1 parent 62eb1a5 commit 2634383

Some content is hidden

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

45 files changed

+1822
-791
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Tab indentation
7+
[*]
8+
indent_style = tab
9+
trim_trailing_whitespace = true
10+
11+
# The indent size used in the `package.json` file cannot be changed
12+
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
13+
[{*.yml,*.yaml,*.json}]
14+
indent_style = space
15+
indent_size = 2

.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/node_modules/**
2+
**/lib/vscode/**
3+
**/dist/**

.eslintrc.json

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"ecmaVersion": 6,
6+
"sourceType": "module"
7+
},
8+
"plugins": [
9+
"@typescript-eslint",
10+
"jsdoc"
11+
],
12+
"rules": {
13+
"constructor-super": "warn",
14+
"curly": "warn",
15+
"eqeqeq": "warn",
16+
"no-buffer-constructor": "warn",
17+
"no-caller": "warn",
18+
"no-debugger": "warn",
19+
"no-duplicate-case": "warn",
20+
"no-duplicate-imports": "warn",
21+
"no-eval": "warn",
22+
"no-extra-semi": "warn",
23+
"no-new-wrappers": "warn",
24+
"no-redeclare": "off",
25+
"no-sparse-arrays": "warn",
26+
"no-throw-literal": "warn",
27+
"no-unsafe-finally": "warn",
28+
"no-unused-labels": "warn",
29+
"no-restricted-globals": [
30+
"warn",
31+
"name",
32+
"length",
33+
"event",
34+
"closed",
35+
"external",
36+
"status",
37+
"origin",
38+
"orientation",
39+
"context"
40+
], // non-complete list of globals that are easy to access unintentionally
41+
"no-var": "warn",
42+
"jsdoc/no-types": "warn",
43+
"semi": "off",
44+
"@typescript-eslint/semi": "warn",
45+
"@typescript-eslint/naming-convention": [
46+
"warn",
47+
{
48+
"selector": "class",
49+
"format": [
50+
"PascalCase"
51+
]
52+
}
53+
]
54+
},
55+
"overrides": [
56+
{
57+
"files": [
58+
"*.js"
59+
],
60+
"rules": {
61+
"jsdoc/no-types": "off"
62+
}
63+
}
64+
]
65+
}

extensions/github1s/src/api.ts

+45-45
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,63 @@ import * as vscode from 'vscode';
77
import { fetch, RequestError, RequestRateLimitError, RequestInvalidTokenError, RequestNotFoundError, throttledReportNetworkError } from './util/fetch';
88

99
interface UriState {
10-
owner: string;
11-
repo: string;
12-
branch: string;
13-
path: string;
14-
};
10+
owner: string;
11+
repo: string;
12+
branch: string;
13+
path: string;
14+
}
1515

1616
const parseUri = (uri: vscode.Uri): UriState => {
17-
const [owner, repo, branch] = (uri.authority || '').split('+').filter(Boolean);
18-
return {
19-
owner,
20-
repo,
21-
branch,
22-
path: uri.path,
23-
};
17+
const [owner, repo, branch] = (uri.authority || '').split('+').filter(Boolean);
18+
return {
19+
owner,
20+
repo,
21+
branch,
22+
path: uri.path,
23+
};
2424
};
2525

2626
const handleRequestError = (error: RequestError) => {
27-
if (error instanceof RequestRateLimitError) {
28-
if (!error.token) {
29-
throw vscode.FileSystemError.NoPermissions('API Rate Limit Exceeded, Please Offer an OAuth Token.');
30-
}
31-
throw vscode.FileSystemError.NoPermissions('API Rate Limit Exceeded, Please Change Another OAuth Token.');
32-
}
33-
if (error instanceof RequestInvalidTokenError) {
34-
throw vscode.FileSystemError.NoPermissions('Current OAuth Token Is Invalid, Please Change Another One.');
35-
}
36-
if (error instanceof RequestNotFoundError) {
37-
throw vscode.FileSystemError.NoPermissions('Current OAuth Token Is Invalid, Please Change Another One.');
38-
}
39-
if (error instanceof RequestNotFoundError) {
40-
throw vscode.FileSystemError.FileNotFound('GitHub Resource Not Found');
41-
}
42-
throw vscode.FileSystemError.Unavailable(error.message || 'Unknown Error Occurred When Request To GitHub');
27+
if (error instanceof RequestRateLimitError) {
28+
if (!error.token) {
29+
throw vscode.FileSystemError.NoPermissions('API Rate Limit Exceeded, Please Offer an OAuth Token.');
30+
}
31+
throw vscode.FileSystemError.NoPermissions('API Rate Limit Exceeded, Please Change Another OAuth Token.');
32+
}
33+
if (error instanceof RequestInvalidTokenError) {
34+
throw vscode.FileSystemError.NoPermissions('Current OAuth Token Is Invalid, Please Change Another One.');
35+
}
36+
if (error instanceof RequestNotFoundError) {
37+
throw vscode.FileSystemError.NoPermissions('Current OAuth Token Is Invalid, Please Change Another One.');
38+
}
39+
if (error instanceof RequestNotFoundError) {
40+
throw vscode.FileSystemError.FileNotFound('GitHub Resource Not Found');
41+
}
42+
throw vscode.FileSystemError.Unavailable(error.message || 'Unknown Error Occurred When Request To GitHub');
4343
};
4444

4545
export const readGitHubDirectory = (uri: vscode.Uri) => {
46-
const state: UriState = parseUri(uri);
47-
return fetch(`https://api.github.com/repos/${state.owner}/${state.repo}/git/trees/${state.branch}${state.path.replace(/^\//, ':')}`)
48-
.catch(handleRequestError)
46+
const state: UriState = parseUri(uri);
47+
return fetch(`https://api.github.com/repos/${state.owner}/${state.repo}/git/trees/${state.branch}${state.path.replace(/^\//, ':')}`)
48+
.catch(handleRequestError);
4949
};
5050

5151
export const readGitHubFile = (uri: vscode.Uri, fileSha: string) => {
52-
const state: UriState = parseUri(uri);
53-
return fetch(`https://api.github.com/repos/${state.owner}/${state.repo}/git/blobs/${fileSha}`)
54-
.catch(handleRequestError);
52+
const state: UriState = parseUri(uri);
53+
return fetch(`https://api.github.com/repos/${state.owner}/${state.repo}/git/blobs/${fileSha}`)
54+
.catch(handleRequestError);
5555
};
5656

5757
export const validateToken = (token: string) => {
58-
const authHeaders = token ? { Authorization: `token ${token}` } : {};
59-
return self.fetch(`https://api.github.com`, { headers: { ...authHeaders } }).then(response => ({
60-
token: !!token, // if the token is not empty
61-
valid: response.status !== 401 ? true : false, // if the request is valid
62-
limit: +response.headers.get('X-RateLimit-Limit') || 0, // limit count
63-
remaining: +response.headers.get('X-RateLimit-Remaining') || 0, // remains request count
64-
reset: +response.headers.get('X-RateLimit-Reset') || 0, // reset time
65-
})).catch(() => {
66-
throttledReportNetworkError();
67-
throw new RequestError('Request Failed, Maybe an Network Error', token);
68-
});
58+
const authHeaders = token ? { Authorization: `token ${token}` } : {};
59+
return self.fetch(`https://api.github.com`, { headers: { ...authHeaders } }).then(response => ({
60+
token: !!token, // if the token is not empty
61+
valid: response.status !== 401 ? true : false, // if the request is valid
62+
limit: +response.headers.get('X-RateLimit-Limit') || 0, // limit count
63+
remaining: +response.headers.get('X-RateLimit-Remaining') || 0, // remains request count
64+
reset: +response.headers.get('X-RateLimit-Reset') || 0, // reset time
65+
})).catch(() => {
66+
throttledReportNetworkError();
67+
throw new RequestError('Request Failed, Maybe an Network Error', token);
68+
});
6969
};

extensions/github1s/src/commands.ts

+49-45
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,59 @@ import { getExtensionContext } from './util';
88
import { validateToken } from './api';
99

1010
export const commandValidateToken = (silent: boolean = false) => {
11-
const context = getExtensionContext();
12-
const oAuthToken = context.globalState.get('github-oauth-token') as string || '';
13-
return validateToken(oAuthToken).then(tokenStatus => {
14-
if (!silent) {
15-
const remaining = tokenStatus.remaining;
16-
if (!oAuthToken) {
17-
if (remaining > 0) {
18-
vscode.window.showWarningMessage(`You haven\'t set a GitHub OAuth Token yet, and you can have ${remaining} requests in the current rate limit window.`);
19-
} else {
20-
vscode.window.showWarningMessage('You haven\'t set a GitHub OAuth Token yet, and the rate limit is exceeded.');
21-
}
22-
} else if (!tokenStatus.valid) {
23-
vscode.window.showErrorMessage('Current GitHub OAuth Token is invalid.');
24-
} else if (tokenStatus.valid && tokenStatus.remaining > 0) {
25-
vscode.window.showInformationMessage(`Current GitHub OAuth Token is OK, and you can have ${remaining} requests in the current rate limit window.`);
26-
} else if (tokenStatus.valid && tokenStatus.remaining <= 0) {
27-
vscode.window.showWarningMessage('Current GitHub OAuth Token is Valid, but the rate limit is exceeded.');
28-
}
29-
}
30-
return tokenStatus;
31-
});
11+
const context = getExtensionContext();
12+
const oAuthToken = context.globalState.get('github-oauth-token') as string || '';
13+
return validateToken(oAuthToken).then(tokenStatus => {
14+
if (!silent) {
15+
const remaining = tokenStatus.remaining;
16+
if (!oAuthToken) {
17+
if (remaining > 0) {
18+
vscode.window.showWarningMessage(`You haven\'t set a GitHub OAuth Token yet, and you can have ${remaining} requests in the current rate limit window.`);
19+
} else {
20+
vscode.window.showWarningMessage('You haven\'t set a GitHub OAuth Token yet, and the rate limit is exceeded.');
21+
}
22+
} else if (!tokenStatus.valid) {
23+
vscode.window.showErrorMessage('Current GitHub OAuth Token is invalid.');
24+
} else if (tokenStatus.valid && tokenStatus.remaining > 0) {
25+
vscode.window.showInformationMessage(`Current GitHub OAuth Token is OK, and you can have ${remaining} requests in the current rate limit window.`);
26+
} else if (tokenStatus.valid && tokenStatus.remaining <= 0) {
27+
vscode.window.showWarningMessage('Current GitHub OAuth Token is Valid, but the rate limit is exceeded.');
28+
}
29+
}
30+
return tokenStatus;
31+
});
3232
};
3333

3434
export const commandUpdateToken = (silent: boolean = false) => {
35-
return vscode.window.showInputBox({
36-
placeHolder: 'Please input the GitHub OAuth Token',
37-
}).then(token => {
38-
if (!token) return;
39-
return getExtensionContext()!.globalState.update('github-oauth-token', token || '').then(() => {
40-
// we don't need wait validate, so we don't `return`
41-
validateToken(token).then(tokenStatus => {
42-
if (!silent) {
43-
if (!tokenStatus.valid) vscode.window.showErrorMessage('GitHub OAuth Token have updated, but it is invalid.')
44-
else if (tokenStatus.remaining <= 0) vscode.window.showWarningMessage('GitHub OAuth Token have updated, but the rate limit is exceeded.');
45-
else vscode.window.showInformationMessage('GitHub OAuth Token have updated.');
46-
}
47-
tokenStatus.valid && tokenStatus.remaining > 0 && vscode.commands.executeCommand('workbench.files.action.refreshFilesExplorer');
48-
});
49-
});
50-
});
35+
return vscode.window.showInputBox({
36+
placeHolder: 'Please input the GitHub OAuth Token',
37+
}).then(token => {
38+
if (!token) {
39+
return;
40+
}
41+
return getExtensionContext()!.globalState.update('github-oauth-token', token || '').then(() => {
42+
// we don't need wait validate, so we don't `return`
43+
validateToken(token).then(tokenStatus => {
44+
if (!silent) {
45+
if (!tokenStatus.valid) {vscode.window.showErrorMessage('GitHub OAuth Token have updated, but it is invalid.');}
46+
else if (tokenStatus.remaining <= 0) {vscode.window.showWarningMessage('GitHub OAuth Token have updated, but the rate limit is exceeded.');}
47+
else {
48+
vscode.window.showInformationMessage('GitHub OAuth Token have updated.');
49+
}
50+
}
51+
tokenStatus.valid && tokenStatus.remaining > 0 && vscode.commands.executeCommand('workbench.files.action.refreshFilesExplorer');
52+
});
53+
});
54+
});
5155
};
5256

5357
export const commandClearToken = (silent: boolean = false) => {
54-
return vscode.window.showWarningMessage('Would you want to clear the saved GitHub OAuth Token?', { modal: true }, 'Confirm').then(choose => {
55-
if (choose === 'Confirm') {
56-
return getExtensionContext()!.globalState.update('github-oauth-token', '').then(() => {
57-
!silent && vscode.window.showInformationMessage('You have cleared the saved GitHb OAuth Token.');
58-
}).then(() => true);
59-
}
60-
return false;
61-
});
58+
return vscode.window.showWarningMessage('Would you want to clear the saved GitHub OAuth Token?', { modal: true }, 'Confirm').then(choose => {
59+
if (choose === 'Confirm') {
60+
return getExtensionContext()!.globalState.update('github-oauth-token', '').then(() => {
61+
!silent && vscode.window.showInformationMessage('You have cleared the saved GitHb OAuth Token.');
62+
}).then(() => true);
63+
}
64+
return false;
65+
});
6266
};

extensions/github1s/src/extension.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import { setExtensionContext } from './util';
1010
import { commandUpdateToken, commandValidateToken, commandClearToken } from './commands';
1111

1212
export function activate(context: vscode.ExtensionContext) {
13-
setExtensionContext(context);
14-
context.subscriptions.push(new GitHub1sFS());
13+
setExtensionContext(context);
14+
context.subscriptions.push(new GitHub1sFS());
1515

16-
context.subscriptions.push(vscode.window.registerWebviewViewProvider(SettingsView.viewType, new SettingsView()));
16+
context.subscriptions.push(vscode.window.registerWebviewViewProvider(SettingsView.viewType, new SettingsView()));
1717

18-
context.subscriptions.push(vscode.commands.registerCommand('github1s.validate-token', commandValidateToken));
18+
context.subscriptions.push(vscode.commands.registerCommand('github1s.validate-token', commandValidateToken));
1919
context.subscriptions.push(vscode.commands.registerCommand('github1s.update-token', commandUpdateToken));
2020
context.subscriptions.push(vscode.commands.registerCommand('github1s.clear-token', commandClearToken));
21-
};
21+
}

0 commit comments

Comments
 (0)