Skip to content

Commit aa2071c

Browse files
committed
Stop throwing error on space after defined keyword
1 parent 59ad629 commit aa2071c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/lint/rules/spacing.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,20 @@ pub struct NspUnaryRule {
677677
pub type NspUnaryArgs = ZeroRange;
678678

679679
impl NspUnaryArgs {
680+
fn is_exception(node: &UnaryExpressionContent) -> bool {
681+
// Defined keyword counts as UnaryOp for DLS, but we allow space after it
682+
match node.operation.get_token() {
683+
Some(token) => match token.kind {
684+
TokenKind::Defined => true,
685+
_ => false,
686+
},
687+
None => false,
688+
}
689+
}
690+
680691
pub fn from_unary_expr(node: &UnaryExpressionContent)
681692
-> Option<NspUnaryArgs> {
693+
if Self::is_exception(node) { return None; }
682694
let mut gap = node.range();
683695
gap.col_start = node.operation.range().col_end;
684696
gap.col_end = node.expr.range().col_start;

src/lint/rules/tests/spacing/nsp_unary.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,16 @@ method this_is_some_method(conf_object_t *dummy_obj) {
4343
fn no_space_unary_correct() {
4444
let rules = set_up();
4545
assert_snippet(NO_SPACE_UNARY_CORRECT, vec![], &rules);
46+
}
47+
48+
static UNARY_EXCEPTIONS: &str = "
49+
method this_is_some_method(conf_object_t *dummy_obj) {
50+
if (!defined attr_workaround)
51+
return;
52+
}
53+
";
54+
#[test]
55+
fn unary_exceptions() {
56+
let rules = set_up();
57+
assert_snippet(UNARY_EXCEPTIONS, vec![], &rules);
4658
}

0 commit comments

Comments
 (0)