-
Notifications
You must be signed in to change notification settings - Fork 70
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
Moved cli frontend of the cairo linter to scarb command #1873
base: main
Are you sure you want to change the base?
Conversation
20943e9
to
38b357e
Compare
38b357e
to
2fa56b2
Compare
FYI, will change the |
.filter(|compilation_unit| { | ||
let is_main_component = compilation_unit.main_package_id() == package.id; | ||
let has_test_components = | ||
compilation_unit.components().iter().any(|component| { | ||
component.target_kind() == TargetKind::TEST | ||
&& component.package.id == package.id | ||
}); | ||
let is_integration_test_package = | ||
compilation_unit.main_package_id().name.to_string() | ||
== format!("{}_integrationtest", package.id.name) | ||
&& compilation_unit.main_package_id().version == package.id.version; | ||
is_main_component || has_test_components || is_integration_test_package | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should work in a slightly different way.
- Compilation units should be deduplicated per package, as there is no need to lint both
lib
andstarknet-contract
targets and each of them will get own CU. - To handle tests:
For unit tests (i.e. those defined in module tree under src
dir), whether tests will be checked or not is decided purely by cfg attrs. If you want to run checks of those, choose package CU with test target kind. When not, choose lib/starknet-contract/any available.
For integration tests (i.e. those in tests
dir), to find integration tests CU of the package you should:
- Take package you want to lint
- Find target of this package with target kind
test
andtest-type
param set tointegration
- Take name of this target from previous step
- Use this name and package id to construct new package id with
scarb/scarb/src/core/package/id.rs
Line 37 in fefeab6
pub fn for_test_target(self, target_name: SmolStr) -> Self { - Find CU with main package id equal to the one from previous step
We cannot rely on format!("{}_integrationtest"
though, while this happens to be the default name we add in auto-detected test targets, it can also be changed in Scarb manifest file (by defining the test target manually).
- Note, that if package relies on procedural macros, we need to compile them before linting the package. This means we need to take compilation units of those proc macro packages and run
ops::compile_unit
on them. See howscarb check
does this:scarb/scarb/src/ops/compile.rs
Lines 242 to 274 in fefeab6
// Select proc macro units that need to be compiled for Cairo compilation units. let required_plugins = units .iter() .flat_map(|unit| match unit { CompilationUnit::Cairo(unit) => unit .cairo_plugins .iter() .map(|p| p.package.id) .collect_vec(), _ => Vec::new(), }) .collect::<HashSet<PackageId>>(); // We guarantee that proc-macro units are always processed first, // so that all required plugins are compiled before we start checking Cairo units. let units = units.into_iter().sorted_by_key(|unit| { if matches!(unit, CompilationUnit::ProcMacro(_)) { 0 } else { 1 } }); for unit in units { if matches!(unit, CompilationUnit::ProcMacro(_)) && required_plugins.contains(&unit.main_package_id()) { compile_unit(unit, ws)?; } else { check_unit(unit, ws)?; } } Ok(())
} else { | ||
vec![compilation_units | ||
.iter() | ||
.find(|compilation_unit| compilation_unit.main_package_id() == package.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this would also check package units tests - see my previous comment.
Moved the fixing logic back to cairo-lint-core. software-mansion/cairo-lint#179. As soon as it's merged, will upgrade the deps here in Scarb |
@wawel37 Maybe we could calculate the change in |
TBH I've thought about it. I think both of the solutions are good. I mean, if we put the logic of mutating the files back in the Scarb, the responsibility of fixing will be separated to 2 different places but on the other hand everything that mutates files will stay within Scarb logic. tl;dr: |
No description provided.