11use crate :: linter:: { EarlyLintPass , EarlyLintVisitor , Lint , LintContext , Linter } ;
2- use foundry_compilers:: solc:: SolcLanguage ;
2+ use foundry_compilers:: { solc:: SolcLanguage , ProjectPathsConfig } ;
33use foundry_config:: lint:: Severity ;
44use rayon:: iter:: { IntoParallelIterator , ParallelIterator } ;
55use solar_ast:: { visit:: Visit , Arena } ;
@@ -22,8 +22,9 @@ pub mod med;
2222
2323/// Linter implementation to analyze Solidity source code responsible for identifying
2424/// vulnerabilities gas optimizations, and best practices.
25- #[ derive( Debug , Clone , Default ) ]
25+ #[ derive( Debug , Clone ) ]
2626pub struct SolidityLinter {
27+ path_config : ProjectPathsConfig ,
2728 severity : Option < Vec < Severity > > ,
2829 lints_included : Option < Vec < SolLint > > ,
2930 lints_excluded : Option < Vec < SolLint > > ,
@@ -32,8 +33,9 @@ pub struct SolidityLinter {
3233}
3334
3435impl SolidityLinter {
35- pub fn new ( ) -> Self {
36+ pub fn new ( path_config : ProjectPathsConfig ) -> Self {
3637 Self {
38+ path_config,
3739 severity : None ,
3840 lints_included : None ,
3941 lints_excluded : None ,
@@ -73,11 +75,15 @@ impl SolidityLinter {
7375 let _ = sess. enter ( || -> Result < ( ) , diagnostics:: ErrorGuaranteed > {
7476 // Declare all available passes and lints
7577 let mut passes_and_lints = Vec :: new ( ) ;
76- passes_and_lints. extend ( gas:: create_lint_passes ( ) ) ;
7778 passes_and_lints. extend ( high:: create_lint_passes ( ) ) ;
7879 passes_and_lints. extend ( med:: create_lint_passes ( ) ) ;
7980 passes_and_lints. extend ( info:: create_lint_passes ( ) ) ;
8081
82+ // Do not apply gas-severity rules on tests and scripts
83+ if !self . path_config . is_test_or_script ( file) {
84+ passes_and_lints. extend ( gas:: create_lint_passes ( ) ) ;
85+ }
86+
8187 // Filter based on linter config
8288 let mut passes: Vec < Box < dyn EarlyLintPass < ' _ > > > = passes_and_lints
8389 . into_iter ( )
0 commit comments