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 semi_noninvasive_parents test #462

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct Opts<Identifier: Clone + Send + Sync + ValueEnum + 'static> {
#[clap(long, help = "Dump removal candidates and exit (for debugging)")]
dump_candidates: bool,
#[clap(long, help = "Assume testing framework is <FRAMEWORK>")]
framework: Option<framework::Auto<Identifier>>,
framework: Option<framework::auto::Auto<Identifier>>,
#[clap(long, help = "Do not perform dry runs")]
no_dry_run: bool,
#[clap(long, help = "Do not output to an sqlite database")]
Expand Down Expand Up @@ -64,7 +64,7 @@ pub struct Opts<Identifier: Clone + Send + Sync + ValueEnum + 'static> {
}

impl<Identifier: Clone + Send + Sync + ValueEnum> From<Opts<Identifier>>
for (Necessist, framework::Auto<Identifier>)
for (Necessist, framework::auto::Auto<Identifier>)
{
fn from(opts: Opts<Identifier>) -> Self {
let Opts {
Expand Down
6 changes: 3 additions & 3 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub struct Config {
// to parameterize every function that takes a `Necessist` as an argument.
pub fn necessist<Identifier: Applicable + Display + IntoEnumIterator + ToImplementation>(
opts: &Necessist,
framework: framework::Auto<Identifier>,
framework: framework::auto::Auto<Identifier>,
) -> Result<()> {
let mut opts = opts.clone();

Expand Down Expand Up @@ -158,7 +158,7 @@ pub fn necessist<Identifier: Applicable + Display + IntoEnumIterator + ToImpleme
#[allow(clippy::type_complexity)]
fn prepare<Identifier: Applicable + Display + IntoEnumIterator + ToImplementation>(
context: &LightContext,
framework: framework::Auto<Identifier>,
framework: framework::auto::Auto<Identifier>,
) -> Result<
Option<(
Option<sqlite::Sqlite>,
Expand Down Expand Up @@ -387,7 +387,7 @@ fn dump(context: &LightContext, removals: &[Removal]) {

fn find_framework<Identifier: Applicable + Display + IntoEnumIterator + ToImplementation>(
context: &LightContext,
identifier: framework::Auto<Identifier>,
identifier: framework::auto::Auto<Identifier>,
) -> Result<Box<dyn framework::Interface>> {
let implementation = identifier.to_implementation(context)?;

Expand Down
14 changes: 7 additions & 7 deletions core/src/framework/auto.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Applicable, Interface, ToImplementation, Union};
use super::{union, Applicable, Interface, ToImplementation};
use crate::LightContext;
use anyhow::{ensure, Result};
use std::fmt::Display;
Expand All @@ -14,11 +14,11 @@ enum Singleton {
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct Auto<T>(Union<Singleton, T>);
pub struct Auto<T>(union::Union<Singleton, T>);

impl<T> Default for Auto<T> {
fn default() -> Self {
Self(Union::Left(Singleton::Auto))
Self(union::Union::Left(Singleton::Auto))
}
}

Expand All @@ -28,7 +28,7 @@ where
{
fn to_implementation(&self, context: &LightContext) -> Result<Option<Box<dyn Interface>>> {
match &self.0 {
Union::Left(_) => {
union::Union::Left(_) => {
let unflattened_frameworks = T::iter()
.map(|framework| {
if framework.applicable(context)? {
Expand Down Expand Up @@ -61,7 +61,7 @@ where
Ok(None)
}
}
Union::Right(framework) => framework.to_implementation(context),
union::Union::Right(framework) => framework.to_implementation(context),
}
}
}
Expand All @@ -73,7 +73,7 @@ where
{
fn value_variants<'a>() -> &'a [Self] {
Box::leak(
Union::<Singleton, T>::value_variants()
union::Union::<Singleton, T>::value_variants()
.iter()
.cloned()
.map(Self)
Expand All @@ -87,6 +87,6 @@ where
}

fn from_str(input: &str, ignore_case: bool) -> Result<Self, String> {
Union::<Singleton, T>::from_str(input, ignore_case).map(Self)
union::Union::<Singleton, T>::from_str(input, ignore_case).map(Self)
}
}
11 changes: 4 additions & 7 deletions core/src/framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ use heck::ToKebabCase;
use std::{any::type_name, path::Path};
use subprocess::{Exec, Popen};

mod auto;
pub use auto::Auto;
pub mod auto;

mod empty;
pub use empty::Empty;
pub mod empty;

mod union;
pub use union::Union;
pub mod union;

#[allow(dead_code)]
type AutoUnion<T, U> = Auto<Union<T, U>>;
type AutoUnion<T, U> = auto::Auto<union::Union<T, U>>;

pub type Postprocess = dyn Fn(&LightContext, Popen) -> Result<bool>;

Expand Down
13 changes: 4 additions & 9 deletions core/src/offset_based_rewriter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,26 @@

mod impls;

use impls::LazyRewriter;

#[cfg(feature = "check-rewrites")]
use impls::EagerRewriter;

pub trait Interface {
fn contents(self) -> String;
fn rewrite(&mut self, start: usize, end: usize, replacement: &str) -> String;
}

#[derive(Debug)]
pub struct OffsetBasedRewriter<'original> {
lazy: LazyRewriter<'original>,
lazy: impls::LazyRewriter<'original>,

#[cfg(feature = "check-rewrites")]
eager: EagerRewriter,
eager: impls::EagerRewriter,
}

impl<'original> OffsetBasedRewriter<'original> {
pub fn new(original: &'original str) -> Self {
Self {
lazy: LazyRewriter::new(original),
lazy: impls::LazyRewriter::new(original),

#[cfg(feature = "check-rewrites")]
eager: EagerRewriter::new(original),
eager: impls::EagerRewriter::new(original),
}
}
}
Expand Down
13 changes: 4 additions & 9 deletions core/src/offset_calculator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,25 @@ use proc_macro2::LineColumn;

mod impls;

use impls::CachingOffsetCalculator;

#[cfg(feature = "check-offsets")]
use impls::StatelessOffsetCalculator;

pub trait Interface {
fn offset_from_line_column(&mut self, line_column: LineColumn) -> (usize, bool);
}

#[derive(Debug)]
pub struct OffsetCalculator<'original> {
caching: CachingOffsetCalculator<'original>,
caching: impls::CachingOffsetCalculator<'original>,

#[cfg(feature = "check-offsets")]
stateless: StatelessOffsetCalculator<'original>,
stateless: impls::StatelessOffsetCalculator<'original>,
}

impl<'original> OffsetCalculator<'original> {
pub fn new(original: &'original str) -> Self {
Self {
caching: CachingOffsetCalculator::new(original),
caching: impls::CachingOffsetCalculator::new(original),

#[cfg(feature = "check-offsets")]
stateless: StatelessOffsetCalculator::new(original),
stateless: impls::StatelessOffsetCalculator::new(original),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates_io/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use clap::Parser;
use necessist_core::{cli, framework::Auto, necessist, Necessist};
use necessist_core::{cli, framework::auto::Auto, necessist, Necessist};
use necessist_frameworks::Identifier;
use std::env::args;

Expand Down
3 changes: 1 addition & 2 deletions frameworks/src/foundry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{collections::BTreeMap, fs::read_to_string, path::Path, process::Comman
use walkdir::WalkDir;

mod visitor;
use visitor::visit;

#[derive(Debug)]
pub struct Foundry {
Expand Down Expand Up @@ -52,7 +51,7 @@ impl Low for Foundry {
util::strip_prefix(test_file, context.root).unwrap()
)
})?;
let spans_visited = visit(
let spans_visited = visitor::visit(
self,
context.root.clone(),
test_file,
Expand Down
4 changes: 2 additions & 2 deletions frameworks/src/golang/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use tree_sitter::Parser;
use walkdir::WalkDir;

mod visitor;
use visitor::visit;

#[derive(Debug)]
pub struct Golang {
Expand Down Expand Up @@ -55,7 +54,8 @@ impl Low for Golang {
util::strip_prefix(test_file, context.root).unwrap()
)
})?;
let spans_visited = visit(self, context.root.clone(), test_file, &text, &tree)?;
let spans_visited =
visitor::visit(self, context.root.clone(), test_file, &text, &tree)?;
spans.extend(spans_visited);
Ok(())
};
Expand Down
3 changes: 1 addition & 2 deletions frameworks/src/hardhat_ts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use swc_core::{
use walkdir::WalkDir;

mod visitor;
use visitor::visit;

#[derive(Debug, Eq, PartialEq)]
enum ItMessageState {
Expand Down Expand Up @@ -113,7 +112,7 @@ impl High for HardhatTs {
util::strip_prefix(test_file, context.root).unwrap()
)
})?;
let spans_visited = visit(
let spans_visited = visitor::visit(
config,
self,
source_map,
Expand Down
12 changes: 6 additions & 6 deletions frameworks/src/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ use syn::parse_file;
use walkdir::WalkDir;

mod parsing;
use parsing::{cached_test_file_fs_module_path, cached_test_file_package, Parsing};

mod try_insert;
use try_insert::TryInsert;
#[allow(unused_imports)]
use try_insert::{self as _, TryInsert};

mod visitor;
use visitor::visit;

#[derive(Debug)]
pub struct Rust {
Expand Down Expand Up @@ -59,7 +58,7 @@ impl Low for Rust {
) -> Result<Vec<Span>> {
check_config(context, config)?;

let mut parsing = Parsing::default();
let mut parsing = parsing::Parsing::default();
let mut spans = Vec::new();

#[cfg_attr(
Expand All @@ -77,7 +76,8 @@ impl Low for Rust {
util::strip_prefix(test_file, context.root).unwrap()
)
})?;
let spans_visited = visit(context, config, self, &mut parsing, test_file, &file)?;
let spans_visited =
visitor::visit(context, config, self, &mut parsing, test_file, &file)?;
spans.extend(spans_visited);
Ok(())
};
Expand Down Expand Up @@ -173,7 +173,7 @@ impl Rust {
self.test_file_flags_cache
.entry(test_file.to_path_buf())
.or_try_insert_with(|| {
let package = cached_test_file_package(test_file_package_map, test_file)?;
let package = parsing::cached_test_file_package(test_file_package_map, test_file)?;

let mut flags = vec![
"--manifest-path".to_owned(),
Expand Down
10 changes: 5 additions & 5 deletions frameworks/src/rust/visitor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{cached_test_file_fs_module_path, Parsing, Rust};
use super::{parsing, Rust};
use anyhow::{Error, Result};
use necessist_core::{
warn, Config, LightContext, SourceFile, Span, ToInternalSpan, WarnFlags, Warning,
Expand All @@ -23,7 +23,7 @@ pub(super) fn visit(
context: &LightContext,
config: &Config,
framework: &mut Rust,
parsing: &mut Parsing,
parsing: &mut parsing::Parsing,
test_file: &Path,
file: &File,
) -> Result<Vec<Span>> {
Expand All @@ -40,7 +40,7 @@ struct Visitor<'ast, 'context, 'config, 'framework, 'parsing> {
context: &'context LightContext<'context>,
config: &'config Config,
framework: &'framework mut Rust,
parsing: &'parsing mut Parsing,
parsing: &'parsing mut parsing::Parsing,
source_file: SourceFile,
module_path: Vec<&'ast Ident>,
test_ident: Option<&'ast Ident>,
Expand Down Expand Up @@ -150,7 +150,7 @@ where
context: &'context LightContext,
config: &'config Config,
framework: &'framework mut Rust,
parsing: &'parsing mut Parsing,
parsing: &'parsing mut parsing::Parsing,
test_file: &Path,
) -> Self {
Self {
Expand Down Expand Up @@ -201,7 +201,7 @@ where
}

fn test_path(&mut self, span: &Span, ident: &Ident) -> Result<Vec<String>> {
let mut test_path = cached_test_file_fs_module_path(
let mut test_path = parsing::cached_test_file_fs_module_path(
&mut self.parsing.test_file_fs_module_path_cache,
&mut self.parsing.test_file_package_cache,
&span.source_file,
Expand Down
2 changes: 1 addition & 1 deletion necessist/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use anyhow::Result;
use clap::Parser;
use log::debug;
use necessist_core::{cli, framework::Auto, necessist, Necessist};
use necessist_core::{cli, framework::auto::Auto, necessist, Necessist};
use necessist_frameworks::Identifier;
use std::{
env::{args, var},
Expand Down
Loading