mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-02 18:02:23 +00:00
Accept commas in default copyright pattern (#9498)
## Summary Adds commas as an accepted separator between copyright years by default, which is actually documented in one spot, but not currently accurate. Fixes #9477.
This commit is contained in:
parent
a06ffeb54e
commit
594b232e0f
12 changed files with 192 additions and 6 deletions
|
@ -231,7 +231,7 @@ linter.flake8_bandit.check_typed_exception = false
|
|||
linter.flake8_bugbear.extend_immutable_calls = []
|
||||
linter.flake8_builtins.builtins_ignorelist = []
|
||||
linter.flake8_comprehensions.allow_dict_calls_with_keyword_arguments = false
|
||||
linter.flake8_copyright.notice_rgx = (?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}(-\d{4})*
|
||||
linter.flake8_copyright.notice_rgx = (?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}((-|,\s)\d{4})*
|
||||
linter.flake8_copyright.author = none
|
||||
linter.flake8_copyright.min_file_size = 0
|
||||
linter.flake8_errmsg.max_string_length = 0
|
||||
|
|
|
@ -71,6 +71,20 @@ import os
|
|||
r"
|
||||
# Copyright (C) 2021-2023
|
||||
|
||||
import os
|
||||
"
|
||||
.trim(),
|
||||
&settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]),
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn notice_with_comma() {
|
||||
let diagnostics = test_snippet(
|
||||
r"
|
||||
# Copyright (C) 2021, 2022
|
||||
|
||||
import os
|
||||
"
|
||||
.trim(),
|
||||
|
@ -85,6 +99,126 @@ import os
|
|||
r"
|
||||
# Copyright (C) 2023 Ruff
|
||||
|
||||
import os
|
||||
"
|
||||
.trim(),
|
||||
&settings::LinterSettings {
|
||||
flake8_copyright: super::settings::Settings {
|
||||
author: Some("Ruff".to_string()),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice])
|
||||
},
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_author_with_dash() {
|
||||
let diagnostics = test_snippet(
|
||||
r"
|
||||
# Copyright (C) 2022-2023 Ruff
|
||||
|
||||
import os
|
||||
"
|
||||
.trim(),
|
||||
&settings::LinterSettings {
|
||||
flake8_copyright: super::settings::Settings {
|
||||
author: Some("Ruff".to_string()),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice])
|
||||
},
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_author_with_dash_invalid_space() {
|
||||
let diagnostics = test_snippet(
|
||||
r"
|
||||
# Copyright (C) 2022- 2023 Ruff
|
||||
|
||||
import os
|
||||
"
|
||||
.trim(),
|
||||
&settings::LinterSettings {
|
||||
flake8_copyright: super::settings::Settings {
|
||||
author: Some("Ruff".to_string()),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice])
|
||||
},
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_author_with_dash_invalid_spaces() {
|
||||
let diagnostics = test_snippet(
|
||||
r"
|
||||
# Copyright (C) 2022 - 2023 Ruff
|
||||
|
||||
import os
|
||||
"
|
||||
.trim(),
|
||||
&settings::LinterSettings {
|
||||
flake8_copyright: super::settings::Settings {
|
||||
author: Some("Ruff".to_string()),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice])
|
||||
},
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_author_with_comma_invalid_no_space() {
|
||||
let diagnostics = test_snippet(
|
||||
r"
|
||||
# Copyright (C) 2022,2023 Ruff
|
||||
|
||||
import os
|
||||
"
|
||||
.trim(),
|
||||
&settings::LinterSettings {
|
||||
flake8_copyright: super::settings::Settings {
|
||||
author: Some("Ruff".to_string()),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice])
|
||||
},
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_author_with_comma_invalid_spaces() {
|
||||
let diagnostics = test_snippet(
|
||||
r"
|
||||
# Copyright (C) 2022 , 2023 Ruff
|
||||
|
||||
import os
|
||||
"
|
||||
.trim(),
|
||||
&settings::LinterSettings {
|
||||
flake8_copyright: super::settings::Settings {
|
||||
author: Some("Ruff".to_string()),
|
||||
..super::settings::Settings::default()
|
||||
},
|
||||
..settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice])
|
||||
},
|
||||
);
|
||||
assert_messages!(diagnostics);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn valid_author_with_comma_valid_space() {
|
||||
let diagnostics = test_snippet(
|
||||
r"
|
||||
# Copyright (C) 2022, 2023 Ruff
|
||||
|
||||
import os
|
||||
"
|
||||
.trim(),
|
||||
|
|
|
@ -15,7 +15,7 @@ pub struct Settings {
|
|||
}
|
||||
|
||||
pub static COPYRIGHT: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"(?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}(-\d{4})*").unwrap());
|
||||
Lazy::new(|| Regex::new(r"(?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}((-|,\s)\d{4})*").unwrap());
|
||||
|
||||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
|
||||
---
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
|
||||
---
|
||||
<filename>:1:1: CPY001 Missing copyright notice at top of file
|
||||
|
|
||||
1 | # Copyright (C) 2022,2023 Ruff
|
||||
| CPY001
|
||||
2 |
|
||||
3 | import os
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
|
||||
---
|
||||
<filename>:1:1: CPY001 Missing copyright notice at top of file
|
||||
|
|
||||
1 | # Copyright (C) 2022 , 2023 Ruff
|
||||
| CPY001
|
||||
2 |
|
||||
3 | import os
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
|
||||
---
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
|
||||
---
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
|
||||
---
|
||||
<filename>:1:1: CPY001 Missing copyright notice at top of file
|
||||
|
|
||||
1 | # Copyright (C) 2022- 2023 Ruff
|
||||
| CPY001
|
||||
2 |
|
||||
3 | import os
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/flake8_copyright/mod.rs
|
||||
---
|
||||
<filename>:1:1: CPY001 Missing copyright notice at top of file
|
||||
|
|
||||
1 | # Copyright (C) 2022 - 2023 Ruff
|
||||
| CPY001
|
||||
2 |
|
||||
3 | import os
|
||||
|
|
|
@ -1131,15 +1131,15 @@ impl Flake8ComprehensionsOptions {
|
|||
pub struct Flake8CopyrightOptions {
|
||||
/// The regular expression used to match the copyright notice, compiled
|
||||
/// with the [`regex`](https://docs.rs/regex/latest/regex/) crate.
|
||||
///
|
||||
/// Defaults to `(?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}(-\d{4})*`, which matches
|
||||
/// Defaults to `(?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}((-|,\s)\d{4})*`, which matches
|
||||
/// the following:
|
||||
/// - `Copyright 2023`
|
||||
/// - `Copyright (C) 2023`
|
||||
/// - `Copyright 2021-2023`
|
||||
/// - `Copyright (C) 2021-2023`
|
||||
/// - `Copyright (C) 2021, 2023`
|
||||
#[option(
|
||||
default = r#"(?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}([-,]\d{4})*"#,
|
||||
default = r#"(?i)Copyright\s+((?:\(C\)|©)\s+)?\d{4}((-|,\s)\d{4})*"#,
|
||||
value_type = "str",
|
||||
example = r#"notice-rgx = "(?i)Copyright \\(C\\) \\d{4}""#
|
||||
)]
|
||||
|
|
2
ruff.schema.json
generated
2
ruff.schema.json
generated
|
@ -959,7 +959,7 @@
|
|||
"minimum": 0.0
|
||||
},
|
||||
"notice-rgx": {
|
||||
"description": "The regular expression used to match the copyright notice, compiled with the [`regex`](https://docs.rs/regex/latest/regex/) crate.\n\nDefaults to `(?i)Copyright\\s+((?:\\(C\\)|©)\\s+)?\\d{4}(-\\d{4})*`, which matches the following: - `Copyright 2023` - `Copyright (C) 2023` - `Copyright 2021-2023` - `Copyright (C) 2021-2023`",
|
||||
"description": "The regular expression used to match the copyright notice, compiled with the [`regex`](https://docs.rs/regex/latest/regex/) crate. Defaults to `(?i)Copyright\\s+((?:\\(C\\)|©)\\s+)?\\d{4}((-|,\\s)\\d{4})*`, which matches the following: - `Copyright 2023` - `Copyright (C) 2023` - `Copyright 2021-2023` - `Copyright (C) 2021-2023` - `Copyright (C) 2021, 2023`",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue