Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add task-tags & ignore-overlong-task-comments settings #1550

Merged
merged 4 commits into from Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions README.md
Expand Up @@ -2224,6 +2224,27 @@ 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)

A list of check code prefixes to consider un-autofix-able.
Expand Down Expand Up @@ -2970,6 +2991,27 @@ 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"]).
not-my-profile marked this conversation as resolved.
Show resolved Hide resolved

**Default value**: `false`

**Type**: `bool`

**Example usage**:

```toml
[tool.ruff.pycodestyle]
ignore-overlong-task-comments = true
```

---

### `pydocstyle`

#### [`convention`](#convention)
Expand Down
14 changes: 14 additions & 0 deletions flake8_to_ruff/src/converter.rs
Expand Up @@ -390,6 +390,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
task_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -402,6 +403,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -450,6 +452,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
task_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -462,6 +465,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -510,6 +514,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
task_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -522,6 +527,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -570,6 +576,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
task_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -582,6 +589,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -630,6 +638,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
task_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -647,6 +656,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -699,6 +709,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
task_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -711,6 +722,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: Some(pydocstyle::settings::Options {
convention: Some(Convention::Numpy),
}),
Expand Down Expand Up @@ -762,6 +774,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
task_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -779,6 +792,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down
6 changes: 6 additions & 0 deletions resources/test/fixtures/pycodestyle/E501_1.py
@@ -0,0 +1,6 @@
# 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`
34 changes: 34 additions & 0 deletions ruff.schema.json
Expand Up @@ -288,6 +288,17 @@
}
}
},
"pycodestyle": {
"description": "Options for the `pycodestyle` plugin.",
"anyOf": [
{
"$ref": "#/definitions/Pycodestyle"
},
{
"type": "null"
}
]
},
"pydocstyle": {
"description": "Options for the `pydocstyle` plugin.",
"anyOf": [
Expand Down Expand Up @@ -366,6 +377,16 @@
}
]
},
"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": {
"description": "A list of check code prefixes to consider un-autofix-able.",
"type": [
Expand Down Expand Up @@ -1443,6 +1464,19 @@
},
"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": {
"type": "object",
"properties": {
Expand Down
2 changes: 1 addition & 1 deletion src/checkers/lines.rs
Expand Up @@ -57,7 +57,7 @@ pub fn check_lines(
}

if enforce_line_too_long {
if let Some(check) = line_too_long(index, line, settings.line_length) {
if let Some(check) = line_too_long(index, line, settings) {
checks.push(check);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/eradicate/checks.rs
Expand Up @@ -31,7 +31,7 @@ pub fn commented_out_code(
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.
if is_standalone_comment(&line) && comment_contains_code(&line) {
if is_standalone_comment(&line) && comment_contains_code(&line, &settings.task_tags[..]) {
let mut check = Check::new(CheckKind::CommentedOutCode, Range::new(start, end));
if matches!(autofix, flags::Autofix::Enabled)
&& settings.fixable.contains(&CheckCode::ERA001)
Expand Down