-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(packages/eslint-plugin-sui): Make deprecated-decorator rules run…
…ning on Classes, Methods and Ar
- Loading branch information
Showing
3 changed files
with
151 additions
and
130 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,76 @@ | ||
function getDecoratorsByNode(node, {isAClass, isAMethod, isArrowFunction}) { | ||
if (isAClass) { | ||
return node.decorators | ||
} | ||
|
||
if (isArrowFunction) { | ||
const methodNode = node.parent | ||
return methodNode.decorators ?? [] | ||
} | ||
|
||
if (isAMethod) { | ||
return node.decorators ?? [] | ||
} | ||
|
||
return [] | ||
} | ||
|
||
function getElementName(node, {isAClass, isAMethod, isArrowFunction}) { | ||
if (isAClass) { | ||
const className = node.id?.name ?? 'UnknownClass' | ||
return `${className}` | ||
} | ||
|
||
if (isArrowFunction) { | ||
const methodNode = node.parent | ||
const classNode = methodNode?.parent?.parent | ||
const className = classNode.id?.name ?? 'UnknownClass' | ||
const methodName = methodNode.key?.name ?? 'UnknownMethod' | ||
|
||
return `${className}.${methodName}` | ||
} | ||
|
||
if (isAMethod) { | ||
const classNode = node.parent?.parent | ||
const className = classNode.id?.name ?? 'UnknownClass' | ||
const methodName = node.key?.name ?? 'UnknownMethod' | ||
|
||
return `${className}.${methodName}` | ||
} | ||
|
||
return 'unknown' | ||
} | ||
|
||
function getElementMessageName(elementName, {isAClass, isAMethod, isArrowFunction}) { | ||
if (isAClass) { | ||
return `class ${elementName}` | ||
} | ||
|
||
if (isAMethod || isArrowFunction) { | ||
return `method ${elementName}` | ||
} | ||
|
||
return 'Unknown' | ||
} | ||
|
||
function remarkElement(node, {isAClass, isAMethod, isArrowFunction}) { | ||
if (isAClass) { | ||
return node.id | ||
} | ||
|
||
if (isArrowFunction) { | ||
const methodNode = node.parent | ||
return methodNode.key | ||
} | ||
|
||
if (isAMethod) { | ||
return node.key | ||
} | ||
|
||
return node | ||
} | ||
|
||
module.exports.getDecoratorsByNode = getDecoratorsByNode | ||
module.exports.getElementMessageName = getElementMessageName | ||
module.exports.getElementName = getElementName | ||
module.exports.remarkElement = remarkElement |