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

Moved cli frontend of the cairo linter to scarb command #1873

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

wawel37
Copy link
Member

@wawel37 wawel37 commented Jan 8, 2025

No description provided.

Cargo.toml Outdated Show resolved Hide resolved
scarb/src/bin/scarb/args.rs Outdated Show resolved Hide resolved
scarb/src/bin/scarb/args.rs Outdated Show resolved Hide resolved
scarb/src/bin/scarb/args.rs Outdated Show resolved Hide resolved
scarb/src/ops/lint.rs Outdated Show resolved Hide resolved
scarb/src/ops/lint.rs Outdated Show resolved Hide resolved
scarb/src/ops/lint.rs Outdated Show resolved Hide resolved
scarb/src/ops/lint.rs Outdated Show resolved Hide resolved
@wawel37 wawel37 marked this pull request as ready for review January 9, 2025 11:21
@wawel37 wawel37 requested a review from a team as a code owner January 9, 2025 11:21
@wawel37 wawel37 force-pushed the cairo-lint-extension branch from 20943e9 to 38b357e Compare January 9, 2025 11:21
@wawel37 wawel37 force-pushed the cairo-lint-extension branch from 38b357e to 2fa56b2 Compare January 9, 2025 11:23
@wawel37
Copy link
Member Author

wawel37 commented Jan 9, 2025

FYI, will change the cairo-toolchain-xtasks version after we merge this

@wawel37 wawel37 requested review from maciektr and mkaput January 9, 2025 12:06
scarb/tests/lint.rs Outdated Show resolved Hide resolved
scarb/src/ops/lint.rs Outdated Show resolved Hide resolved
Comment on lines +64 to +76
.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
})
Copy link
Contributor

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.

  1. Compilation units should be deduplicated per package, as there is no need to lint both lib and starknet-contract targets and each of them will get own CU.
  2. 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 and test-type param set to integration
  • Take name of this target from previous step
  • Use this name and package id to construct new package id with
    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).

  1. 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 how scarb check does this:
    // 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)
Copy link
Contributor

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.

scarb/src/ops/lint.rs Show resolved Hide resolved
scarb/src/ops/lint.rs Outdated Show resolved Hide resolved
scarb/src/ops/lint.rs Outdated Show resolved Hide resolved
scarb/src/ops/lint.rs Outdated Show resolved Hide resolved
scarb/src/ops/compile.rs Outdated Show resolved Hide resolved
scarb/src/ops/expand.rs Outdated Show resolved Hide resolved
scarb/src/bin/scarb/args.rs Show resolved Hide resolved
scarb/src/ops/lint.rs Outdated Show resolved Hide resolved
scarb/src/ops/lint.rs Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
scarb/src/ops/lint.rs Outdated Show resolved Hide resolved
@wawel37
Copy link
Member Author

wawel37 commented Jan 10, 2025

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

@maciektr
Copy link
Contributor

@wawel37 Maybe we could calculate the change in cairo-lint-core and write to file here in Scarb? Wdyt?

@wawel37
Copy link
Member Author

wawel37 commented Jan 10, 2025

@wawel37 Maybe we could calculate the change in cairo-lint-core and write to file here in Scarb? Wdyt?

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:
I don't have a strong opinion on that. Maybe @mkaput got some opinion on that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants