Skip to content

Commit 679a8ab

Browse files
authored
Perfect the codebase for wamr-ide (#1817)
Fix errors and warnings reported by eslint Add CONTRIBUTING document for vscode-extension
1 parent 676c3c7 commit 679a8ab

14 files changed

Lines changed: 317 additions & 300 deletions
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
22
"root": true,
33
"parser": "@typescript-eslint/parser",
4+
"extends": ["plugin:@typescript-eslint/recommended"],
45
"parserOptions": {
5-
"ecmaVersion": 6,
6+
"ecmaVersion": "latest",
67
"sourceType": "module"
78
},
8-
"plugins": [
9-
"@typescript-eslint"
10-
],
9+
"plugins": ["@typescript-eslint"],
1110
"rules": {
1211
"@typescript-eslint/naming-convention": "warn",
1312
"@typescript-eslint/semi": "warn",
@@ -16,9 +15,5 @@
1615
"no-throw-literal": "warn",
1716
"semi": "off"
1817
},
19-
"ignorePatterns": [
20-
"out",
21-
"dist",
22-
"**/*.d.ts"
23-
]
18+
"ignorePatterns": ["out", "dist", "**/*.d.ts"]
2419
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# CONTRIBUTING
2+
3+
## Pull requests
4+
5+
To submit your change:
6+
7+
- Make sure your code is in line with our
8+
[coding conventions](##Coding-conventions).
9+
- Create an [issue] describing the bug the PR fixes or the feature you intend
10+
to implement.
11+
- Submit a [pull request] into the main branch.
12+
13+
## Coding conventions
14+
15+
#### Format
16+
17+
The codebase is formatted by `Prettier` and the `.prettierrc.json` has been
18+
configured.
19+
20+
- VSCode along with `Format on Save` configuration could easily format your
21+
code during development.
22+
- You can run `prettier-format-check` and `prettier-format-apply` to check and
23+
format your codebase with `prettier` in terminal.
24+
25+
#### Lint
26+
27+
`ESlint` is used as linter for the codebase and the `.eslintrc.json` has been
28+
configured.
29+
30+
- It's suggested to run `npm run lint` then fix errors and warnings before
31+
committing.
32+
33+
[issue]: https://github.com/bytecodealliance/wasm-micro-runtime/issues
34+
[pull request]: https://github.com/bytecodealliance/wasm-micro-runtime/pulls

test-tools/wamr-ide/VSCode-Extension/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
"watch": "tsc -watch -p ./",
230230
"pretest": "npm run compile && npm run lint",
231231
"lint": "eslint src --ext ts",
232+
"lint-fix": "eslint --fix src --ext ts",
232233
"test": "node ./out/test/runTest.js",
233234
"prettier-format-check": "prettier --config .prettierrc.json 'src/**/*.ts' --check",
234235
"prettier-format-apply": "prettier --config .prettierrc.json 'src/**/*.ts' --write"

test-tools/wamr-ide/VSCode-Extension/resource/webview/js/configbuildtarget.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
*/
55

6-
76
const vscode = acquireVsCodeApi();
87

98
document.getElementById('btn_submit').onclick = () => {
@@ -12,16 +11,16 @@ document.getElementById('btn_submit').onclick = () => {
1211

1312
function submitFunc() {
1413
let outputFileName = document.getElementById('output_file_name').value;
15-
let initmemSize = document.getElementById('initial_mem_size').value;
16-
let maxmemSize = document.getElementById('max_mem_size').value;
14+
let initMemSize = document.getElementById('initial_mem_size').value;
15+
let maxMemSize = document.getElementById('max_mem_size').value;
1716
let stackSize = document.getElementById('stack_size').value;
1817
let exportedSymbols = document.getElementById('exported_symbols').value;
1918

2019
vscode.postMessage({
2120
command: 'config_build_target',
2221
outputFileName: outputFileName,
23-
initmemSize: initmemSize,
24-
maxmemSize: maxmemSize,
22+
initMemSize: initMemSize,
23+
maxMemSize: maxMemSize,
2524
stackSize: stackSize,
2625
exportedSymbols: exportedSymbols,
2726
});

test-tools/wamr-ide/VSCode-Extension/src/debugConfigurationProvider.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import * as os from 'os';
99
export class WasmDebugConfigurationProvider
1010
implements vscode.DebugConfigurationProvider
1111
{
12-
constructor() {}
13-
1412
/* default port set as 1234 */
1513
private port = 1234;
1614
private hostPath!: string;
@@ -29,7 +27,7 @@ export class WasmDebugConfigurationProvider
2927
return this.providerPromise;
3028
}
3129

32-
public setDebugConfig(hostPath: string, port: number) {
30+
public setDebugConfig(hostPath: string, port: number): void {
3331
this.port = port;
3432
this.hostPath = hostPath;
3533
/* linux and windows has different debug configuration */
@@ -57,7 +55,7 @@ export class WasmDebugConfigurationProvider
5755
}
5856
}
5957

60-
public getDebugConfig() {
58+
public getDebugConfig(): vscode.DebugConfiguration {
6159
return this.wasmDebugConfig;
6260
}
6361
}

test-tools/wamr-ide/VSCode-Extension/src/decorationProvider.ts

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ export class DecorationProvider implements vscode.FileDecorationProvider {
2626
public onDidChangeFileDecorations: vscode.Event<
2727
vscode.Uri | vscode.Uri[] | undefined
2828
>;
29-
private _eventEmiter: vscode.EventEmitter<vscode.Uri | vscode.Uri[]>;
29+
private eventEmitter: vscode.EventEmitter<vscode.Uri | vscode.Uri[]>;
3030

3131
constructor() {
32-
this._eventEmiter = new vscode.EventEmitter();
33-
this.onDidChangeFileDecorations = this._eventEmiter.event;
32+
this.eventEmitter = new vscode.EventEmitter();
33+
this.onDidChangeFileDecorations = this.eventEmitter.event;
3434
this.disposables.push(
3535
vscode.window.registerFileDecorationProvider(this)
3636
);
@@ -39,34 +39,27 @@ export class DecorationProvider implements vscode.FileDecorationProvider {
3939
public provideFileDecoration(
4040
uri: vscode.Uri
4141
): vscode.ProviderResult<vscode.FileDecoration> {
42-
let currentPrjDir,
43-
prjConfigDir,
44-
configFilePath,
45-
configData,
46-
includePathArr = new Array(),
47-
excludeFileArr = new Array(),
48-
pathRelative;
49-
50-
/* Read include_paths and exclude_fils from the config file */
51-
currentPrjDir =
42+
const currentPrjDir =
5243
os.platform() === 'win32'
5344
? (vscode.workspace.workspaceFolders?.[0].uri.fsPath as string)
5445
: os.platform() === 'linux' || os.platform() === 'darwin'
55-
? (currentPrjDir = vscode.workspace.workspaceFolders?.[0].uri
56-
.path as string)
46+
? (vscode.workspace.workspaceFolders?.[0].uri.path as string)
5747
: '';
5848

59-
pathRelative = (uri.fsPath ? uri.fsPath : uri.toString()).replace(
49+
const pathRelative = (uri.fsPath ? uri.fsPath : uri.toString()).replace(
6050
currentPrjDir,
6151
'..'
6252
);
6353

64-
prjConfigDir = path.join(currentPrjDir, '.wamr');
65-
configFilePath = path.join(prjConfigDir, 'compilation_config.json');
54+
const prjConfigDir = path.join(currentPrjDir, '.wamr');
55+
const configFilePath = path.join(
56+
prjConfigDir,
57+
'compilation_config.json'
58+
);
6659
if (readFromFile(configFilePath) !== '') {
67-
configData = JSON.parse(readFromFile(configFilePath));
68-
includePathArr = configData['include_paths'];
69-
excludeFileArr = configData['exclude_files'];
60+
const configData = JSON.parse(readFromFile(configFilePath));
61+
const includePathArr = configData['includePaths'];
62+
const excludeFileArr = configData['excludeFiles'];
7063

7164
if (includePathArr.indexOf(pathRelative) > -1) {
7265
return DECORATION_INCLUDE_PATHS;
@@ -81,7 +74,7 @@ export class DecorationProvider implements vscode.FileDecorationProvider {
8174
}
8275

8376
public updateDecorationsForSource(uri: vscode.Uri): void {
84-
this._eventEmiter.fire(uri);
77+
this.eventEmitter.fire(uri);
8578
}
8679
}
8780

0 commit comments

Comments
 (0)