From 07227a1178a26171c1765fd6d73248cd8e59a09f Mon Sep 17 00:00:00 2001 From: Victorien Elvinger Date: Sun, 2 Mar 2025 20:23:49 +0100 Subject: [PATCH] refactor(noOctalEscape): fixes and improvements --- .../src/analyzer/linter/rules.rs | 3 +- .../src/lint/nursery/no_octal_escape.rs | 133 +- .../nursery/no_useless_escape_in_string.rs | 10 +- .../specs/nursery/noOctalEscape/invalid.js | 77 +- .../nursery/noOctalEscape/invalid.js.snap | 1338 +++-------------- .../specs/nursery/noOctalEscape/valid.js | 47 +- .../specs/nursery/noOctalEscape/valid.js.snap | 48 +- .../@biomejs/backend-jsonrpc/src/workspace.ts | 2 +- .../@biomejs/biome/configuration_schema.json | 2 +- 9 files changed, 318 insertions(+), 1342 deletions(-) diff --git a/crates/biome_configuration/src/analyzer/linter/rules.rs b/crates/biome_configuration/src/analyzer/linter/rules.rs index 51b01505e439..f11bdc010154 100644 --- a/crates/biome_configuration/src/analyzer/linter/rules.rs +++ b/crates/biome_configuration/src/analyzer/linter/rules.rs @@ -3111,7 +3111,7 @@ pub struct Nursery { Option>, #[doc = "Disallow octal escape sequences in string literals"] #[serde(skip_serializing_if = "Option::is_none")] - pub no_octal_escape: Option>, + pub no_octal_escape: Option>, #[doc = "Restricts imports of \"package private\" exports."] #[serde(skip_serializing_if = "Option::is_none")] pub no_package_private_imports: @@ -3345,6 +3345,7 @@ impl Nursery { RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[9]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[10]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[21]), + RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[24]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[34]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[35]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[36]), diff --git a/crates/biome_js_analyze/src/lint/nursery/no_octal_escape.rs b/crates/biome_js_analyze/src/lint/nursery/no_octal_escape.rs index 6988385b8130..5be55342f07e 100644 --- a/crates/biome_js_analyze/src/lint/nursery/no_octal_escape.rs +++ b/crates/biome_js_analyze/src/lint/nursery/no_octal_escape.rs @@ -1,9 +1,12 @@ use biome_analyze::{ - Ast, Rule, RuleDiagnostic, RuleSource, context::RuleContext, declare_lint_rule, + Ast, FixKind, Rule, RuleDiagnostic, RuleSource, context::RuleContext, declare_lint_rule, }; use biome_console::markup; -use biome_js_syntax::JsStringLiteralExpression; -use biome_rowan::AstNode; +use biome_diagnostics::Severity; +use biome_js_syntax::{JsLiteralMemberName, JsStringLiteralExpression, JsSyntaxToken}; +use biome_rowan::{BatchMutationExt, SyntaxResult, TextRange, declare_node_union}; + +use crate::JsRuleAction; declare_lint_rule! { /// Disallow octal escape sequences in string literals @@ -16,15 +19,14 @@ declare_lint_rule! { /// ### Invalid /// /// ```js,expect_diagnostic - /// var foo = "Copyright \251"; + /// const foo = "Copyright \251"; /// ``` /// /// ### Valid /// /// ```js - /// var foo = "Copyright \u00A9"; // unicode - /// - /// var foo = "Copyright \xA9"; // hexadecimal + /// const foo = "Copyright \u00A9"; // unicode escape + /// const bar = "Copyright \xA9"; // hexadecimal escape /// ``` /// pub NoOctalEscape { @@ -32,28 +34,34 @@ declare_lint_rule! { name: "noOctalEscape", language: "js", sources: &[RuleSource::Eslint("no-octal-escape")], - recommended: false, + recommended: true, + severity: Severity::Warning, + fix_kind: FixKind::Safe, } } impl Rule for NoOctalEscape { - type Query = Ast; - type State = (); + type Query = Ast; + type State = RuleState; type Signals = Option; type Options = (); fn run(ctx: &RuleContext) -> Self::Signals { - let node = ctx.query(); - let token = node.value_token().ok()?; - let text = token.text(); - - let bytes = text.as_bytes(); - let mut byte_it = bytes.iter(); - while let Some(&byte) = byte_it.next() { + let token = ctx.query().value_token().ok()?; + let mut it = token.text_trimmed().bytes().enumerate(); + while let Some((index, byte)) = it.next() { if byte == b'\\' { - if let Some(&next_byte) = byte_it.next() { - if (b'0'..=b'7').contains(&next_byte) { - return Some(()); + if let Some((_, byte)) = it.next() { + if matches!(byte, b'0'..=b'7') { + let len = 2 + it + .clone() + .take(5) + .take_while(|(_, byte)| matches!(byte, b'0'..=b'7')) + .count(); + // Ignore the non-deprecated `\0` + if byte != b'0' || len > 2 { + return Some(RuleState { index, len }); + } } } } @@ -61,24 +69,73 @@ impl Rule for NoOctalEscape { None } - fn diagnostic(ctx: &RuleContext, _state: &Self::State) -> Option { - let node = ctx.query(); - let token = node.value_token().ok()?; - let text = token.text(); - Some( - RuleDiagnostic::new( - rule_category!(), - node.range(), - markup! { - "Don't use ""octal" - }, + fn diagnostic( + ctx: &RuleContext, + RuleState { index, len }: &Self::State, + ) -> Option { + let token = ctx.query().value_token().ok()?; + let escape_start = token + .text_trimmed_range() + .start() + .checked_add((*index as u32).into())?; + Some(RuleDiagnostic::new( + rule_category!(), + TextRange::at(escape_start, (*len as u32).into()), + markup! { + "Don't use deprecated ""octal escape sequences""." + }, + )) + } + + fn action( + ctx: &RuleContext, + RuleState { index, len }: &Self::State, + ) -> Option { + let token = ctx.query().value_token().ok()?; + let text = token.text_trimmed(); + let octal = &text[(index + 1)..(index + len)]; + let codepoint = u32::from_str_radix(octal, 8).ok()?; + let before_octal = &text[..(index + 1)]; + let after_octal = &text[(index + len)..]; + let (new_text, unicode_or_hexa) = if codepoint <= 0xff { + ( + format!("{before_octal}x{codepoint:02x}{after_octal}"), + "hexadecimal", + ) + } else { + ( + format!("{before_octal}u{codepoint:04x}{after_octal}"), + "unicode", ) - .note(markup! { - "Don't use octal escape sequences: " {text} - }) - .note(markup! { - "Use unicode or hexidecimal escape sequences instead." - }), - ) + }; + let new_token = JsSyntaxToken::new_detached(token.kind(), &new_text, [], []); + let mut mutation = ctx.root().begin(); + mutation.replace_token_transfer_trivia(token.clone(), new_token); + Some(JsRuleAction::new( + ctx.metadata().action_category(ctx.category(), ctx.group()), + ctx.metadata().applicability(), + markup! { "Use "{unicode_or_hexa}" escape sequences instead." }.to_owned(), + mutation, + )) } } + +declare_node_union! { + /// Any string literal excluding JsxString. + pub AnyJsStringLiteral = JsStringLiteralExpression | JsLiteralMemberName +} +impl AnyJsStringLiteral { + pub fn value_token(&self) -> SyntaxResult { + match self { + AnyJsStringLiteral::JsStringLiteralExpression(node) => node.value_token(), + AnyJsStringLiteral::JsLiteralMemberName(node) => node.value(), + } + } +} + +pub struct RuleState { + // Index of the escape sequence (starts with `\`) + index: usize, + // Length of the escape sequence + len: usize, +} diff --git a/crates/biome_js_analyze/src/lint/nursery/no_useless_escape_in_string.rs b/crates/biome_js_analyze/src/lint/nursery/no_useless_escape_in_string.rs index aa34c62d43b2..6b759059bedd 100644 --- a/crates/biome_js_analyze/src/lint/nursery/no_useless_escape_in_string.rs +++ b/crates/biome_js_analyze/src/lint/nursery/no_useless_escape_in_string.rs @@ -62,7 +62,7 @@ declare_lint_rule! { } impl Rule for NoUselessEscapeInString { - type Query = Ast; + type Query = Ast; type State = (JsSyntaxToken, usize); type Signals = Option; type Options = (); @@ -70,12 +70,12 @@ impl Rule for NoUselessEscapeInString { fn run(ctx: &RuleContext) -> Self::Signals { let node = ctx.query(); match node { - AnyString::JsStringLiteralExpression(literal) => { + AnyJsString::JsStringLiteralExpression(literal) => { let token = literal.value_token().ok()?; let text = token.text(); next_useless_escape(text, text.bytes().next()?).map(|index| (token, index)) } - AnyString::JsTemplateExpression(template) => { + AnyJsString::JsTemplateExpression(template) => { if template.tag().is_some() { return None; } @@ -94,7 +94,7 @@ impl Rule for NoUselessEscapeInString { } None } - AnyString::JsLiteralMemberName(member_name) => { + AnyJsString::JsLiteralMemberName(member_name) => { let Ok(token) = member_name.value() else { return None; }; @@ -141,7 +141,7 @@ impl Rule for NoUselessEscapeInString { declare_node_union! { /// Any string literal excluding JsxString. - pub AnyString = JsStringLiteralExpression | JsTemplateExpression | JsLiteralMemberName + pub AnyJsString = JsStringLiteralExpression | JsTemplateExpression | JsLiteralMemberName } /// Returns the index in `str` of the first useless escape. diff --git a/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/invalid.js b/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/invalid.js index c3e9feac620f..ccde2dd20dd6 100644 --- a/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/invalid.js +++ b/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/invalid.js @@ -1,64 +1,15 @@ -var foo = "foo \01 bar"; -var foo = "foo \000 bar"; -var foo = "foo \377 bar"; -var foo = "foo \378 bar"; -var foo = "foo \37a bar"; -var foo = "foo \381 bar"; -var foo = "foo \3a1 bar"; -var foo = "foo \251 bar"; -var foo = "foo \258 bar"; -var foo = "foo \25a bar"; -var foo = "\3s51"; -var foo = "\77"; -var foo = "\78"; -var foo = "\5a"; -var foo = "\751"; -var foo = "foo \400 bar"; -var foo = "foo \400 bar"; -var foo = "\t\1"; -var foo = "\\\751"; -'\0\1' -'\0 \1' -'\0\01' -'\0 \01' -'\0a\1' -'\0a\01' -'\0\08' -'\1' -'\2' -'\7' -'\00' -'\01' -'\02' -'\07' -'\08' -'\09' -'\10' -'\12' -' \1' -'\1 ' -'a\1' -'\1a' -'a\1a' -' \01' -'\01 ' -'a\01' -'\01a' -'a\01a' -'a\08a' -'\n\1' -'\n\01' -'\n\08' -'\\\1' -'\\\01' -'\\\08' -'\\n\1' -'\01\02' -'\02\01' -'\01\2' -'\2\01' -'\08\1' -'foo \1 bar \2' - - +0; +"foo \01 bar"; +"foo \000 bar"; +"foo \377 bar"; +"foo \378 bar"; +"foo \37a bar"; +"foo \381 bar"; +"foo \3a1 bar"; +"foo \751 bar"; +"foo \258 bar"; +"foo \25a bar"; +const o = { + '\31': 0, +}; diff --git a/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/invalid.js.snap b/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/invalid.js.snap index fc1c98d4790b..6e7ce489c14c 100644 --- a/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/invalid.js.snap +++ b/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/invalid.js.snap @@ -1,1271 +1,285 @@ --- source: crates/biome_js_analyze/tests/spec_tests.rs expression: invalid.js -snapshot_kind: text --- # Input ```js -var foo = "foo \01 bar"; -var foo = "foo \000 bar"; -var foo = "foo \377 bar"; -var foo = "foo \378 bar"; -var foo = "foo \37a bar"; -var foo = "foo \381 bar"; -var foo = "foo \3a1 bar"; -var foo = "foo \251 bar"; -var foo = "foo \258 bar"; -var foo = "foo \25a bar"; -var foo = "\3s51"; -var foo = "\77"; -var foo = "\78"; -var foo = "\5a"; -var foo = "\751"; -var foo = "foo \400 bar"; -var foo = "foo \400 bar"; -var foo = "\t\1"; -var foo = "\\\751"; -'\0\1' -'\0 \1' -'\0\01' -'\0 \01' -'\0a\1' -'\0a\01' -'\0\08' -'\1' -'\2' -'\7' -'\00' -'\01' -'\02' -'\07' -'\08' -'\09' -'\10' -'\12' -' \1' -'\1 ' -'a\1' -'\1a' -'a\1a' -' \01' -'\01 ' -'a\01' -'\01a' -'a\01a' -'a\08a' -'\n\1' -'\n\01' -'\n\08' -'\\\1' -'\\\01' -'\\\08' -'\\n\1' -'\01\02' -'\02\01' -'\01\2' -'\2\01' -'\08\1' -'foo \1 bar \2' - - +0; +"foo \01 bar"; +"foo \000 bar"; +"foo \377 bar"; +"foo \378 bar"; +"foo \37a bar"; +"foo \381 bar"; +"foo \3a1 bar"; +"foo \751 bar"; +"foo \258 bar"; +"foo \25a bar"; +const o = { + '\31': 0, +}; ``` # Diagnostics ``` -invalid.js:1:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - > 1 │ var foo = "foo \01 bar"; - │ ^^^^^^^^^^^^^ - 2 │ var foo = "foo \000 bar"; - 3 │ var foo = "foo \377 bar"; - - i Don't use octal escape sequences: "foo \01 bar" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:2:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 1 │ var foo = "foo \01 bar"; - > 2 │ var foo = "foo \000 bar"; - │ ^^^^^^^^^^^^^^ - 3 │ var foo = "foo \377 bar"; - 4 │ var foo = "foo \378 bar"; - - i Don't use octal escape sequences: "foo \000 bar" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:3:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 1 │ var foo = "foo \01 bar"; - 2 │ var foo = "foo \000 bar"; - > 3 │ var foo = "foo \377 bar"; - │ ^^^^^^^^^^^^^^ - 4 │ var foo = "foo \378 bar"; - 5 │ var foo = "foo \37a bar"; - - i Don't use octal escape sequences: "foo \377 bar" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:4:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 2 │ var foo = "foo \000 bar"; - 3 │ var foo = "foo \377 bar"; - > 4 │ var foo = "foo \378 bar"; - │ ^^^^^^^^^^^^^^ - 5 │ var foo = "foo \37a bar"; - 6 │ var foo = "foo \381 bar"; - - i Don't use octal escape sequences: "foo \378 bar" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:5:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 3 │ var foo = "foo \377 bar"; - 4 │ var foo = "foo \378 bar"; - > 5 │ var foo = "foo \37a bar"; - │ ^^^^^^^^^^^^^^ - 6 │ var foo = "foo \381 bar"; - 7 │ var foo = "foo \3a1 bar"; - - i Don't use octal escape sequences: "foo \37a bar" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:6:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 4 │ var foo = "foo \378 bar"; - 5 │ var foo = "foo \37a bar"; - > 6 │ var foo = "foo \381 bar"; - │ ^^^^^^^^^^^^^^ - 7 │ var foo = "foo \3a1 bar"; - 8 │ var foo = "foo \251 bar"; - - i Don't use octal escape sequences: "foo \381 bar" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:7:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 5 │ var foo = "foo \37a bar"; - 6 │ var foo = "foo \381 bar"; - > 7 │ var foo = "foo \3a1 bar"; - │ ^^^^^^^^^^^^^^ - 8 │ var foo = "foo \251 bar"; - 9 │ var foo = "foo \258 bar"; - - i Don't use octal escape sequences: "foo \3a1 bar" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:8:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 6 │ var foo = "foo \381 bar"; - 7 │ var foo = "foo \3a1 bar"; - > 8 │ var foo = "foo \251 bar"; - │ ^^^^^^^^^^^^^^ - 9 │ var foo = "foo \258 bar"; - 10 │ var foo = "foo \25a bar"; - - i Don't use octal escape sequences: "foo \251 bar" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:9:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 7 │ var foo = "foo \3a1 bar"; - 8 │ var foo = "foo \251 bar"; - > 9 │ var foo = "foo \258 bar"; - │ ^^^^^^^^^^^^^^ - 10 │ var foo = "foo \25a bar"; - 11 │ var foo = "\3s51"; - - i Don't use octal escape sequences: "foo \258 bar" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:10:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 8 │ var foo = "foo \251 bar"; - 9 │ var foo = "foo \258 bar"; - > 10 │ var foo = "foo \25a bar"; - │ ^^^^^^^^^^^^^^ - 11 │ var foo = "\3s51"; - 12 │ var foo = "\77"; - - i Don't use octal escape sequences: "foo \25a bar" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:11:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 9 │ var foo = "foo \258 bar"; - 10 │ var foo = "foo \25a bar"; - > 11 │ var foo = "\3s51"; - │ ^^^^^^^ - 12 │ var foo = "\77"; - 13 │ var foo = "\78"; - - i Don't use octal escape sequences: "\3s51" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:12:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 10 │ var foo = "foo \25a bar"; - 11 │ var foo = "\3s51"; - > 12 │ var foo = "\77"; - │ ^^^^^ - 13 │ var foo = "\78"; - 14 │ var foo = "\5a"; - - i Don't use octal escape sequences: "\77" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:13:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 11 │ var foo = "\3s51"; - 12 │ var foo = "\77"; - > 13 │ var foo = "\78"; - │ ^^^^^ - 14 │ var foo = "\5a"; - 15 │ var foo = "\751"; - - i Don't use octal escape sequences: "\78" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:14:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 12 │ var foo = "\77"; - 13 │ var foo = "\78"; - > 14 │ var foo = "\5a"; - │ ^^^^^ - 15 │ var foo = "\751"; - 16 │ var foo = "foo \400 bar"; - - i Don't use octal escape sequences: "\5a" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:15:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 13 │ var foo = "\78"; - 14 │ var foo = "\5a"; - > 15 │ var foo = "\751"; - │ ^^^^^^ - 16 │ var foo = "foo \400 bar"; - 17 │ var foo = "foo \400 bar"; - - i Don't use octal escape sequences: "\751" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:16:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 14 │ var foo = "\5a"; - 15 │ var foo = "\751"; - > 16 │ var foo = "foo \400 bar"; - │ ^^^^^^^^^^^^^^ - 17 │ var foo = "foo \400 bar"; - 18 │ var foo = "\t\1"; - - i Don't use octal escape sequences: "foo \400 bar" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:17:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 15 │ var foo = "\751"; - 16 │ var foo = "foo \400 bar"; - > 17 │ var foo = "foo \400 bar"; - │ ^^^^^^^^^^^^^^ - 18 │ var foo = "\t\1"; - 19 │ var foo = "\\\751"; - - i Don't use octal escape sequences: "foo \400 bar" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:18:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 16 │ var foo = "foo \400 bar"; - 17 │ var foo = "foo \400 bar"; - > 18 │ var foo = "\t\1"; - │ ^^^^^^ - 19 │ var foo = "\\\751"; - 20 │ '\0\1' - - i Don't use octal escape sequences: "\t\1" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:19:11 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 17 │ var foo = "foo \400 bar"; - 18 │ var foo = "\t\1"; - > 19 │ var foo = "\\\751"; - │ ^^^^^^^^ - 20 │ '\0\1' - 21 │ '\0 \1' - - i Don't use octal escape sequences: "\\\751" - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:20:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 18 │ var foo = "\t\1"; - 19 │ var foo = "\\\751"; - > 20 │ '\0\1' - │ ^^^^^^ - 21 │ '\0 \1' - 22 │ '\0\01' - - i Don't use octal escape sequences: - '\0\1' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:21:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 19 │ var foo = "\\\751"; - 20 │ '\0\1' - > 21 │ '\0 \1' - │ ^^^^^^^ - 22 │ '\0\01' - 23 │ '\0 \01' - - i Don't use octal escape sequences: - '\0 \1' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:22:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 20 │ '\0\1' - 21 │ '\0 \1' - > 22 │ '\0\01' - │ ^^^^^^^ - 23 │ '\0 \01' - 24 │ '\0a\1' - - i Don't use octal escape sequences: - '\0\01' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:23:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 21 │ '\0 \1' - 22 │ '\0\01' - > 23 │ '\0 \01' - │ ^^^^^^^^ - 24 │ '\0a\1' - 25 │ '\0a\01' - - i Don't use octal escape sequences: - '\0 \01' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:24:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 22 │ '\0\01' - 23 │ '\0 \01' - > 24 │ '\0a\1' - │ ^^^^^^^ - 25 │ '\0a\01' - 26 │ '\0\08' - - i Don't use octal escape sequences: - '\0a\1' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:25:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 23 │ '\0 \01' - 24 │ '\0a\1' - > 25 │ '\0a\01' - │ ^^^^^^^^ - 26 │ '\0\08' - 27 │ '\1' - - i Don't use octal escape sequences: - '\0a\01' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:26:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 24 │ '\0a\1' - 25 │ '\0a\01' - > 26 │ '\0\08' - │ ^^^^^^^ - 27 │ '\1' - 28 │ '\2' - - i Don't use octal escape sequences: - '\0\08' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:27:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 25 │ '\0a\01' - 26 │ '\0\08' - > 27 │ '\1' - │ ^^^^ - 28 │ '\2' - 29 │ '\7' - - i Don't use octal escape sequences: - '\1' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:28:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 26 │ '\0\08' - 27 │ '\1' - > 28 │ '\2' - │ ^^^^ - 29 │ '\7' - 30 │ '\00' - - i Don't use octal escape sequences: - '\2' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:29:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 27 │ '\1' - 28 │ '\2' - > 29 │ '\7' - │ ^^^^ - 30 │ '\00' - 31 │ '\01' - - i Don't use octal escape sequences: - '\7' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:30:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 28 │ '\2' - 29 │ '\7' - > 30 │ '\00' - │ ^^^^^ - 31 │ '\01' - 32 │ '\02' - - i Don't use octal escape sequences: - '\00' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:31:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 29 │ '\7' - 30 │ '\00' - > 31 │ '\01' - │ ^^^^^ - 32 │ '\02' - 33 │ '\07' - - i Don't use octal escape sequences: - '\01' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:32:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 30 │ '\00' - 31 │ '\01' - > 32 │ '\02' - │ ^^^^^ - 33 │ '\07' - 34 │ '\08' - - i Don't use octal escape sequences: - '\02' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:33:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 31 │ '\01' - 32 │ '\02' - > 33 │ '\07' - │ ^^^^^ - 34 │ '\08' - 35 │ '\09' - - i Don't use octal escape sequences: - '\07' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:34:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 32 │ '\02' - 33 │ '\07' - > 34 │ '\08' - │ ^^^^^ - 35 │ '\09' - 36 │ '\10' - - i Don't use octal escape sequences: - '\08' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:35:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 33 │ '\07' - 34 │ '\08' - > 35 │ '\09' - │ ^^^^^ - 36 │ '\10' - 37 │ '\12' - - i Don't use octal escape sequences: - '\09' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:36:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 34 │ '\08' - 35 │ '\09' - > 36 │ '\10' - │ ^^^^^ - 37 │ '\12' - 38 │ ' \1' - - i Don't use octal escape sequences: - '\10' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:37:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 35 │ '\09' - 36 │ '\10' - > 37 │ '\12' - │ ^^^^^ - 38 │ ' \1' - 39 │ '\1 ' - - i Don't use octal escape sequences: - '\12' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:38:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 36 │ '\10' - 37 │ '\12' - > 38 │ ' \1' - │ ^^^^^ - 39 │ '\1 ' - 40 │ 'a\1' - - i Don't use octal escape sequences: - ' \1' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:39:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 37 │ '\12' - 38 │ ' \1' - > 39 │ '\1 ' - │ ^^^^^ - 40 │ 'a\1' - 41 │ '\1a' - - i Don't use octal escape sequences: - '\1 ' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:40:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 38 │ ' \1' - 39 │ '\1 ' - > 40 │ 'a\1' - │ ^^^^^ - 41 │ '\1a' - 42 │ 'a\1a' - - i Don't use octal escape sequences: - 'a\1' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:41:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 39 │ '\1 ' - 40 │ 'a\1' - > 41 │ '\1a' - │ ^^^^^ - 42 │ 'a\1a' - 43 │ ' \01' - - i Don't use octal escape sequences: - '\1a' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:42:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 40 │ 'a\1' - 41 │ '\1a' - > 42 │ 'a\1a' - │ ^^^^^^ - 43 │ ' \01' - 44 │ '\01 ' - - i Don't use octal escape sequences: - 'a\1a' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:43:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 41 │ '\1a' - 42 │ 'a\1a' - > 43 │ ' \01' - │ ^^^^^^ - 44 │ '\01 ' - 45 │ 'a\01' - - i Don't use octal escape sequences: - ' \01' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:44:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 42 │ 'a\1a' - 43 │ ' \01' - > 44 │ '\01 ' - │ ^^^^^^ - 45 │ 'a\01' - 46 │ '\01a' - - i Don't use octal escape sequences: - '\01 ' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:45:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 43 │ ' \01' - 44 │ '\01 ' - > 45 │ 'a\01' - │ ^^^^^^ - 46 │ '\01a' - 47 │ 'a\01a' - - i Don't use octal escape sequences: - 'a\01' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:46:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 44 │ '\01 ' - 45 │ 'a\01' - > 46 │ '\01a' - │ ^^^^^^ - 47 │ 'a\01a' - 48 │ 'a\08a' - - i Don't use octal escape sequences: - '\01a' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:47:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 45 │ 'a\01' - 46 │ '\01a' - > 47 │ 'a\01a' - │ ^^^^^^^ - 48 │ 'a\08a' - 49 │ '\n\1' - - i Don't use octal escape sequences: - 'a\01a' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:48:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 46 │ '\01a' - 47 │ 'a\01a' - > 48 │ 'a\08a' - │ ^^^^^^^ - 49 │ '\n\1' - 50 │ '\n\01' - - i Don't use octal escape sequences: - 'a\08a' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:49:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 47 │ 'a\01a' - 48 │ 'a\08a' - > 49 │ '\n\1' - │ ^^^^^^ - 50 │ '\n\01' - 51 │ '\n\08' - - i Don't use octal escape sequences: - '\n\1' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:50:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - i Don't use octal - - 48 │ 'a\08a' - 49 │ '\n\1' - > 50 │ '\n\01' - │ ^^^^^^^ - 51 │ '\n\08' - 52 │ '\\\1' - - i Don't use octal escape sequences: - '\n\01' - - i Use unicode or hexidecimal escape sequences instead. - - -``` - -``` -invalid.js:51:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:2:6 lint/nursery/noOctalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - i Don't use octal + ! Don't use deprecated octal escape sequences. - 49 │ '\n\1' - 50 │ '\n\01' - > 51 │ '\n\08' - │ ^^^^^^^ - 52 │ '\\\1' - 53 │ '\\\01' + 1 │ 0; + > 2 │ "foo \01 bar"; + │ ^^^ + 3 │ "foo \000 bar"; + 4 │ "foo \377 bar"; - i Don't use octal escape sequences: - '\n\08' + i Safe fix: Use hexadecimal escape sequences instead. - i Use unicode or hexidecimal escape sequences instead. + 1 1 │ 0; + 2 │ - "foo·\01·bar"; + 2 │ + "foo·\x01·bar"; + 3 3 │ "foo \000 bar"; + 4 4 │ "foo \377 bar"; ``` ``` -invalid.js:52:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:3:6 lint/nursery/noOctalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - i Don't use octal + ! Don't use deprecated octal escape sequences. - 50 │ '\n\01' - 51 │ '\n\08' - > 52 │ '\\\1' - │ ^^^^^^ - 53 │ '\\\01' - 54 │ '\\\08' + 1 │ 0; + 2 │ "foo \01 bar"; + > 3 │ "foo \000 bar"; + │ ^^^^ + 4 │ "foo \377 bar"; + 5 │ "foo \378 bar"; - i Don't use octal escape sequences: - '\\\1' + i Safe fix: Use hexadecimal escape sequences instead. - i Use unicode or hexidecimal escape sequences instead. + 1 1 │ 0; + 2 2 │ "foo \01 bar"; + 3 │ - "foo·\000·bar"; + 3 │ + "foo·\x00·bar"; + 4 4 │ "foo \377 bar"; + 5 5 │ "foo \378 bar"; ``` ``` -invalid.js:53:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:4:6 lint/nursery/noOctalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - i Don't use octal + ! Don't use deprecated octal escape sequences. - 51 │ '\n\08' - 52 │ '\\\1' - > 53 │ '\\\01' - │ ^^^^^^^ - 54 │ '\\\08' - 55 │ '\\n\1' + 2 │ "foo \01 bar"; + 3 │ "foo \000 bar"; + > 4 │ "foo \377 bar"; + │ ^^^^ + 5 │ "foo \378 bar"; + 6 │ "foo \37a bar"; - i Don't use octal escape sequences: - '\\\01' + i Safe fix: Use hexadecimal escape sequences instead. - i Use unicode or hexidecimal escape sequences instead. + 2 2 │ "foo \01 bar"; + 3 3 │ "foo \000 bar"; + 4 │ - "foo·\377·bar"; + 4 │ + "foo·\xff·bar"; + 5 5 │ "foo \378 bar"; + 6 6 │ "foo \37a bar"; ``` ``` -invalid.js:54:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:5:6 lint/nursery/noOctalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - i Don't use octal + ! Don't use deprecated octal escape sequences. - 52 │ '\\\1' - 53 │ '\\\01' - > 54 │ '\\\08' - │ ^^^^^^^ - 55 │ '\\n\1' - 56 │ '\01\02' + 3 │ "foo \000 bar"; + 4 │ "foo \377 bar"; + > 5 │ "foo \378 bar"; + │ ^^^ + 6 │ "foo \37a bar"; + 7 │ "foo \381 bar"; - i Don't use octal escape sequences: - '\\\08' + i Safe fix: Use hexadecimal escape sequences instead. - i Use unicode or hexidecimal escape sequences instead. + 3 3 │ "foo \000 bar"; + 4 4 │ "foo \377 bar"; + 5 │ - "foo·\378·bar"; + 5 │ + "foo·\x1f8·bar"; + 6 6 │ "foo \37a bar"; + 7 7 │ "foo \381 bar"; ``` ``` -invalid.js:55:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:6:6 lint/nursery/noOctalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - i Don't use octal + ! Don't use deprecated octal escape sequences. - 53 │ '\\\01' - 54 │ '\\\08' - > 55 │ '\\n\1' - │ ^^^^^^^ - 56 │ '\01\02' - 57 │ '\02\01' + 4 │ "foo \377 bar"; + 5 │ "foo \378 bar"; + > 6 │ "foo \37a bar"; + │ ^^^ + 7 │ "foo \381 bar"; + 8 │ "foo \3a1 bar"; - i Don't use octal escape sequences: - '\\n\1' + i Safe fix: Use hexadecimal escape sequences instead. - i Use unicode or hexidecimal escape sequences instead. + 4 4 │ "foo \377 bar"; + 5 5 │ "foo \378 bar"; + 6 │ - "foo·\37a·bar"; + 6 │ + "foo·\x1fa·bar"; + 7 7 │ "foo \381 bar"; + 8 8 │ "foo \3a1 bar"; ``` ``` -invalid.js:56:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:7:6 lint/nursery/noOctalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - i Don't use octal + ! Don't use deprecated octal escape sequences. - 54 │ '\\\08' - 55 │ '\\n\1' - > 56 │ '\01\02' - │ ^^^^^^^^ - 57 │ '\02\01' - 58 │ '\01\2' + 5 │ "foo \378 bar"; + 6 │ "foo \37a bar"; + > 7 │ "foo \381 bar"; + │ ^^ + 8 │ "foo \3a1 bar"; + 9 │ "foo \751 bar"; - i Don't use octal escape sequences: - '\01\02' + i Safe fix: Use hexadecimal escape sequences instead. - i Use unicode or hexidecimal escape sequences instead. + 5 5 │ "foo \378 bar"; + 6 6 │ "foo \37a bar"; + 7 │ - "foo·\381·bar"; + 7 │ + "foo·\x0381·bar"; + 8 8 │ "foo \3a1 bar"; + 9 9 │ "foo \751 bar"; ``` ``` -invalid.js:57:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:8:6 lint/nursery/noOctalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - i Don't use octal + ! Don't use deprecated octal escape sequences. - 55 │ '\\n\1' - 56 │ '\01\02' - > 57 │ '\02\01' - │ ^^^^^^^^ - 58 │ '\01\2' - 59 │ '\2\01' + 6 │ "foo \37a bar"; + 7 │ "foo \381 bar"; + > 8 │ "foo \3a1 bar"; + │ ^^ + 9 │ "foo \751 bar"; + 10 │ "foo \258 bar"; - i Don't use octal escape sequences: - '\02\01' + i Safe fix: Use hexadecimal escape sequences instead. - i Use unicode or hexidecimal escape sequences instead. + 6 6 │ "foo \37a bar"; + 7 7 │ "foo \381 bar"; + 8 │ - "foo·\3a1·bar"; + 8 │ + "foo·\x03a1·bar"; + 9 9 │ "foo \751 bar"; + 10 10 │ "foo \258 bar"; ``` ``` -invalid.js:58:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:9:6 lint/nursery/noOctalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - i Don't use octal + ! Don't use deprecated octal escape sequences. - 56 │ '\01\02' - 57 │ '\02\01' - > 58 │ '\01\2' - │ ^^^^^^^ - 59 │ '\2\01' - 60 │ '\08\1' + 7 │ "foo \381 bar"; + 8 │ "foo \3a1 bar"; + > 9 │ "foo \751 bar"; + │ ^^^^ + 10 │ "foo \258 bar"; + 11 │ "foo \25a bar"; - i Don't use octal escape sequences: - '\01\2' + i Safe fix: Use unicode escape sequences instead. - i Use unicode or hexidecimal escape sequences instead. + 7 7 │ "foo \381 bar"; + 8 8 │ "foo \3a1 bar"; + 9 │ - "foo·\751·bar"; + 9 │ + "foo·\u01e9·bar"; + 10 10 │ "foo \258 bar"; + 11 11 │ "foo \25a bar"; ``` ``` -invalid.js:59:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:10:6 lint/nursery/noOctalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - i Don't use octal + ! Don't use deprecated octal escape sequences. - 57 │ '\02\01' - 58 │ '\01\2' - > 59 │ '\2\01' - │ ^^^^^^^ - 60 │ '\08\1' - 61 │ 'foo \1 bar \2' + 8 │ "foo \3a1 bar"; + 9 │ "foo \751 bar"; + > 10 │ "foo \258 bar"; + │ ^^^ + 11 │ "foo \25a bar"; + 12 │ - i Don't use octal escape sequences: - '\2\01' + i Safe fix: Use hexadecimal escape sequences instead. - i Use unicode or hexidecimal escape sequences instead. + 8 8 │ "foo \3a1 bar"; + 9 9 │ "foo \751 bar"; + 10 │ - "foo·\258·bar"; + 10 │ + "foo·\x158·bar"; + 11 11 │ "foo \25a bar"; + 12 12 │ ``` ``` -invalid.js:60:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:11:6 lint/nursery/noOctalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - i Don't use octal + ! Don't use deprecated octal escape sequences. - 58 │ '\01\2' - 59 │ '\2\01' - > 60 │ '\08\1' - │ ^^^^^^^ - 61 │ 'foo \1 bar \2' - 62 │ + 9 │ "foo \751 bar"; + 10 │ "foo \258 bar"; + > 11 │ "foo \25a bar"; + │ ^^^ + 12 │ + 13 │ const o = { - i Don't use octal escape sequences: - '\08\1' + i Safe fix: Use hexadecimal escape sequences instead. - i Use unicode or hexidecimal escape sequences instead. + 9 9 │ "foo \751 bar"; + 10 10 │ "foo \258 bar"; + 11 │ - "foo·\25a·bar"; + 11 │ + "foo·\x15a·bar"; + 12 12 │ + 13 13 │ const o = { ``` ``` -invalid.js:61:1 lint/nursery/noOctalEscape ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +invalid.js:14:6 lint/nursery/noOctalEscape FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - i Don't use octal + ! Don't use deprecated octal escape sequences. - 59 │ '\2\01' - 60 │ '\08\1' - > 61 │ 'foo \1 bar \2' - │ ^^^^^^^^^^^^^^^ - 62 │ + 13 │ const o = { + > 14 │ '\31': 0, + │ ^^^ + 15 │ }; + 16 │ - i Don't use octal escape sequences: - 'foo \1 bar \2' + i Safe fix: Use hexadecimal escape sequences instead. - i Use unicode or hexidecimal escape sequences instead. + 12 12 │ + 13 13 │ const o = { + 14 │ - ····'\31':·0, + 14 │ + ····'\x19':·0, + 15 15 │ }; + 16 16 │ ``` diff --git a/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/valid.js b/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/valid.js index c3f35e01e9d8..b2186aece0a1 100644 --- a/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/valid.js +++ b/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/valid.js @@ -1,35 +1,12 @@ -"var foo = \"\\x51\";", -"var foo = \"foo \\\\251 bar\";", -"var foo = /([abc]) \\1/g;", -"var foo = '\\0';", -"'\\0'", -"'\\8'", -"'\\9'", -"'\\0 '", -"' \\0'", -"'a\\0'", -"'\\0a'", -"'a\\8a'", -"'\\0\\8'", -"'\\8\\0'", -"'\\80'", -"'\\81'", -"'\\\\'", -"'\\\\0'", -"'\\\\08'", -"'\\\\1'", -"'\\\\01'", -"'\\\\12'", -"'\\\\\\0'", -"'\\\\\\8'", -"'\\0\\\\'", -"'0'", -"'1'", -"'8'", -"'01'", -"'08'", -"'80'", -"'12'", -"'\\a'", -"'\\n'" -"\t\r\n" \ No newline at end of file +/([abc]) \1/g; +"\x51" /* \01 */; +"foo \\251 bar"; +"\8"; +"\9"; +"\0 "; +"\0a"; +"\\"; +"0"; +"1"; +"\a"; +"\n"; \ No newline at end of file diff --git a/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/valid.js.snap b/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/valid.js.snap index fbd3dc1274fc..5828d91e1545 100644 --- a/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/valid.js.snap +++ b/crates/biome_js_analyze/tests/specs/nursery/noOctalEscape/valid.js.snap @@ -1,43 +1,19 @@ --- source: crates/biome_js_analyze/tests/spec_tests.rs expression: valid.js -snapshot_kind: text --- # Input ```js -"var foo = \"\\x51\";", -"var foo = \"foo \\\\251 bar\";", -"var foo = /([abc]) \\1/g;", -"var foo = '\\0';", -"'\\0'", -"'\\8'", -"'\\9'", -"'\\0 '", -"' \\0'", -"'a\\0'", -"'\\0a'", -"'a\\8a'", -"'\\0\\8'", -"'\\8\\0'", -"'\\80'", -"'\\81'", -"'\\\\'", -"'\\\\0'", -"'\\\\08'", -"'\\\\1'", -"'\\\\01'", -"'\\\\12'", -"'\\\\\\0'", -"'\\\\\\8'", -"'\\0\\\\'", -"'0'", -"'1'", -"'8'", -"'01'", -"'08'", -"'80'", -"'12'", -"'\\a'", -"'\\n'" -"\t\r\n" +/([abc]) \1/g; +"\x51" /* \01 */; +"foo \\251 bar"; +"\8"; +"\9"; +"\0 "; +"\0a"; +"\\"; +"0"; +"1"; +"\a"; +"\n"; ``` diff --git a/packages/@biomejs/backend-jsonrpc/src/workspace.ts b/packages/@biomejs/backend-jsonrpc/src/workspace.ts index 1ca8369578e1..0c2496e9a29a 100644 --- a/packages/@biomejs/backend-jsonrpc/src/workspace.ts +++ b/packages/@biomejs/backend-jsonrpc/src/workspace.ts @@ -1543,7 +1543,7 @@ export interface Nursery { /** * Disallow octal escape sequences in string literals */ - noOctalEscape?: RuleConfiguration_for_Null; + noOctalEscape?: RuleFixConfiguration_for_Null; /** * Restricts imports of "package private" exports. */ diff --git a/packages/@biomejs/biome/configuration_schema.json b/packages/@biomejs/biome/configuration_schema.json index b3e7f1137e7c..cd204ecbf71d 100644 --- a/packages/@biomejs/biome/configuration_schema.json +++ b/packages/@biomejs/biome/configuration_schema.json @@ -2623,7 +2623,7 @@ "noOctalEscape": { "description": "Disallow octal escape sequences in string literals", "anyOf": [ - { "$ref": "#/definitions/RuleConfiguration" }, + { "$ref": "#/definitions/RuleFixConfiguration" }, { "type": "null" } ] },