Skip to content

Commit 2e7c345

Browse files
authored
ENH copyright-notice: check in the first 4096 bytes instead of 1024 (#11927)
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary related to #5306 The check right now only checks in the first 1024 bytes, and that's really not enough when there's a docstring at the beginning of a file. A more proper fix might be needed, which might be more complex (and I don't have the `rust` skills to implement that). But this temporary "fix" might enable more users to use this. Context: We want to use this rule in https://github.com/scikit-learn/scikit-learn/ and we got blocked because of this hardcoded rule (which TBH took us quite a while to figure out why it was failing since it's not documented). ## Test Plan This is already kinda tested, modified the test for the new byte number. <!-- How was it tested? -->
1 parent 1d73d60 commit 2e7c345

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

crates/ruff_linter/src/rules/flake8_copyright/mod.rs

+30
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,36 @@ import os
295295
# Content Content Content Content Content Content Content Content Content Content
296296
# Content Content Content Content Content Content Content Content Content Content
297297
# Content Content Content Content Content Content Content Content Content Content
298+
# Content Content Content Content Content Content Content Content Content Content
299+
# Content Content Content Content Content Content Content Content Content Content
300+
# Content Content Content Content Content Content Content Content Content Content
301+
# Content Content Content Content Content Content Content Content Content Content
302+
# Content Content Content Content Content Content Content Content Content Content
303+
# Content Content Content Content Content Content Content Content Content Content
304+
# Content Content Content Content Content Content Content Content Content Content
305+
# Content Content Content Content Content Content Content Content Content Content
306+
# Content Content Content Content Content Content Content Content Content Content
307+
# Content Content Content Content Content Content Content Content Content Content
308+
# Content Content Content Content Content Content Content Content Content Content
309+
# Content Content Content Content Content Content Content Content Content Content
310+
# Content Content Content Content Content Content Content Content Content Content
311+
# Content Content Content Content Content Content Content Content Content Content
312+
# Content Content Content Content Content Content Content Content Content Content
313+
# Content Content Content Content Content Content Content Content Content Content
314+
# Content Content Content Content Content Content Content Content Content Content
315+
# Content Content Content Content Content Content Content Content Content Content
316+
# Content Content Content Content Content Content Content Content Content Content
317+
# Content Content Content Content Content Content Content Content Content Content
318+
# Content Content Content Content Content Content Content Content Content Content
319+
# Content Content Content Content Content Content Content Content Content Content
320+
# Content Content Content Content Content Content Content Content Content Content
321+
# Content Content Content Content Content Content Content Content Content Content
322+
# Content Content Content Content Content Content Content Content Content Content
323+
# Content Content Content Content Content Content Content Content Content Content
324+
# Content Content Content Content Content Content Content Content Content Content
325+
# Content Content Content Content Content Content Content Content Content Content
326+
# Content Content Content Content Content Content Content Content Content Content
327+
# Content Content Content Content Content Content Content Content Content Content
298328
299329
# Copyright 2023
300330
"

crates/ruff_linter/src/rules/flake8_copyright/rules/missing_copyright_notice.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::settings::LinterSettings;
88
/// ## What it does
99
/// Checks for the absence of copyright notices within Python files.
1010
///
11+
/// Note that this check only searches within the first 4096 bytes of the file.
12+
///
1113
/// ## Why is this bad?
1214
/// In some codebases, it's common to have a license header at the top of every
1315
/// file. This rule ensures that the license header is present.
@@ -31,8 +33,8 @@ pub(crate) fn missing_copyright_notice(
3133
return None;
3234
}
3335

34-
// Only search the first 1024 bytes in the file.
35-
let contents = locator.up_to(locator.floor_char_boundary(TextSize::new(1024)));
36+
// Only search the first 4096 bytes in the file.
37+
let contents = locator.up_to(locator.floor_char_boundary(TextSize::new(4096)));
3638

3739
// Locate the copyright notice.
3840
if let Some(match_) = settings.flake8_copyright.notice_rgx.find(contents) {

0 commit comments

Comments
 (0)