Skip to content

Commit

Permalink
Conaclos/xstack/lint rule scripts (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos authored Sep 15, 2023
1 parent 9c28238 commit accf9b7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 42 deletions.
28 changes: 7 additions & 21 deletions crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
// associated hyperlink, then a list of string literals defining the remaining
// categories without a link.

// PLEASE, DON'T EDIT THIS FILE BY HAND.
// Use `just new-lintrule` to create a new rule.
// lint rules are lexicographically sorted and
// must be between `define_categories! {\n` and `\n ;\n`.

define_categories! {
// Lint categories
// a11y
"lint/a11y/noAccessKey": "https://biomejs.dev/linter/rules/no-access-key",
"lint/a11y/noAutofocus": "https://biomejs.dev/linter/rules/no-autofocus",
"lint/a11y/noBlankTarget": "https://biomejs.dev/linter/rules/no-blank-target",
Expand All @@ -32,8 +35,6 @@ define_categories! {
"lint/a11y/useValidAnchor": "https://biomejs.dev/linter/rules/use-valid-anchor",
"lint/a11y/useValidAriaProps": "https://biomejs.dev/linter/rules/use-valid-aria-props",
"lint/a11y/useValidLang": "https://biomejs.dev/linter/rules/use-valid-lang",

// complexity
"lint/complexity/noExtraBooleanCast": "https://biomejs.dev/linter/rules/no-extra-boolean-cast",
"lint/complexity/noForEach": "https://biomejs.dev/linter/rules/no-for-each",
"lint/complexity/noMultipleSpacesInRegularExpressionLiterals": "https://biomejs.dev/linter/rules/no-multiple-spaces-in-regular-expression-literals",
Expand All @@ -50,16 +51,13 @@ define_categories! {
"lint/complexity/useOptionalChain": "https://biomejs.dev/linter/rules/use-optional-chain",
"lint/complexity/useSimpleNumberKeys": "https://biomejs.dev/linter/rules/use-simple-number-keys",
"lint/complexity/useSimplifiedLogicExpression": "https://biomejs.dev/linter/rules/use-simplified-logic-expression",

// correctness
"lint/correctness/noChildrenProp": "https://biomejs.dev/linter/rules/no-children-prop",
"lint/correctness/noConstAssign": "https://biomejs.dev/linter/rules/no-const-assign",
"lint/correctness/noConstructorReturn": "https://biomejs.dev/linter/rules/no-constructor-return",
"lint/correctness/noEmptyPattern": "https://biomejs.dev/linter/rules/no-empty-pattern",
"lint/correctness/noGlobalObjectCalls": "https://biomejs.dev/linter/rules/no-global-object-calls",
"lint/correctness/noInnerDeclarations": "https://biomejs.dev/linter/rules/no-inner-declarations",
"lint/correctness/noInvalidConstructorSuper": "https://biomejs.dev/linter/rules/no-invalid-constructor-super",
"lint/correctness/useIsNan": "https://biomejs.dev/linter/rules/use-is-nan",
"lint/correctness/noNewSymbol": "https://biomejs.dev/linter/rules/no-new-symbol",
"lint/correctness/noPrecisionLoss": "https://biomejs.dev/linter/rules/no-precision-loss",
"lint/correctness/noRenderReturnValue": "https://biomejs.dev/linter/rules/no-render-return-value",
Expand All @@ -76,14 +74,13 @@ define_categories! {
"lint/correctness/noUnusedVariables": "https://biomejs.dev/linter/rules/no-unused-variables",
"lint/correctness/noVoidElementsWithChildren": "https://biomejs.dev/linter/rules/no-void-elements-with-children",
"lint/correctness/noVoidTypeReturn": "https://biomejs.dev/linter/rules/no-void-type-return",
"lint/correctness/useIsNan": "https://biomejs.dev/linter/rules/use-is-nan",
"lint/correctness/useValidForDirection": "https://biomejs.dev/linter/rules/use-valid-for-direction",
"lint/correctness/useYield": "https://biomejs.dev/linter/rules/use-yield",

// nursery
"lint/nursery/noConfusingVoidType": "https://biomejs.dev/linter/rules/no-confusing-void-type",
"lint/nursery/noAccumulatingSpread": "https://biomejs.dev/linter/rules/no-accumulating-spread",
"lint/nursery/noAriaUnsupportedElements": "https://biomejs.dev/linter/rules/no-aria-unsupported-elements",
"lint/nursery/noBannedTypes": "https://biomejs.dev/linter/rules/no-banned-types",
"lint/nursery/noConfusingVoidType": "https://biomejs.dev/linter/rules/no-confusing-void-type",
"lint/nursery/noConstantCondition": "https://biomejs.dev/linter/rules/no-constant-condition",
"lint/nursery/noControlCharactersInRegex": "https://biomejs.dev/linter/rules/no-control-characters-in-regex",
"lint/nursery/noDuplicateJsonKeys": "https://biomejs.dev/linter/rules/no-duplicate-json-keys",
Expand Down Expand Up @@ -112,16 +109,9 @@ define_categories! {
"lint/nursery/useIsArray": "https://biomejs.dev/linter/rules/use-is-array",
"lint/nursery/useLiteralEnumMembers": "https://biomejs.dev/linter/rules/use-literal-enum-members",
"lint/nursery/useNamingConvention": "https://biomejs.dev/linter/rules/use-naming-convention",
// nursery end

// performance
"lint/performance/noDelete": "https://biomejs.dev/linter/rules/no-delete",

// security
"lint/security/noDangerouslySetInnerHtml": "https://biomejs.dev/linter/rules/no-dangerously-set-inner-html",
"lint/security/noDangerouslySetInnerHtmlWithChildren": "https://biomejs.dev/linter/rules/no-dangerously-set-inner-html-with-children",

// style
"lint/style/noArguments": "https://biomejs.dev/linter/rules/no-arguments",
"lint/style/noCommaOperator": "https://biomejs.dev/linter/rules/no-comma-operator",
"lint/style/noImplicitBoolean": "https://biomejs.dev/linter/rules/no-implicit-boolean",
Expand All @@ -148,8 +138,6 @@ define_categories! {
"lint/style/useSingleVarDeclarator": "https://biomejs.dev/linter/rules/use-single-var-declarator",
"lint/style/useTemplate": "https://biomejs.dev/linter/rules/use-template",
"lint/style/useWhile": "https://biomejs.dev/linter/rules/use-while",

// suspicious
"lint/suspicious/noArrayIndexKey": "https://biomejs.dev/linter/rules/no-array-index-key",
"lint/suspicious/noAssignInExpressions": "https://biomejs.dev/linter/rules/no-assign-in-expressions",
"lint/suspicious/noAsyncPromiseExecutor": "https://biomejs.dev/linter/rules/no-async-promise-executor",
Expand Down Expand Up @@ -183,9 +171,7 @@ define_categories! {
"lint/suspicious/useDefaultSwitchClauseLast": "https://biomejs.dev/linter/rules/use-default-switch-clause-last",
"lint/suspicious/useNamespaceKeyword": "https://biomejs.dev/linter/rules/use-namespace-keyword",
"lint/suspicious/useValidTypeof": "https://biomejs.dev/linter/rules/use-valid-typeof",

;

// General categories
"files/missingHandler",
"format",
Expand Down
4 changes: 2 additions & 2 deletions packages/@biomejs/backend-jsonrpc/src/workspace.ts

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

30 changes: 12 additions & 18 deletions xtask/codegen/src/generate_new_lintrule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,31 +93,25 @@ impl Rule for {rule_name_upper_camel} {{
std::fs::write(file_name, code).unwrap();

let categories_path = "crates/biome_diagnostics_categories/src/categories.rs";
let categories = std::fs::read_to_string(categories_path).unwrap();
let mut categories = std::fs::read_to_string(categories_path).unwrap();

if !categories.contains(&rule_name_lower_camel) {
let kebab_case_rule = rule_name_lower_camel.to_case(Case::Kebab);
// We sort rules to reduce conflicts between contributions made in parallel.
let rule_line = format!(
r#" "lint/nursery/{rule_name_lower_camel}": "https://biomejs.dev/lint/rules/{kebab_case_rule}","#
);
let nursery_start = " // nursery\n";
let nursery_end = "\n // nursery end";
debug_assert!(categories.contains(nursery_start));
debug_assert!(categories.contains(nursery_end));
let nursery_start_index = categories.find(nursery_start).unwrap() + nursery_start.len();
let nursery_end_index = categories.find(nursery_end).unwrap();
let nursery_category = &categories[nursery_start_index..nursery_end_index];
let mut nursery_rules: Vec<&str> = nursery_category
.split('\n')
.chain(Some(&rule_line[..]))
.collect();
nursery_rules.sort();
let new_nursery_category = nursery_rules.join("\n");

let categories = categories.replace(nursery_category, &new_nursery_category);
debug_assert!(categories.contains(&rule_name_lower_camel));

let lint_start = "define_categories! {\n";
let lint_end = "\n ;\n";
debug_assert!(categories.contains(lint_start));
debug_assert!(categories.contains(lint_end));
let lint_start_index = categories.find(lint_start).unwrap() + lint_start.len();
let lint_end_index = categories.find(lint_end).unwrap();
let lint_rule_text = &categories[lint_start_index..lint_end_index];
let mut lint_rules: Vec<_> = lint_rule_text.lines().chain(Some(&rule_line[..])).collect();
lint_rules.sort();
let new_lint_rule_text = lint_rules.join("\n");
categories.replace_range(lint_start_index..lint_end_index, &new_lint_rule_text);
std::fs::write(categories_path, categories).unwrap();
}

Expand Down
15 changes: 14 additions & 1 deletion xtask/codegen/src/promote_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,24 @@ pub fn promote_rule(rule_name: &str, new_group: &str) {
let categories_path = "crates/biome_diagnostics_categories/src/categories.rs";
let categories = std::fs::read_to_string(categories_path).unwrap();

let categories = categories.replace(
let mut categories = categories.replace(
&format!("lint/nursery/{}", rule_name),
&format!("lint/{}/{}", new_group, rule_name),
);

// We sort rules to reduce conflicts between contributions made in parallel.
let lint_start = "define_categories! {\n";
let lint_end = "\n ;\n";
debug_assert!(categories.contains(lint_start));
debug_assert!(categories.contains(lint_end));
let lint_start_index = categories.find(lint_start).unwrap() + lint_start.len();
let lint_end_index = categories.find(lint_end).unwrap();
let lint_rule_text = &categories[lint_start_index..lint_end_index];
let mut lint_rules: Vec<_> = lint_rule_text.lines().collect();
lint_rules.sort();
let new_lint_rule_text = lint_rules.join("\n");
categories.replace_range(lint_start_index..lint_end_index, &new_lint_rule_text);

move_file(rule_path, new_rule_path, &file::CopyOptions::default()).unwrap();
std::fs::write(categories_path, categories).unwrap();

Expand Down

0 comments on commit accf9b7

Please sign in to comment.