Skip to content

Commit

Permalink
Edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed May 8, 2024
1 parent d09f772 commit 0e2a952
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rules/prefer-string-raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,15 @@ const create = context => {
if (
!isStringLiteral(node)
|| isDirective(node.parent)
|| ((node.parent.type === 'ImportDeclaration' || node.parent.type === 'ExportNamedDeclaration') && node.parent.source === node)
|| (
(
node.parent.type === 'ImportDeclaration'
|| node.parent.type === 'ExportNamedDeclaration'
|| node.parent.type === 'ExportAllDeclaration'
) && node.parent.source === node
)
|| (node.parent.type === 'Property' && !node.parent.computed && node.parent.key === node)
|| (node.parent.type === 'JSXAttribute' && node.parent.value === node)
) {
return;
}
Expand Down
11 changes: 11 additions & 0 deletions test/prefer-string-raw.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@ test.snapshot({
String.raw`'a\\b'`,
String.raw`import foo from "./foo\\bar.js";`,
String.raw`export {foo} from "./foo\\bar.js";`,
String.raw`export * from "./foo\\bar.js";`,
String.raw`a = {'a\\b': ''}`,
outdent`
a = "\\\\a \\
b"
`,
String.raw`a = 'a\\b\u{51}c'`,
{
code: String.raw`<Component attribute="a\\b" />`,
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
},
],
invalid: [
String.raw`a = 'a\\b'`,
Expand Down

0 comments on commit 0e2a952

Please sign in to comment.