Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-spiders-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@byondxr/eslint-plugin-automate": patch
---

LINT_COMMENT_PREFIX
10 changes: 2 additions & 8 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@
"node": true,
"browser": true
},
"plugins": [
"unused-imports",
"@typescript-eslint",
"prefer-arrow-functions",
"import",
"react-refresh",
"jsx-a11y"
],
"plugins": ["unused-imports", "@typescript-eslint", "import", "react-refresh", "jsx-a11y"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
Expand Down Expand Up @@ -58,6 +51,7 @@
},
{
"files": ["*.ts", "*.tsx"],
"plugins": ["prefer-arrow-functions"],
"rules": {
"import/order": [
"error",
Expand Down
147 changes: 72 additions & 75 deletions packages/eslint-plugin-automate/src/rules/exhaustive-deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

import { ESLintUtils } from '@typescript-eslint/utils'
import {
getCurrentLineRange,
getPrevLineRange,
getUpdatedLintComment,
// getCurrentLineRange,
// getPrevLineRange,
// getUpdatedLintComment,
isNodeTypeIncludesFunction,
LINT_COMMENT_PREFIX,
SELECTOR_LOCAL_FUNCTION_DEPENDECY_COMMENT,
SELECTOR_LOCAL_REF_DEPENDECY_COMMENT,
} from '../utils/ast-utils'
// CHANGE V1

Expand Down Expand Up @@ -443,34 +440,34 @@ const rule = createESLintRule<Options, MessageIds>({
const dependencyNode = getDependency(referenceNode, isHookIncludeAllDeps)
const dependency = analyzePropertyChain(dependencyNode, optionalChains)

// CHANGE V3 TODO
let _node = dependencyNode
let currentLine = _node.loc.start.line
let prevLineText = context.getSourceCode().getLines()[currentLine - 2]
if (
dependencyNode.type === 'MemberExpression' &&
dependencyNode.property.type === 'Identifier' &&
dependencyNode.property.name === 'current'
) {
const existingComment = prevLineText?.includes(LINT_COMMENT_PREFIX) ? prevLineText : ''
const newFlag = `${_node.object.name}.${_node.property.name} - ${SELECTOR_LOCAL_REF_DEPENDECY_COMMENT}`
const newComment = getUpdatedLintComment(newFlag, existingComment)
if (!prevLineText?.includes(newFlag)) {
context.report({
node: _node,
messageId:
'will be noted as local dependency causing a selector to not be cached globally',
fix(fixer) {
return prevLineText.includes(LINT_COMMENT_PREFIX)
? fixer.replaceTextRange(getPrevLineRange(context, _node), `${newComment}`)
: fixer.insertTextBeforeRange(
getCurrentLineRange(context, _node),
`${newComment}\n`
)
},
})
}
}
// // CHANGE V3 TODO
// let _node = dependencyNode
// let currentLine = _node.loc.start.line
// let prevLineText = context.getSourceCode().getLines()[currentLine - 2]
// if (
// dependencyNode.type === 'MemberExpression' &&
// dependencyNode.property.type === 'Identifier' &&
// dependencyNode.property.name === 'current'
// ) {
// const existingComment = prevLineText?.includes(LINT_COMMENT_PREFIX) ? prevLineText : ''
// const newFlag = `${_node.object.name}.${_node.property.name} - ${SELECTOR_LOCAL_REF_DEPENDECY_COMMENT}`
// const newComment = getUpdatedLintComment(newFlag, existingComment)
// if (!prevLineText?.includes(newFlag)) {
// context.report({
// node: _node,
// messageId:
// 'will be noted as local dependency causing a selector to not be cached globally',
// fix(fixer) {
// return prevLineText.includes(LINT_COMMENT_PREFIX)
// ? fixer.replaceTextRange(getPrevLineRange(context, _node), `${newComment}`)
// : fixer.insertTextBeforeRange(
// getCurrentLineRange(context, _node),
// `${newComment}\n`
// )
// },
// })
// }
// }
// else if (prevLineText?.includes('ref dependency')) {
// context.report({
// node: _node,
Expand Down Expand Up @@ -1355,49 +1352,49 @@ function collectRecommendations({
isNodeTypeIncludesFunction(context, value.references[0].identifier)
)
),
]
]
: [_dependencies, new Map()]

if (isHookIncludeAllDeps && functionDeps.size > 0) {
Array.from(_dependencies)
.filter(([key, value]) => isNodeTypeIncludesFunction(context, value.references[0].identifier))
.forEach(([key, value]) => {
// CHANGE V3

let _node = value.references[0].identifier
if (!_node.name.endsWith('__global')) {
let currentLine = _node.loc.start.line
let prevLineText = context.getSourceCode().getLines()[currentLine - 2]
const existingComment = prevLineText?.includes(LINT_COMMENT_PREFIX) ? prevLineText : ''
const newFlag = `${_node.name} - ${SELECTOR_LOCAL_FUNCTION_DEPENDECY_COMMENT}`
const newComment = getUpdatedLintComment(newFlag, existingComment)
if (!prevLineText?.includes(newFlag)) {
context.report({
node: _node,
messageId: 'will be noted as local dependency causing a selector to not be cached globally',
fix(fixer) {
return prevLineText.includes(LINT_COMMENT_PREFIX)
? fixer.replaceTextRange(getPrevLineRange(context, _node), `${newComment}`)
: fixer.insertTextBeforeRange(
getCurrentLineRange(context, _node),
`${newComment}\n`
)
},
})
}
}
// else if (prevLineText?.includes('function dependency')) {
// console.log('2')
// context.report({
// node: _node,
// messageId: 'will be noted as local dependency causing a selector to not be cached globally',
// fix(fixer) {
// return fixer.removeRange(getPrevLineRange(context, _node))
// },
// })
// }
})
}
// if (isHookIncludeAllDeps && functionDeps.size > 0) {
// Array.from(_dependencies)
// .filter(([key, value]) => isNodeTypeIncludesFunction(context, value.references[0].identifier))
// .forEach(([key, value]) => {
// // CHANGE V3

// // let _node = value.references[0].identifier
// // if (!_node.name.endsWith('__global')) {
// // let currentLine = _node.loc.start.line
// // let prevLineText = context.getSourceCode().getLines()[currentLine - 2]
// // const existingComment = prevLineText?.includes(LINT_COMMENT_PREFIX) ? prevLineText : ''
// // const newFlag = `${_node.name} - ${SELECTOR_LOCAL_FUNCTION_DEPENDECY_COMMENT}`
// // const newComment = getUpdatedLintComment(newFlag, existingComment)
// // if (!prevLineText?.includes(newFlag)) {
// // context.report({
// // node: _node,
// // messageId: 'will be noted as local dependency causing a selector to not be cached globally',
// // fix(fixer) {
// // return prevLineText.includes(LINT_COMMENT_PREFIX)
// // ? fixer.replaceTextRange(getPrevLineRange(context, _node), `${newComment}`)
// // : fixer.insertTextBeforeRange(
// // getCurrentLineRange(context, _node),
// // `${newComment}\n`
// // )
// // },
// // })
// // }
// // }
// // else if (prevLineText?.includes('function dependency')) {
// // console.log('2')
// // context.report({
// // node: _node,
// // messageId: 'will be noted as local dependency causing a selector to not be cached globally',
// // fix(fixer) {
// // return fixer.removeRange(getPrevLineRange(context, _node))
// // },
// // })
// // }
// })
// }

// console.log({
// realfndep: functionDeps.get('realfn')?.references?.[0],
Expand Down