Skip to content
Merged
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
12 changes: 11 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_multi_str.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::AstNodeId;
use oxc_span::Span;

use crate::{context::LintContext, rule::Rule, AstNode};
Expand Down Expand Up @@ -38,7 +39,7 @@ impl Rule for NoMultiStr {
// https://github.com/eslint/eslint/blob/9e6d6405c3ee774c2e716a3453ede9696ced1be7/lib/shared/ast-utils.js#L12
let position =
source.find(|ch| matches!(ch, '\r' | '\n' | '\u{2028}' | '\u{2029}')).unwrap_or(0);
if position != 0 {
if position != 0 && !is_within_jsx_attribute_item(node.id(), ctx) {
// We found the "newline" character but want to highlight the '\', so go back one
// character.
let multi_span_start =
Expand All @@ -52,6 +53,13 @@ impl Rule for NoMultiStr {
}
}

fn is_within_jsx_attribute_item(id: AstNodeId, ctx: &LintContext) -> bool {
if matches!(ctx.nodes().parent_kind(id), Some(AstKind::JSXAttributeItem(_))) {
return true;
}
false
}

#[test]
fn test() {
use crate::tester::Tester;
Expand All @@ -61,6 +69,8 @@ fn test() {
"var a = <div>
<h1>Wat</h1>
</div>;", // { "ecmaVersion": 6, "parserOptions": { "ecmaFeatures": { "jsx": true } } }
r#"<div class="line1
line2"></div>"#, // jsx
];

let fail = vec![
Expand Down