Skip to content

Commit

Permalink
fix: detect dependencies in template literals
Browse files Browse the repository at this point in the history
  • Loading branch information
hugop95 authored Sep 6, 2024
1 parent f81f58b commit 4e0e6d8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rules/sort-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ export default createEslintRule<SortClassesOptions, MESSAGE_ID>({
if ('properties' in nodeValue) {
nodeValue.properties.forEach(traverseNode)
}

if ('expressions' in nodeValue) {
nodeValue.expressions.forEach(traverseNode)
}
}

let traverseNode = (nodeValue: TSESTree.Node[] | TSESTree.Node) => {
Expand Down
42 changes: 42 additions & 0 deletions test/sort-classes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3448,6 +3448,48 @@ describe(ruleName, () => {
},
)

ruleTester.run(
`${ruleName}(${type}) detects dependencies in template literal expressions`,
rule,
{
valid: [
{
code: dedent`
class Class {
b = 1
a = \`\${this.b}\`
static b = 1
static a = \`\${this.b}\`
}
`,
options: [
{
...options,
groups: ['property'],
},
],
},
{
code: dedent`
class Class {
b = 1
a = \`\${this.b}\`
static b = 1
static a = \`\${Class.b}\`
}
`,
options: [
{
...options,
groups: ['property'],
},
],
},
],
invalid: [],
},
)

ruleTester.run(
`${ruleName}(${type}) separates static from non-static dependencies`,
rule,
Expand Down

0 comments on commit 4e0e6d8

Please sign in to comment.