Skip to content

feat: suggest a preferred format for MAC addresses (Resolves #575) - #576

Merged
SJrX merged 3 commits into
242.xfrom
mac-auto-formatter
Nov 7, 2026
Merged

SJrX merged 3 commits into
242.xfrom
mac-auto-formatter

Conversation

@sjrx-claude-sandbox

@sjrx-claude-sandbox sjrx-claude-sandbox commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

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.
  • PreferredMacFormat setting 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) or 001a.2b3c.4d5e (Cisco style).
  • formatMac() / macAddressBytes() in MacAddress.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, trimmed valueText) back onto the raw value with valueTextOffsets(), 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

  • Hardware-address families: the forms are grouped by length (IPV4_TUNNEL_HW_ADDR, ETHERNET_HW_ADDR, IPV6_TUNNEL_HW_ADDR, INFINIBAND_HW_ADDR). Each is Labeled exactly once, and only the 6-byte family carries the new SemanticTag.MAC_ADDRESS. The inspection therefore covers strict MAC options and the MACs inside Match=/Link= hardware-address lists, and never touches tunnel or InfiniBand addresses or IP literals.
  • WakeOnLanPassword= uses a new untagged SECUREON_PASSWORD grammar, so a SecureOn password spelled like a MAC isn't treated as an address.
  • HARDWARE_ADDRESS ordering 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 above HARDWARE_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 for formatMac.
  • 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, and WakeOnLanPassword= 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-build snapshot (RxCoalesceCQENSec=). Those are a local environment issue, not a regression.

The settings combo box has no automated test and hasn't been checked in runIde yet.

🤖 Generated with Claude Code

@sjrx-claude-sandbox sjrx-claude-sandbox changed the title feat: suggest a preferred format for MAC addresses (Resolves #575) feat: suggest a preferred format for MAC addresses (Resolves #575) (TODO Check RunIDE) Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Unit Test Results (grammar engine false)

1 940 tests   1 940 ✅  1m 41s ⏱️
  530 suites      0 💤
  530 files        0 ❌

Results for commit cf52c8b.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Unit Test Results (grammar engine true)

1 940 tests   1 940 ✅  1m 43s ⏱️
  530 suites      0 💤
  530 files        0 ❌

Results for commit cf52c8b.

♻️ This comment has been updated with latest results.

SJrX and others added 2 commits November 7, 2026 12:31
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>
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>
@sjrx-claude-sandbox sjrx-claude-sandbox changed the title feat: suggest a preferred format for MAC addresses (Resolves #575) (TODO Check RunIDE) feat: suggest a preferred format for MAC addresses (Resolves #575) Nov 7, 2026
@SJrX
SJrX merged commit 4f9793d into 242.x Nov 7, 2026
5 checks passed
@SJrX
SJrX deleted the mac-auto-formatter branch November 7, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggest a preferred format for MAC addresses

2 participants