From 6bbf3f46c40d6bfb83c2f81af4c3b840dd586099 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 15 Sep 2022 20:40:06 -0400 Subject: [PATCH] Add .gitignore to .ruff_cache (#208) --- src/cache.rs | 13 ++++++++++++- src/lib.rs | 2 +- src/main.rs | 3 +++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cache.rs b/src/cache.rs index b5f5df82af..b3678fc85c 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -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, diff --git a/src/lib.rs b/src/lib.rs index a14e6e2d3a..6f84021edb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/main.rs b/src/main.rs index baf52a96c4..aafb34c62f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 { settings.extend_exclude = cli.extend_exclude; } + cache::init()?; + if cli.watch { if cli.fix { println!("Warning: --fix is not enabled in watch mode.");