mirror of
https://github.com/danbulant/oxc
synced 2026-05-23 06:08:47 +00:00
fix(linter): skip no-multi-str on jsx attributes (#4666)
This commit is contained in:
parent
229a0e9c45
commit
cbf08d2761
1 changed files with 11 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
use oxc_ast::AstKind;
|
use oxc_ast::AstKind;
|
||||||
use oxc_diagnostics::OxcDiagnostic;
|
use oxc_diagnostics::OxcDiagnostic;
|
||||||
use oxc_macros::declare_oxc_lint;
|
use oxc_macros::declare_oxc_lint;
|
||||||
|
use oxc_semantic::AstNodeId;
|
||||||
use oxc_span::Span;
|
use oxc_span::Span;
|
||||||
|
|
||||||
use crate::{context::LintContext, rule::Rule, AstNode};
|
use crate::{context::LintContext, rule::Rule, AstNode};
|
||||||
|
|
@ -38,7 +39,7 @@ impl Rule for NoMultiStr {
|
||||||
// https://github.com/eslint/eslint/blob/9e6d6405c3ee774c2e716a3453ede9696ced1be7/lib/shared/ast-utils.js#L12
|
// https://github.com/eslint/eslint/blob/9e6d6405c3ee774c2e716a3453ede9696ced1be7/lib/shared/ast-utils.js#L12
|
||||||
let position =
|
let position =
|
||||||
source.find(|ch| matches!(ch, '\r' | '\n' | '\u{2028}' | '\u{2029}')).unwrap_or(0);
|
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
|
// We found the "newline" character but want to highlight the '\', so go back one
|
||||||
// character.
|
// character.
|
||||||
let multi_span_start =
|
let multi_span_start =
|
||||||
|
|
@ -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]
|
#[test]
|
||||||
fn test() {
|
fn test() {
|
||||||
use crate::tester::Tester;
|
use crate::tester::Tester;
|
||||||
|
|
@ -61,6 +69,8 @@ fn test() {
|
||||||
"var a = <div>
|
"var a = <div>
|
||||||
<h1>Wat</h1>
|
<h1>Wat</h1>
|
||||||
</div>;", // { "ecmaVersion": 6, "parserOptions": { "ecmaFeatures": { "jsx": true } } }
|
</div>;", // { "ecmaVersion": 6, "parserOptions": { "ecmaFeatures": { "jsx": true } } }
|
||||||
|
r#"<div class="line1
|
||||||
|
line2"></div>"#, // jsx
|
||||||
];
|
];
|
||||||
|
|
||||||
let fail = vec![
|
let fail = vec![
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue