From 61904f6b11857c273423e7cab8dff2d4dc5007e5 Mon Sep 17 00:00:00 2001 From: jw013 Date: Mon, 1 Apr 2024 01:14:44 -0400 Subject: [PATCH] make_new_lints adds lints in sorted order (#733) Goal is to reduce merge conflicts (#730). Sort existing lints. --- scripts/make_new_lint.sh | 47 ++++++++++++++++++++++++++---------- src/query.rs | 52 ++++++++++++++++++++-------------------- 2 files changed, 60 insertions(+), 39 deletions(-) diff --git a/scripts/make_new_lint.sh b/scripts/make_new_lint.sh index 4a125e78..202f093e 100755 --- a/scripts/make_new_lint.sh +++ b/scripts/make_new_lint.sh @@ -78,21 +78,42 @@ fi # Add the new lint to the `add_lints!()` macro. echo -n "Registering lint in src/query.rs ..." -if awk -v lint_name="$NEW_LINT_NAME" ' - /^add_lints!\(/ { searching = 1 } - searching && $0 ~ "[[:space:]]" lint_name "," { found = 1; exit } - END { if (found) { exit 0 } else { exit 1 } } -' "$SRC_QUERY_FILE"; then - printf ' already exists.\n' -else - tmp="${SRC_QUERY_FILE}.tmp" - sed -e '/^add_lints!($/ a\'" - $NEW_LINT_NAME," "$SRC_QUERY_FILE" > "$tmp" && mv -- "$tmp" "$SRC_QUERY_FILE" || { - code=$? - rm -f "$tmp" - exit "$code" +# Requirements on $SRC_QUERY_FILE: +# - one lint per line, with leading indent (a nonzero amount of whitespace) +# - lint lines must be sorted +# - lints begin with a line that begins with add_lints!( +# - lints end with a line that begins with ) +if updated_text=$(awk -v lint="$NEW_LINT_NAME" ' + BEGIN { + lint = "" lint + } + + searching { + current_lint = "" $2 + if (lint == current_lint) { + searching = 0 + } else if ($0 ~ /^\)/ || lint < current_lint) { + printf(" %s,\n", lint) + inserted = 1 + searching = 0 + } + } + + { print } + + /^add_lints!\(/ { + searching = 1 + FS = "[,[:space:]]+" + } + + END { + exit !inserted } +' "$SRC_QUERY_FILE"); then + printf '%s\n' "$updated_text" > "$SRC_QUERY_FILE" printf ' done!\n' +else + printf ' already exists.\n' fi echo '' diff --git a/src/query.rs b/src/query.rs index 74d6d086..fa90ba3d 100644 --- a/src/query.rs +++ b/src/query.rs @@ -476,15 +476,6 @@ macro_rules! add_lints { } add_lints!( - union_missing, - function_export_name_changed, - union_field_missing, - pub_static_now_doc_hidden, - function_abi_no_longer_unwind, - pub_module_level_const_now_doc_hidden, - enum_struct_variant_field_now_doc_hidden, - enum_tuple_variant_field_now_doc_hidden, - trait_method_now_doc_hidden, auto_trait_impl_removed, constructible_struct_adds_field, constructible_struct_adds_private_field, @@ -499,9 +490,17 @@ add_lints!( enum_repr_transparent_removed, enum_struct_variant_field_added, enum_struct_variant_field_missing, + enum_struct_variant_field_now_doc_hidden, + enum_tuple_variant_field_added, + enum_tuple_variant_field_missing, + enum_tuple_variant_field_now_doc_hidden, enum_variant_added, enum_variant_missing, + exported_function_changed_abi, + function_abi_no_longer_unwind, + function_changed_abi, function_const_removed, + function_export_name_changed, function_missing, function_must_use_added, function_now_doc_hidden, @@ -512,39 +511,40 @@ add_lints!( inherent_method_must_use_added, inherent_method_unsafe_added, method_parameter_count_changed, + module_missing, + pub_module_level_const_missing, + pub_module_level_const_now_doc_hidden, + pub_static_missing, + pub_static_now_doc_hidden, + repr_c_removed, + repr_packed_added, + repr_packed_removed, sized_impl_removed, struct_marked_non_exhaustive, struct_missing, struct_must_use_added, struct_now_doc_hidden, struct_pub_field_missing, + struct_pub_field_now_doc_hidden, struct_repr_transparent_removed, struct_with_pub_fields_changed_type, trait_method_missing, + trait_method_now_doc_hidden, + trait_method_unsafe_added, + trait_method_unsafe_removed, trait_missing, trait_must_use_added, trait_now_doc_hidden, + trait_removed_associated_constant, + trait_removed_associated_type, + trait_removed_supertrait, trait_unsafe_added, trait_unsafe_removed, tuple_struct_to_plain_struct, type_marked_deprecated, + union_field_missing, + union_missing, + union_now_doc_hidden, unit_struct_changed_kind, variant_marked_non_exhaustive, - enum_tuple_variant_field_missing, - enum_tuple_variant_field_added, - trait_removed_supertrait, - pub_module_level_const_missing, - pub_static_missing, - trait_removed_associated_type, - module_missing, - trait_removed_associated_constant, - function_changed_abi, - trait_method_unsafe_added, - trait_method_unsafe_removed, - struct_pub_field_now_doc_hidden, - repr_c_removed, - repr_packed_added, - repr_packed_removed, - exported_function_changed_abi, - union_now_doc_hidden, );