feat: remove report_fixme option

This commit is contained in:
Caleb Cartwright 2022-05-29 21:48:59 -05:00 committed by Caleb Cartwright
parent 4c8db85939
commit 825561deb8
5 changed files with 19 additions and 83 deletions

View File

@ -2168,18 +2168,6 @@ mod sit;
**Note** `mod` with `#[macro_export]` will not be reordered since that could change the semantics
of the original source code.
## `report_fixme`
Report `FIXME` items in comments.
- **Default value**: `"Never"`
- **Possible values**: `"Always"`, `"Unnumbered"`, `"Never"`
- **Stable**: No (tracking issue: [#3394](https://github.com/rust-lang/rustfmt/issues/3394))
Warns about any comments containing `FIXME` in them when set to `"Always"`. If
it contains a `#X` (with `X` being a number) in parentheses following the
`FIXME`, `"Unnumbered"` will ignore it.
## `required_version`
Require a specific version of rustfmt. If you want to make sure that the

View File

@ -164,8 +164,6 @@ create_config! {
error_on_unformatted: bool, false, false,
"Error if unable to get comments or string literals within max_width, \
or they are left with trailing whitespaces";
report_fixme: ReportTactic, ReportTactic::Never, false,
"Report all, none or unnumbered occurrences of FIXME in source file comments";
ignore: IgnoreList, IgnoreList::default(), false,
"Skip formatting the specified files and directories";
@ -623,7 +621,6 @@ skip_children = false
hide_parse_errors = false
error_on_line_overflow = false
error_on_unformatted = false
report_fixme = "Never"
ignore = []
emit_mode = "Files"
make_backup = false

View File

@ -497,7 +497,7 @@ impl<'a> FormatLines<'a> {
skipped_range: &'a [(usize, usize)],
config: &'a Config,
) -> FormatLines<'a> {
let issue_seeker = BadIssueSeeker::new(config.report_fixme());
let issue_seeker = BadIssueSeeker::new();
FormatLines {
name,
skipped_range,

View File

@ -6,8 +6,6 @@ use std::fmt;
use crate::config::ReportTactic;
const FIX_ME_CHARS: &[char] = &['f', 'i', 'x', 'm', 'e'];
// Enabled implementation detail is here because it is
// irrelevant outside the issues module
fn is_enabled(report_tactic: ReportTactic) -> bool {
@ -16,7 +14,7 @@ fn is_enabled(report_tactic: ReportTactic) -> bool {
#[derive(Clone, Copy)]
enum Seeking {
Issue { fixme_idx: usize },
Issue {},
Number { issue: Issue, part: NumberPart },
}
@ -30,7 +28,7 @@ enum NumberPart {
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub struct Issue {
issue_type: IssueType,
issue_type: Option<IssueType>,
// Indicates whether we're looking for issues with missing numbers, or
// all issues of this type.
missing_number: bool,
@ -39,7 +37,7 @@ pub struct Issue {
impl fmt::Display for Issue {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
let msg = match self.issue_type {
IssueType::Fixme => "FIXME",
_ => "",
};
let details = if self.missing_number {
" without issue number"
@ -52,9 +50,7 @@ impl fmt::Display for Issue {
}
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
enum IssueType {
Fixme,
}
enum IssueType {}
enum IssueClassification {
Good,
@ -64,27 +60,25 @@ enum IssueClassification {
pub(crate) struct BadIssueSeeker {
state: Seeking,
report_fixme: ReportTactic,
}
impl BadIssueSeeker {
pub(crate) fn new(report_fixme: ReportTactic) -> BadIssueSeeker {
pub(crate) fn new() -> BadIssueSeeker {
BadIssueSeeker {
state: Seeking::Issue { fixme_idx: 0 },
report_fixme,
state: Seeking::Issue {},
}
}
pub(crate) fn is_disabled(&self) -> bool {
!is_enabled(self.report_fixme)
true
}
// Check whether or not the current char is conclusive evidence for an
// unnumbered TO-DO or FIX-ME.
pub(crate) fn inspect(&mut self, c: char) -> Option<Issue> {
match self.state {
Seeking::Issue { fixme_idx } => {
self.state = self.inspect_issue(c, fixme_idx);
Seeking::Issue {} => {
self.state = self.inspect_issue(c, 0);
}
Seeking::Number { issue, part } => {
let result = self.inspect_number(c, issue, part);
@ -93,7 +87,7 @@ impl BadIssueSeeker {
return None;
}
self.state = Seeking::Issue { fixme_idx: 0 };
self.state = Seeking::Issue {};
if let IssueClassification::Bad(issue) = result {
return Some(issue);
@ -106,25 +100,10 @@ impl BadIssueSeeker {
fn inspect_issue(&mut self, c: char, mut fixme_idx: usize) -> Seeking {
if let Some(lower_case_c) = c.to_lowercase().next() {
if is_enabled(self.report_fixme) && lower_case_c == FIX_ME_CHARS[fixme_idx] {
// Exploit the fact that the character sets of todo and fixme
// are disjoint by adding else.
fixme_idx += 1;
if fixme_idx == FIX_ME_CHARS.len() {
return Seeking::Number {
issue: Issue {
issue_type: IssueType::Fixme,
missing_number: matches!(self.report_fixme, ReportTactic::Unnumbered),
},
part: NumberPart::OpenParen,
};
}
} else {
fixme_idx = 0;
}
fixme_idx = 0;
}
Seeking::Issue { fixme_idx }
Seeking::Issue {}
}
fn inspect_number(
@ -175,7 +154,7 @@ impl BadIssueSeeker {
#[test]
fn find_unnumbered_issue() {
fn check_fail(text: &str, failing_pos: usize) {
let mut seeker = BadIssueSeeker::new(ReportTactic::Unnumbered);
let mut seeker = BadIssueSeeker::new();
assert_eq!(
Some(failing_pos),
text.find(|c| seeker.inspect(c).is_some())
@ -183,51 +162,24 @@ fn find_unnumbered_issue() {
}
fn check_pass(text: &str) {
let mut seeker = BadIssueSeeker::new(ReportTactic::Unnumbered);
let mut seeker = BadIssueSeeker::new();
assert_eq!(None, text.find(|c| seeker.inspect(c).is_some()));
}
check_fail(" \n FIXME\n", 8);
check_fail("FIXME(\n", 6);
check_fail("FIXME(#\n", 7);
check_fail("FIXME(#1\n", 8);
check_fail("FIXME(#)1\n", 7);
check_pass("FIXME(#1222)\n");
check_fail("FIXME(#12\n22)\n", 9);
check_pass("FIXME(@maintainer, #1222, hello)\n");
}
#[test]
fn find_issue() {
fn is_bad_issue(text: &str, report_fixme: ReportTactic) -> bool {
let mut seeker = BadIssueSeeker::new(report_fixme);
fn is_bad_issue(text: &str) -> bool {
let mut seeker = BadIssueSeeker::new();
text.chars().any(|c| seeker.inspect(c).is_some())
}
assert!(is_bad_issue("This is a FIXME(#1)\n", ReportTactic::Always));
assert!(is_bad_issue(
"This is a FixMe(#1) mixed case\n",
ReportTactic::Always,
));
assert!(!is_bad_issue("bad FIXME\n", ReportTactic::Never));
}
#[test]
fn issue_type() {
let mut seeker = BadIssueSeeker::new(ReportTactic::Unnumbered);
let seeker = BadIssueSeeker::new();
let expected = Some(Issue {
issue_type: IssueType::Fixme,
issue_type: None,
missing_number: true,
});
assert_eq!(
expected,
"Test. FIXME: bad, bad, not good"
.chars()
.map(|c| seeker.inspect(c))
.find(Option::is_some)
.unwrap()
);
}

View File

@ -6,6 +6,5 @@ brace_style = "SameLineWhere"
fn_args_layout = "Tall"
trailing_comma = "Vertical"
indent_style = "Block"
report_fixme = "Never"
reorder_imports = false
format_strings = true