diff options
author | Akshay <[email protected]> | 2021-12-04 07:32:57 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2021-12-04 07:34:20 +0000 |
commit | 21775f28cd1bdde8eddd84a508813b01d620db89 (patch) | |
tree | ca78b5732040253bc49baafa5f1889e848172daa /lib/src/utils.rs | |
parent | 1079486539d44b2e70c623fb4948d6e0b9b11812 (diff) |
new lint: empty_inherit
Diffstat (limited to 'lib/src/utils.rs')
-rw-r--r-- | lib/src/utils.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/src/utils.rs b/lib/src/utils.rs new file mode 100644 index 0000000..d7cf4c8 --- /dev/null +++ b/lib/src/utils.rs | |||
@@ -0,0 +1,16 @@ | |||
1 | use rnix::{SyntaxKind, SyntaxNode, TextRange}; | ||
2 | |||
3 | pub fn with_preceeding_whitespace(node: &SyntaxNode) -> TextRange { | ||
4 | let start = node | ||
5 | .prev_sibling_or_token() | ||
6 | .map(|t| { | ||
7 | if t.kind() == SyntaxKind::TOKEN_WHITESPACE { | ||
8 | t.text_range().start() | ||
9 | } else { | ||
10 | t.text_range().end() | ||
11 | } | ||
12 | }) | ||
13 | .unwrap_or(node.text_range().start()); | ||
14 | let end = node.text_range().end(); | ||
15 | TextRange::new(start, end) | ||
16 | } | ||