Add .gitignore to .ruff_cache (#208)

This commit is contained in:
Charlie Marsh 2022-09-15 20:40:06 -04:00 committed by GitHub
parent 4ac4e8c991
commit 6bbf3f46c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View File

@ -1,8 +1,10 @@
use std::collections::hash_map::DefaultHasher;
use std::fs::Metadata;
use std::fs::{File, Metadata};
use std::hash::{Hash, Hasher};
use std::io::Write;
use std::path::Path;
use anyhow::Result;
use cacache::Error::EntryNotFound;
use filetime::FileTime;
use log::error;
@ -83,6 +85,15 @@ fn cache_key(path: &Path, settings: &Settings, autofix: &fixer::Mode) -> String
)
}
pub fn init() -> Result<()> {
let gitignore_path = Path::new(cache_dir()).join(".gitignore");
if gitignore_path.exists() {
return Ok(());
}
let mut file = File::create(gitignore_path)?;
file.write_all(b"*").map_err(|e| e.into())
}
pub fn get(
path: &Path,
metadata: &Metadata,

View File

@ -2,7 +2,7 @@ extern crate core;
mod ast;
mod autofix;
mod cache;
pub mod cache;
pub mod check_ast;
mod check_lines;
pub mod checks;

View File

@ -12,6 +12,7 @@ use notify::{raw_watcher, RecursiveMode, Watcher};
use rayon::prelude::*;
use walkdir::DirEntry;
use ::ruff::cache;
use ::ruff::checks::CheckCode;
use ::ruff::checks::CheckKind;
use ::ruff::fs::iter_python_files;
@ -168,6 +169,8 @@ fn inner_main() -> Result<ExitCode> {
settings.extend_exclude = cli.extend_exclude;
}
cache::init()?;
if cli.watch {
if cli.fix {
println!("Warning: --fix is not enabled in watch mode.");