fix(rslint_parser): comments detection
MODIFY
crates/rslint_parser/src/tests.rs
crates/rslint_parser/src/tests.rs
use crate::ast::{JsAnyRoot, JsCallArguments};
-use crate::{parse, parse_module, AstNode, Parse, SourceType, SyntaxNode, SyntaxToken};
+use crate::{
+ parse, parse_module, AstNode, Parse, SourceType, SyntaxNode, SyntaxNodeExt, SyntaxToken,
+};
use expect_test::expect_file;
use rome_rowan::{SyntaxKind, TextSize};
use rslint_errors::file::SimpleFile;
@@ -313,3 +315,12 @@ pub fn just_trivia_must_be_appended_to_eof() {
assert_eq!(TextSize::from(0), start);
assert_eq!(TextSize::from(34), end);
}
+
+#[test]
+pub fn node_contains_comments() {
+ let text = "true && true // comment";
+ let root = parse_module(text, 0);
+ let syntax = root.syntax();
+
+ assert!(syntax.contains_comments());
+}

MODIFY
crates/rslint_parser/src/util.rs
crates/rslint_parser/src/util.rs
@@ -160,7 +160,7 @@ pub trait SyntaxNodeExt {
fn contains_comments(&self) -> bool {
self.tokens()
.iter()
- .any(|tok| tok.kind() == JsSyntaxKind::COMMENT)
+ .any(|tok| tok.has_leading_comments() || tok.has_trailing_comments())
}
/// Get the first child with a specific kind.

fix(rslint_parser): comments detection (#2177)