use crate::Token;
use crate::expr::{Expr, SequenceExpr};
use crate::linting::expr_linter::Chunk;
use crate::linting::{ExprLinter, Lint, LintKind, Suggestion};
use crate::token_string_ext::TokenStringExt;
pub struct ItLooksLikeThat {
expr: SequenceExpr,
}
impl Default for ItLooksLikeThat {
fn default() -> Self {
Self {
expr: SequenceExpr::fixed_phrase("it looks like that")
.then_whitespace()
.then_kind_where(|kind| {
let is_subj = kind.is_subject_pronoun();
let is_ing = kind.is_verb_progressive_form();
let is_definitely_rel_pron = is_subj || is_ing;
let is_v3psgpres = kind.is_verb_third_person_singular_present_form();
let is_vmodal_or_aux = kind.is_auxiliary_verb();
let is_vpret = kind.is_verb_simple_past_form();
let is_noun = kind.is_noun();
let is_oov = kind.is_oov();
let maybe_demonstrative_or_determiner =
is_v3psgpres || is_vmodal_or_aux || is_vpret || is_noun || is_oov;
is_definitely_rel_pron || !maybe_demonstrative_or_determiner
}),
}
}
}
impl ExprLinter for ItLooksLikeThat {
type Unit = Chunk;
fn expr(&self) -> &dyn Expr {
&self.expr
}
fn match_to_lint(&self, toks: &[Token], _: &[char]) -> Option<Lint> {
let that_span = toks[6..8].span()?;
Some(Lint {
span: that_span,
lint_kind: LintKind::Redundancy,
suggestions: vec![Suggestion::Remove],
message: "`that` is redundant and ungrammatical here".to_string(),
priority: 31,
})
}
fn description(&self) -> &str {
"Corrects `it looks like that` to just `it looks like`."
}
}
#[cfg(test)]
mod tests {
mod that_noun {
use super::super::ItLooksLikeThat;
use crate::linting::tests::assert_no_lints;
#[test]
fn dont_flag_that_noun_is_also_verb_part_of_np() {
assert_no_lints(
"It looks like that file tree view is just for things that have already been committed?",
ItLooksLikeThat::default(),
);
}
#[test]
fn dont_flag_that_noun_is_also_adj() {
assert_no_lints(
"Yes, unfortunately it looks like that metric kind isn't supported yet.",
ItLooksLikeThat::default(),
);
}
#[test]
fn cant_flag_that_noun_is_also_verb_function() {
assert_no_lints(
"It looks like that function Config.validate_doc_path is only called in one place",
ItLooksLikeThat::default(),
);
}
#[test]
fn dont_flag_that_noun_is_also_verb_test() {
assert_no_lints(
"It looks like that test runs with -sOFFSCREEN_FRAMEBUFFER",
ItLooksLikeThat::default(),
);
}
#[test]
fn dont_flag_that_oov() {
assert_no_lints(
"It looks like that nms is not working.",
ItLooksLikeThat::default(),
);
}
#[test]
fn dont_flag_that_noun_pad() {
assert_no_lints(
"It looks like that pad was not covered in solder mask or glue",
ItLooksLikeThat::default(),
);
}
#[test]
fn dont_flag_that_noun_plural() {
assert_no_lints(
"The issue we're running into is that it looks like that nodes not only want to peer via raft",
ItLooksLikeThat::default(),
);
}
}
mod that_det {
use super::super::ItLooksLikeThat;
use crate::linting::tests::assert_suggestion_result;
#[test]
fn fix_that_the() {
assert_suggestion_result(
"it looks like that the original products should have NULL in the value column",
ItLooksLikeThat::default(),
"it looks like the original products should have NULL in the value column",
);
}
#[test]
fn fix_that_some() {
assert_suggestion_result(
"From first expresion it looks like that some tokkens or what was cached",
ItLooksLikeThat::default(),
"From first expresion it looks like some tokkens or what was cached",
);
}
}
mod that_verb {
use super::super::ItLooksLikeThat;
use crate::linting::tests::{assert_no_lints, assert_suggestion_result};
#[test]
fn dont_flag_that_verb_3p_sing_pres_is() {
assert_no_lints(
"Looking at the code it looks like that is not the case",
ItLooksLikeThat::default(),
);
}
#[test]
fn dont_flag_that_verb_3p_sing_pres_comes() {
assert_no_lints(
"it looks like that comes with additional compile-time dependencies",
ItLooksLikeThat::default(),
);
}
#[test]
fn fix_that_it_verb_lemma() {
assert_suggestion_result(
"It looks like that Renovate decides to not reuse the branch when there are no changes in it",
ItLooksLikeThat::default(),
"It looks like Renovate decides to not reuse the branch when there are no changes in it",
);
}
#[test]
fn dont_flag_that_modal_verb_might() {
assert_no_lints(
"It looks like that might be exactly what I needed!",
ItLooksLikeThat::default(),
);
}
#[test]
fn dont_flag_that_verb_modal_would() {
assert_no_lints(
"but it looks like that would require writing the data out to vsimem and reading it back",
ItLooksLikeThat::default(),
);
}
#[test]
fn fix_that_verb_ing_have() {
assert_suggestion_result(
"It looks like that having <br> tags inside them breaks the rendering",
ItLooksLikeThat::default(),
"It looks like having <br> tags inside them breaks the rendering",
);
}
#[test]
fn fix_that_verb_ing_using() {
assert_suggestion_result(
"it looks like that using TensorFlow in conjunction with packages that use pybind11_abseil will fail",
ItLooksLikeThat::default(),
"it looks like using TensorFlow in conjunction with packages that use pybind11_abseil will fail",
);
}
#[test]
fn dont_flag_that_verb_simple_past() {
assert_no_lints(
"but it looks like that got accidentally reverted at some point",
ItLooksLikeThat::default(),
);
}
}
mod pronoun {
use super::super::ItLooksLikeThat;
use crate::linting::tests::{assert_no_lints, assert_suggestion_result};
#[test]
fn fix_that_subj_obj_pronoun_it_was() {
assert_suggestion_result(
"It looks like that it was not improved a lot.",
ItLooksLikeThat::default(),
"It looks like it was not improved a lot.",
);
}
#[test]
fn fix_that_subj_obj_pronoun_it_works() {
assert_suggestion_result(
"Thx, it looks like that it works for Inpainting itself",
ItLooksLikeThat::default(),
"Thx, it looks like it works for Inpainting itself",
);
}
#[test]
fn fix_that_subj_obj_pronoun_you() {
assert_suggestion_result(
"It looks like that you can't use the files in combination.",
ItLooksLikeThat::default(),
"It looks like you can't use the files in combination.",
);
}
#[test]
fn dont_flag_thats() {
assert_no_lints(
"it looks like that's how you access the system changeset functionality",
ItLooksLikeThat::default(),
);
}
}
mod conjunction {
use super::super::ItLooksLikeThat;
use crate::linting::tests::assert_no_lints;
#[test]
fn cant_flag_that_if() {
assert_no_lints(
"It looks like that if the server goes away in the middle of a request, and a request is cancelled",
ItLooksLikeThat::default(),
);
}
#[test]
fn cant_flag_that_but() {
assert_no_lints(
"Yes, it looks like that but it is unreasonable since the shim executable is in the same directory",
ItLooksLikeThat::default(),
);
}
}
}