Disallow unreachable_pub (#4314)

This commit is contained in:
Jonathan Plasse 2023-05-12 00:00:00 +02:00 committed by GitHub
parent 97802e7466
commit c10a4535b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
444 changed files with 1376 additions and 1106 deletions

View file

@ -4,16 +4,16 @@ use anyhow::Result;
use crate::{generate_cli_help, generate_docs, generate_json_schema};
pub const REGENERATE_ALL_COMMAND: &str = "cargo dev generate-all";
pub(crate) const REGENERATE_ALL_COMMAND: &str = "cargo dev generate-all";
#[derive(clap::Args)]
pub struct Args {
pub(crate) struct Args {
#[arg(long, default_value_t, value_enum)]
mode: Mode,
}
#[derive(Copy, Clone, PartialEq, Eq, clap::ValueEnum, Default)]
pub enum Mode {
pub(crate) enum Mode {
/// Update the content in the `configuration.md`.
#[default]
Write,
@ -31,7 +31,7 @@ impl Mode {
}
}
pub fn main(args: &Args) -> Result<()> {
pub(crate) fn main(args: &Args) -> Result<()> {
generate_json_schema::main(&generate_json_schema::Args { mode: args.mode })?;
generate_cli_help::main(&generate_cli_help::Args { mode: args.mode })?;
generate_docs::main(&generate_docs::Args {

View file

@ -19,7 +19,7 @@ const SUBCOMMAND_HELP_BEGIN_PRAGMA: &str = "<!-- Begin auto-generated subcommand
const SUBCOMMAND_HELP_END_PRAGMA: &str = "<!-- End auto-generated subcommand help. -->";
#[derive(clap::Args)]
pub struct Args {
pub(crate) struct Args {
#[arg(long, default_value_t, value_enum)]
pub(crate) mode: Mode,
}

View file

@ -15,13 +15,13 @@ use ruff_diagnostics::AutofixKind;
use crate::ROOT_DIR;
#[derive(clap::Args)]
pub struct Args {
pub(crate) struct Args {
/// Write the generated docs to stdout (rather than to the filesystem).
#[arg(long)]
pub(crate) dry_run: bool,
}
pub fn main(args: &Args) -> Result<()> {
pub(crate) fn main(args: &Args) -> Result<()> {
for rule in Rule::iter() {
if let Some(explanation) = rule.explanation() {
let mut output = String::new();

View file

@ -12,13 +12,13 @@ use schemars::schema_for;
use crate::ROOT_DIR;
#[derive(clap::Args)]
pub struct Args {
pub(crate) struct Args {
/// Write the generated table to stdout (rather than to `ruff.schema.json`).
#[arg(long, default_value_t, value_enum)]
pub(crate) mode: Mode,
}
pub fn main(args: &Args) -> Result<()> {
pub(crate) fn main(args: &Args) -> Result<()> {
let schema = schema_for!(Options);
let schema_string = serde_json::to_string_pretty(&schema).unwrap();
let filename = "ruff.schema.json";

View file

@ -24,7 +24,7 @@ fn emit_field(output: &mut String, name: &str, field: &OptionField, group_name:
output.push('\n');
}
pub fn generate() -> String {
pub(crate) fn generate() -> String {
let mut output: String = "### Top-level\n\n".into();
let sorted_options: Vec<_> = Options::metadata()

View file

@ -39,7 +39,7 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>,
table_out.push('\n');
}
pub fn generate() -> String {
pub(crate) fn generate() -> String {
// Generate the table string.
let mut table_out = format!("The {FIX_SYMBOL} emoji indicates that a rule is automatically fixable by the `--fix` command-line option.\n\n");
for linter in Linter::iter() {

View file

@ -8,13 +8,13 @@ use anyhow::Result;
use rustpython_parser as parser;
#[derive(clap::Args)]
pub struct Args {
pub(crate) struct Args {
/// Python file for which to generate the AST.
#[arg(required = true)]
file: PathBuf,
}
pub fn main(args: &Args) -> Result<()> {
pub(crate) fn main(args: &Args) -> Result<()> {
let contents = fs::read_to_string(&args.file)?;
let python_ast = parser::parse_program(&contents, &args.file.to_string_lossy())?;
println!("{python_ast:#?}");

View file

@ -7,13 +7,13 @@ use std::path::PathBuf;
use anyhow::{bail, Result};
#[derive(clap::Args)]
pub struct Args {
pub(crate) struct Args {
/// Python file for which to generate the CST.
#[arg(required = true)]
file: PathBuf,
}
pub fn main(args: &Args) -> Result<()> {
pub(crate) fn main(args: &Args) -> Result<()> {
let contents = fs::read_to_string(&args.file)?;
match libcst_native::parse_module(&contents, None) {
Ok(python_cst) => {

View file

@ -8,13 +8,13 @@ use anyhow::Result;
use rustpython_parser::{lexer, Mode};
#[derive(clap::Args)]
pub struct Args {
pub(crate) struct Args {
/// Python file for which to generate the AST.
#[arg(required = true)]
file: PathBuf,
}
pub fn main(args: &Args) -> Result<()> {
pub(crate) fn main(args: &Args) -> Result<()> {
let contents = fs::read_to_string(&args.file)?;
for (tok, range) in lexer::lex(&contents, Mode::Module).flatten() {
println!(

View file

@ -9,13 +9,13 @@ use anyhow::Result;
use ruff::round_trip;
#[derive(clap::Args)]
pub struct Args {
pub(crate) struct Args {
/// Python file to round-trip.
#[arg(required = true)]
file: PathBuf,
}
pub fn main(args: &Args) -> Result<()> {
pub(crate) fn main(args: &Args) -> Result<()> {
let contents = fs::read_to_string(&args.file)?;
println!("{}", round_trip(&contents, &args.file.to_string_lossy())?);
Ok(())