mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
Disallow unreachable_pub
(#4314)
This commit is contained in:
parent
97802e7466
commit
c10a4535b9
444 changed files with 1376 additions and 1106 deletions
|
@ -162,7 +162,7 @@ fn cache_key(
|
|||
|
||||
#[allow(dead_code)]
|
||||
/// Initialize the cache at the specified `Path`.
|
||||
pub fn init(path: &Path) -> Result<()> {
|
||||
pub(crate) fn init(path: &Path) -> Result<()> {
|
||||
// Create the cache directories.
|
||||
fs::create_dir_all(path.join(content_dir()))?;
|
||||
|
||||
|
@ -197,7 +197,7 @@ fn del_sync(cache_dir: &Path, key: u64) -> Result<(), std::io::Error> {
|
|||
}
|
||||
|
||||
/// Get a value from the cache.
|
||||
pub fn get(
|
||||
pub(crate) fn get(
|
||||
path: &Path,
|
||||
package: Option<&Path>,
|
||||
metadata: &fs::Metadata,
|
||||
|
@ -246,7 +246,7 @@ pub fn get(
|
|||
}
|
||||
|
||||
/// Set a value in the cache.
|
||||
pub fn set(
|
||||
pub(crate) fn set(
|
||||
path: &Path,
|
||||
package: Option<&Path>,
|
||||
metadata: &fs::Metadata,
|
||||
|
@ -265,7 +265,12 @@ pub fn set(
|
|||
}
|
||||
|
||||
/// Delete a value from the cache.
|
||||
pub fn del(path: &Path, package: Option<&Path>, metadata: &fs::Metadata, settings: &AllSettings) {
|
||||
pub(crate) fn del(
|
||||
path: &Path,
|
||||
package: Option<&Path>,
|
||||
metadata: &fs::Metadata,
|
||||
settings: &AllSettings,
|
||||
) {
|
||||
drop(del_sync(
|
||||
&settings.cli.cache_dir,
|
||||
cache_key(path, package, metadata, &settings.lib),
|
||||
|
|
|
@ -13,7 +13,7 @@ use ruff::{packaging, resolver, warn_user_once};
|
|||
use crate::args::Overrides;
|
||||
|
||||
/// Add `noqa` directives to a collection of files.
|
||||
pub fn add_noqa(
|
||||
pub(crate) fn add_noqa(
|
||||
files: &[PathBuf],
|
||||
pyproject_config: &PyprojectConfig,
|
||||
overrides: &Overrides,
|
||||
|
|
|
@ -11,7 +11,7 @@ use ruff::logging::LogLevel;
|
|||
use ruff_cache::CACHE_DIR_NAME;
|
||||
|
||||
/// Clear any caches in the current directory or any subdirectories.
|
||||
pub fn clean(level: LogLevel) -> Result<()> {
|
||||
pub(crate) fn clean(level: LogLevel) -> Result<()> {
|
||||
let mut stderr = BufWriter::new(io::stderr().lock());
|
||||
for entry in WalkDir::new(&*path_dedot::CWD)
|
||||
.into_iter()
|
||||
|
|
|
@ -25,7 +25,7 @@ struct LinterCategoryInfo {
|
|||
name: &'static str,
|
||||
}
|
||||
|
||||
pub fn linter(format: HelpFormat) -> Result<()> {
|
||||
pub(crate) fn linter(format: HelpFormat) -> Result<()> {
|
||||
let mut stdout = BufWriter::new(io::stdout().lock());
|
||||
let mut output = String::new();
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
pub mod add_noqa;
|
||||
pub mod clean;
|
||||
pub mod config;
|
||||
pub mod linter;
|
||||
pub mod rule;
|
||||
pub mod run;
|
||||
pub mod run_stdin;
|
||||
pub mod show_files;
|
||||
pub mod show_settings;
|
||||
pub(crate) mod add_noqa;
|
||||
pub(crate) mod clean;
|
||||
pub(crate) mod config;
|
||||
pub(crate) mod linter;
|
||||
pub(crate) mod rule;
|
||||
pub(crate) mod run;
|
||||
pub(crate) mod run_stdin;
|
||||
pub(crate) mod show_files;
|
||||
pub(crate) mod show_settings;
|
||||
|
|
|
@ -16,7 +16,7 @@ struct Explanation<'a> {
|
|||
}
|
||||
|
||||
/// Explain a `Rule` to the user.
|
||||
pub fn rule(rule: Rule, format: HelpFormat) -> Result<()> {
|
||||
pub(crate) fn rule(rule: Rule, format: HelpFormat) -> Result<()> {
|
||||
let (linter, _) = Linter::parse_code(&rule.noqa_code().to_string()).unwrap();
|
||||
let mut stdout = BufWriter::new(io::stdout().lock());
|
||||
let mut output = String::new();
|
||||
|
|
|
@ -25,7 +25,7 @@ use crate::diagnostics::Diagnostics;
|
|||
use crate::panic::catch_unwind;
|
||||
|
||||
/// Run the linter over a collection of files.
|
||||
pub fn run(
|
||||
pub(crate) fn run(
|
||||
files: &[PathBuf],
|
||||
pyproject_config: &PyprojectConfig,
|
||||
overrides: &Overrides,
|
||||
|
|
|
@ -18,7 +18,7 @@ fn read_from_stdin() -> Result<String> {
|
|||
}
|
||||
|
||||
/// Run the linter over a single file, read from `stdin`.
|
||||
pub fn run_stdin(
|
||||
pub(crate) fn run_stdin(
|
||||
filename: Option<&Path>,
|
||||
pyproject_config: &PyprojectConfig,
|
||||
overrides: &Overrides,
|
||||
|
|
|
@ -10,7 +10,7 @@ use ruff::{resolver, warn_user_once};
|
|||
use crate::args::Overrides;
|
||||
|
||||
/// Show the list of files to be checked based on current settings.
|
||||
pub fn show_files(
|
||||
pub(crate) fn show_files(
|
||||
files: &[PathBuf],
|
||||
pyproject_config: &PyprojectConfig,
|
||||
overrides: &Overrides,
|
||||
|
|
|
@ -10,7 +10,7 @@ use ruff::resolver::PyprojectConfig;
|
|||
use crate::args::Overrides;
|
||||
|
||||
/// Print the user-facing configuration settings.
|
||||
pub fn show_settings(
|
||||
pub(crate) fn show_settings(
|
||||
files: &[PathBuf],
|
||||
pyproject_config: &PyprojectConfig,
|
||||
overrides: &Overrides,
|
||||
|
|
|
@ -25,17 +25,17 @@ use ruff_python_ast::source_code::{LineIndex, SourceCode, SourceFileBuilder};
|
|||
use crate::cache;
|
||||
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
pub struct Diagnostics {
|
||||
pub messages: Vec<Message>,
|
||||
pub fixed: FxHashMap<String, FixTable>,
|
||||
pub imports: ImportMap,
|
||||
pub(crate) struct Diagnostics {
|
||||
pub(crate) messages: Vec<Message>,
|
||||
pub(crate) fixed: FxHashMap<String, FixTable>,
|
||||
pub(crate) imports: ImportMap,
|
||||
/// Jupyter notebook indexing table for each input file that is a jupyter notebook
|
||||
/// so we can rewrite the diagnostics in the end
|
||||
pub jupyter_index: FxHashMap<String, JupyterIndex>,
|
||||
pub(crate) jupyter_index: FxHashMap<String, JupyterIndex>,
|
||||
}
|
||||
|
||||
impl Diagnostics {
|
||||
pub fn new(messages: Vec<Message>, imports: ImportMap) -> Self {
|
||||
pub(crate) fn new(messages: Vec<Message>, imports: ImportMap) -> Self {
|
||||
Self {
|
||||
messages,
|
||||
fixed: FxHashMap::default(),
|
||||
|
@ -100,7 +100,7 @@ fn load_jupyter_notebook(path: &Path) -> Result<(String, JupyterIndex), Box<Diag
|
|||
}
|
||||
|
||||
/// Lint the source code at the given `Path`.
|
||||
pub fn lint_path(
|
||||
pub(crate) fn lint_path(
|
||||
path: &Path,
|
||||
package: Option<&Path>,
|
||||
settings: &AllSettings,
|
||||
|
@ -226,7 +226,7 @@ pub fn lint_path(
|
|||
|
||||
/// Generate `Diagnostic`s from source code content derived from
|
||||
/// stdin.
|
||||
pub fn lint_stdin(
|
||||
pub(crate) fn lint_stdin(
|
||||
path: Option<&Path>,
|
||||
package: Option<&Path>,
|
||||
contents: &str,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#[derive(Default, Debug)]
|
||||
pub(crate) struct PanicError {
|
||||
pub info: String,
|
||||
pub backtrace: Option<std::backtrace::Backtrace>,
|
||||
pub(crate) info: String,
|
||||
pub(crate) backtrace: Option<std::backtrace::Backtrace>,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for PanicError {
|
||||
|
|
|
@ -76,7 +76,7 @@ pub(crate) struct Printer {
|
|||
}
|
||||
|
||||
impl Printer {
|
||||
pub const fn new(
|
||||
pub(crate) const fn new(
|
||||
format: SerializationFormat,
|
||||
log_level: LogLevel,
|
||||
autofix_level: flags::FixMode,
|
||||
|
@ -93,7 +93,7 @@ impl Printer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn write_to_user(&self, message: &str) {
|
||||
pub(crate) fn write_to_user(&self, message: &str) {
|
||||
if self.log_level >= LogLevel::Default {
|
||||
notify_user!("{}", message);
|
||||
}
|
||||
|
@ -153,7 +153,11 @@ impl Printer {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write_once(&self, diagnostics: &Diagnostics, writer: &mut impl Write) -> Result<()> {
|
||||
pub(crate) fn write_once(
|
||||
&self,
|
||||
diagnostics: &Diagnostics,
|
||||
writer: &mut impl Write,
|
||||
) -> Result<()> {
|
||||
if matches!(self.log_level, LogLevel::Silent) {
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -240,7 +244,7 @@ impl Printer {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write_statistics(&self, diagnostics: &Diagnostics) -> Result<()> {
|
||||
pub(crate) fn write_statistics(&self, diagnostics: &Diagnostics) -> Result<()> {
|
||||
let statistics: Vec<ExpandedStatistics> = diagnostics
|
||||
.messages
|
||||
.iter()
|
||||
|
@ -335,7 +339,7 @@ impl Printer {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn write_continuously(&self, diagnostics: &Diagnostics) -> Result<()> {
|
||||
pub(crate) fn write_continuously(&self, diagnostics: &Diagnostics) -> Result<()> {
|
||||
if matches!(self.log_level, LogLevel::Silent) {
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -369,7 +373,7 @@ impl Printer {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn clear_screen() -> Result<()> {
|
||||
pub(crate) fn clear_screen() -> Result<()> {
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
clearscreen::clear()?;
|
||||
Ok(())
|
||||
|
|
|
@ -14,7 +14,7 @@ use crate::args::Overrides;
|
|||
|
||||
/// Resolve the relevant settings strategy and defaults for the current
|
||||
/// invocation.
|
||||
pub fn resolve(
|
||||
pub(crate) fn resolve(
|
||||
isolated: bool,
|
||||
config: Option<&Path>,
|
||||
overrides: &Overrides,
|
||||
|
|
|
@ -24,7 +24,7 @@ struct Blackd {
|
|||
const BIN_NAME: &str = "ruff";
|
||||
|
||||
impl Blackd {
|
||||
pub fn new() -> Result<Self> {
|
||||
pub(crate) fn new() -> Result<Self> {
|
||||
// Get free TCP port to run on
|
||||
let address = TcpListener::bind(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 0))?.local_addr()?;
|
||||
|
||||
|
@ -63,7 +63,7 @@ impl Blackd {
|
|||
}
|
||||
|
||||
/// Format given code with blackd.
|
||||
pub fn check(&self, code: &[u8]) -> Result<Vec<u8>> {
|
||||
pub(crate) fn check(&self, code: &[u8]) -> Result<Vec<u8>> {
|
||||
match self
|
||||
.client
|
||||
.post(&format!("http://{}/", self.address))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue