Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proc-macro to derive CheckCodePrefix #1656

Merged
merged 3 commits into from Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci.yaml
Expand Up @@ -42,9 +42,8 @@ jobs:
- run: cargo build --all --release
- run: ./target/release/ruff_dev generate-all
- run: git diff --quiet README.md || echo "::error file=README.md::This file is outdated. Run 'cargo +nightly dev generate-all'."
- run: git diff --quiet src/registry_gen.rs || echo "::error file=src/registry_gen.rs::This file is outdated. Run 'cargo +nightly dev generate-all'."
- run: git diff --quiet ruff.schema.json || echo "::error file=ruff.schema.json::This file is outdated. Run 'cargo +nightly dev generate-all'."
- run: git diff --exit-code -- README.md src/registry_gen.rs ruff.schema.json
- run: git diff --exit-code -- README.md ruff.schema.json

cargo-fmt:
name: "cargo fmt"
Expand Down
15 changes: 3 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake8_to_ruff/src/converter.rs
Expand Up @@ -7,7 +7,7 @@ use ruff::flake8_pytest_style::types::{
use ruff::flake8_quotes::settings::Quote;
use ruff::flake8_tidy_imports::settings::Strictness;
use ruff::pydocstyle::settings::Convention;
use ruff::registry_gen::CheckCodePrefix;
use ruff::registry::CheckCodePrefix;
use ruff::settings::options::Options;
use ruff::settings::pyproject::Pyproject;
use ruff::{
Expand Down Expand Up @@ -345,7 +345,7 @@ mod tests {

use anyhow::Result;
use ruff::pydocstyle::settings::Convention;
use ruff::registry_gen::CheckCodePrefix;
use ruff::registry::CheckCodePrefix;
use ruff::settings::options::Options;
use ruff::settings::pyproject::Pyproject;
use ruff::{flake8_quotes, pydocstyle};
Expand Down
5 changes: 2 additions & 3 deletions flake8_to_ruff/src/parser.rs
Expand Up @@ -3,8 +3,7 @@ use std::str::FromStr;
use anyhow::{bail, Result};
use once_cell::sync::Lazy;
use regex::Regex;
use ruff::registry::PREFIX_REDIRECTS;
use ruff::registry_gen::CheckCodePrefix;
use ruff::registry::{CheckCodePrefix, PREFIX_REDIRECTS};
use ruff::settings::types::PatternPrefixPair;
use rustc_hash::FxHashMap;

Expand Down Expand Up @@ -201,7 +200,7 @@ pub fn collect_per_file_ignores(
#[cfg(test)]
mod tests {
use anyhow::Result;
use ruff::registry_gen::CheckCodePrefix;
use ruff::registry::CheckCodePrefix;
use ruff::settings::types::PatternPrefixPair;

use crate::parser::{parse_files_to_codes_mapping, parse_prefix_codes, parse_strings};
Expand Down
2 changes: 1 addition & 1 deletion flake8_to_ruff/src/plugin.rs
Expand Up @@ -3,7 +3,7 @@ use std::fmt;
use std::str::FromStr;

use anyhow::anyhow;
use ruff::registry_gen::CheckCodePrefix;
use ruff::registry::CheckCodePrefix;

#[derive(Clone, Ord, PartialOrd, Eq, PartialEq)]
pub enum Plugin {
Expand Down
1 change: 0 additions & 1 deletion ruff_dev/Cargo.toml
Expand Up @@ -6,7 +6,6 @@ edition = "2021"
[dependencies]
anyhow = { version = "1.0.66" }
clap = { version = "4.0.1", features = ["derive"] }
codegen = { version = "0.2.0" }
itertools = { version = "0.10.5" }
libcst = { git = "https://github.com/charliermarsh/LibCST", rev = "f2f0b7a487a8725d161fe8b3ed73a6758b21e177" }
once_cell = { version = "1.16.0" }
Expand Down
8 changes: 1 addition & 7 deletions ruff_dev/src/generate_all.rs
Expand Up @@ -3,10 +3,7 @@
use anyhow::Result;
use clap::Args;

use crate::{
generate_check_code_prefix, generate_cli_help, generate_json_schema, generate_options,
generate_rules_table,
};
use crate::{generate_cli_help, generate_json_schema, generate_options, generate_rules_table};

#[derive(Args)]
pub struct Cli {
Expand All @@ -16,9 +13,6 @@ pub struct Cli {
}

pub fn main(cli: &Cli) -> Result<()> {
generate_check_code_prefix::main(&generate_check_code_prefix::Cli {
dry_run: cli.dry_run,
})?;
generate_json_schema::main(&generate_json_schema::Cli {
dry_run: cli.dry_run,
})?;
Expand Down
221 changes: 0 additions & 221 deletions ruff_dev/src/generate_check_code_prefix.rs

This file was deleted.

1 change: 0 additions & 1 deletion ruff_dev/src/lib.rs
Expand Up @@ -12,7 +12,6 @@
)]

pub mod generate_all;
pub mod generate_check_code_prefix;
pub mod generate_cli_help;
pub mod generate_json_schema;
pub mod generate_options;
Expand Down
7 changes: 2 additions & 5 deletions ruff_dev/src/main.rs
Expand Up @@ -14,8 +14,8 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use ruff_dev::{
generate_all, generate_check_code_prefix, generate_cli_help, generate_json_schema,
generate_options, generate_rules_table, print_ast, print_cst, print_tokens, round_trip,
generate_all, generate_cli_help, generate_json_schema, generate_options, generate_rules_table,
print_ast, print_cst, print_tokens, round_trip,
};

#[derive(Parser)]
Expand All @@ -30,8 +30,6 @@ struct Cli {
enum Commands {
/// Run all code and documentation generation steps.
GenerateAll(generate_all::Cli),
/// Generate the `CheckCodePrefix` enum.
GenerateCheckCodePrefix(generate_check_code_prefix::Cli),
/// Generate JSON schema for the TOML configuration file.
GenerateJSONSchema(generate_json_schema::Cli),
/// Generate a Markdown-compatible table of supported lint rules.
Expand All @@ -54,7 +52,6 @@ fn main() -> Result<()> {
let cli = Cli::parse();
match &cli.command {
Commands::GenerateAll(args) => generate_all::main(args)?,
Commands::GenerateCheckCodePrefix(args) => generate_check_code_prefix::main(args)?,
Commands::GenerateJSONSchema(args) => generate_json_schema::main(args)?,
Commands::GenerateRulesTable(args) => generate_rules_table::main(args)?,
Commands::GenerateOptions(args) => generate_options::main(args)?,
Expand Down
1 change: 1 addition & 0 deletions ruff_macros/Cargo.toml
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
proc-macro = true

[dependencies]
once_cell = { version = "1.17.0" }
proc-macro2 = { version = "1.0.47" }
quote = { version = "1.0.21" }
syn = { version = "1.0.103", features = ["derive", "parsing"] }
Expand Down