Repository navigation
feat: suggest a preferred format for MAC addresses (Resolves #575) - #576
Merged
Merged
Conversation
Unit Test Results (grammar engine false)1 940 tests 1 940 ✅ 1m 41s ⏱️ Results for commit cf52c8b. ♻️ This comment has been updated with latest results. |
Unit Test Results (grammar engine true)1 940 tests 1 940 ✅ 1m 43s ⏱️ Results for commit cf52c8b. ♻️ This comment has been updated with latest results. |
sjrx-claude-sandbox
force-pushed
the
mac-auto-formatter
branch
from
November 7, 2026 18:51
3252d50 to
163524a
Compare
Add a MacAddressFormatInspection (grammar engine only) that flags 6-byte MAC addresses not written in the user's preferred format and offers a quick fix to rewrite them. The format is a new project setting on the "systemd Unit Files" page: leave alone, colon lower (systemd's own output, default), colon upper, hyphen upper or dot (Cisco) lower. Hardware-address families are now grouped by length (IPv4 tunnel, Ethernet, IPv6 tunnel, InfiniBand), each Labeled exactly once. Only the 6-byte Ethernet family carries the new SemanticTag.MAC_ADDRESS, so the inspection also covers MACs inside Match=/Link= hardware-address lists without touching tunnel or InfiniBand addresses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Share one ReplaceValueSpanQuickFix between the MAC and IPv6 fixes. It edits the document in place and only replaces text that still matches, falling back to a unique whole-token match, so "Fix all" on a value with several addresses no longer works from stale offsets. - Share a TaggedSpanRewriteInspection base for the MAC and IPv6 inspections. It maps valueText offsets back onto the raw value with valueTextOffsets(), so values continued over several lines are highlighted and fixed in the right place. - Stop tagging [Link] WakeOnLanPassword= as a MAC: it uses a new untagged SECUREON_PASSWORD grammar. - Order HARDWARE_ADDRESS so the classic engine accepts 16- and 20-byte colon addresses. Before, their first 8 fields matched as an IPv6 literal and the rest was rejected. This predates the PR; it was found by the new test. - Make macAddressBytes() in MacAddress.kt the one MAC parser (AdActorSystem now uses it), hoist its regexes, and return early from formatMac for LEAVE_ALONE. - Restart highlighting when any experimental setting changes, not only the MAC format. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sjrx-claude-sandbox
force-pushed
the
mac-auto-formatter
branch
from
November 7, 2026 19:31
163524a to
4dc60cb
Compare
Next to "Convert MAC address to ...", the MAC address format inspection now offers "Set preferred MAC address format to ..." when the address is written in one of the other formats on offer. It changes the setting and leaves the file alone. Also add the inspection's description (the Inspections settings page showed "Can't find inspection description") and drop "(grammar engine only)" from the setting's label. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #575.
What
MacAddressFormatInspection(weak warning, grammar engine only) flags 6-byte MAC addresses that aren't in the preferred format, with a quick fix that rewrites just that address.PreferredMacFormatsetting on Settings → systemd Unit Files: leave alone,00:1a:2b:3c:4d:5e(systemd's own output, the default),00:1A:…,00-1A-…(Windows style) or001a.2b3c.4d5e(Cisco style).formatMac()/macAddressBytes()inMacAddress.kt: one parser for every accepted spelling (colon, hyphen or dot, any case, short fields allowed), and a printer for each format.Bond.AdActorSystem=now uses the same parser.Shared with the IPv6 inspection
TaggedSpanRewriteInspection: a base class for "rewrite spans the grammar tagged X". Both the MAC and IPv6 inspections extend it. It maps grammar offsets (on the joined, trimmedvalueText) back onto the raw value withvalueTextOffsets(), so values continued over several lines are highlighted and fixed in the right place.ReplaceValueSpanQuickFix: both fixes extend it. It edits the document in place, and only replaces text that still matches (falling back to a unique whole-token match). That makes "Fix all" safe on a value holding several addresses.Grammar
IPV4_TUNNEL_HW_ADDR,ETHERNET_HW_ADDR,IPV6_TUNNEL_HW_ADDR,INFINIBAND_HW_ADDR). Each isLabeledexactly once, and only the 6-byte family carries the newSemanticTag.MAC_ADDRESS. The inspection therefore covers strict MAC options and the MACs insideMatch=/Link=hardware-address lists, and never touches tunnel or InfiniBand addresses or IP literals.WakeOnLanPassword=uses a new untaggedSECUREON_PASSWORDgrammar, so a SecureOn password spelled like a MAC isn't treated as an address.HARDWARE_ADDRESSordering fix (this bug predates the PR): the classic engine rejected 16- and 20-byte colon addresses, because their first 8 fields matched as an IPv6 literal first. The families are now ordered around the IP literals, and the reasoning is in the comment aboveHARDWARE_ADDRESS.Settings
Changing any experimental setting now restarts highlighting, so toggling the grammar engine also updates MAC and IPv6 warnings straight away.
Tests
MacAddressFormatTest: unit tests forformatMac.MacAddressFormatInspectionTest: flagging, the setting and engine gating, the quick fix in single values and lists, Fix all across a list, a continuation line,Match=fields, andWakeOnLanPassword=not being flagged.MacAddressGrammarTest: every hardware-address length in every separator style under both engines, IP literals under the classic engine, and the tagging of each family.The full suite passes locally, except for two tests that need gperf data newer than my local
systemd-buildsnapshot (RxCoalesceCQENSec=). Those are a local environment issue, not a regression.The settings combo box has no automated test and hasn't been checked in
runIdeyet.🤖 Generated with Claude Code