Skip to content

Commit

Permalink
Add comment-tags & allow-overlong-lines-for-comment-tags settings
Browse files Browse the repository at this point in the history
It's quite common for TODO comments to be longer than line-length
so that you can quickly display them in full with `git grep TODO`.

Previously the ERA001 (CommentedOutCode) lint already hardcoded
TODO|FIXME|XXX within a regular expression to skip such comments.

This commit introduces a new comment-tags setting to make the comment
tags that should be skipped by lints configurable and adapts the E501
(LineTooLong) lint to optionally respect that new setting.
  • Loading branch information
not-my-profile committed Jan 3, 2023
1 parent 8329237 commit 98a9791
Show file tree
Hide file tree
Showing 17 changed files with 421 additions and 101 deletions.
38 changes: 38 additions & 0 deletions README.md
Expand Up @@ -1741,6 +1741,24 @@ cache-dir = "~/.cache/ruff"
---
#### [`comment-tags`](#comment-tags)
A list of comment tags to recognize (e.g. TODO, FIXME, XXX).
Comments starting with these tags will be skipped by E501 and ERA001.
**Default value**: `["TODO", "FIXME", "XXX"]`
**Type**: `Vec<String>`
**Example usage**:
```toml
[tool.ruff]
comment-tags = ["TODO", "FIXME", "HACK"]
```
---
#### [`dummy-variable-rgx`](#dummy-variable-rgx)
A regular expression used to identify "dummy" variables, or those which
Expand Down Expand Up @@ -2953,6 +2971,26 @@ staticmethod-decorators = ["staticmethod", "stcmthd"]
---
### `pycodestyle`
#### [`allow-overlong-lines-for-comment-tags`](#allow-overlong-lines-for-comment-tags)
Whether or not E501 (LineTooLong) should be triggered for comments
starting with one of the `comment-tags`.
**Default value**: `false`
**Type**: `bool`
**Example usage**:
```toml
[tool.ruff.pycodestyle]
allow-overlong-lines-for-comment-tags = true
```
---
### `pydocstyle`
#### [`convention`](#convention)
Expand Down
14 changes: 14 additions & 0 deletions flake8_to_ruff/src/converter.rs
Expand Up @@ -397,6 +397,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
comment_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -409,6 +410,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -457,6 +459,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
comment_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -469,6 +472,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -517,6 +521,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
comment_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -529,6 +534,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -577,6 +583,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
comment_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -589,6 +596,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -637,6 +645,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
comment_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -654,6 +663,7 @@ mod tests {
isort: None,
mccabe: None,
pep8_naming: None,
pycodestyle: None,
pydocstyle: None,
pyupgrade: None,
});
Expand Down Expand Up @@ -705,6 +715,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
comment_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -717,6 +728,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 @@ -768,6 +780,7 @@ mod tests {
src: None,
target_version: None,
unfixable: None,
comment_tags: None,
update_check: None,
flake8_annotations: None,
flake8_bugbear: None,
Expand All @@ -785,6 +798,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 comment-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 comment-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 comment-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 comment-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 comment-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 comment-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 @@ -22,6 +22,16 @@
"null"
]
},
"comment-tags": {
"description": "A list of comment tags to recognize (e.g. TODO, FIXME, XXX). Comments starting with these tags will be skipped by E501 and ERA001.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"dummy-variable-rgx": {
"description": "A regular expression used to identify \"dummy\" variables, or those which should be ignored when evaluating (e.g.) unused-variable checks. The default expression matches `_`, `__`, and `_var`, but not `_var_`.",
"type": [
Expand Down Expand Up @@ -288,6 +298,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 @@ -1418,6 +1439,19 @@
},
"additionalProperties": false
},
"Pycodestyle": {
"type": "object",
"properties": {
"allow-overlong-lines-for-comment-tags": {
"description": "Whether or not E501 (LineTooLong) should be triggered for comments starting with one of the `comment-tags`.",
"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.comment_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

0 comments on commit 98a9791

Please sign in to comment.