diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f8261b02a8..1a3cbb883df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Custom signature topic in Events - #[2031](/~https://github.com/paritytech/ink/pull/2031) - Linter: `non_fallible_api` lint - [#2004](/~https://github.com/paritytech/ink/pull/2004) +- Linter: Publish the linting crates on crates.io - [#2060](/~https://github.com/paritytech/ink/pull/2060) ### Fixed - Fix the `StorageVec` type by excluding the `len_cached` field from its type info - [#2052](/~https://github.com/paritytech/ink/pull/2052) diff --git a/linting/Cargo.toml b/linting/Cargo.toml index 82264da62e4..a3159ba46ec 100644 --- a/linting/Cargo.toml +++ b/linting/Cargo.toml @@ -3,8 +3,21 @@ resolver = "2" members = [ "mandatory", "extra", + "utils", ] +[workspace.package] +version = "5.0.0-rc" +authors = ["Parity Technologies "] +edition = "2021" +license = "Apache-2.0" +repository = "/~https://github.com/paritytech/ink" +homepage = "https://www.parity.io/" +keywords = ["parity", "blockchain", "edsl", "dylint", "linting"] + +[workspace.dependencies] +ink_linting_utils = { version = "=5.0.0-rc", path = "utils" } + [workspace.metadata.dylint] libraries = [ { path = "mandatory" }, diff --git a/linting/extra/Cargo.toml b/linting/extra/Cargo.toml index 3fff7174a2c..2cf9797fb70 100644 --- a/linting/extra/Cargo.toml +++ b/linting/extra/Cargo.toml @@ -1,38 +1,41 @@ [package] name = "ink_linting" -version = "5.0.0-rc" -authors = ["Parity Technologies "] -edition = "2021" -publish = false +version.workspace = true +authors.workspace = true +edition.workspace = true -license = "Apache-2.0" +license.workspace = true readme = "README.md" -repository = "/~https://github.com/paritytech/ink" +repository.workspace = true documentation = "https://docs.rs/ink_linting" -homepage = "/~https://github.com/paritytech/ink" -description = "Extra linting rules for ink! smart contracts" -keywords = ["parity", "blockchain", "ink", "smart contracts", "substrate"] +homepage.workspace = true +description = "Extra ink! linting rules" +keywords.workspace = true include = ["Cargo.toml", "*.rs", "LICENSE"] [lib] crate-type = ["cdylib"] [dependencies] -clippy_utils = { git = "/~https://github.com/rust-lang/rust-clippy", rev = "1d334696587ac22b3a9e651e7ac684ac9e0697b2" } dylint_linting = "2.1.12" if_chain = "1.0.2" log = "0.4.14" regex = "1.5.4" -# ink! dependencies used in the linter implementation -ink_env = { path = "../../crates/env", default-features = false } +ink_linting_utils = { workspace = true } +ink_env = { version = "=5.0.0-rc", path = "../../crates/env", default-features = false } [dev-dependencies] dylint_testing = "2.1.12" -# The following are ink! dependencies, they are only required for the `ui` tests. -ink = { path = "../../crates/ink", default-features = false, features = ["std"] } -ink_metadata = { path = "../../crates/metadata", default-features = false } -ink_primitives = { path = "../../crates/primitives", default-features = false } -ink_storage = { path = "../../crates/storage", default-features = false } + +# The ink! dependencies used to build the `ui` tests and to compile the linting +# library with `--default-features=std` (see the `features` section bellow). +# +# These cannot be moved to the workspace level because `cargo` does not provide +# the `[[workspace.dev-dependencies]]` directive. +ink = { version = "=5.0.0-rc", path = "../../crates/ink", default-features = false, features = ["std"] } +ink_metadata = { version = "=5.0.0-rc", path = "../../crates/metadata", default-features = false } +ink_primitives = { version = "=5.0.0-rc", path = "../../crates/primitives", default-features = false } +ink_storage = { version = "=5.0.0-rc", path = "../../crates/storage", default-features = false } scale = { package = "parity-scale-codec", version = "3.4", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"] } diff --git a/linting/extra/src/lib.rs b/linting/extra/src/lib.rs index 00cc666d70a..19c7ebe69a5 100644 --- a/linting/extra/src/lib.rs +++ b/linting/extra/src/lib.rs @@ -32,7 +32,6 @@ extern crate rustc_session; extern crate rustc_span; extern crate rustc_type_ir; -mod ink_utils; mod non_fallible_api; mod primitive_topic; mod storage_never_freed; diff --git a/linting/extra/src/non_fallible_api.rs b/linting/extra/src/non_fallible_api.rs index 82364cbe3de..24a5ff1e358 100644 --- a/linting/extra/src/non_fallible_api.rs +++ b/linting/extra/src/non_fallible_api.rs @@ -12,16 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::ink_utils::{ +use if_chain::if_chain; +use ink_linting_utils::{ + clippy::{ + diagnostics::span_lint_and_then, + is_lint_allowed, + match_def_path, + }, expand_unnamed_consts, find_contract_impl_id, }; -use clippy_utils::{ - diagnostics::span_lint_and_then, - is_lint_allowed, - match_def_path, -}; -use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{ self as hir, diff --git a/linting/extra/src/primitive_topic.rs b/linting/extra/src/primitive_topic.rs index a54daa5608b..da86ed7de93 100644 --- a/linting/extra/src/primitive_topic.rs +++ b/linting/extra/src/primitive_topic.rs @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -use clippy_utils::{ +use if_chain::if_chain; +use ink_linting_utils::clippy::{ diagnostics::span_lint_and_then, is_lint_allowed, match_def_path, source::snippet_opt, }; -use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{ self, diff --git a/linting/extra/src/storage_never_freed.rs b/linting/extra/src/storage_never_freed.rs index 6f623fd5d19..bafa3ed6ebc 100644 --- a/linting/extra/src/storage_never_freed.rs +++ b/linting/extra/src/storage_never_freed.rs @@ -12,18 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::ink_utils::{ +use if_chain::if_chain; +use ink_linting_utils::{ + clippy::{ + diagnostics::span_lint_and_help, + is_lint_allowed, + match_def_path, + match_path, + }, expand_unnamed_consts, find_contract_impl_id, find_storage_struct, }; -use clippy_utils::{ - diagnostics::span_lint_and_help, - is_lint_allowed, - match_def_path, - match_path, -}; -use if_chain::if_chain; use rustc_hir::{ self as hir, def::{ diff --git a/linting/extra/src/strict_balance_equality.rs b/linting/extra/src/strict_balance_equality.rs index bdcc7705dbe..a5bfb3f83c3 100644 --- a/linting/extra/src/strict_balance_equality.rs +++ b/linting/extra/src/strict_balance_equality.rs @@ -12,16 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::ink_utils::{ +use if_chain::if_chain; +use ink_linting_utils::{ + clippy::{ + diagnostics::span_lint_hir_and_then, + match_any_def_paths, + match_def_path, + }, expand_unnamed_consts, find_contract_impl_id, }; -use clippy_utils::{ - diagnostics::span_lint_hir_and_then, - match_any_def_paths, - match_def_path, -}; -use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{ self as hir, diff --git a/linting/mandatory/Cargo.toml b/linting/mandatory/Cargo.toml index db178816137..753dc39b0f2 100644 --- a/linting/mandatory/Cargo.toml +++ b/linting/mandatory/Cargo.toml @@ -1,37 +1,41 @@ [package] name = "ink_linting_mandatory" -version = "5.0.0-rc" -authors = ["Parity Technologies "] -edition = "2021" -publish = false +version.workspace = true +authors.workspace = true +edition.workspace = true -license = "Apache-2.0" +license.workspace = true readme = "README.md" -repository = "/~https://github.com/paritytech/ink" -documentation = "https://docs.rs/ink_linting" -homepage = "/~https://github.com/paritytech/ink" -description = "Mandatory ink! linting rules integrated in contracts' build process" -keywords = ["parity", "blockchain", "ink", "smart contracts", "substrate"] +repository.workspace = true +documentation = "https://docs.rs/ink_linting_mandatory" +homepage.workspace = true +description = "Mandatory ink! linting rules" +keywords.workspace = true include = ["Cargo.toml", "*.rs", "LICENSE"] [lib] crate-type = ["cdylib"] [dependencies] -clippy_utils = { git = "/~https://github.com/rust-lang/rust-clippy", rev = "1d334696587ac22b3a9e651e7ac684ac9e0697b2" } dylint_linting = "2.1.12" if_chain = "1.0.2" log = "0.4.14" regex = "1.5.4" +ink_linting_utils = { workspace = true } [dev-dependencies] dylint_testing = "2.1.12" -# The following are ink! dependencies, they are only required for the `ui` tests. -ink_env = { path = "../../crates/env", default-features = false } -ink = { path = "../../crates/ink", default-features = false, features = ["std"] } -ink_metadata = { path = "../../crates/metadata", default-features = false } -ink_primitives = { path = "../../crates/primitives", default-features = false } -ink_storage = { path = "../../crates/storage", default-features = false } + +# The ink! dependencies used to build the `ui` tests and to compile the linting +# library with `--default-features=std` (see the `features` section bellow). +# +# These cannot be moved to the workspace level because `cargo` does not provide +# the `[[workspace.dev-dependencies]]` directive. +ink = { version = "=5.0.0-rc", path = "../../crates/ink", default-features = false, features = ["std"] } +ink_env = { version = "=5.0.0-rc", path = "../../crates/env", default-features = false } +ink_metadata = { version = "=5.0.0-rc", path = "../../crates/metadata", default-features = false } +ink_primitives = { version = "=5.0.0-rc", path = "../../crates/primitives", default-features = false } +ink_storage = { version = "=5.0.0-rc", path = "../../crates/storage", default-features = false } scale = { package = "parity-scale-codec", version = "3.4", default-features = false, features = ["derive"] } scale-info = { version = "2.6", default-features = false, features = ["derive"] } diff --git a/linting/mandatory/src/no_main.rs b/linting/mandatory/src/no_main.rs index 3fff050b3b4..2fcf89bfac8 100644 --- a/linting/mandatory/src/no_main.rs +++ b/linting/mandatory/src/no_main.rs @@ -16,8 +16,8 @@ use ast::{ AttrStyle, Crate, }; -use clippy_utils::diagnostics::span_lint_and_help; use if_chain::if_chain; +use ink_linting_utils::clippy::diagnostics::span_lint_and_help; use rustc_ast as ast; use rustc_lint::{ EarlyContext, diff --git a/linting/utils/Cargo.toml b/linting/utils/Cargo.toml new file mode 100644 index 00000000000..59f6a16c1eb --- /dev/null +++ b/linting/utils/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "ink_linting_utils" +version.workspace = true +authors.workspace = true +edition.workspace = true + +license.workspace = true +readme = "README.md" +repository.workspace = true +documentation = "https://docs.rs/ink_linting_utils" +homepage.workspace = true +description = "Utilities used internally in ink_linting" +keywords.workspace = true +include = ["Cargo.toml", "*.rs", "LICENSE"] + +[dependencies] +if_chain = "1.0.2" +parity_clippy_utils = "0.1.73" + +[package.metadata.rust-analyzer] +rustc_private = true diff --git a/linting/utils/LICENSE b/linting/utils/LICENSE new file mode 120000 index 00000000000..ea5b60640b0 --- /dev/null +++ b/linting/utils/LICENSE @@ -0,0 +1 @@ +../LICENSE \ No newline at end of file diff --git a/linting/utils/README.md b/linting/utils/README.md new file mode 100644 index 00000000000..3cd9a91e37f --- /dev/null +++ b/linting/utils/README.md @@ -0,0 +1,2 @@ +# ink! linting utilities +This crate implements various utility functions used in `ink_linting` crates. It also provides access to the specific version of the `clippy_utils` crate. diff --git a/linting/extra/src/ink_utils.rs b/linting/utils/src/lib.rs similarity index 86% rename from linting/extra/src/ink_utils.rs rename to linting/utils/src/lib.rs index c63fa825b5e..117884b862b 100644 --- a/linting/extra/src/ink_utils.rs +++ b/linting/utils/src/lib.rs @@ -12,7 +12,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -use clippy_utils::match_def_path; +#![doc( + html_logo_url = "https://use.ink/img/crate-docs/logo.png", + html_favicon_url = "https://use.ink/crate-docs/favicon.png" +)] +#![feature(rustc_private)] +#![feature(box_patterns)] + +extern crate rustc_ast; +extern crate rustc_errors; +extern crate rustc_hir; +extern crate rustc_index; +extern crate rustc_lint; +extern crate rustc_middle; +extern crate rustc_mir_dataflow; +extern crate rustc_session; +extern crate rustc_span; +extern crate rustc_type_ir; + +pub use parity_clippy_utils as clippy; + +use clippy::match_def_path; use if_chain::if_chain; use rustc_hir::{ ExprKind, @@ -34,10 +54,7 @@ fn has_storage_attr(cx: &LateContext, hir: HirId) -> bool { } /// Returns `ItemId` of the structure annotated with `#[ink(storage)]` -pub(crate) fn find_storage_struct( - cx: &LateContext, - item_ids: &[ItemId], -) -> Option { +pub fn find_storage_struct(cx: &LateContext, item_ids: &[ItemId]) -> Option { item_ids .iter() .find(|&item_id| { @@ -78,10 +95,7 @@ fn items_in_unnamed_const(cx: &LateContext<'_>, id: &ItemId) -> Vec { } /// Collect all the `ItemId`s in nested `const _: () = {}` -pub(crate) fn expand_unnamed_consts( - cx: &LateContext<'_>, - item_ids: &[ItemId], -) -> Vec { +pub fn expand_unnamed_consts(cx: &LateContext<'_>, item_ids: &[ItemId]) -> Vec { item_ids.iter().fold(Vec::new(), |mut acc, item_id| { acc.push(*item_id); acc.append(&mut items_in_unnamed_const(cx, item_id)); @@ -124,7 +138,7 @@ fn eq_hir_struct_tys(lhs: &Ty<'_>, rhs: &Ty<'_>) -> bool { } /// Finds an ID of the implementation of the contract struct containing user-defined code -pub(crate) fn find_contract_impl_id( +pub fn find_contract_impl_id( cx: &LateContext<'_>, item_ids: Vec, ) -> Option {