mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
Replace one more copy-pasted clippy_project_root fn
This commit is contained in:
parent
3036a2c30e
commit
3f2532b904
1 changed files with 3 additions and 20 deletions
|
@ -1,8 +1,9 @@
|
||||||
|
use clippy_dev::clippy_project_root;
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::Path;
|
||||||
|
|
||||||
pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str>) -> Result<(), io::Error> {
|
pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str>) -> Result<(), io::Error> {
|
||||||
let pass = pass.expect("`pass` argument is validated by clap");
|
let pass = pass.expect("`pass` argument is validated by clap");
|
||||||
|
@ -55,7 +56,7 @@ pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str
|
||||||
}
|
}
|
||||||
|
|
||||||
fn open_files(lint_name: &str) -> Result<(File, File), io::Error> {
|
fn open_files(lint_name: &str) -> Result<(File, File), io::Error> {
|
||||||
let project_root = project_root()?;
|
let project_root = clippy_project_root();
|
||||||
|
|
||||||
let test_file_path = project_root.join("tests").join("ui").join(format!("{}.rs", lint_name));
|
let test_file_path = project_root.join("tests").join("ui").join(format!("{}.rs", lint_name));
|
||||||
let lint_file_path = project_root
|
let lint_file_path = project_root
|
||||||
|
@ -82,24 +83,6 @@ fn open_files(lint_name: &str) -> Result<(File, File), io::Error> {
|
||||||
Ok((test_file, lint_file))
|
Ok((test_file, lint_file))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn project_root() -> Result<PathBuf, io::Error> {
|
|
||||||
let current_dir = std::env::current_dir()?;
|
|
||||||
for path in current_dir.ancestors() {
|
|
||||||
let result = std::fs::read_to_string(path.join("Cargo.toml"));
|
|
||||||
if let Err(err) = &result {
|
|
||||||
if err.kind() == io::ErrorKind::NotFound {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let content = result?;
|
|
||||||
if content.contains("[package]\nname = \"clippy\"") {
|
|
||||||
return Ok(path.to_path_buf());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(io::Error::new(ErrorKind::Other, "Unable to find project root"))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_camel_case(name: &str) -> String {
|
fn to_camel_case(name: &str) -> String {
|
||||||
name.split('_')
|
name.split('_')
|
||||||
.map(|s| {
|
.map(|s| {
|
||||||
|
|
Loading…
Add table
Reference in a new issue