diff --git a/playground/.prettierignore b/playground/.prettierignore deleted file mode 100644 index 0333a638eb..0000000000 --- a/playground/.prettierignore +++ /dev/null @@ -1 +0,0 @@ -src/ruff_options.ts diff --git a/playground/src/ruff_options.ts b/playground/src/ruff_options.ts deleted file mode 100644 index 181736f5b9..0000000000 --- a/playground/src/ruff_options.ts +++ /dev/null @@ -1,244 +0,0 @@ - -// This file is auto-generated by `cargo dev generate-playground-options`. -export interface OptionGroup { - name: string; - fields: { - name: string; - default: string; - type: string; - }[]; -}; - -export const AVAILABLE_OPTIONS: OptionGroup[] = [ - {"name": "globals", "fields": [ - { - "name": "allowed-confusables", - "default": '[]', - "type": 'Vec', - }, - { - "name": "dummy-variable-rgx", - "default": '"^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"', - "type": 'Regex', - }, - { - "name": "extend-ignore", - "default": '[]', - "type": 'Vec', - }, - { - "name": "extend-select", - "default": '[]', - "type": 'Vec', - }, - { - "name": "external", - "default": '[]', - "type": 'Vec', - }, - { - "name": "fix-only", - "default": 'false', - "type": 'bool', - }, - { - "name": "ignore", - "default": '[]', - "type": 'Vec', - }, - { - "name": "line-length", - "default": '88', - "type": 'usize', - }, - { - "name": "required-version", - "default": 'None', - "type": 'String', - }, - { - "name": "select", - "default": '["E", "F"]', - "type": 'Vec', - }, - { - "name": "target-version", - "default": '"py310"', - "type": 'PythonVersion', - }, - { - "name": "unfixable", - "default": '[]', - "type": 'Vec', - }, - { - "name": "update-check", - "default": 'true', - "type": 'bool', - }, - ]}, - {"name": "flake8-annotations", "fields": [ - { - "name": "allow-star-arg-any", - "default": 'false', - "type": 'bool', - }, - { - "name": "mypy-init-return", - "default": 'false', - "type": 'bool', - }, - { - "name": "suppress-dummy-args", - "default": 'false', - "type": 'bool', - }, - { - "name": "suppress-none-returning", - "default": 'false', - "type": 'bool', - }, - ]}, - {"name": "flake8-bugbear", "fields": [ - { - "name": "extend-immutable-calls", - "default": '[]', - "type": 'Vec', - }, - ]}, - {"name": "flake8-errmsg", "fields": [ - { - "name": "max-string-length", - "default": '0', - "type": 'usize', - }, - ]}, - {"name": "flake8-import-conventions", "fields": [ - { - "name": "aliases", - "default": '{"altair": "alt", "matplotlib.pyplot": "plt", "numpy": "np", "pandas": "pd", "seaborn": "sns"}', - "type": 'FxHashMap', - }, - { - "name": "extend-aliases", - "default": '{}', - "type": 'FxHashMap', - }, - ]}, - {"name": "flake8-quotes", "fields": [ - { - "name": "avoid-escape", - "default": 'true', - "type": 'bool', - }, - { - "name": "docstring-quotes", - "default": '"double"', - "type": 'Quote', - }, - { - "name": "inline-quotes", - "default": '"double"', - "type": 'Quote', - }, - { - "name": "multiline-quotes", - "default": '"double"', - "type": 'Quote', - }, - ]}, - {"name": "flake8-tidy-imports", "fields": [ - { - "name": "ban-relative-imports", - "default": '"parents"', - "type": 'Strictness', - }, - ]}, - {"name": "flake8-unused-arguments", "fields": [ - { - "name": "ignore-variadic-names", - "default": 'false', - "type": 'bool', - }, - ]}, - {"name": "isort", "fields": [ - { - "name": "combine-as-imports", - "default": 'false', - "type": 'bool', - }, - { - "name": "extra-standard-library", - "default": '[]', - "type": 'Vec', - }, - { - "name": "force-single-line", - "default": 'false', - "type": 'bool', - }, - { - "name": "force-wrap-aliases", - "default": 'false', - "type": 'bool', - }, - { - "name": "known-first-party", - "default": '[]', - "type": 'Vec', - }, - { - "name": "known-third-party", - "default": '[]', - "type": 'Vec', - }, - { - "name": "single-line-exclusions", - "default": '[]', - "type": 'Vec', - }, - { - "name": "split-on-trailing-comma", - "default": 'true', - "type": 'bool', - }, - ]}, - {"name": "mccabe", "fields": [ - { - "name": "max-complexity", - "default": '10', - "type": 'usize', - }, - ]}, - {"name": "pep8-naming", "fields": [ - { - "name": "classmethod-decorators", - "default": '["classmethod"]', - "type": 'Vec', - }, - { - "name": "ignore-names", - "default": '["setUp", "tearDown", "setUpClass", "tearDownClass", "setUpModule", "tearDownModule", "asyncSetUp", "asyncTearDown", "setUpTestData", "failureException", "longMessage", "maxDiff"]', - "type": 'Vec', - }, - { - "name": "staticmethod-decorators", - "default": '["staticmethod"]', - "type": 'Vec', - }, - ]}, - {"name": "pydocstyle", "fields": [ - { - "name": "convention", - "default": 'None', - "type": 'Convention', - }, - ]}, - {"name": "pyupgrade", "fields": [ - { - "name": "keep-runtime-typing", - "default": 'false', - "type": 'bool', - }, - ]}, -]; \ No newline at end of file diff --git a/ruff_dev/src/generate_all.rs b/ruff_dev/src/generate_all.rs index 2e00c444de..7f5dfa127f 100644 --- a/ruff_dev/src/generate_all.rs +++ b/ruff_dev/src/generate_all.rs @@ -4,8 +4,7 @@ use anyhow::Result; use clap::Args; use crate::{ - generate_check_code_prefix, generate_json_schema, generate_options, - generate_playground_options, generate_rules_table, + generate_check_code_prefix, generate_json_schema, generate_options, generate_rules_table, }; #[derive(Args)] @@ -28,8 +27,5 @@ pub fn main(cli: &Cli) -> Result<()> { generate_options::main(&generate_options::Cli { dry_run: cli.dry_run, })?; - generate_playground_options::main(&generate_playground_options::Cli { - dry_run: cli.dry_run, - })?; Ok(()) } diff --git a/ruff_dev/src/generate_playground_options.rs b/ruff_dev/src/generate_playground_options.rs deleted file mode 100644 index 8f833171fb..0000000000 --- a/ruff_dev/src/generate_playground_options.rs +++ /dev/null @@ -1,142 +0,0 @@ -//! Generate typescript file defining options to be used by the web playground. - -use std::fs::OpenOptions; -use std::io::Write; -use std::path::PathBuf; - -use anyhow::Result; -use clap::Args; -use itertools::Itertools; -use ruff::settings::options::Options; -use ruff::settings::options_base::{ConfigurationOptions, OptionEntry, OptionField}; - -#[derive(Args)] -pub struct Cli { - /// Write the generated table to stdout (rather than to `TODO`). - #[arg(long)] - pub(crate) dry_run: bool, -} - -fn emit_field(output: &mut String, field: &OptionField) { - output.push_str(&textwrap::indent( - &textwrap::dedent(&format!( - " - {{ - \"name\": \"{}\", - \"default\": '{}', - \"type\": '{}', - }},", - field.name, field.default, field.value_type - )), - " ", - )); -} - -pub fn main(cli: &Cli) -> Result<()> { - let mut output = String::new(); - - // Generate all the top-level fields. - output.push_str(&format!("{{\"name\": \"{}\", \"fields\": [", "globals")); - for field in Options::get_available_options() - .into_iter() - .filter_map(|entry| { - if let OptionEntry::Field(field) = entry { - Some(field) - } else { - None - } - }) - // Filter out options that don't make sense in the playground. - .filter(|field| { - !matches!( - field.name, - "src" - | "fix" - | "format" - | "exclude" - | "extend" - | "extend-exclude" - | "fixable" - | "force-exclude" - | "ignore-init-module-imports" - | "respect-gitignore" - | "show-source" - | "cache-dir" - | "per-file-ignores" - ) - }) - .sorted_by_key(|field| field.name) - { - emit_field(&mut output, &field); - } - output.push_str("\n]},\n"); - - // Generate all the sub-groups. - for group in Options::get_available_options() - .into_iter() - .filter_map(|entry| { - if let OptionEntry::Group(group) = entry { - Some(group) - } else { - None - } - }) - .sorted_by_key(|group| group.name) - { - output.push_str(&format!("{{\"name\": \"{}\", \"fields\": [", group.name)); - for field in group - .fields - .iter() - .filter_map(|entry| { - if let OptionEntry::Field(field) = entry { - Some(field) - } else { - None - } - }) - .sorted_by_key(|field| field.name) - { - emit_field(&mut output, field); - } - output.push_str("\n]},\n"); - } - - let prefix = textwrap::dedent( - r" - // This file is auto-generated by `cargo dev generate-playground-options`. - export interface OptionGroup { - name: string; - fields: { - name: string; - default: string; - type: string; - }[]; - }; - - export const AVAILABLE_OPTIONS: OptionGroup[] = [ - ", - ); - let postfix = "];"; - - if cli.dry_run { - print!("{output}"); - } else { - let file = PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .parent() - .expect("Failed to find root directory") - .join("playground") - .join("src") - .join("ruff_options.ts"); - - let mut f = OpenOptions::new() - .create(true) - .write(true) - .truncate(true) - .open(file)?; - write!(f, "{prefix}")?; - write!(f, "{}", textwrap::indent(&output, " "))?; - write!(f, "{postfix}")?; - } - - Ok(()) -} diff --git a/ruff_dev/src/lib.rs b/ruff_dev/src/lib.rs index 4c09edf226..0be6f5d9e8 100644 --- a/ruff_dev/src/lib.rs +++ b/ruff_dev/src/lib.rs @@ -15,7 +15,6 @@ pub mod generate_all; pub mod generate_check_code_prefix; pub mod generate_json_schema; pub mod generate_options; -pub mod generate_playground_options; pub mod generate_rules_table; pub mod print_ast; pub mod print_cst; diff --git a/ruff_dev/src/main.rs b/ruff_dev/src/main.rs index 67ae09b200..255a3065f5 100644 --- a/ruff_dev/src/main.rs +++ b/ruff_dev/src/main.rs @@ -15,8 +15,7 @@ use anyhow::Result; use clap::{Parser, Subcommand}; use ruff_dev::{ generate_all, generate_check_code_prefix, generate_json_schema, generate_options, - generate_playground_options, generate_rules_table, print_ast, print_cst, print_tokens, - round_trip, + generate_rules_table, print_ast, print_cst, print_tokens, round_trip, }; #[derive(Parser)] @@ -39,9 +38,6 @@ enum Commands { GenerateRulesTable(generate_rules_table::Cli), /// Generate a Markdown-compatible listing of configuration options. GenerateOptions(generate_options::Cli), - /// Generate typescript file defining options to be used by the web - /// playground. - GeneratePlaygroundOptions(generate_playground_options::Cli), /// Print the AST for a given Python file. PrintAST(print_ast::Cli), /// Print the LibCST CST for a given Python file. @@ -60,7 +56,6 @@ fn main() -> Result<()> { Commands::GenerateJSONSchema(args) => generate_json_schema::main(args)?, Commands::GenerateRulesTable(args) => generate_rules_table::main(args)?, Commands::GenerateOptions(args) => generate_options::main(args)?, - Commands::GeneratePlaygroundOptions(args) => generate_playground_options::main(args)?, Commands::PrintAST(args) => print_ast::main(args)?, Commands::PrintCST(args) => print_cst::main(args)?, Commands::PrintTokens(args) => print_tokens::main(args)?,