-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: extend no-deprecated-classes to handle expressions
- Loading branch information
Showing
6 changed files
with
289 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function removeDuplicates<T>(array: T[]): T[] { | ||
return [...new Set(array)]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { ESLintNode } from 'vue-eslint-parser/ast/nodes'; | ||
|
||
function getStringLiteralValue(node: ESLintNode, stringOnly: boolean = false) { | ||
if (node.type === 'Literal') { | ||
if (node.value == null) { | ||
if (!stringOnly && node.bigint != null) | ||
return node.bigint; | ||
|
||
return null; | ||
} | ||
if (typeof node.value === 'string') | ||
return node.value; | ||
|
||
if (!stringOnly) | ||
return String(node.value); | ||
|
||
return null; | ||
} | ||
if ( | ||
node.type === 'TemplateLiteral' | ||
&& node.expressions.length === 0 | ||
&& node.quasis.length === 1 | ||
) | ||
return node.quasis[0].value.cooked; | ||
|
||
return null; | ||
} | ||
|
||
export function getStaticPropertyName(node: ESLintNode) { | ||
if (node.type === 'Property' || node.type === 'MethodDefinition') { | ||
if (!node.computed) { | ||
const key = node.key; | ||
if (key.type === 'Identifier') | ||
return key.name; | ||
} | ||
const key = node.key; | ||
return getStringLiteralValue(key); | ||
} | ||
else if (node.type === 'MemberExpression') { | ||
if (!node.computed) { | ||
const property = node.property; | ||
if (property.type === 'Identifier') | ||
return property.name; | ||
|
||
return null; | ||
} | ||
const property = node.property; | ||
return getStringLiteralValue(property); | ||
} | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters