Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Ignore SPDX and contract size for tests #775

Merged
merged 5 commits into from
Jan 8, 2022

Conversation

onbjerg
Copy link
Collaborator

@onbjerg onbjerg commented Jan 8, 2022

Motivation

Following discussion in foundry-rs/foundry#399 we want to be able to ignore some errors for tests and dependencies, but not for source.

Solution

This PR just ignores 2 errors for both tests and dependencies by default: the SPDX and contract size warnings.

// files. if we are looking at one of these warnings
// from a test file we skip
if self.is_test(&source_location.file)
&& (*code == 1878 || *code == 5574) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super keen on this, but I am not entirely sure what direction to go in with fully configurable error codes based on types either in terms of DX or configuration. Is this fine for now or does anyone have any pointers on how to make this more elegant?

Comment on lines 540 to 547
pub fn has_warning<'a>(&self, ignored_error_codes: &'a [u64]) -> bool {
self.errors.iter().any(|err| {
let is_ignored = err.error_code.as_ref().map_or(false, |code| {
!ignored_error_codes.contains(code)
});

err.severity.is_warning() && !is_ignored
})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realized we had to filter for errors here too

self.compiler_output.has_warning(&self.ignored_error_codes)
}

fn is_test<T: AsRef<str>>(&self, contract_path: T) -> bool {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how robust this is and I couldn't really figure out a good way to do it for deps, should the test be "if it sits in node_modules or lib then it is a dependency"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, one idea I have is to leave this completely up to the user,

rn we're using it like this:

output.diagnostics(&self.ignored_error_codes).fmt(f)

perhaps we can add something like

 filter: dyn ContractFilter

trait ContractFilter {
   fn matches(&self, contract: &Contract) -> bool;
}

impl ContractFilter for () {
  fn matches(&self) -> boo {true}
}

then implement this for Fn(&str) -> bool

so we can add a CompilerOutput::diagnostics_with_filter(error_codes, dyn ContractFilter)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also do that for filtering of warnings in general, so instead of a contract filter etc. we just give the user

  • has_warnings
  • has_errors
  • a way to iterate the errors and filter them themselves

unless there is a specific reason we have this in ethers-solc as opposed to foundry?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sg, so we should map each error to its contract and ignore an error if:

  • ignored error code
  • contract should be ignored

@onbjerg onbjerg marked this pull request as ready for review January 8, 2022 16:55
@onbjerg onbjerg changed the title Granular error codes Ignore SPDX and contract size for tests Jan 8, 2022
@onbjerg onbjerg force-pushed the granular-error-codes branch from 08a001f to 371afb9 Compare January 8, 2022 16:59
Comment on lines 542 to 543
let is_ignored =
err.error_code.as_ref().map_or(false, |code| !ignored_error_codes.contains(code));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be more efficient to compute this only if err.severity.is_warning() == true

Copy link
Owner

@gakonst gakonst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gakonst gakonst merged commit 48bd3f1 into gakonst:master Jan 8, 2022
gakonst added a commit to foundry-rs/foundry that referenced this pull request Jan 8, 2022
* Pull latest ethers

* Do not suppress warnings on build

* Add `--ignored-error-codes` option

* chore: remove double success with warnings log

* chore: fix dai resolve addr test

https://github.com/gakonst/ethers-rs/pull/771/files

* fix: do not log output warnings if ignored

using gakonst/ethers-rs#775,
warnings for test contracts are not going to be logged.

Co-authored-by: Georgios Konstantopoulos <[email protected]>
charisma98 added a commit to charisma98/foundry that referenced this pull request Mar 4, 2023
* Pull latest ethers

* Do not suppress warnings on build

* Add `--ignored-error-codes` option

* chore: remove double success with warnings log

* chore: fix dai resolve addr test

https://github.com/gakonst/ethers-rs/pull/771/files

* fix: do not log output warnings if ignored

using gakonst/ethers-rs#775,
warnings for test contracts are not going to be logged.

Co-authored-by: Georgios Konstantopoulos <[email protected]>
0129general added a commit to 0129general/FoundryProject that referenced this pull request May 8, 2024
* Pull latest ethers

* Do not suppress warnings on build

* Add `--ignored-error-codes` option

* chore: remove double success with warnings log

* chore: fix dai resolve addr test

https://github.com/gakonst/ethers-rs/pull/771/files

* fix: do not log output warnings if ignored

using gakonst/ethers-rs#775,
warnings for test contracts are not going to be logged.

Co-authored-by: Georgios Konstantopoulos <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants