Skip to content

Commit

Permalink
Allow SPDX license headers to exceed the line length
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 19, 2024
1 parent bc9b457 commit f3f05aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -82,3 +82,8 @@ class Bar:
"""
This is a long sentence that ends with a shortened URL and, therefore, could easily be broken across multiple lines ([source](https://ruff.rs))
"""


# OK
# SPDX-FileCopyrightText: Copyright 2012-2015 Charlie Marsh <very-long-email-address@fake.com>
# SPDX-License-Identifier: a very long license identifier that exceeds the line length limit
11 changes: 10 additions & 1 deletion crates/ruff_linter/src/rules/pycodestyle/overlong.rs
Expand Up @@ -53,7 +53,7 @@ impl Overlong {
};

let mut chunks = line.split_whitespace();
let (Some(_), Some(second_chunk)) = (chunks.next(), chunks.next()) else {
let (Some(first_chunk), Some(second_chunk)) = (chunks.next(), chunks.next()) else {
// Single word / no printable chars - no way to make the line shorter.
return None;
};
Expand All @@ -67,6 +67,15 @@ impl Overlong {
}
}

// Do not enforce the line length limit for SPDX license headers, which are machine-readable
// and explicitly _not_ recommended to wrap over multiple lines.
if matches!(
(first_chunk, second_chunk),
("#", "SPDX-License-Identifier:" | "SPDX-FileCopyrightText:")
) {
return None;
}

// Obtain the start offset of the part of the line that exceeds the limit.
let mut start_offset = line.start();
let mut start_width = LineWidthBuilder::new(tab_size);
Expand Down

0 comments on commit f3f05aa

Please sign in to comment.