Bug 1807248 - [geckodriver] Fix clippy lint warnings for all the crates. r=webdriver-reviewers,jgraham

Differential Revision: https://phabricator.services.mozilla.com/D165465
This commit is contained in:
Henrik Skupin 2023-01-03 19:26:37 +00:00
Родитель 960de47586
Коммит 3110c2946d
15 изменённых файлов: 43 добавлений и 42 удалений

Просмотреть файл

@ -79,11 +79,11 @@ impl Hg {
impl BuildInfo for Hg {
fn hash(&self) -> Option<String> {
self.exec(&["log", "-r.", "-T{node|short}"])
self.exec(["log", "-r.", "-T{node|short}"])
}
fn date(&self) -> Option<String> {
self.exec(&["log", "-r.", "-T{date|isodate}"])
self.exec(["log", "-r.", "-T{date|isodate}"])
}
}
@ -105,13 +105,13 @@ impl Git {
}
fn to_hg_sha(&self, git_sha: String) -> Option<String> {
self.exec(&["cinnabar", "git2hg", &git_sha])
self.exec(["cinnabar", "git2hg", &git_sha])
}
}
impl BuildInfo for Git {
fn hash(&self) -> Option<String> {
self.exec(&["rev-parse", "HEAD"])
self.exec(["rev-parse", "HEAD"])
.and_then(|sha| self.to_hg_sha(sha))
.map(|mut s| {
s.truncate(12);
@ -120,7 +120,7 @@ impl BuildInfo for Git {
}
fn date(&self) -> Option<String> {
self.exec(&["log", "-1", "--date=short", "--pretty=format:%cd"])
self.exec(["log", "-1", "--date=short", "--pretty=format:%cd"])
}
}

Просмотреть файл

@ -32,7 +32,7 @@ impl Command {
}
fn first_entry(&self) -> (String, serde_json::Value) {
match serde_json::to_value(&self).unwrap() {
match serde_json::to_value(self).unwrap() {
Value::String(cmd) => (cmd, Value::Object(Map::new())),
Value::Object(items) => {
let mut iter = items.iter();

Просмотреть файл

@ -291,7 +291,7 @@ impl AndroidHandler {
{
// To configure GeckoView, we use the automation techniques documented at
// https://mozilla.github.io/geckoview/consumer/docs/automation.
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
pub struct Config {
pub env: Mapping,
pub args: Vec<String>,

Просмотреть файл

@ -17,6 +17,7 @@ use webdriver::error::{ErrorStatus, WebDriverError, WebDriverResult};
/// A running Gecko instance.
#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum Browser {
Local(LocalBrowser),
Remote(RemoteBrowser),
@ -482,7 +483,7 @@ mod tests {
let prefs_path = initial_prefs.path.clone();
let mut conflicting_backup_path = initial_prefs.path.clone();
conflicting_backup_path.set_extension("geckodriver_backup".to_string());
conflicting_backup_path.set_extension("geckodriver_backup");
println!("{:?}", conflicting_backup_path);
let mut file = File::create(&conflicting_backup_path).unwrap();
file.write_all(b"test").unwrap();
@ -501,7 +502,7 @@ mod tests {
assert!(user_prefs.path.exists());
let mut backup_path = user_prefs.path.clone();
backup_path.set_extension("geckodriver_backup_1".to_string());
backup_path.set_extension("geckodriver_backup_1");
assert!(backup_path.exists());

Просмотреть файл

@ -433,7 +433,7 @@ impl FirefoxOptions {
rv.log = FirefoxOptions::load_log(options)?;
rv.prefs = FirefoxOptions::load_prefs(options)?;
if let Some(profile) = FirefoxOptions::load_profile(
settings.profile_root.as_ref().map(|x| x.as_path()),
settings.profile_root.as_deref(),
options,
)? {
rv.profile = ProfileType::Path(profile);

Просмотреть файл

@ -16,7 +16,7 @@ use webdriver::httpapi::WebDriverExtensionRoute;
use webdriver::Parameters;
pub fn extension_routes() -> Vec<(Method, &'static str, GeckoExtensionRoute)> {
return vec![
vec![
(
Method::GET,
"/session/{sessionId}/moz/context",
@ -42,10 +42,10 @@ pub fn extension_routes() -> Vec<(Method, &'static str, GeckoExtensionRoute)> {
"/session/{sessionId}/moz/screenshot/full",
GeckoExtensionRoute::TakeFullScreenshot,
),
];
]
}
#[derive(Clone, PartialEq)]
#[derive(Clone, PartialEq, Eq)]
pub enum GeckoExtensionRoute {
GetContext,
SetContext,
@ -104,7 +104,7 @@ impl WebDriverExtensionCommand for GeckoExtensionCommand {
}
}
#[derive(Clone, Debug, PartialEq, Serialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
pub struct AddonInstallParameters {
pub path: String,
pub temporary: Option<bool>,
@ -168,30 +168,30 @@ impl<'de> Deserialize<'de> for AddonInstallParameters {
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct AddonUninstallParameters {
pub id: String,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum GeckoContext {
Content,
Chrome,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GeckoContextParameters {
pub context: GeckoContext,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct XblLocatorParameters {
pub name: String,
pub value: String,
}
#[derive(Default, Debug, PartialEq)]
#[derive(Default, Debug, PartialEq, Eq)]
pub struct LogOptions {
pub level: Option<logging::Level>,
}

Просмотреть файл

@ -397,7 +397,7 @@ mod tests {
set_truncate(true);
assert_eq!(
truncate_message(&format_args!("{}", long_message)),
Some((part.to_owned(), part.to_owned()))
Some((part.to_owned(), part))
);
}
}

Просмотреть файл

@ -162,8 +162,8 @@ fn server_address(webdriver_host: &str, webdriver_port: u16) -> ProgramResult<So
}
// Prefer ipv4 address
socket_addrs.sort_by(|a, b| {
let a_val = if a.ip().is_ipv4() { 0 } else { 1 };
let b_val = if b.ip().is_ipv4() { 0 } else { 1 };
let a_val = i32::from(!a.ip().is_ipv4());
let b_val = i32::from(!b.ip().is_ipv4());
a_val.partial_cmp(&b_val).expect("Comparison failed")
});
Ok(socket_addrs.remove(0))
@ -477,7 +477,7 @@ fn make_command<'a>() -> Command<'a> {
.long("log")
.takes_value(true)
.value_name("LEVEL")
.possible_values(&["fatal", "error", "warn", "info", "config", "debug", "trace"])
.possible_values(["fatal", "error", "warn", "info", "config", "debug", "trace"])
.help("Set Gecko log level"),
)
.arg(
@ -507,7 +507,7 @@ fn make_command<'a>() -> Command<'a> {
.arg(
Arg::new("android_storage")
.long("android-storage")
.possible_values(&["auto", "app", "internal", "sdcard"])
.possible_values(["auto", "app", "internal", "sdcard"])
.value_name("ANDROID_STORAGE")
.help("Selects storage location to be used for test data (deprecated)."),
)

Просмотреть файл

@ -189,14 +189,14 @@ impl MarionetteHandler {
options,
marionette_port,
websocket_port,
self.settings.profile_root.as_ref().map(|x| x.as_path()),
self.settings.profile_root.as_deref(),
)?)
} else if !self.settings.connect_existing {
Browser::Local(LocalBrowser::new(
options,
marionette_port,
self.settings.jsdebugger,
self.settings.profile_root.as_ref().map(|x| x.as_path()),
self.settings.profile_root.as_deref(),
)?)
} else {
Browser::Existing(marionette_port)
@ -296,7 +296,7 @@ struct MarionetteSession {
impl MarionetteSession {
fn new(session_id: Option<String>, capabilities: Map<String, Value>) -> MarionetteSession {
let initital_id = session_id.unwrap_or_else(|| "".to_string());
let initital_id = session_id.unwrap_or_default();
MarionetteSession {
session_id: initital_id,
capabilities,
@ -1273,7 +1273,7 @@ impl MarionetteConnection {
}
fn send(&mut self, data: String) -> WebDriverResult<String> {
if self.stream.write(&*data.as_bytes()).is_err() {
if self.stream.write(data.as_bytes()).is_err() {
let mut err = WebDriverError::new(
ErrorStatus::UnknownError,
"Failed to write request to stream",
@ -1354,7 +1354,7 @@ impl ToMarionette<Map<String, Value>> for AddonInstallParameters {
if self.temporary.is_some() {
data.insert(
"temporary".to_string(),
serde_json::to_value(&self.temporary)?,
serde_json::to_value(self.temporary)?,
);
}
Ok(data)

Просмотреть файл

@ -187,7 +187,7 @@ fn read_response(stream: &mut TcpStream, has_output: bool, has_length: bool) ->
// command failed. First split-off the `FAIL` and length of the message.
response = response.split_off(8);
let message = std::str::from_utf8(&*response).map(|s| format!("adb error: {}", s))?;
let message = std::str::from_utf8(&response).map(|s| format!("adb error: {}", s))?;
return Err(DeviceError::Adb(message));
}

Просмотреть файл

@ -294,7 +294,7 @@ impl<'a> PrefTokenizer<'a> {
break;
}
}
self.position.column = (self.pos - col_pos as usize) as u32;
self.position.column = (self.pos - col_pos) as u32;
} else {
self.position.column -= 1;
}
@ -810,7 +810,7 @@ pub fn serialize_token<T: Write>(token: &PrefToken, output: &mut T) -> Result<()
&*data_buf
}
PrefToken::Int(data, _) => {
data_buf.push_str(&*data.to_string());
data_buf.push_str(&data.to_string());
&*data_buf
}
PrefToken::Bool(data, _) => {

Просмотреть файл

@ -132,7 +132,7 @@ pub enum Arg {
impl Arg {
pub fn new(name: &str) -> Arg {
match &*name {
match name {
"foreground" => Arg::Foreground,
"marionette" => Arg::Marionette,
"no-remote" => Arg::NoRemote,

Просмотреть файл

@ -77,7 +77,7 @@ impl AppVersion {
pub fn version(&self) -> Option<Version> {
self.version_string
.as_ref()
.and_then(|x| Version::from_str(&*x).ok())
.and_then(|x| Version::from_str(x).ok())
}
}
@ -240,14 +240,14 @@ pub fn firefox_version(binary: &Path) -> VersionResult<AppVersion> {
/// version string from the output
pub fn firefox_binary_version(binary: &Path) -> VersionResult<Version> {
let output = Command::new(binary)
.args(&["--version"])
.args(["--version"])
.stdout(Stdio::piped())
.spawn()
.and_then(|child| child.wait_with_output())
.ok();
if let Some(x) = output {
let output_str = str::from_utf8(&*x.stdout)
let output_str = str::from_utf8(&x.stdout)
.map_err(|_| Error::VersionError("Couldn't parse version output as UTF8".into()))?;
parse_binary_version(output_str)
} else {

Просмотреть файл

@ -319,10 +319,10 @@ impl SpecNewSessionParameters {
})?;
if url.username() != ""
|| url.password() != None
|| url.password().is_some()
|| url.path() != "/"
|| url.query() != None
|| url.fragment() != None
|| url.query().is_some()
|| url.fragment().is_some()
{
return Err(WebDriverError::new(
ErrorStatus::InvalidArgument,
@ -471,7 +471,7 @@ impl CapabilitiesMatching for SpecNewSessionParameters {
let version_cond = value.as_str().unwrap_or("");
if let Some(version) = browserValue {
if !browser_capabilities
.compare_browser_version(&*version, version_cond)
.compare_browser_version(&version, version_cond)
.unwrap_or(false)
{
return false;

Просмотреть файл

@ -10,7 +10,7 @@ use crate::error::WebDriverResult;
use crate::Parameters;
pub fn standard_routes<U: WebDriverExtensionRoute>() -> Vec<(Method, &'static str, Route<U>)> {
return vec![
vec![
(Method::POST, "/session", Route::NewSession),
(Method::DELETE, "/session/{sessionId}", Route::DeleteSession),
(Method::POST, "/session/{sessionId}/url", Route::Get),
@ -289,7 +289,7 @@ pub fn standard_routes<U: WebDriverExtensionRoute>() -> Vec<(Method, &'static st
),
(Method::POST, "/session/{sessionId}/print", Route::Print),
(Method::GET, "/status", Route::Status),
];
]
}
#[derive(Clone, Copy, Debug)]