obi1kenobi / cargo-semver-checks

Scan your Rust crate for semver violations.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make the `make_new_lint.sh` script avoid merge conflicts when registering the new lints

obi1kenobi opened this issue · comments

Currently, the make_new_lint.sh script adds new lints at the beginning of the list of lints, right at the start of the add_lints!( macro:

# 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"
}
printf ' done!\n'
fi

If multiple contributors are working on adding lints concurrently, they both going to attempt to add their new lints on that first line. This will inevitably cause a merge conflict, even though the resolution is simple: add both lints to the list. The conflict adds regrettable friction to our contributing process: contributors have to keep resolving the conflict or risk CI no longer running for them.

One possible way to solve this is to:

  • lexicographically sort all lints in the add_lints!() macro's list
  • have the make_new_lint.sh script add each lint into its lexicographically appropriate location, which is likely to avoid most conflicts.

We'd like the solution to work cross-platform with as few extra dependencies as possible, so if taking the above approach, tweaking the existing awk approach would be preferable to something completely new and more heavyweight.

Open to other approaches as well, if they happen to be easier to pull off.

Related to #682 so cc @jw013 in case you have an idea on how to best do this 👆