refactor: remove code for bad issue (e.g. todo/fixme) reporting
This commit is contained in:
parent
825561deb8
commit
5e4296767f
@ -146,6 +146,6 @@ fn error_kind_to_snippet_annotation_type(error_kind: &ErrorKind) -> AnnotationTy
|
||||
| ErrorKind::BadAttr
|
||||
| ErrorKind::InvalidGlobPattern(_)
|
||||
| ErrorKind::VersionMismatch => AnnotationType::Error,
|
||||
ErrorKind::BadIssue(_) | ErrorKind::DeprecatedAttr => AnnotationType::Warning,
|
||||
ErrorKind::DeprecatedAttr => AnnotationType::Warning,
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
use crate::comment::{CharClasses, FullCodeCharKind};
|
||||
use crate::config::{Config, FileName, Verbosity};
|
||||
use crate::formatting::generated::is_generated_file;
|
||||
use crate::issues::BadIssueSeeker;
|
||||
use crate::modules::Module;
|
||||
use crate::parse::parser::{DirectoryOwnership, Parser, ParserError};
|
||||
use crate::parse::session::ParseSess;
|
||||
@ -332,7 +331,6 @@ pub(crate) fn format_len(&self) -> (usize, usize) {
|
||||
ErrorKind::LineOverflow(found, max) => (max, found - max),
|
||||
ErrorKind::TrailingWhitespace
|
||||
| ErrorKind::DeprecatedAttr
|
||||
| ErrorKind::BadIssue(_)
|
||||
| ErrorKind::BadAttr
|
||||
| ErrorKind::LostComment
|
||||
| ErrorKind::LicenseCheck => {
|
||||
@ -483,11 +481,9 @@ struct FormatLines<'a> {
|
||||
cur_line: usize,
|
||||
newline_count: usize,
|
||||
errors: Vec<FormattingError>,
|
||||
issue_seeker: BadIssueSeeker,
|
||||
line_buffer: String,
|
||||
current_line_contains_string_literal: bool,
|
||||
format_line: bool,
|
||||
allow_issue_seek: bool,
|
||||
config: &'a Config,
|
||||
}
|
||||
|
||||
@ -497,7 +493,6 @@ fn new(
|
||||
skipped_range: &'a [(usize, usize)],
|
||||
config: &'a Config,
|
||||
) -> FormatLines<'a> {
|
||||
let issue_seeker = BadIssueSeeker::new();
|
||||
FormatLines {
|
||||
name,
|
||||
skipped_range,
|
||||
@ -506,8 +501,6 @@ fn new(
|
||||
cur_line: 1,
|
||||
newline_count: 0,
|
||||
errors: vec![],
|
||||
allow_issue_seek: !issue_seeker.is_disabled(),
|
||||
issue_seeker,
|
||||
line_buffer: String::with_capacity(config.max_width() * 2),
|
||||
current_line_contains_string_literal: false,
|
||||
format_line: config.file_lines().contains_line(name, 1),
|
||||
@ -536,13 +529,6 @@ fn iterate(&mut self, text: &mut String) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if self.allow_issue_seek && self.format_line {
|
||||
// Add warnings for bad fixmes
|
||||
if let Some(issue) = self.issue_seeker.inspect(c) {
|
||||
self.push_err(ErrorKind::BadIssue(issue), false, false);
|
||||
}
|
||||
}
|
||||
|
||||
if c == '\n' {
|
||||
self.new_line(kind);
|
||||
} else {
|
||||
|
185
src/issues.rs
185
src/issues.rs
@ -1,185 +0,0 @@
|
||||
// Objects for seeking through a char stream for occurrences of TODO and FIXME.
|
||||
// Depending on the loaded configuration, may also check that these have an
|
||||
// associated issue number.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use crate::config::ReportTactic;
|
||||
|
||||
// Enabled implementation detail is here because it is
|
||||
// irrelevant outside the issues module
|
||||
fn is_enabled(report_tactic: ReportTactic) -> bool {
|
||||
report_tactic != ReportTactic::Never
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum Seeking {
|
||||
Issue {},
|
||||
Number { issue: Issue, part: NumberPart },
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum NumberPart {
|
||||
OpenParen,
|
||||
Pound,
|
||||
Number,
|
||||
CloseParen,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
|
||||
pub struct Issue {
|
||||
issue_type: Option<IssueType>,
|
||||
// Indicates whether we're looking for issues with missing numbers, or
|
||||
// all issues of this type.
|
||||
missing_number: bool,
|
||||
}
|
||||
|
||||
impl fmt::Display for Issue {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
let msg = match self.issue_type {
|
||||
_ => "",
|
||||
};
|
||||
let details = if self.missing_number {
|
||||
" without issue number"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
write!(fmt, "{}{}", msg, details)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
|
||||
enum IssueType {}
|
||||
|
||||
enum IssueClassification {
|
||||
Good,
|
||||
Bad(Issue),
|
||||
None,
|
||||
}
|
||||
|
||||
pub(crate) struct BadIssueSeeker {
|
||||
state: Seeking,
|
||||
}
|
||||
|
||||
impl BadIssueSeeker {
|
||||
pub(crate) fn new() -> BadIssueSeeker {
|
||||
BadIssueSeeker {
|
||||
state: Seeking::Issue {},
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_disabled(&self) -> bool {
|
||||
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 {} => {
|
||||
self.state = self.inspect_issue(c, 0);
|
||||
}
|
||||
Seeking::Number { issue, part } => {
|
||||
let result = self.inspect_number(c, issue, part);
|
||||
|
||||
if let IssueClassification::None = result {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.state = Seeking::Issue {};
|
||||
|
||||
if let IssueClassification::Bad(issue) = result {
|
||||
return Some(issue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn inspect_issue(&mut self, c: char, mut fixme_idx: usize) -> Seeking {
|
||||
if let Some(lower_case_c) = c.to_lowercase().next() {
|
||||
fixme_idx = 0;
|
||||
}
|
||||
|
||||
Seeking::Issue {}
|
||||
}
|
||||
|
||||
fn inspect_number(
|
||||
&mut self,
|
||||
c: char,
|
||||
issue: Issue,
|
||||
mut part: NumberPart,
|
||||
) -> IssueClassification {
|
||||
if !issue.missing_number || c == '\n' {
|
||||
return IssueClassification::Bad(issue);
|
||||
} else if c == ')' {
|
||||
return if let NumberPart::CloseParen = part {
|
||||
IssueClassification::Good
|
||||
} else {
|
||||
IssueClassification::Bad(issue)
|
||||
};
|
||||
}
|
||||
|
||||
match part {
|
||||
NumberPart::OpenParen => {
|
||||
if c != '(' {
|
||||
return IssueClassification::Bad(issue);
|
||||
} else {
|
||||
part = NumberPart::Pound;
|
||||
}
|
||||
}
|
||||
NumberPart::Pound => {
|
||||
if c == '#' {
|
||||
part = NumberPart::Number;
|
||||
}
|
||||
}
|
||||
NumberPart::Number => {
|
||||
if ('0'..='9').contains(&c) {
|
||||
part = NumberPart::CloseParen;
|
||||
} else {
|
||||
return IssueClassification::Bad(issue);
|
||||
}
|
||||
}
|
||||
NumberPart::CloseParen => {}
|
||||
}
|
||||
|
||||
self.state = Seeking::Number { part, issue };
|
||||
|
||||
IssueClassification::None
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_unnumbered_issue() {
|
||||
fn check_fail(text: &str, failing_pos: usize) {
|
||||
let mut seeker = BadIssueSeeker::new();
|
||||
assert_eq!(
|
||||
Some(failing_pos),
|
||||
text.find(|c| seeker.inspect(c).is_some())
|
||||
);
|
||||
}
|
||||
|
||||
fn check_pass(text: &str) {
|
||||
let mut seeker = BadIssueSeeker::new();
|
||||
assert_eq!(None, text.find(|c| seeker.inspect(c).is_some()));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find_issue() {
|
||||
fn is_bad_issue(text: &str) -> bool {
|
||||
let mut seeker = BadIssueSeeker::new();
|
||||
text.chars().any(|c| seeker.inspect(c).is_some())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_type() {
|
||||
let seeker = BadIssueSeeker::new();
|
||||
let expected = Some(Issue {
|
||||
issue_type: None,
|
||||
missing_number: true,
|
||||
});
|
||||
}
|
@ -39,7 +39,6 @@
|
||||
use crate::comment::LineClasses;
|
||||
use crate::emitter::Emitter;
|
||||
use crate::formatting::{FormatErrorMap, FormattingError, ReportedErrors, SourceFile};
|
||||
use crate::issues::Issue;
|
||||
use crate::modules::ModuleResolutionError;
|
||||
use crate::parse::parser::DirectoryOwnership;
|
||||
use crate::shape::Indent;
|
||||
@ -69,7 +68,6 @@
|
||||
pub(crate) mod formatting;
|
||||
mod ignore_path;
|
||||
mod imports;
|
||||
mod issues;
|
||||
mod items;
|
||||
mod lists;
|
||||
mod macros;
|
||||
@ -110,9 +108,6 @@ pub enum ErrorKind {
|
||||
/// Line ends in whitespace.
|
||||
#[error("left behind trailing whitespace")]
|
||||
TrailingWhitespace,
|
||||
/// TODO or FIXME item without an issue number.
|
||||
#[error("found {0}")]
|
||||
BadIssue(Issue),
|
||||
/// License check has failed.
|
||||
#[error("license check failed")]
|
||||
LicenseCheck,
|
||||
@ -236,8 +231,7 @@ fn track_errors(&self, new_errors: &[FormattingError]) {
|
||||
ErrorKind::LostComment => {
|
||||
errs.has_unformatted_code_errors = true;
|
||||
}
|
||||
ErrorKind::BadIssue(_)
|
||||
| ErrorKind::LicenseCheck
|
||||
ErrorKind::LicenseCheck
|
||||
| ErrorKind::DeprecatedAttr
|
||||
| ErrorKind::BadAttr
|
||||
| ErrorKind::VersionMismatch => {
|
||||
|
Loading…
Reference in New Issue
Block a user