mirror of https://github.com/astral-sh/ruff
Remove generated TypeScript options (#1456)
This commit is contained in:
parent
9db825c731
commit
e9a4cb1c1d
|
|
@ -1 +0,0 @@
|
||||||
src/ruff_options.ts
|
|
||||||
|
|
@ -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<char>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "dummy-variable-rgx",
|
|
||||||
"default": '"^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"',
|
|
||||||
"type": 'Regex',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "extend-ignore",
|
|
||||||
"default": '[]',
|
|
||||||
"type": 'Vec<CheckCodePrefix>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "extend-select",
|
|
||||||
"default": '[]',
|
|
||||||
"type": 'Vec<CheckCodePrefix>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "external",
|
|
||||||
"default": '[]',
|
|
||||||
"type": 'Vec<String>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fix-only",
|
|
||||||
"default": 'false',
|
|
||||||
"type": 'bool',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ignore",
|
|
||||||
"default": '[]',
|
|
||||||
"type": 'Vec<CheckCodePrefix>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "line-length",
|
|
||||||
"default": '88',
|
|
||||||
"type": 'usize',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "required-version",
|
|
||||||
"default": 'None',
|
|
||||||
"type": 'String',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "select",
|
|
||||||
"default": '["E", "F"]',
|
|
||||||
"type": 'Vec<CheckCodePrefix>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "target-version",
|
|
||||||
"default": '"py310"',
|
|
||||||
"type": 'PythonVersion',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "unfixable",
|
|
||||||
"default": '[]',
|
|
||||||
"type": 'Vec<CheckCodePrefix>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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<String>',
|
|
||||||
},
|
|
||||||
]},
|
|
||||||
{"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<String, String>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "extend-aliases",
|
|
||||||
"default": '{}',
|
|
||||||
"type": 'FxHashMap<String, String>',
|
|
||||||
},
|
|
||||||
]},
|
|
||||||
{"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<String>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "force-single-line",
|
|
||||||
"default": 'false',
|
|
||||||
"type": 'bool',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "force-wrap-aliases",
|
|
||||||
"default": 'false',
|
|
||||||
"type": 'bool',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "known-first-party",
|
|
||||||
"default": '[]',
|
|
||||||
"type": 'Vec<String>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "known-third-party",
|
|
||||||
"default": '[]',
|
|
||||||
"type": 'Vec<String>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "single-line-exclusions",
|
|
||||||
"default": '[]',
|
|
||||||
"type": 'Vec<String>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"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<String>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "ignore-names",
|
|
||||||
"default": '["setUp", "tearDown", "setUpClass", "tearDownClass", "setUpModule", "tearDownModule", "asyncSetUp", "asyncTearDown", "setUpTestData", "failureException", "longMessage", "maxDiff"]',
|
|
||||||
"type": 'Vec<String>',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "staticmethod-decorators",
|
|
||||||
"default": '["staticmethod"]',
|
|
||||||
"type": 'Vec<String>',
|
|
||||||
},
|
|
||||||
]},
|
|
||||||
{"name": "pydocstyle", "fields": [
|
|
||||||
{
|
|
||||||
"name": "convention",
|
|
||||||
"default": 'None',
|
|
||||||
"type": 'Convention',
|
|
||||||
},
|
|
||||||
]},
|
|
||||||
{"name": "pyupgrade", "fields": [
|
|
||||||
{
|
|
||||||
"name": "keep-runtime-typing",
|
|
||||||
"default": 'false',
|
|
||||||
"type": 'bool',
|
|
||||||
},
|
|
||||||
]},
|
|
||||||
];
|
|
||||||
|
|
@ -4,8 +4,7 @@ use anyhow::Result;
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
generate_check_code_prefix, generate_json_schema, generate_options,
|
generate_check_code_prefix, generate_json_schema, generate_options, generate_rules_table,
|
||||||
generate_playground_options, generate_rules_table,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
|
|
@ -28,8 +27,5 @@ pub fn main(cli: &Cli) -> Result<()> {
|
||||||
generate_options::main(&generate_options::Cli {
|
generate_options::main(&generate_options::Cli {
|
||||||
dry_run: cli.dry_run,
|
dry_run: cli.dry_run,
|
||||||
})?;
|
})?;
|
||||||
generate_playground_options::main(&generate_playground_options::Cli {
|
|
||||||
dry_run: cli.dry_run,
|
|
||||||
})?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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(())
|
|
||||||
}
|
|
||||||
|
|
@ -15,7 +15,6 @@ pub mod generate_all;
|
||||||
pub mod generate_check_code_prefix;
|
pub mod generate_check_code_prefix;
|
||||||
pub mod generate_json_schema;
|
pub mod generate_json_schema;
|
||||||
pub mod generate_options;
|
pub mod generate_options;
|
||||||
pub mod generate_playground_options;
|
|
||||||
pub mod generate_rules_table;
|
pub mod generate_rules_table;
|
||||||
pub mod print_ast;
|
pub mod print_ast;
|
||||||
pub mod print_cst;
|
pub mod print_cst;
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,7 @@ use anyhow::Result;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use ruff_dev::{
|
use ruff_dev::{
|
||||||
generate_all, generate_check_code_prefix, generate_json_schema, generate_options,
|
generate_all, generate_check_code_prefix, generate_json_schema, generate_options,
|
||||||
generate_playground_options, generate_rules_table, print_ast, print_cst, print_tokens,
|
generate_rules_table, print_ast, print_cst, print_tokens, round_trip,
|
||||||
round_trip,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
|
@ -39,9 +38,6 @@ enum Commands {
|
||||||
GenerateRulesTable(generate_rules_table::Cli),
|
GenerateRulesTable(generate_rules_table::Cli),
|
||||||
/// Generate a Markdown-compatible listing of configuration options.
|
/// Generate a Markdown-compatible listing of configuration options.
|
||||||
GenerateOptions(generate_options::Cli),
|
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.
|
/// Print the AST for a given Python file.
|
||||||
PrintAST(print_ast::Cli),
|
PrintAST(print_ast::Cli),
|
||||||
/// Print the LibCST CST for a given Python file.
|
/// 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::GenerateJSONSchema(args) => generate_json_schema::main(args)?,
|
||||||
Commands::GenerateRulesTable(args) => generate_rules_table::main(args)?,
|
Commands::GenerateRulesTable(args) => generate_rules_table::main(args)?,
|
||||||
Commands::GenerateOptions(args) => generate_options::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::PrintAST(args) => print_ast::main(args)?,
|
||||||
Commands::PrintCST(args) => print_cst::main(args)?,
|
Commands::PrintCST(args) => print_cst::main(args)?,
|
||||||
Commands::PrintTokens(args) => print_tokens::main(args)?,
|
Commands::PrintTokens(args) => print_tokens::main(args)?,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue