Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
fix rust and js formating issues
Browse files Browse the repository at this point in the history
Signed-off-by: Jasti Sri Radhe Shyam <[email protected]>
  • Loading branch information
radhe-zeeve committed Dec 13, 2023
1 parent 7b81d50 commit 9dcb656
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 49 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"crates/rust_analyzer_wasm/webdriver.json",
"sysbox/*",
"config/data/*",
"*.svg"
"*.svg",
"docker/*"
],
"words": [
"dcdd",
Expand Down
9 changes: 1 addition & 8 deletions config/versions.json
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
[
"4.3.0",
"4.2.1",
"4.2.0",
"4.1.0",
"4.0.1",
"4.0.0"
]
["4.3.0", "4.2.1", "4.2.0", "4.1.0", "4.0.1", "4.0.0"]
6 changes: 5 additions & 1 deletion crates/backend/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ pub struct Opts {
#[arg(short = 'f', long = "frontend_folder")]
pub frontend_folder: Option<String>,

#[arg(long = "versions_file_path", default_value = "./config/versions.json", env = "VERSIONS_FILE_PATH")]
#[arg(
long = "versions_file_path",
default_value = "./config/versions.json",
env = "VERSIONS_FILE_PATH"
)]
pub versions_file_path: String,

#[arg(short = 'g', long = "github_token", env = "GITHUB_GIST_TOKEN")]
Expand Down
2 changes: 1 addition & 1 deletion crates/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async fn main() -> std::io::Result<()> {
get().to(route_status),
)
.app_data(web::Data::new(AppVersionState {
versions_file_path: versions_file_path,
versions_file_path,
}))
.service(
web::resource("/version_list").to(route_version_list)
Expand Down
1 change: 0 additions & 1 deletion crates/backend/src/services/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ pub async fn route_status() -> HttpResponse<BoxBody> {
HttpResponse::Ok().body("ink-compiler is live")
}


// -------------------------------------------------------------------------------------------------
// TESTS
// -------------------------------------------------------------------------------------------------
Expand Down
11 changes: 8 additions & 3 deletions crates/backend/src/services/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

//! This module contains the service which serves the backend as static files.

use std::path::{PathBuf, Path};
use actix_web::{Result, web};
use actix_files as fs;
use actix_web::{
web,
Result,
};
use std::path::Path;

pub struct FrontendState {
pub frontend_folder: String,
Expand All @@ -29,7 +32,9 @@ pub fn route_frontend(at: &str, dir: &str) -> actix_files::Files {
pub async fn route_frontend_version(
data: web::Data<FrontendState>,
) -> Result<actix_files::NamedFile> {
Ok(fs::NamedFile::open(PathBuf::from(Path::new(&data.frontend_folder).join("index.html")))?)
Ok(fs::NamedFile::open(
Path::new(&data.frontend_folder).join("index.html"),
)?)
}

#[cfg(test)]
Expand Down
13 changes: 10 additions & 3 deletions crates/backend/src/services/version.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
use std::fs;

use actix_web::{body::BoxBody, web, HttpResponse};
use actix_web::{
body::BoxBody,
web,
HttpResponse,
};

pub use sandbox::VersionListResult;
use serde_json::{json, Value};
use serde_json::{
json,
Value,
};

pub struct AppVersionState {
pub versions_file_path: String,
Expand All @@ -17,7 +24,7 @@ pub async fn route_version_list(
data: web::Data<AppVersionState>,
) -> HttpResponse<BoxBody> {
let versions_file_path = &data.versions_file_path;
let versions_arr_string = read_json_file(&versions_file_path).unwrap();
let versions_arr_string = read_json_file(versions_file_path).unwrap();
let versions_arr_json: Value =
serde_json::from_str(versions_arr_string.as_str()).expect("Failed to parse JSON");
let versions_json = json!({
Expand Down
4 changes: 2 additions & 2 deletions crates/generate-bindings/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ mod cli;

use crate::cli::Cli;
use backend::services::{
version::VersionListResult,
contract::{
CompilationRequest,
CompilationResult,
Expand All @@ -38,6 +37,7 @@ use backend::services::{
GistLoadResponse,
},
},
version::VersionListResult,
};
use clap::Parser;
use std::{
Expand Down Expand Up @@ -65,7 +65,7 @@ fn main() -> std::io::Result<()> {
GistLoadResponse,
GistCreateRequest,
GistCreateResponse,
VersionListResult
VersionListResult,
);

let path = Path::new(&target);
Expand Down
5 changes: 4 additions & 1 deletion crates/sandbox/src/build_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
//! strategy. This allows easy mocking.

use crate::docker_command;
use std::{path::Path, time::Duration};
use std::{
path::Path,
time::Duration,
};
use tokio::process::Command;

const DOCKER_PROCESS_TIMEOUT_SOFT: Duration = Duration::from_secs(20);
Expand Down
6 changes: 3 additions & 3 deletions crates/sandbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub enum FormattingResult {
#[serde(rename_all = "snake_case")]
// #[serde(tag = "type", content = "payload", rename_all = "SCREAMING_SNAKE_CASE")]
pub struct VersionListResult {
versions: Vec<String>
versions: Vec<String>,
}

// -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -201,8 +201,8 @@ impl Sandbox {
pub fn compile(&self, req: &CompilationRequest) -> Result<CompilationResult> {
self.write_source_code(&req.source)?;

let command = build_compile_command(&self.input_file, &self.output_dir, &req.version);

let command =
build_compile_command(&self.input_file, &self.output_dir, &req.version);
println!("Executing command: \n{:?}", command);

let output = run_command_with_timeout(command)?;
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/MenuSelectElementWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const MenuSelectElementWrapper = ({ children, onClick }: Props): ReactEle
return (
<button
className="dark:bg-elevation dark:border-dark border-light border-t last:rounded-b py-2 px-4 w-full text-lg"
onClick={(e?) => onClick(e)} >
onClick={(e?) => onClick(e)}
>
{children}
</button>
);
Expand Down
4 changes: 1 addition & 3 deletions packages/ink-editor/src/api/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ const mapResponse = async (response: Response): Promise<versionListApiResponse>
payload: { status: response.status },
};

export const versionListRequest = (
config: Config,
): Promise<versionListApiResponse> => {
export const versionListRequest = (config: Config): Promise<versionListApiResponse> => {
const opts: RequestInit = {
method: 'GET',
mode: 'cors',
Expand Down
10 changes: 5 additions & 5 deletions packages/playground/src/app/Header/VersionsSubmenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MenuSelectElementWrapper, MenuElementWrapper } from '@paritytech/components/';
import { MenuSelectElementWrapper } from '@paritytech/components/';
import { ReactElement, useContext } from 'react';
import { AppContext } from '~/context/app/';
import { Dispatch, State } from '~/context/app/reducer';
Expand All @@ -10,11 +10,11 @@ export const VersionsSubmenu = (): ReactElement => {
return (
<div className="w-56">
<h2 className="px-4 pt-1 pb-2">Supported Versions</h2>
{state.versionList.map((version) => (
{state.versionList.map(version => (
<MenuSelectElementWrapper
onClick={() => {
setVersion(version, state, { app: dispatch });
}}
onClick={() => {
setVersion(version, state, { app: dispatch });
}}
>
{version} {state.version === version ? '- Active' : ''}
</MenuSelectElementWrapper>
Expand Down
24 changes: 14 additions & 10 deletions packages/playground/src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
BrowserRouter,
useParams,
useSearchParams,
} from "react-router-dom";
} from 'react-router-dom';

const App = (): ReactElement => {
const [state, dispatch]: [State, Dispatch] = useContext(AppContext);
Expand All @@ -36,16 +36,19 @@ const App = (): ReactElement => {
if (state.version && versionParam != `v${state.version}`) {
navigateVersion(state.version);
}
}, [state.version])
}, [state.version]);

useEffect(() => {
if (versionParam?.startsWith('v') && state.versionList.includes(versionParam?.replace('v', ''))) {
setVersion(versionParam?.replace('v', ''), state, { app: dispatch })
if (
versionParam?.startsWith('v') &&
state.versionList.includes(versionParam?.replace('v', ''))
) {
setVersion(versionParam?.replace('v', ''), state, { app: dispatch });
} else if (state.versionList.length > 0 && state.versionList[0]) {
setVersion(state.versionList[0], state, { app: dispatch });
navigateVersion(state.versionList[0]);
}
}, [state.versionList])
}, [state.versionList]);

useEffect(() => {
const searchParamCode = searchParams.get('code');
Expand All @@ -54,15 +57,16 @@ const App = (): ReactElement => {
const model = monaco.editor.getModel(uri as monaco.Uri);
if (!model) return;
model.setValue(searchParamCode ?? code);
if (searchParamCode) setSearchParams((oldSearchParams) => {
oldSearchParams.delete('code')
return oldSearchParams;
});
if (searchParamCode)
setSearchParams(oldSearchParams => {
oldSearchParams.delete('code');
return oldSearchParams;
});
});
loadVersionList(state, { app: dispatch }).then(() => {
const version = versionParam ? versionParam?.replace('v', '') : '';
setVersion(version, state, { app: dispatch });
})
});
}, [uri]);

useEffect(() => {
Expand Down
5 changes: 4 additions & 1 deletion packages/playground/src/context/side-effects/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export async function compile(state: State, dispatch: Dispatch, dispatchMessage:

const code = model.getValue();

const result = await compileRequest({ compileUrl: COMPILE_URL || '' }, { source: code, version: state.version });
const result = await compileRequest(
{ compileUrl: COMPILE_URL || '' },
{ source: code, version: state.version }
);

dispatch({
type: 'SET_COMPILE_STATE',
Expand Down
7 changes: 4 additions & 3 deletions packages/playground/src/context/side-effects/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ export async function testing(state: State, dispatch: Dispatch, dispatchMessage:

const code = model.getValue();

const result = await testingRequest({ compileUrl: TESTING_URL || '' }, { source: code, version: state.version }).then(
interpret_response
);
const result = await testingRequest(
{ compileUrl: TESTING_URL || '' },
{ source: code, version: state.version }
).then(interpret_response);

dispatch({
type: 'SET_TESTING_STATE',
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/context/side-effects/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ export async function setVersion(version: string, state: State, dispatch: Dispat
type: 'SET_VERSION_STATE',
payload: version,
});
}
}
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct_field_align_threshold = 0
enum_discrim_align_threshold = 0
match_arm_blocks = true
force_multiline_blocks = true # changed
fn_args_layout = "Tall"
fn_params_layout = "Tall"
brace_style = "SameLineWhere"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = false # changed
Expand Down

0 comments on commit 9dcb656

Please sign in to comment.