Skip to content

Commit

Permalink
Add No Shadow rule for eslint (#87)
Browse files Browse the repository at this point in the history
This PR adds so-shadow rule to enlist, in order to prevent bugs during
comparison in nested scopes.
Additionally this PR back fixes all violations of this rule.

---------

Co-authored-by: Filip Andrzej Kaminski <[email protected]>
  • Loading branch information
2 people authored and Filip Andrzej Kaminski committed Apr 15, 2024
1 parent f73e937 commit b4a33c8
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 21 deletions.
3 changes: 2 additions & 1 deletion packages/vscode-extension/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
"semi": "off",
"@typescript-eslint/no-shadow": "error"
},
"ignorePatterns": ["webview-ui/**"]
}
4 changes: 2 additions & 2 deletions packages/vscode-extension/src/dependency/DependencyChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class DependencyChecker implements Disposable {
Logger.debug("Setup dependency checker listeners.");
this.webview.onDidReceiveMessage(
(message: any) => {
const command = message.command;
switch (command) {
const webviewCommand = message.command;
switch (webviewCommand) {
case "checkNodejsInstalled":
Logger.debug("Received checkNodejsInstalled command.");
this.checkNodejsInstalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export class DependencyInstaller implements Disposable {
Logger.debug("Setup dependency installer listeners.");
this.webview.onDidReceiveMessage(
(message: any) => {
const command = message.command;
const webviewCommand = message.command;

switch (command) {
switch (webviewCommand) {
case "installPods":
Logger.debug("Received installPods command.");
this.installPods();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export async function listSimulators(): Promise<DeviceInfo[]> {

const simulators: DeviceInfo[] = Object.entries(devicesPerRuntime)
.map(([runtimeID, devices]) => {
const runtime = runtimes.find((runtime) => runtime.identifier === runtimeID);
const runtime = runtimes.find((item) => item.identifier === runtimeID);

return devices.map((device) => {
return {
Expand Down
8 changes: 4 additions & 4 deletions packages/vscode-extension/src/panels/WebviewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ export class WebviewController implements Disposable {
const argsWithCallbacks = args.map((arg: any) => {
if (typeof arg === "object" && "__callbackId" in arg) {
const callbackId = arg.__callbackId;
return (...args: any[]) => {
return (...options: any[]) => {
this.webview.postMessage({
command: "callback",
callbackId,
args,
options,
});
};
} else {
Expand All @@ -118,11 +118,11 @@ export class WebviewController implements Disposable {
const result = callableObject[method](...argsWithCallbacks);
if (result instanceof Promise) {
result
.then((result) => {
.then((res) => {
this.webview.postMessage({
command: "callResult",
callId,
result,
res,
});
})
.catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export class WorkspaceConfigController implements Disposable, WorkspaceConfig {
if (!event.affectsConfiguration("ReactNativeIDE")) {
return;
}
const configuration = workspace.getConfiguration("ReactNativeIDE");
const config = workspace.getConfiguration("ReactNativeIDE");
this.config = {
panelLocation: configuration.get<PanelLocation>("panelLocation")!,
relativeAppLocation: configuration.get<string>("relativeAppLocation")!,
panelLocation: config.get<PanelLocation>("panelLocation")!,
relativeAppLocation: config.get<string>("relativeAppLocation")!,
};
this.eventEmitter.emit("configChange", this.config);
});
Expand Down
6 changes: 3 additions & 3 deletions packages/vscode-extension/src/project/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export class Devtools implements Disposable {
}

public rpc(event: string, payload: any, responseEvent: string, callback: (payload: any) => void) {
const listener = (event: string, payload: any) => {
if (event === responseEvent) {
callback(payload);
const listener = (message: string, data: any) => {
if (message === responseEvent) {
callback(data);
this.removeListener(listener);
}
};
Expand Down
6 changes: 3 additions & 3 deletions packages/vscode-extension/src/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class Project implements Disposable, MetroDelegate, ProjectInterface {
const lastDeviceId = extensionContext.workspaceState.get(LAST_SELECTED_DEVICE_KEY) as
| string
| undefined;
let device = devices.find((device) => device.id === lastDeviceId);
let device = devices.find((item) => item.id === lastDeviceId);
if (!device && devices.length > 0) {
device = devices[0];
}
Expand All @@ -92,8 +92,8 @@ export class Project implements Disposable, MetroDelegate, ProjectInterface {

const devices = await this.deviceManager.listAllDevices();
if (!selectInitialDevice(devices)) {
const listener = (devices: DeviceInfo[]) => {
if (selectInitialDevice(devices)) {
const listener = (newDevices: DeviceInfo[]) => {
if (selectInitialDevice(newDevices)) {
this.deviceManager.removeListener("devicesChanged", listener);
}
};
Expand Down
4 changes: 2 additions & 2 deletions packages/vscode-extension/src/utilities/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ export async function calculateMD5(path: string, hash: Hash = createHash("md5"))

for await (let file of files) {
let filePath = join(path, file);
const stat = await fs.promises.stat(filePath);
const fileStat = await fs.promises.stat(filePath);

if (stat.isDirectory()) {
if (fileStat.isDirectory()) {
hash = await calculateMD5(filePath, hash);
} else {
hash = await calculateFileMD5(filePath, hash);
Expand Down

0 comments on commit b4a33c8

Please sign in to comment.