refactor: Refactor code using clippy (#5863)

**Description:**

I temporarily updated rustc to use newer version of `cargo clippy`.
This commit is contained in:
Donny/강동윤 2022-09-15 00:05:59 +09:00 committed by GitHub
parent 55a4e18991
commit dfb01bde71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 29 additions and 31 deletions

View File

@ -57,14 +57,14 @@ impl ReduceCommand {
let m = parse_js(fm)?;
let code = print_js(cm, &m.module, false)?;
fs::write(&src_path, code.as_bytes()).context("failed to strip comments")?;
fs::write(src_path, code.as_bytes()).context("failed to strip comments")?;
//
let dir = TempDir::new("dbg-swc").context("failed to create a temp directory")?;
let input = dir.path().join("input.js");
fs::copy(&src_path, &input).context("failed to copy")?;
fs::copy(src_path, &input).context("failed to copy")?;
let mut c = Command::new("creduce");
@ -90,7 +90,7 @@ impl ReduceCommand {
if let Some(1) = status.code() {
if self.remove {
fs::remove_file(&src_path).context("failed to remove")?;
fs::remove_file(src_path).context("failed to remove")?;
}
} else {
dbg!(&status, status.code());

View File

@ -579,7 +579,7 @@ impl SourceMapGenConfig for SwcSourceMapConfig<'_> {
_ => return f.to_string(),
};
let rel = pathdiff::diff_paths(&target, base_path);
let rel = pathdiff::diff_paths(target, base_path);
match rel {
Some(v) => {
let s = v.to_string_lossy().to_string();

View File

@ -336,7 +336,7 @@ fn unignore(path: &Path) {
create_dir_all(new_path.parent().unwrap()).expect("failed to create parent dir");
rename(&path, &new_path).expect("failed to rename");
rename(path, &new_path).expect("failed to rename");
}
fn test_file_with_opts(

View File

@ -41,7 +41,7 @@ impl Visit for AtRuleNoUnknown {
fn visit_at_rule(&mut self, at_rule: &AtRule) {
if let AtRuleName::Ident(Ident { value, .. }) = &at_rule.name {
if let Some(AtRulePrelude::ListOfComponentValues(_)) = at_rule.prelude.as_deref() {
if self.ignored.iter().all(|item| !item.is_match(&value)) {
if self.ignored.iter().all(|item| !item.is_match(value)) {
let message = format!("Unexpected unknown at-rule \"@{}\".", &value);
self.ctx.report(&at_rule.name, message);

View File

@ -1273,7 +1273,7 @@ where
// '+'? n <signed-integer>
// -n <signed-integer>
// <n-dimension> <signed-integer>
tok!("number") if dash_after_n == None => {
tok!("number") if dash_after_n.is_none() => {
let number = match bump!(self) {
Token::Number { value, raw, .. } => (value, raw),
_ => {
@ -1356,7 +1356,7 @@ where
}
// '+'? n
// -n
_ if dash_after_n == None => {}
_ if dash_after_n.is_none() => {}
_ => {
return Err(Error::new(span, ErrorKind::InvalidAnPlusBMicrosyntax));
}

View File

@ -2651,7 +2651,7 @@ where
if has_question_mark {
// 1. If there are any code points left in text, this is an invalid <urange>,
// and this algorithm must exit.
if next != None {
if next.is_some() {
return Err(Error::new(
span,
ErrorKind::Expected("no characters after '?' in unicode range"),
@ -2681,7 +2681,7 @@ where
// 4. If there are no code points left in text, The end value is the same as the
// start value. Exit this algorithm.
if next == None {
if next.is_none() {
return Ok(UnicodeRange {
span: span!(self, span.lo),
prefix,
@ -2735,7 +2735,7 @@ where
));
}
if chars.next() != None {
if chars.next().is_some() {
return Err(Error::new(
span,
ErrorKind::Expected("no characters after end in unicode range"),

View File

@ -88,7 +88,7 @@ fn do_test(entry: &Path, minify: bool) {
.expect("to_str() failed")
.to_string();
let input = read_to_string(&entry).unwrap();
let input = read_to_string(entry).unwrap();
let ignore = IGNORED_PASS_TESTS.contains(&&*file_name);

View File

@ -345,7 +345,7 @@ impl<I: Tokens> Parser<I> {
} else {
(None, false, false)
};
if accessibility == None && !is_override && !readonly {
if accessibility.is_none() && !is_override && !readonly {
let pat = self.parse_formal_param_pat()?;
Ok(ParamOrTsParamProp::Param(Param {
span: span!(self, param_start),

View File

@ -150,7 +150,7 @@ fn run_spec(file: &Path, output_json: &Path) {
// github actions.
let input = {
let mut buf = String::new();
File::open(&file).unwrap().read_to_string(&mut buf).unwrap();
File::open(file).unwrap().read_to_string(&mut buf).unwrap();
buf
};
@ -170,7 +170,7 @@ fn run_spec(file: &Path, output_json: &Path) {
serde_json::to_string_pretty(&program).expect("failed to serialize module as json");
if StdErr::from(json.clone())
.compare_to_file(&output_json)
.compare_to_file(output_json)
.is_err()
{
panic!()

View File

@ -248,8 +248,8 @@ fn identity_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> {
e.into_diagnostic(handler).emit();
}
let output = String::from_utf8_lossy(&*wr.0.read().unwrap()).to_string();
let expected = String::from_utf8_lossy(&*wr2.0.read().unwrap()).to_string();
let output = String::from_utf8_lossy(&wr.0.read().unwrap()).to_string();
let expected = String::from_utf8_lossy(&wr2.0.read().unwrap()).to_string();
if output == expected {
return Ok(());
}

View File

@ -692,7 +692,7 @@ where
super_is_callable_constructor: self.config.super_is_callable_constructor,
});
insert_this |= (mode == None && !is_always_initialized)
insert_this |= (mode.is_none() && !is_always_initialized)
|| mode == Some(SuperFoldingMode::Assign);
if insert_this {

View File

@ -733,7 +733,7 @@ fn test_fixture_inner<P>(
println!("----- {} -----", Color::Green.paint("Actual"));
let actual =
tester.apply_transform(tr, "input.js", syntax, &read_to_string(&input).unwrap())?;
tester.apply_transform(tr, "input.js", syntax, &read_to_string(input).unwrap())?;
match ::std::env::var("PRINT_HYGIENE") {
Ok(ref s) if s == "1" => {

View File

@ -36,7 +36,7 @@ where
b.iter(|| {
let module = module.clone();
let _ = helpers::HELPERS.set(&Default::default(), || {
helpers::HELPERS.set(&Default::default(), || {
let mut tr = tr();
black_box(module.fold_with(&mut tr));
@ -79,7 +79,7 @@ fn common_typescript(b: &mut Bencher) {
b.iter(|| {
let module = module.clone();
let _ = helpers::HELPERS.set(&Default::default(), || {
helpers::HELPERS.set(&Default::default(), || {
black_box(module.fold_with(&mut strip(top_level_mark)));
});
});

View File

@ -224,7 +224,7 @@ fn identity(entry: PathBuf) {
emitter.emit_module(&module).unwrap();
}
let js_content = String::from_utf8_lossy(&*wr.0.read().unwrap()).to_string();
let js_content = String::from_utf8_lossy(&wr.0.read().unwrap()).to_string();
println!("---------------- JS ----------------\n\n{}", js_content);

View File

@ -945,7 +945,7 @@ pub trait ExprExt {
Expr::Tpl(..) | Expr::Object(ObjectLit { .. }) | Expr::Array(ArrayLit { .. }) => {
return (
Pure,
num_from_str(&*match self.as_pure_string(ctx) {
num_from_str(&match self.as_pure_string(ctx) {
Known(v) => v,
Unknown => return (MayBeImpure, Unknown),
}),

View File

@ -130,7 +130,7 @@ fn assert_flavor(flavor: Flavor, input: &Path, output_json_path: &Path) {
}
NormalizedOutput::from(actual_str)
.compare_to_file(&output_json_path)
.compare_to_file(output_json_path)
.unwrap();
Ok(())

View File

@ -181,7 +181,7 @@ where
/// Add node `n` to the graph.
pub fn add_node(&mut self, n: N) -> N {
self.nodes.entry(n).or_insert(Vec::new());
self.nodes.entry(n).or_default();
n
}

View File

@ -486,7 +486,7 @@ where
namespace,
tag_name,
..
}) if is_html_tag_name(*namespace, &**tag_name)
}) if is_html_tag_name(*namespace, tag_name)
&& !matches!(
&**tag_name,
"a" | "audio"

View File

@ -991,8 +991,7 @@ fn html5lib_test_tree_construction(input: PathBuf) {
.expect("failed to get relative filename")
.to_str()
.unwrap()
.replace('/', "_")
.replace('.', "_");
.replace(['/', '.'], "_");
let tests_base = tests_base.unwrap();
let dir = tests_base

View File

@ -63,7 +63,7 @@ pub fn find_executable(name: &str) -> Option<PathBuf> {
let path = env::var_os("PATH").and_then(|paths| {
env::split_paths(&paths)
.filter_map(|dir| {
let full_path = dir.join(&name);
let full_path = dir.join(name);
if full_path.is_file() {
Some(full_path)
} else {

View File

@ -144,8 +144,7 @@ pub fn expand(callee: &Ident, attr: Config) -> Result<Vec<ItemFn>, Error> {
RE.replace_all(
path_for_name
.to_string_lossy()
.replace('\\', "__")
.replace('/', "__")
.replace(['\\', '/'], "__")
.as_str(),
"_",
)