Skip to content

Commit

Permalink
Added support of --skip--linting flag. (use-ink#468)
Browse files Browse the repository at this point in the history
* Added support of `--skip--linting` flag.

* Correct number of PR
  • Loading branch information
xgreenx authored Mar 18, 2022
1 parent 6fc0277 commit 82157f4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- `--skip-linting` flag that allows to skip the linting step during build process - [#468](https://github.com/paritytech/cargo-contract/pull/468)

## [1.0.0] - 2022-03-17

### Changed
Expand Down
56 changes: 42 additions & 14 deletions src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub(crate) struct ExecuteArgs {
unstable_flags: UnstableFlags,
optimization_passes: OptimizationPasses,
keep_debug_symbols: bool,
skip_linting: bool,
output_type: OutputType,
}

Expand All @@ -73,6 +74,9 @@ pub struct BuildCommand {
/// Build offline
#[clap(long = "--offline")]
build_offline: bool,
/// Skips linting checks during the build process
#[clap(long = "--skip-linting")]
skip_linting: bool,
/// Which build artifacts to generate.
///
/// - `all`: Generate the Wasm, the metadata and a bundled `<name>.contract` file.
Expand Down Expand Up @@ -176,6 +180,7 @@ impl BuildCommand {
unstable_flags,
optimization_passes,
keep_debug_symbols: self.keep_debug_symbols,
skip_linting: self.skip_linting,
output_type,
};

Expand Down Expand Up @@ -211,6 +216,7 @@ impl CheckCommand {
unstable_flags,
optimization_passes: OptimizationPasses::Zero,
keep_debug_symbols: false,
skip_linting: false,
output_type: OutputType::default(),
};

Expand Down Expand Up @@ -760,6 +766,7 @@ pub(crate) fn execute(args: ExecuteArgs) -> Result<BuildResult> {
unstable_flags,
optimization_passes,
keep_debug_symbols,
skip_linting,
output_type,
} = args;

Expand All @@ -771,13 +778,22 @@ pub(crate) fn execute(args: ExecuteArgs) -> Result<BuildResult> {
}

let build = || -> Result<OptimizationResult> {
maybe_println!(
verbosity,
" {} {}",
format!("[1/{}]", build_artifact.steps()).bold(),
"Checking ink! linting rules".bright_green().bold()
);
exec_cargo_dylint(&crate_metadata, verbosity)?;
if skip_linting {
maybe_println!(
verbosity,
" {} {}",
format!("[1/{}]", build_artifact.steps()).bold(),
"Skip ink! linting rules".bright_yellow().bold()
);
} else {
maybe_println!(
verbosity,
" {} {}",
format!("[1/{}]", build_artifact.steps()).bold(),
"Checking ink! linting rules".bright_green().bold()
);
exec_cargo_dylint(&crate_metadata, verbosity)?;
}

maybe_println!(
verbosity,
Expand Down Expand Up @@ -816,13 +832,22 @@ pub(crate) fn execute(args: ExecuteArgs) -> Result<BuildResult> {

let (opt_result, metadata_result) = match build_artifact {
BuildArtifacts::CheckOnly => {
maybe_println!(
verbosity,
" {} {}",
format!("[1/{}]", build_artifact.steps()).bold(),
"Checking ink! linting rules".bright_green().bold()
);
exec_cargo_dylint(&crate_metadata, verbosity)?;
if skip_linting {
maybe_println!(
verbosity,
" {} {}",
format!("[1/{}]", build_artifact.steps()).bold(),
"Skip ink! linting rules".bright_yellow().bold()
);
} else {
maybe_println!(
verbosity,
" {} {}",
format!("[1/{}]", build_artifact.steps()).bold(),
"Checking ink! linting rules".bright_green().bold()
);
exec_cargo_dylint(&crate_metadata, verbosity)?;
}

maybe_println!(
verbosity,
Expand Down Expand Up @@ -1029,6 +1054,7 @@ mod tests_ci_only {
// we choose zero optimization passes as the "cli" parameter
optimization_passes: Some(OptimizationPasses::Zero),
keep_debug_symbols: false,
skip_linting: false,
output_json: false,
};

Expand Down Expand Up @@ -1070,6 +1096,7 @@ mod tests_ci_only {
// we choose no optimization passes as the "cli" parameter
optimization_passes: None,
keep_debug_symbols: false,
skip_linting: false,
output_json: false,
};

Expand Down Expand Up @@ -1239,6 +1266,7 @@ mod tests_ci_only {
unstable_options: UnstableOptions::default(),
optimization_passes: None,
keep_debug_symbols: false,
skip_linting: false,
output_json: false,
};
let res = cmd.exec().expect("build failed");
Expand Down

0 comments on commit 82157f4

Please sign in to comment.