Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(all): Use parity-clippy-utils
This is necessary, because we need all the dependencies available on
crates.io to publish our crates.
  • Loading branch information
jubnzv committed Jan 12, 2024
commit cff5707e2cd7ff175364d5a58e893d0b8cd767b3
1 change: 1 addition & 0 deletions linting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"mandatory",
"extra",
"utils",
]

[workspace.metadata.dylint]
Expand Down
3 changes: 1 addition & 2 deletions linting/extra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name = "ink_linting"
version = "5.0.0-rc"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
publish = false

license = "Apache-2.0"
readme = "README.md"
Expand All @@ -18,11 +17,11 @@ include = ["Cargo.toml", "*.rs", "LICENSE"]
crate-type = ["cdylib"]

[dependencies]
ink_linting_clippy_utils = "0.1.73"
dylint_linting = "2.1.12"
if_chain = "1.0.2"
log = "0.4.14"
regex = "1.5.4"
ink_utils = { path = "../utils" }
# ink! dependencies used in the linter implementation
ink_env = { path = "../../crates/env", default-features = false }

Expand Down
1 change: 0 additions & 1 deletion linting/extra/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions linting/extra/src/non_fallible_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_utils::{
clippy::{
diagnostics::span_lint_and_then,
is_lint_allowed,
match_def_path,
},
expand_unnamed_consts,
find_contract_impl_id,
};
use if_chain::if_chain;
use ink_linting_clippy_utils::{
diagnostics::span_lint_and_then,
is_lint_allowed,
match_def_path,
};
use rustc_errors::Applicability;
use rustc_hir::{
self as hir,
Expand Down
2 changes: 1 addition & 1 deletion linting/extra/src/primitive_topic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use if_chain::if_chain;
use ink_linting_clippy_utils::{
use ink_utils::clippy::{
diagnostics::span_lint_and_then,
is_lint_allowed,
match_def_path,
Expand Down
16 changes: 8 additions & 8 deletions linting/extra/src/storage_never_freed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_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 if_chain::if_chain;
use ink_linting_clippy_utils::{
diagnostics::span_lint_and_help,
is_lint_allowed,
match_def_path,
match_path,
};
use rustc_hir::{
self as hir,
def::{
Expand Down
14 changes: 7 additions & 7 deletions linting/extra/src/strict_balance_equality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_utils::{
clippy::{
diagnostics::span_lint_hir_and_then,
match_any_def_paths,
match_def_path,
},
expand_unnamed_consts,
find_contract_impl_id,
};
use if_chain::if_chain;
use ink_linting_clippy_utils::{
diagnostics::span_lint_hir_and_then,
match_any_def_paths,
match_def_path,
};
use rustc_errors::Applicability;
use rustc_hir::{
self as hir,
Expand Down
3 changes: 1 addition & 2 deletions linting/mandatory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name = "ink_linting_mandatory"
version = "5.0.0-rc"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
publish = false

license = "Apache-2.0"
readme = "README.md"
Expand All @@ -18,11 +17,11 @@ include = ["Cargo.toml", "*.rs", "LICENSE"]
crate-type = ["cdylib"]

[dependencies]
ink_linting_clippy_utils = "0.1.73"
dylint_linting = "2.1.12"
if_chain = "1.0.2"
log = "0.4.14"
regex = "1.5.4"
ink_utils = { path = "../utils" }

[dev-dependencies]
dylint_testing = "2.1.12"
Expand Down
2 changes: 1 addition & 1 deletion linting/mandatory/src/no_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use ast::{
Crate,
};
use if_chain::if_chain;
use ink_linting_clippy_utils::diagnostics::span_lint_and_help;
use ink_utils::clippy::diagnostics::span_lint_and_help;
use rustc_ast as ast;
use rustc_lint::{
EarlyContext,
Expand Down
21 changes: 21 additions & 0 deletions linting/utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "ink_utils"
version = "5.0.0-rc"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"

license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/paritytech/ink"
documentation = "https://docs.rs/ink_linting"
homepage = "https://github.com/paritytech/ink"
description = "Utilities used internally in ink_linting crates"
keywords = ["parity", "blockchain", "ink", "smart contracts", "substrate"]
include = ["Cargo.toml", "*.rs", "LICENSE"]

[dependencies]
if_chain = "1.0.2"
parity_clippy_utils = "0.1.73"

[package.metadata.rust-analyzer]
rustc_private = true
34 changes: 24 additions & 10 deletions linting/extra/src/ink_utils.rs → linting/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,28 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![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 ink_linting_clippy_utils::match_def_path;
use rustc_hir::{
ExprKind,
HirId,
Expand All @@ -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<ItemId> {
pub fn find_storage_struct(cx: &LateContext, item_ids: &[ItemId]) -> Option<ItemId> {
item_ids
.iter()
.find(|&item_id| {
Expand Down Expand Up @@ -78,10 +95,7 @@ fn items_in_unnamed_const(cx: &LateContext<'_>, id: &ItemId) -> Vec<ItemId> {
}

/// Collect all the `ItemId`s in nested `const _: () = {}`
pub(crate) fn expand_unnamed_consts(
cx: &LateContext<'_>,
item_ids: &[ItemId],
) -> Vec<ItemId> {
pub fn expand_unnamed_consts(cx: &LateContext<'_>, item_ids: &[ItemId]) -> Vec<ItemId> {
item_ids.iter().fold(Vec::new(), |mut acc, item_id| {
acc.push(*item_id);
acc.append(&mut items_in_unnamed_const(cx, item_id));
Expand Down Expand Up @@ -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<ItemId>,
) -> Option<ItemId> {
Expand Down