Compare commits

...

1 Commits

Author SHA1 Message Date
Charlie Marsh
5120b36b67 Consider alternate split points for line-too-long exemptions 2023-11-30 22:53:50 -05:00
4 changed files with 62 additions and 9 deletions

View File

@@ -53,16 +53,24 @@ impl Overlong {
};
let mut chunks = line.split_whitespace();
let (Some(_), Some(second_chunk)) = (chunks.next(), chunks.next()) else {
// Single word / no printable chars - no way to make the line shorter.
return None;
};
if let (Some(_), Some(second_chunk)) = (chunks.next(), chunks.next()) {
// Do not enforce the line length for lines that end with a URL, as long as the URL
// begins before the limit.
let last_chunk = chunks.last().unwrap_or(second_chunk);
if last_chunk.contains("://") {
if width.get() - last_chunk.width() <= limit.value() as usize {
return None;
}
}
} else {
// This is a single word. If's a URL, ignore it.
if line.contains("://") {
return None;
}
// Do not enforce the line length for lines that end with a URL, as long as the URL
// begins before the limit.
let last_chunk = chunks.last().unwrap_or(second_chunk);
if last_chunk.contains("://") {
if width.get() - last_chunk.width() <= limit.value() as usize {
// This is a single word. If there are no split points, ignore it.
indexer.comment_ranges()
if !line.contains(['(', '[', ')', ']', '{', '}', ';']) {
return None;
}
}

View File

@@ -79,6 +79,15 @@ E501_2.py:14:6: E501 Line too long (7 > 6)
16 | [1, 2]
|
E501_2.py:15:6: E501 Line too long (7 > 6)
|
13 | [12]
14 | [12 ]
15 | [1,2]
| ^ E501
16 | [1, 2]
|
E501_2.py:16:6: E501 Line too long (8 > 6)
|
14 | [12 ]

View File

@@ -89,6 +89,15 @@ E501_2.py:10:3: E501 Line too long (13 > 6)
12 | if True: # noqa: E501
|
E501_2.py:13:4: E501 Line too long (8 > 6)
|
12 | if True: # noqa: E501
13 | [12]
| ^^ E501
14 | [12 ]
15 | [1,2]
|
E501_2.py:14:4: E501 Line too long (9 > 6)
|
12 | if True: # noqa: E501
@@ -99,6 +108,15 @@ E501_2.py:14:4: E501 Line too long (9 > 6)
16 | [1, 2]
|
E501_2.py:15:4: E501 Line too long (9 > 6)
|
13 | [12]
14 | [12 ]
15 | [1,2]
| ^^^ E501
16 | [1, 2]
|
E501_2.py:16:4: E501 Line too long (10 > 6)
|
14 | [12 ]

View File

@@ -89,6 +89,15 @@ E501_2.py:10:2: E501 Line too long (21 > 6)
12 | if True: # noqa: E501
|
E501_2.py:13:2: E501 Line too long (12 > 6)
|
12 | if True: # noqa: E501
13 | [12]
| ^^^^ E501
14 | [12 ]
15 | [1,2]
|
E501_2.py:14:2: E501 Line too long (13 > 6)
|
12 | if True: # noqa: E501
@@ -99,6 +108,15 @@ E501_2.py:14:2: E501 Line too long (13 > 6)
16 | [1, 2]
|
E501_2.py:15:2: E501 Line too long (13 > 6)
|
13 | [12]
14 | [12 ]
15 | [1,2]
| ^^^^^ E501
16 | [1, 2]
|
E501_2.py:16:2: E501 Line too long (14 > 6)
|
14 | [12 ]