Revert "Add task-tags & ignore-overlong-task-comments settings (#1550)"

This reverts commit ca48492137.
This commit is contained in:
Charlie Marsh 2023-01-04 23:26:23 -05:00 committed by Charlie Marsh
parent 7b59cd2d32
commit 3400be18a6
17 changed files with 105 additions and 436 deletions

View file

@ -2232,27 +2232,6 @@ target-version = "py37"
--- ---
#### [`task-tags`](#task-tags)
A list of task tags to recognize (e.g., "TODO", "FIXME", "XXX").
Comments starting with these tags will be ignored by commented-out code
detection (`ERA`), and skipped by line-length checks (`E501`) if
`ignore-overlong-task-comments` is set to `true`.
**Default value**: `["TODO", "FIXME", "XXX"]`
**Type**: `Vec<String>`
**Example usage**:
```toml
[tool.ruff]
task-tags = ["HACK"]
```
---
#### [`unfixable`](#unfixable) #### [`unfixable`](#unfixable)
A list of check code prefixes to consider un-autofix-able. A list of check code prefixes to consider un-autofix-able.
@ -3036,27 +3015,6 @@ staticmethod-decorators = ["staticmethod", "stcmthd"]
--- ---
### `pycodestyle`
#### [`ignore-overlong-task-comments`](#ignore-overlong-task-comments)
Whether or not line-length checks (`E501`) should be triggered for
comments starting with `task-tags` (by default: ["TODO", "FIXME",
and "XXX"]).
**Default value**: `false`
**Type**: `bool`
**Example usage**:
```toml
[tool.ruff.pycodestyle]
ignore-overlong-task-comments = true
```
---
### `pydocstyle` ### `pydocstyle`
#### [`convention`](#convention) #### [`convention`](#convention)

View file

@ -390,7 +390,6 @@ mod tests {
src: None, src: None,
target_version: None, target_version: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
flake8_annotations: None, flake8_annotations: None,
flake8_bandit: None, flake8_bandit: None,
@ -404,7 +403,6 @@ mod tests {
isort: None, isort: None,
mccabe: None, mccabe: None,
pep8_naming: None, pep8_naming: None,
pycodestyle: None,
pydocstyle: None, pydocstyle: None,
pyupgrade: None, pyupgrade: None,
}); });
@ -453,7 +451,6 @@ mod tests {
src: None, src: None,
target_version: None, target_version: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
flake8_annotations: None, flake8_annotations: None,
flake8_bandit: None, flake8_bandit: None,
@ -467,7 +464,6 @@ mod tests {
isort: None, isort: None,
mccabe: None, mccabe: None,
pep8_naming: None, pep8_naming: None,
pycodestyle: None,
pydocstyle: None, pydocstyle: None,
pyupgrade: None, pyupgrade: None,
}); });
@ -516,7 +512,6 @@ mod tests {
src: None, src: None,
target_version: None, target_version: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
flake8_annotations: None, flake8_annotations: None,
flake8_bandit: None, flake8_bandit: None,
@ -530,7 +525,6 @@ mod tests {
isort: None, isort: None,
mccabe: None, mccabe: None,
pep8_naming: None, pep8_naming: None,
pycodestyle: None,
pydocstyle: None, pydocstyle: None,
pyupgrade: None, pyupgrade: None,
}); });
@ -579,7 +573,6 @@ mod tests {
src: None, src: None,
target_version: None, target_version: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
flake8_annotations: None, flake8_annotations: None,
flake8_bandit: None, flake8_bandit: None,
@ -593,7 +586,6 @@ mod tests {
isort: None, isort: None,
mccabe: None, mccabe: None,
pep8_naming: None, pep8_naming: None,
pycodestyle: None,
pydocstyle: None, pydocstyle: None,
pyupgrade: None, pyupgrade: None,
}); });
@ -642,7 +634,6 @@ mod tests {
src: None, src: None,
target_version: None, target_version: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
flake8_annotations: None, flake8_annotations: None,
flake8_bandit: None, flake8_bandit: None,
@ -661,7 +652,6 @@ mod tests {
isort: None, isort: None,
mccabe: None, mccabe: None,
pep8_naming: None, pep8_naming: None,
pycodestyle: None,
pydocstyle: None, pydocstyle: None,
pyupgrade: None, pyupgrade: None,
}); });
@ -714,7 +704,6 @@ mod tests {
src: None, src: None,
target_version: None, target_version: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
flake8_annotations: None, flake8_annotations: None,
flake8_bandit: None, flake8_bandit: None,
@ -728,7 +717,6 @@ mod tests {
isort: None, isort: None,
mccabe: None, mccabe: None,
pep8_naming: None, pep8_naming: None,
pycodestyle: None,
pydocstyle: Some(pydocstyle::settings::Options { pydocstyle: Some(pydocstyle::settings::Options {
convention: Some(Convention::Numpy), convention: Some(Convention::Numpy),
}), }),
@ -780,7 +768,6 @@ mod tests {
src: None, src: None,
target_version: None, target_version: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
flake8_annotations: None, flake8_annotations: None,
flake8_bandit: None, flake8_bandit: None,
@ -799,7 +786,6 @@ mod tests {
isort: None, isort: None,
mccabe: None, mccabe: None,
pep8_naming: None, pep8_naming: None,
pycodestyle: None,
pydocstyle: None, pydocstyle: None,
pyupgrade: None, pyupgrade: None,
}); });

View file

@ -1,6 +0,0 @@
# TODO: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep`
# TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep`
# TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep`
# FIXME: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep`
# FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep`
# FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep`

View file

@ -299,17 +299,6 @@
} }
} }
}, },
"pycodestyle": {
"description": "Options for the `pycodestyle` plugin.",
"anyOf": [
{
"$ref": "#/definitions/Pycodestyle"
},
{
"type": "null"
}
]
},
"pydocstyle": { "pydocstyle": {
"description": "Options for the `pydocstyle` plugin.", "description": "Options for the `pydocstyle` plugin.",
"anyOf": [ "anyOf": [
@ -388,16 +377,6 @@
} }
] ]
}, },
"task-tags": {
"description": "A list of task tags to recognize (e.g., \"TODO\", \"FIXME\", \"XXX\").\n\nComments starting with these tags will be ignored by commented-out code detection (`ERA`), and skipped by line-length checks (`E501`) if `ignore-overlong-task-comments` is set to `true`.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"unfixable": { "unfixable": {
"description": "A list of check code prefixes to consider un-autofix-able.", "description": "A list of check code prefixes to consider un-autofix-able.",
"type": [ "type": [
@ -1508,19 +1487,6 @@
}, },
"additionalProperties": false "additionalProperties": false
}, },
"Pycodestyle": {
"type": "object",
"properties": {
"ignore-overlong-task-comments": {
"description": "Whether or not line-length checks (`E501`) should be triggered for comments starting with `task-tags` (by default: [\"TODO\", \"FIXME\", and \"XXX\"]).",
"type": [
"boolean",
"null"
]
}
},
"additionalProperties": false
},
"Pydocstyle": { "Pydocstyle": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -57,7 +57,7 @@ pub fn check_lines(
} }
if enforce_line_too_long { if enforce_line_too_long {
if let Some(check) = line_too_long(index, line, settings) { if let Some(check) = line_too_long(index, line, settings.line_length) {
checks.push(check); checks.push(check);
} }
} }

View file

@ -31,7 +31,7 @@ pub fn commented_out_code(
let line = locator.slice_source_code_range(&Range::new(location, end_location)); let line = locator.slice_source_code_range(&Range::new(location, end_location));
// Verify that the comment is on its own line, and that it contains code. // Verify that the comment is on its own line, and that it contains code.
if is_standalone_comment(&line) && comment_contains_code(&line, &settings.task_tags[..]) { if is_standalone_comment(&line) && comment_contains_code(&line) {
let mut check = Check::new(CheckKind::CommentedOutCode, Range::new(start, end)); let mut check = Check::new(CheckKind::CommentedOutCode, Range::new(start, end));
if matches!(autofix, flags::Autofix::Enabled) if matches!(autofix, flags::Autofix::Enabled)
&& settings.fixable.contains(&CheckCode::ERA001) && settings.fixable.contains(&CheckCode::ERA001)

View file

@ -4,7 +4,7 @@ use regex::Regex;
static ALLOWLIST_REGEX: Lazy<Regex> = Lazy::new(|| { static ALLOWLIST_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new( Regex::new(
r"^(?i)(?:pylint|pyright|noqa|nosec|type:\s*ignore|fmt:\s*(on|off)|isort:\s*(on|off|skip|skip_file|split|dont-add-imports(:\s*\[.*?])?))" r"^(?i)(?:pylint|pyright|noqa|nosec|type:\s*ignore|fmt:\s*(on|off)|isort:\s*(on|off|skip|skip_file|split|dont-add-imports(:\s*\[.*?])?)|TODO|FIXME|XXX)"
).unwrap() ).unwrap()
}); });
static BRACKET_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[()\[\]{}\s]+$").unwrap()); static BRACKET_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[()\[\]{}\s]+$").unwrap());
@ -30,7 +30,7 @@ static PARTIAL_DICTIONARY_REGEX: Lazy<Regex> =
static PRINT_RETURN_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^(print|return)\b\s*").unwrap()); static PRINT_RETURN_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^(print|return)\b\s*").unwrap());
/// Returns `true` if a comment contains Python code. /// Returns `true` if a comment contains Python code.
pub fn comment_contains_code(line: &str, task_tags: &[String]) -> bool { pub fn comment_contains_code(line: &str) -> bool {
let line = if let Some(line) = line.trim().strip_prefix('#') { let line = if let Some(line) = line.trim().strip_prefix('#') {
line.trim() line.trim()
} else { } else {
@ -47,12 +47,6 @@ pub fn comment_contains_code(line: &str, task_tags: &[String]) -> bool {
return false; return false;
} }
if let Some(first) = line.split(&[' ', ':']).next() {
if task_tags.iter().any(|tag| tag == first) {
return false;
}
}
if CODING_COMMENT_REGEX.is_match(line) { if CODING_COMMENT_REGEX.is_match(line) {
return false; return false;
} }
@ -103,166 +97,142 @@ mod tests {
#[test] #[test]
fn comment_contains_code_basic() { fn comment_contains_code_basic() {
assert!(comment_contains_code("# x = 1", &[])); assert!(comment_contains_code("# x = 1"));
assert!(comment_contains_code("#from foo import eradicate", &[])); assert!(comment_contains_code("#from foo import eradicate"));
assert!(comment_contains_code("#import eradicate", &[])); assert!(comment_contains_code("#import eradicate"));
assert!(comment_contains_code(r#"#"key": value,"#, &[])); assert!(comment_contains_code(r#"#"key": value,"#));
assert!(comment_contains_code(r#"#"key": "value","#, &[])); assert!(comment_contains_code(r#"#"key": "value","#));
assert!(comment_contains_code(r#"#"key": 1 + 1,"#, &[])); assert!(comment_contains_code(r#"#"key": 1 + 1,"#));
assert!(comment_contains_code("#'key': 1 + 1,", &[])); assert!(comment_contains_code("#'key': 1 + 1,"));
assert!(comment_contains_code(r#"#"key": {"#, &[])); assert!(comment_contains_code(r#"#"key": {"#));
assert!(comment_contains_code("#}", &[])); assert!(comment_contains_code("#}"));
assert!(comment_contains_code("#} )]", &[])); assert!(comment_contains_code("#} )]"));
assert!(!comment_contains_code("#", &[])); assert!(!comment_contains_code("#"));
assert!(!comment_contains_code("# This is a (real) comment.", &[])); assert!(!comment_contains_code("# This is a (real) comment."));
assert!(!comment_contains_code("# 123", &[])); assert!(!comment_contains_code("# 123"));
assert!(!comment_contains_code("# 123.1", &[])); assert!(!comment_contains_code("# 123.1"));
assert!(!comment_contains_code("# 1, 2, 3", &[])); assert!(!comment_contains_code("# 1, 2, 3"));
assert!(!comment_contains_code("x = 1 # x = 1", &[])); assert!(!comment_contains_code("x = 1 # x = 1"));
assert!(!comment_contains_code( assert!(!comment_contains_code(
"# pylint: disable=redefined-outer-name", "# pylint: disable=redefined-outer-name"
&[]
),);
assert!(!comment_contains_code(
"# Issue #999: This is not code",
&[]
)); ));
assert!(!comment_contains_code("# Issue #999: This is not code"));
// TODO(charlie): This should be `true` under aggressive mode. // TODO(charlie): This should be `true` under aggressive mode.
assert!(!comment_contains_code("#},", &[])); assert!(!comment_contains_code("#},"));
} }
#[test] #[test]
fn comment_contains_code_with_print() { fn comment_contains_code_with_print() {
assert!(comment_contains_code("#print", &[])); assert!(comment_contains_code("#print"));
assert!(comment_contains_code("#print(1)", &[])); assert!(comment_contains_code("#print(1)"));
assert!(comment_contains_code("#print 1", &[])); assert!(comment_contains_code("#print 1"));
assert!(!comment_contains_code("#to print", &[])); assert!(!comment_contains_code("#to print"));
} }
#[test] #[test]
fn comment_contains_code_with_return() { fn comment_contains_code_with_return() {
assert!(comment_contains_code("#return x", &[])); assert!(comment_contains_code("#return x"));
assert!(!comment_contains_code("#to print", &[])); assert!(!comment_contains_code("#to print"));
} }
#[test] #[test]
fn comment_contains_code_with_multiline() { fn comment_contains_code_with_multiline() {
assert!(comment_contains_code("#else:", &[])); assert!(comment_contains_code("#else:"));
assert!(comment_contains_code("# else : ", &[])); assert!(comment_contains_code("# else : "));
assert!(comment_contains_code(r#"# "foo %d" % \\"#, &[])); assert!(comment_contains_code(r#"# "foo %d" % \\"#));
assert!(comment_contains_code("#elif True:", &[])); assert!(comment_contains_code("#elif True:"));
assert!(comment_contains_code("#x = foo(", &[])); assert!(comment_contains_code("#x = foo("));
assert!(comment_contains_code("#except Exception:", &[])); assert!(comment_contains_code("#except Exception:"));
assert!(!comment_contains_code("# this is = to that :(", &[])); assert!(!comment_contains_code("# this is = to that :("));
assert!(!comment_contains_code("#else", &[])); assert!(!comment_contains_code("#else"));
assert!(!comment_contains_code("#or else:", &[])); assert!(!comment_contains_code("#or else:"));
assert!(!comment_contains_code("#else True:", &[])); assert!(!comment_contains_code("#else True:"));
// Unpacking assignments // Unpacking assignments
assert!(comment_contains_code( assert!(comment_contains_code(
"# user_content_type, _ = TimelineEvent.objects.using(db_alias).get_or_create(", "# user_content_type, _ = TimelineEvent.objects.using(db_alias).get_or_create("
&[]
),);
assert!(comment_contains_code(
"# (user_content_type, _) = TimelineEvent.objects.using(db_alias).get_or_create(",
&[]
),);
assert!(comment_contains_code(
"# ( user_content_type , _ )= TimelineEvent.objects.using(db_alias).get_or_create(",
&[]
)); ));
assert!(comment_contains_code( assert!(comment_contains_code(
"# app_label=\"core\", model=\"user\"", "# (user_content_type, _) = TimelineEvent.objects.using(db_alias).get_or_create("
&[]
)); ));
assert!(comment_contains_code("# )", &[])); assert!(comment_contains_code(
"# ( user_content_type , _ )= TimelineEvent.objects.using(db_alias).get_or_create("
));
assert!(comment_contains_code(
"# app_label=\"core\", model=\"user\""
));
assert!(comment_contains_code("# )"));
// TODO(charlie): This should be `true` under aggressive mode. // TODO(charlie): This should be `true` under aggressive mode.
assert!(!comment_contains_code("#def foo():", &[])); assert!(!comment_contains_code("#def foo():"));
} }
#[test] #[test]
fn comment_contains_code_with_sentences() { fn comment_contains_code_with_sentences() {
assert!(!comment_contains_code("#code is good", &[])); assert!(!comment_contains_code("#code is good"));
} }
#[test] #[test]
fn comment_contains_code_with_encoding() { fn comment_contains_code_with_encoding() {
assert!(comment_contains_code("# codings=utf-8", &[])); assert!(comment_contains_code("# codings=utf-8"));
assert!(!comment_contains_code("# coding=utf-8", &[])); assert!(!comment_contains_code("# coding=utf-8"));
assert!(!comment_contains_code("#coding= utf-8", &[])); assert!(!comment_contains_code("#coding= utf-8"));
assert!(!comment_contains_code("# coding: utf-8", &[])); assert!(!comment_contains_code("# coding: utf-8"));
assert!(!comment_contains_code("# encoding: utf8", &[])); assert!(!comment_contains_code("# encoding: utf8"));
} }
#[test] #[test]
fn comment_contains_code_with_default_allowlist() { fn comment_contains_code_with_default_allowlist() {
assert!(!comment_contains_code("# pylint: disable=A0123", &[])); assert!(!comment_contains_code("# pylint: disable=A0123"));
assert!(!comment_contains_code("# pylint:disable=A0123", &[])); assert!(!comment_contains_code("# pylint:disable=A0123"));
assert!(!comment_contains_code("# pylint: disable = A0123", &[])); assert!(!comment_contains_code("# pylint: disable = A0123"));
assert!(!comment_contains_code("# pylint:disable = A0123", &[])); assert!(!comment_contains_code("# pylint:disable = A0123"));
assert!(!comment_contains_code("# pyright: reportErrorName=true"));
assert!(!comment_contains_code("# noqa"));
assert!(!comment_contains_code("# NOQA"));
assert!(!comment_contains_code("# noqa: A123"));
assert!(!comment_contains_code("# noqa:A123"));
assert!(!comment_contains_code("# nosec"));
assert!(!comment_contains_code("# fmt: on"));
assert!(!comment_contains_code("# fmt: off"));
assert!(!comment_contains_code("# fmt:on"));
assert!(!comment_contains_code("# fmt:off"));
assert!(!comment_contains_code("# isort: on"));
assert!(!comment_contains_code("# isort:on"));
assert!(!comment_contains_code("# isort: off"));
assert!(!comment_contains_code("# isort:off"));
assert!(!comment_contains_code("# isort: skip"));
assert!(!comment_contains_code("# isort:skip"));
assert!(!comment_contains_code("# isort: skip_file"));
assert!(!comment_contains_code("# isort:skip_file"));
assert!(!comment_contains_code("# isort: split"));
assert!(!comment_contains_code("# isort:split"));
assert!(!comment_contains_code("# isort: dont-add-imports"));
assert!(!comment_contains_code("# isort:dont-add-imports"));
assert!(!comment_contains_code( assert!(!comment_contains_code(
"# pyright: reportErrorName=true", "# isort: dont-add-imports: [\"import os\"]"
&[]
));
assert!(!comment_contains_code("# noqa", &[]));
assert!(!comment_contains_code("# NOQA", &[]));
assert!(!comment_contains_code("# noqa: A123", &[]));
assert!(!comment_contains_code("# noqa:A123", &[]));
assert!(!comment_contains_code("# nosec", &[]));
assert!(!comment_contains_code("# fmt: on", &[]));
assert!(!comment_contains_code("# fmt: off", &[]));
assert!(!comment_contains_code("# fmt:on", &[]));
assert!(!comment_contains_code("# fmt:off", &[]));
assert!(!comment_contains_code("# isort: on", &[]));
assert!(!comment_contains_code("# isort:on", &[]));
assert!(!comment_contains_code("# isort: off", &[]));
assert!(!comment_contains_code("# isort:off", &[]));
assert!(!comment_contains_code("# isort: skip", &[]));
assert!(!comment_contains_code("# isort:skip", &[]));
assert!(!comment_contains_code("# isort: skip_file", &[]));
assert!(!comment_contains_code("# isort:skip_file", &[]));
assert!(!comment_contains_code("# isort: split", &[]));
assert!(!comment_contains_code("# isort:split", &[]));
assert!(!comment_contains_code("# isort: dont-add-imports", &[]));
assert!(!comment_contains_code("# isort:dont-add-imports", &[]));
assert!(!comment_contains_code(
"# isort: dont-add-imports: [\"import os\"]",
&[]
)); ));
assert!(!comment_contains_code( assert!(!comment_contains_code(
"# isort:dont-add-imports: [\"import os\"]", "# isort:dont-add-imports: [\"import os\"]"
&[]
)); ));
assert!(!comment_contains_code( assert!(!comment_contains_code(
"# isort: dont-add-imports:[\"import os\"]", "# isort: dont-add-imports:[\"import os\"]"
&[]
)); ));
assert!(!comment_contains_code( assert!(!comment_contains_code(
"# isort:dont-add-imports:[\"import os\"]", "# isort:dont-add-imports:[\"import os\"]"
&[]
));
assert!(!comment_contains_code("# type: ignore", &[]));
assert!(!comment_contains_code("# type:ignore", &[]));
assert!(!comment_contains_code("# type: ignore[import]", &[]));
assert!(!comment_contains_code("# type:ignore[import]", &[]));
assert!(!comment_contains_code(
"# TODO: Do that",
&["TODO".to_string()]
));
assert!(!comment_contains_code(
"# FIXME: Fix that",
&["FIXME".to_string()]
));
assert!(!comment_contains_code(
"# XXX: What ever",
&["XXX".to_string()]
)); ));
assert!(!comment_contains_code("# type: ignore"));
assert!(!comment_contains_code("# type:ignore"));
assert!(!comment_contains_code("# type: ignore[import]"));
assert!(!comment_contains_code("# type:ignore[import]"));
assert!(!comment_contains_code("# TODO: Do that"));
assert!(!comment_contains_code("# FIXME: Fix that"));
assert!(!comment_contains_code("# XXX: What ever"));
} }
} }

View file

@ -18,7 +18,7 @@ use crate::source_code_style::SourceCodeStyleDetector;
use crate::{ use crate::{
directives, flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, directives, flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg,
flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_import_conventions, flake8_pytest_style, flake8_quotes, flake8_tidy_imports,
flake8_unused_arguments, isort, mccabe, pep8_naming, pycodestyle, pydocstyle, pyupgrade, flake8_unused_arguments, isort, mccabe, pep8_naming, pydocstyle, pyupgrade,
}; };
const VERSION: &str = env!("CARGO_PKG_VERSION"); const VERSION: &str = env!("CARGO_PKG_VERSION");
@ -112,7 +112,6 @@ pub fn defaultSettings() -> Result<JsValue, JsValue> {
show_source: None, show_source: None,
src: None, src: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
// Use default options for all plugins. // Use default options for all plugins.
flake8_annotations: Some(flake8_annotations::settings::Settings::default().into()), flake8_annotations: Some(flake8_annotations::settings::Settings::default().into()),
@ -131,7 +130,6 @@ pub fn defaultSettings() -> Result<JsValue, JsValue> {
isort: Some(isort::settings::Settings::default().into()), isort: Some(isort::settings::Settings::default().into()),
mccabe: Some(mccabe::settings::Settings::default().into()), mccabe: Some(mccabe::settings::Settings::default().into()),
pep8_naming: Some(pep8_naming::settings::Settings::default().into()), pep8_naming: Some(pep8_naming::settings::Settings::default().into()),
pycodestyle: Some(pycodestyle::settings::Settings::default().into()),
pydocstyle: Some(pydocstyle::settings::Settings::default().into()), pydocstyle: Some(pydocstyle::settings::Settings::default().into()),
pyupgrade: Some(pyupgrade::settings::Settings::default().into()), pyupgrade: Some(pyupgrade::settings::Settings::default().into()),
})?) })?)

View file

@ -8,44 +8,34 @@ use crate::ast::helpers::except_range;
use crate::ast::types::Range; use crate::ast::types::Range;
use crate::autofix::Fix; use crate::autofix::Fix;
use crate::registry::{Check, CheckKind}; use crate::registry::{Check, CheckKind};
use crate::settings::Settings;
use crate::source_code_locator::SourceCodeLocator; use crate::source_code_locator::SourceCodeLocator;
static URL_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^https?://\S+$").unwrap()); static URL_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^https?://\S+$").unwrap());
/// E501 /// E501
pub fn line_too_long(lineno: usize, line: &str, settings: &Settings) -> Option<Check> { pub fn line_too_long(lineno: usize, line: &str, max_line_length: usize) -> Option<Check> {
let line_length = line.chars().count(); let line_length = line.chars().count();
if line_length <= settings.line_length { if line_length <= max_line_length {
return None; return None;
} }
let mut chunks = line.split_whitespace(); let mut chunks = line.split_whitespace();
let (Some(first), Some(second)) = (chunks.next(), chunks.next()) else { let (Some(first), Some(_)) = (chunks.next(), chunks.next()) else {
// Single word / no printable chars - no way to make the line shorter // Single word / no printable chars - no way to make the line shorter
return None; return None;
}; };
if first == "#" {
if settings.pycodestyle.ignore_overlong_task_comments {
let second = second.trim_end_matches(':');
if settings.task_tags.iter().any(|tag| tag == second) {
return None;
}
}
// Do not enforce the line length for commented lines that end with a URL // Do not enforce the line length for commented lines that end with a URL
// or contain only a single word. // or contain only a single word.
if chunks.last().map_or(true, |c| URL_REGEX.is_match(c)) { if first == "#" && chunks.last().map_or(true, |c| URL_REGEX.is_match(c)) {
return None; return None;
} }
}
Some(Check::new( Some(Check::new(
CheckKind::LineTooLong(line_length, settings.line_length), CheckKind::LineTooLong(line_length, max_line_length),
Range::new( Range::new(
Location::new(lineno + 1, settings.line_length), Location::new(lineno + 1, max_line_length),
Location::new(lineno + 1, line_length), Location::new(lineno + 1, line_length),
), ),
)) ))

View file

@ -1,6 +1,5 @@
pub mod checks; pub mod checks;
pub mod plugins; pub mod plugins;
pub mod settings;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -10,7 +9,6 @@ mod tests {
use anyhow::Result; use anyhow::Result;
use test_case::test_case; use test_case::test_case;
use super::settings::Settings;
use crate::linter::test_path; use crate::linter::test_path;
use crate::registry::CheckCode; use crate::registry::CheckCode;
use crate::settings; use crate::settings;
@ -58,21 +56,4 @@ mod tests {
insta::assert_yaml_snapshot!(checks); insta::assert_yaml_snapshot!(checks);
Ok(()) Ok(())
} }
#[test_case(false)]
#[test_case(true)]
fn task_tags(ignore_overlong_task_comments: bool) -> Result<()> {
let snapshot = format!("task_tags_{ignore_overlong_task_comments}");
let checks = test_path(
Path::new("./resources/test/fixtures/pycodestyle/E501_1.py"),
&settings::Settings {
pycodestyle: Settings {
ignore_overlong_task_comments,
},
..settings::Settings::for_rule(CheckCode::E501)
},
)?;
insta::assert_yaml_snapshot!(snapshot, checks);
Ok(())
}
} }

View file

@ -1,46 +0,0 @@
//! Settings for the `pycodestyle` plugin.
use ruff_macros::ConfigurationOptions;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(
Debug, PartialEq, Eq, Serialize, Deserialize, Default, ConfigurationOptions, JsonSchema,
)]
#[serde(deny_unknown_fields, rename_all = "kebab-case", rename = "Pycodestyle")]
pub struct Options {
#[option(
default = "false",
value_type = "bool",
example = r#"
ignore-overlong-task-comments = true
"#
)]
/// Whether or not line-length checks (`E501`) should be triggered for
/// comments starting with `task-tags` (by default: ["TODO", "FIXME",
/// and "XXX"]).
pub ignore_overlong_task_comments: Option<bool>,
}
#[derive(Debug, Default, Hash)]
pub struct Settings {
pub ignore_overlong_task_comments: bool,
}
impl From<Options> for Settings {
fn from(options: Options) -> Self {
Self {
ignore_overlong_task_comments: options
.ignore_overlong_task_comments
.unwrap_or_default(),
}
}
}
impl From<Settings> for Options {
fn from(settings: Settings) -> Self {
Self {
ignore_overlong_task_comments: Some(settings.ignore_overlong_task_comments),
}
}
}

View file

@ -1,77 +0,0 @@
---
source: src/pycodestyle/mod.rs
expression: checks
---
- kind:
LineTooLong:
- 149
- 88
location:
row: 1
column: 88
end_location:
row: 1
column: 149
fix: ~
parent: ~
- kind:
LineTooLong:
- 148
- 88
location:
row: 2
column: 88
end_location:
row: 2
column: 148
fix: ~
parent: ~
- kind:
LineTooLong:
- 155
- 88
location:
row: 3
column: 88
end_location:
row: 3
column: 155
fix: ~
parent: ~
- kind:
LineTooLong:
- 150
- 88
location:
row: 4
column: 88
end_location:
row: 4
column: 150
fix: ~
parent: ~
- kind:
LineTooLong:
- 149
- 88
location:
row: 5
column: 88
end_location:
row: 5
column: 149
fix: ~
parent: ~
- kind:
LineTooLong:
- 156
- 88
location:
row: 6
column: 88
end_location:
row: 6
column: 156
fix: ~
parent: ~

View file

@ -1,6 +0,0 @@
---
source: src/pycodestyle/mod.rs
expression: checks
---
[]

View file

@ -22,7 +22,7 @@ use crate::settings::types::{
use crate::{ use crate::{
flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions, flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions,
flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, fs, isort, flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, fs, isort,
mccabe, pep8_naming, pycodestyle, pydocstyle, pyupgrade, mccabe, pep8_naming, pydocstyle, pyupgrade,
}; };
#[derive(Debug, Default)] #[derive(Debug, Default)]
@ -52,7 +52,6 @@ pub struct Configuration {
pub src: Option<Vec<PathBuf>>, pub src: Option<Vec<PathBuf>>,
pub target_version: Option<PythonVersion>, pub target_version: Option<PythonVersion>,
pub unfixable: Option<Vec<CheckCodePrefix>>, pub unfixable: Option<Vec<CheckCodePrefix>>,
pub task_tags: Option<Vec<String>>,
pub update_check: Option<bool>, pub update_check: Option<bool>,
// Plugins // Plugins
pub flake8_annotations: Option<flake8_annotations::settings::Options>, pub flake8_annotations: Option<flake8_annotations::settings::Options>,
@ -67,7 +66,6 @@ pub struct Configuration {
pub isort: Option<isort::settings::Options>, pub isort: Option<isort::settings::Options>,
pub mccabe: Option<mccabe::settings::Options>, pub mccabe: Option<mccabe::settings::Options>,
pub pep8_naming: Option<pep8_naming::settings::Options>, pub pep8_naming: Option<pep8_naming::settings::Options>,
pub pycodestyle: Option<pycodestyle::settings::Options>,
pub pydocstyle: Option<pydocstyle::settings::Options>, pub pydocstyle: Option<pydocstyle::settings::Options>,
pub pyupgrade: Option<pyupgrade::settings::Options>, pub pyupgrade: Option<pyupgrade::settings::Options>,
} }
@ -152,7 +150,6 @@ impl Configuration {
.transpose()?, .transpose()?,
target_version: options.target_version, target_version: options.target_version,
unfixable: options.unfixable, unfixable: options.unfixable,
task_tags: options.task_tags,
update_check: options.update_check, update_check: options.update_check,
// Plugins // Plugins
flake8_annotations: options.flake8_annotations, flake8_annotations: options.flake8_annotations,
@ -167,7 +164,6 @@ impl Configuration {
isort: options.isort, isort: options.isort,
mccabe: options.mccabe, mccabe: options.mccabe,
pep8_naming: options.pep8_naming, pep8_naming: options.pep8_naming,
pycodestyle: options.pycodestyle,
pydocstyle: options.pydocstyle, pydocstyle: options.pydocstyle,
pyupgrade: options.pyupgrade, pyupgrade: options.pyupgrade,
}) })
@ -215,7 +211,6 @@ impl Configuration {
src: self.src.or(config.src), src: self.src.or(config.src),
target_version: self.target_version.or(config.target_version), target_version: self.target_version.or(config.target_version),
unfixable: self.unfixable.or(config.unfixable), unfixable: self.unfixable.or(config.unfixable),
task_tags: self.task_tags.or(config.task_tags),
update_check: self.update_check.or(config.update_check), update_check: self.update_check.or(config.update_check),
// Plugins // Plugins
flake8_annotations: self.flake8_annotations.or(config.flake8_annotations), flake8_annotations: self.flake8_annotations.or(config.flake8_annotations),
@ -234,7 +229,6 @@ impl Configuration {
isort: self.isort.or(config.isort), isort: self.isort.or(config.isort),
mccabe: self.mccabe.or(config.mccabe), mccabe: self.mccabe.or(config.mccabe),
pep8_naming: self.pep8_naming.or(config.pep8_naming), pep8_naming: self.pep8_naming.or(config.pep8_naming),
pycodestyle: self.pycodestyle.or(config.pycodestyle),
pydocstyle: self.pydocstyle.or(config.pydocstyle), pydocstyle: self.pydocstyle.or(config.pydocstyle),
pyupgrade: self.pyupgrade.or(config.pyupgrade), pyupgrade: self.pyupgrade.or(config.pyupgrade),
} }

View file

@ -26,7 +26,7 @@ use crate::settings::types::{
use crate::{ use crate::{
flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions, flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions,
flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, isort, flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, isort,
mccabe, one_time_warning, pep8_naming, pycodestyle, pydocstyle, pyupgrade, mccabe, one_time_warning, pep8_naming, pydocstyle, pyupgrade,
}; };
pub mod configuration; pub mod configuration;
@ -60,7 +60,6 @@ pub struct Settings {
pub show_source: bool, pub show_source: bool,
pub src: Vec<PathBuf>, pub src: Vec<PathBuf>,
pub target_version: PythonVersion, pub target_version: PythonVersion,
pub task_tags: Vec<String>,
pub update_check: bool, pub update_check: bool,
// Plugins // Plugins
pub flake8_annotations: flake8_annotations::settings::Settings, pub flake8_annotations: flake8_annotations::settings::Settings,
@ -75,7 +74,6 @@ pub struct Settings {
pub isort: isort::settings::Settings, pub isort: isort::settings::Settings,
pub mccabe: mccabe::settings::Settings, pub mccabe: mccabe::settings::Settings,
pub pep8_naming: pep8_naming::settings::Settings, pub pep8_naming: pep8_naming::settings::Settings,
pub pycodestyle: pycodestyle::settings::Settings,
pub pydocstyle: pydocstyle::settings::Settings, pub pydocstyle: pydocstyle::settings::Settings,
pub pyupgrade: pyupgrade::settings::Settings, pub pyupgrade: pyupgrade::settings::Settings,
} }
@ -176,9 +174,6 @@ impl Settings {
.src .src
.unwrap_or_else(|| vec![project_root.to_path_buf()]), .unwrap_or_else(|| vec![project_root.to_path_buf()]),
target_version: config.target_version.unwrap_or_default(), target_version: config.target_version.unwrap_or_default(),
task_tags: config.task_tags.unwrap_or_else(|| {
vec!["TODO".to_string(), "FIXME".to_string(), "XXX".to_string()]
}),
update_check: config.update_check.unwrap_or(true), update_check: config.update_check.unwrap_or(true),
// Plugins // Plugins
flake8_annotations: config flake8_annotations: config
@ -229,10 +224,6 @@ impl Settings {
.pep8_naming .pep8_naming
.map(std::convert::Into::into) .map(std::convert::Into::into)
.unwrap_or_default(), .unwrap_or_default(),
pycodestyle: config
.pycodestyle
.map(std::convert::Into::into)
.unwrap_or_default(),
pydocstyle: config pydocstyle: config
.pydocstyle .pydocstyle
.map(std::convert::Into::into) .map(std::convert::Into::into)
@ -266,7 +257,6 @@ impl Settings {
show_source: false, show_source: false,
src: vec![path_dedot::CWD.clone()], src: vec![path_dedot::CWD.clone()],
target_version: PythonVersion::Py310, target_version: PythonVersion::Py310,
task_tags: vec!["TODO".to_string(), "FIXME".to_string()],
update_check: false, update_check: false,
flake8_annotations: flake8_annotations::settings::Settings::default(), flake8_annotations: flake8_annotations::settings::Settings::default(),
flake8_bandit: flake8_bandit::settings::Settings::default(), flake8_bandit: flake8_bandit::settings::Settings::default(),
@ -280,7 +270,6 @@ impl Settings {
isort: isort::settings::Settings::default(), isort: isort::settings::Settings::default(),
mccabe: mccabe::settings::Settings::default(), mccabe: mccabe::settings::Settings::default(),
pep8_naming: pep8_naming::settings::Settings::default(), pep8_naming: pep8_naming::settings::Settings::default(),
pycodestyle: pycodestyle::settings::Settings::default(),
pydocstyle: pydocstyle::settings::Settings::default(), pydocstyle: pydocstyle::settings::Settings::default(),
pyupgrade: pyupgrade::settings::Settings::default(), pyupgrade: pyupgrade::settings::Settings::default(),
} }
@ -308,7 +297,6 @@ impl Settings {
show_source: false, show_source: false,
src: vec![path_dedot::CWD.clone()], src: vec![path_dedot::CWD.clone()],
target_version: PythonVersion::Py310, target_version: PythonVersion::Py310,
task_tags: vec!["TODO".to_string()],
update_check: false, update_check: false,
flake8_annotations: flake8_annotations::settings::Settings::default(), flake8_annotations: flake8_annotations::settings::Settings::default(),
flake8_bandit: flake8_bandit::settings::Settings::default(), flake8_bandit: flake8_bandit::settings::Settings::default(),
@ -322,7 +310,6 @@ impl Settings {
isort: isort::settings::Settings::default(), isort: isort::settings::Settings::default(),
mccabe: mccabe::settings::Settings::default(), mccabe: mccabe::settings::Settings::default(),
pep8_naming: pep8_naming::settings::Settings::default(), pep8_naming: pep8_naming::settings::Settings::default(),
pycodestyle: pycodestyle::settings::Settings::default(),
pydocstyle: pydocstyle::settings::Settings::default(), pydocstyle: pydocstyle::settings::Settings::default(),
pyupgrade: pyupgrade::settings::Settings::default(), pyupgrade: pyupgrade::settings::Settings::default(),
} }

View file

@ -10,7 +10,7 @@ use crate::settings::types::{PythonVersion, SerializationFormat, Version};
use crate::{ use crate::{
flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions, flake8_annotations, flake8_bandit, flake8_bugbear, flake8_errmsg, flake8_import_conventions,
flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, isort, flake8_pytest_style, flake8_quotes, flake8_tidy_imports, flake8_unused_arguments, isort,
mccabe, pep8_naming, pycodestyle, pydocstyle, pyupgrade, mccabe, pep8_naming, pydocstyle, pyupgrade,
}; };
#[derive( #[derive(
@ -339,17 +339,6 @@ pub struct Options {
)] )]
/// A list of check code prefixes to consider un-autofix-able. /// A list of check code prefixes to consider un-autofix-able.
pub unfixable: Option<Vec<CheckCodePrefix>>, pub unfixable: Option<Vec<CheckCodePrefix>>,
#[option(
default = r#"["TODO", "FIXME", "XXX"]"#,
value_type = "Vec<String>",
example = r#"task-tags = ["HACK"]"#
)]
/// A list of task tags to recognize (e.g., "TODO", "FIXME", "XXX").
///
/// Comments starting with these tags will be ignored by commented-out code
/// detection (`ERA`), and skipped by line-length checks (`E501`) if
/// `ignore-overlong-task-comments` is set to `true`.
pub task_tags: Option<Vec<String>>,
#[option( #[option(
default = "true", default = "true",
value_type = "bool", value_type = "bool",
@ -395,9 +384,6 @@ pub struct Options {
/// Options for the `pep8-naming` plugin. /// Options for the `pep8-naming` plugin.
pub pep8_naming: Option<pep8_naming::settings::Options>, pub pep8_naming: Option<pep8_naming::settings::Options>,
#[option_group] #[option_group]
/// Options for the `pycodestyle` plugin.
pub pycodestyle: Option<pycodestyle::settings::Options>,
#[option_group]
/// Options for the `pydocstyle` plugin. /// Options for the `pydocstyle` plugin.
pub pydocstyle: Option<pydocstyle::settings::Options>, pub pydocstyle: Option<pydocstyle::settings::Options>,
#[option_group] #[option_group]

View file

@ -188,7 +188,6 @@ mod tests {
src: None, src: None,
target_version: None, target_version: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
flake8_annotations: None, flake8_annotations: None,
flake8_bandit: None, flake8_bandit: None,
@ -202,7 +201,6 @@ mod tests {
isort: None, isort: None,
mccabe: None, mccabe: None,
pep8_naming: None, pep8_naming: None,
pycodestyle: None,
pydocstyle: None, pydocstyle: None,
pyupgrade: None, pyupgrade: None,
}) })
@ -244,7 +242,6 @@ line-length = 79
src: None, src: None,
target_version: None, target_version: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
cache_dir: None, cache_dir: None,
flake8_annotations: None, flake8_annotations: None,
@ -259,7 +256,6 @@ line-length = 79
isort: None, isort: None,
mccabe: None, mccabe: None,
pep8_naming: None, pep8_naming: None,
pycodestyle: None,
pydocstyle: None, pydocstyle: None,
pyupgrade: None, pyupgrade: None,
}) })
@ -302,7 +298,6 @@ exclude = ["foo.py"]
src: None, src: None,
target_version: None, target_version: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
flake8_annotations: None, flake8_annotations: None,
flake8_bandit: None, flake8_bandit: None,
@ -316,7 +311,6 @@ exclude = ["foo.py"]
isort: None, isort: None,
mccabe: None, mccabe: None,
pep8_naming: None, pep8_naming: None,
pycodestyle: None,
pydocstyle: None, pydocstyle: None,
pyupgrade: None, pyupgrade: None,
}) })
@ -359,7 +353,6 @@ select = ["E501"]
src: None, src: None,
target_version: None, target_version: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
flake8_annotations: None, flake8_annotations: None,
flake8_bandit: None, flake8_bandit: None,
@ -373,7 +366,6 @@ select = ["E501"]
isort: None, isort: None,
mccabe: None, mccabe: None,
pep8_naming: None, pep8_naming: None,
pycodestyle: None,
pydocstyle: None, pydocstyle: None,
pyupgrade: None, pyupgrade: None,
}) })
@ -417,7 +409,6 @@ ignore = ["E501"]
src: None, src: None,
target_version: None, target_version: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
flake8_annotations: None, flake8_annotations: None,
flake8_bandit: None, flake8_bandit: None,
@ -431,7 +422,6 @@ ignore = ["E501"]
isort: None, isort: None,
mccabe: None, mccabe: None,
pep8_naming: None, pep8_naming: None,
pycodestyle: None,
pydocstyle: None, pydocstyle: None,
pyupgrade: None, pyupgrade: None,
}) })
@ -505,7 +495,6 @@ other-attribute = 1
format: None, format: None,
force_exclude: None, force_exclude: None,
unfixable: None, unfixable: None,
task_tags: None,
update_check: None, update_check: None,
cache_dir: None, cache_dir: None,
per_file_ignores: Some(FxHashMap::from_iter([( per_file_ignores: Some(FxHashMap::from_iter([(
@ -609,7 +598,6 @@ other-attribute = 1
]), ]),
staticmethod_decorators: Some(vec!["staticmethod".to_string()]), staticmethod_decorators: Some(vec!["staticmethod".to_string()]),
}), }),
pycodestyle: None,
pydocstyle: None, pydocstyle: None,
pyupgrade: None, pyupgrade: None,
} }