Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve no-use-computed-property-like-method rule #1659

Merged
merged 1 commit into from Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 1 addition & 14 deletions lib/rules/no-undef-properties.js
Expand Up @@ -235,7 +235,7 @@ module.exports = {
function getVueComponentContextForTemplate() {
const keys = [...vueComponentContextMap.keys()]
const exported =
keys.find(isScriptSetupProgram) || keys.find(isExportObject)
keys.find(isScriptSetupProgram) || keys.find(utils.isInExportDefault)
return exported && vueComponentContextMap.get(exported)

/**
Expand All @@ -244,19 +244,6 @@ module.exports = {
function isScriptSetupProgram(node) {
return node === programNode
}
/**
* @param {ASTNode} node
*/
function isExportObject(node) {
let parent = node.parent
while (parent) {
if (parent.type === 'ExportDefaultDeclaration') {
return true
}
parent = parent.parent
}
return false
}
}

/**
Expand Down
38 changes: 1 addition & 37 deletions lib/rules/no-unused-properties.js
Expand Up @@ -79,49 +79,13 @@ const PROPERTY_LABEL = {
// Helpers
// ------------------------------------------------------------------------------

/**
* Find the variable of a given name.
* @param {RuleContext} context The rule context
* @param {Identifier} node The variable name to find.
* @returns {Variable|null} The found variable or null.
*/
function findVariable(context, node) {
return eslintUtils.findVariable(getScope(context, node), node)
}
/**
* Gets the scope for the current node
* @param {RuleContext} context The rule context
* @param {ESNode} currentNode The node to get the scope of
* @returns { import('eslint').Scope.Scope } The scope information for this node
*/
function getScope(context, currentNode) {
// On Program node, get the outermost scope to avoid return Node.js special function scope or ES modules scope.
const inner = currentNode.type !== 'Program'
const scopeManager = context.getSourceCode().scopeManager

/** @type {ESNode | null} */
let node = currentNode
for (; node; node = /** @type {ESNode | null} */ (node.parent)) {
const scope = scopeManager.acquire(node, inner)

if (scope) {
if (scope.type === 'function-expression-name') {
return scope.childScopes[0]
}
return scope
}
}

return scopeManager.scopes[0]
}

/**
* @param {RuleContext} context
* @param {Identifier} id
* @returns {Expression}
*/
function findExpression(context, id) {
const variable = findVariable(context, id)
const variable = utils.findVariableByIdentifier(context, id)
if (!variable) {
return id
}
Expand Down