Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Added support for spacing linting rules SpReserved, SpBinop, SpTernary, SpPtrDecl and NspPtrDecl.
- Fixed inability to goto definition/reference on template references in 'in each' and 'for each' constructs
- Fixed incorrect parsing of comments at the last line of a file
- Fixed linter wrongly throwing an error on space after `defined` keyword

## 0.9.12
- Added 'simics\_util\_vect' as a known provisional (with no DLS semantics)
Expand Down
9 changes: 9 additions & 0 deletions src/lint/rules/spacing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,17 @@ pub struct NspUnaryRule {
pub type NspUnaryArgs = ZeroRange;

impl NspUnaryArgs {
fn is_exception(node: &UnaryExpressionContent) -> bool {
// Defined keyword counts as UnaryOp for DLS, but we allow space after it
if let Some(token) = node.operation.get_token() {
return token.kind == TokenKind::Defined
}
false
}

pub fn from_unary_expr(node: &UnaryExpressionContent)
-> Option<NspUnaryArgs> {
if Self::is_exception(node) { return None; }
let mut gap = node.range();
gap.col_start = node.operation.range().col_end;
gap.col_end = node.expr.range().col_start;
Expand Down
12 changes: 12 additions & 0 deletions src/lint/rules/tests/spacing/nsp_unary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,16 @@ method this_is_some_method(conf_object_t *dummy_obj) {
fn no_space_unary_correct() {
let rules = set_up();
assert_snippet(NO_SPACE_UNARY_CORRECT, vec![], &rules);
}

static UNARY_EXCEPTIONS: &str = "
method this_is_some_method(conf_object_t *dummy_obj) {
if (!defined attr_workaround)
return;
}
";
#[test]
fn unary_exceptions() {
let rules = set_up();
assert_snippet(UNARY_EXCEPTIONS, vec![], &rules);
}