From d1f7ddf1114dfe44a88dcbe2dced5f39ed087590 Mon Sep 17 00:00:00 2001 From: Pavel Ravits Date: Sun, 18 Aug 2024 14:05:56 +0300 Subject: [PATCH 1/4] cancel LINT_COMMENT_PREFIX --- .eslintrc.json | 10 +--- .../src/rules/exhaustive-deps.ts | 60 +++++++++---------- 2 files changed, 32 insertions(+), 38 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 960a47b..f635b88 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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": { @@ -58,6 +51,7 @@ }, { "files": ["*.ts", "*.tsx"], + "plugins": ["prefer-arrow-functions"], "rules": { "import/order": [ "error", diff --git a/packages/eslint-plugin-automate/src/rules/exhaustive-deps.ts b/packages/eslint-plugin-automate/src/rules/exhaustive-deps.ts index 6e8fbcd..b0eaf02 100644 --- a/packages/eslint-plugin-automate/src/rules/exhaustive-deps.ts +++ b/packages/eslint-plugin-automate/src/rules/exhaustive-deps.ts @@ -443,34 +443,34 @@ const rule = createESLintRule({ 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, @@ -1355,7 +1355,7 @@ function collectRecommendations({ isNodeTypeIncludesFunction(context, value.references[0].identifier) ) ), - ] + ] : [_dependencies, new Map()] if (isHookIncludeAllDeps && functionDeps.size > 0) { @@ -1381,7 +1381,7 @@ function collectRecommendations({ : fixer.insertTextBeforeRange( getCurrentLineRange(context, _node), `${newComment}\n` - ) + ) }, }) } From 0eb0f0747f8236e72b6f4f540f78171b073b496c Mon Sep 17 00:00:00 2001 From: Pavel Ravits Date: Sun, 18 Aug 2024 14:06:09 +0300 Subject: [PATCH 2/4] docs(changeset): LINT_COMMENT_PREFIX --- .changeset/cyan-spiders-worry.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/cyan-spiders-worry.md diff --git a/.changeset/cyan-spiders-worry.md b/.changeset/cyan-spiders-worry.md new file mode 100644 index 0000000..44a9102 --- /dev/null +++ b/.changeset/cyan-spiders-worry.md @@ -0,0 +1,5 @@ +--- +"@byondxr/eslint-plugin-automate": patch +--- + +LINT_COMMENT_PREFIX From 32911fa163ed85bd9516b1e3e68cc8a593604d1c Mon Sep 17 00:00:00 2001 From: Pavel Ravits Date: Sun, 18 Aug 2024 14:12:38 +0300 Subject: [PATCH 3/4] lint --- .../src/rules/exhaustive-deps.ts | 83 +++++++++---------- 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/packages/eslint-plugin-automate/src/rules/exhaustive-deps.ts b/packages/eslint-plugin-automate/src/rules/exhaustive-deps.ts index b0eaf02..f7cf21d 100644 --- a/packages/eslint-plugin-automate/src/rules/exhaustive-deps.ts +++ b/packages/eslint-plugin-automate/src/rules/exhaustive-deps.ts @@ -8,9 +8,6 @@ import { getPrevLineRange, getUpdatedLintComment, isNodeTypeIncludesFunction, - LINT_COMMENT_PREFIX, - SELECTOR_LOCAL_FUNCTION_DEPENDECY_COMMENT, - SELECTOR_LOCAL_REF_DEPENDECY_COMMENT, } from '../utils/ast-utils' // CHANGE V1 @@ -1358,46 +1355,46 @@ function collectRecommendations({ ] : [_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], From a32f25a1f89317581a0ef020d6acad4d851042de Mon Sep 17 00:00:00 2001 From: Pavel Ravits Date: Sun, 18 Aug 2024 14:14:21 +0300 Subject: [PATCH 4/4] lint --- .../eslint-plugin-automate/src/rules/exhaustive-deps.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/eslint-plugin-automate/src/rules/exhaustive-deps.ts b/packages/eslint-plugin-automate/src/rules/exhaustive-deps.ts index f7cf21d..ba89c95 100644 --- a/packages/eslint-plugin-automate/src/rules/exhaustive-deps.ts +++ b/packages/eslint-plugin-automate/src/rules/exhaustive-deps.ts @@ -4,9 +4,9 @@ import { ESLintUtils } from '@typescript-eslint/utils' import { - getCurrentLineRange, - getPrevLineRange, - getUpdatedLintComment, + // getCurrentLineRange, + // getPrevLineRange, + // getUpdatedLintComment, isNodeTypeIncludesFunction, } from '../utils/ast-utils' // CHANGE V1