Skip to content

Commit

Permalink
make_new_lints adds lints in sorted order (#733)
Browse files Browse the repository at this point in the history
Goal is to reduce merge conflicts (#730).
Sort existing lints.
  • Loading branch information
jw013 authored Apr 1, 2024
1 parent 9bfef69 commit 61904f6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 39 deletions.
47 changes: 34 additions & 13 deletions scripts/make_new_lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down
52 changes: 26 additions & 26 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
);

0 comments on commit 61904f6

Please sign in to comment.