Skip to content

enhancement: Replace mismatched license headers instead of appending a new header during auto-fix #210

Description

@Standing-Man

Problem

Currently, license header detection is tied to the configured comment style.

For example, a repository may configure Rust files (.rs) to use a line-by-line header style:

[mapping.DOUBLESLASH_STYLE]
extensions = ["rs"]

while existing files still contain a block-style header:

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.
 */

In this case:

  1. hawkeye check reports the file as missing a license header because the existing header does not match the configured style.
  2. hawkeye format inserts a new //-style header at the beginning of the file.
  3. The original block-style header remains in place.

As a result, the file ends up containing two license headers.

Expected Behavior

Before inserting a new header during auto-fix, Hawkeye could attempt to detect and remove an existing license header that is semantically valid but does not match the configured comment style.

Example:

Before:

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.
 */

fn main() {}

After:

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.

fn main() {}

instead of:

// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.
 */

fn main() {}

Benefits

  • Avoids duplicate license headers.
  • Makes style migrations easier.
  • Produces cleaner auto-fix results.
  • Reduces manual cleanup after running hawkeye format.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions