|
4 | 4 |
|
5 | 5 | import { ESLintUtils } from '@typescript-eslint/utils'
|
6 | 6 | import {
|
7 |
| - getCurrentLineRange, |
8 |
| - getPrevLineRange, |
9 |
| - getUpdatedLintComment, |
| 7 | + // getCurrentLineRange, |
| 8 | + // getPrevLineRange, |
| 9 | + // getUpdatedLintComment, |
10 | 10 | isNodeTypeIncludesFunction,
|
11 |
| - LINT_COMMENT_PREFIX, |
12 |
| - SELECTOR_LOCAL_FUNCTION_DEPENDECY_COMMENT, |
13 |
| - SELECTOR_LOCAL_REF_DEPENDECY_COMMENT, |
14 | 11 | } from '../utils/ast-utils'
|
15 | 12 | // CHANGE V1
|
16 | 13 |
|
@@ -443,34 +440,34 @@ const rule = createESLintRule<Options, MessageIds>({
|
443 | 440 | const dependencyNode = getDependency(referenceNode, isHookIncludeAllDeps)
|
444 | 441 | const dependency = analyzePropertyChain(dependencyNode, optionalChains)
|
445 | 442 |
|
446 |
| - // CHANGE V3 TODO |
447 |
| - let _node = dependencyNode |
448 |
| - let currentLine = _node.loc.start.line |
449 |
| - let prevLineText = context.getSourceCode().getLines()[currentLine - 2] |
450 |
| - if ( |
451 |
| - dependencyNode.type === 'MemberExpression' && |
452 |
| - dependencyNode.property.type === 'Identifier' && |
453 |
| - dependencyNode.property.name === 'current' |
454 |
| - ) { |
455 |
| - const existingComment = prevLineText?.includes(LINT_COMMENT_PREFIX) ? prevLineText : '' |
456 |
| - const newFlag = `${_node.object.name}.${_node.property.name} - ${SELECTOR_LOCAL_REF_DEPENDECY_COMMENT}` |
457 |
| - const newComment = getUpdatedLintComment(newFlag, existingComment) |
458 |
| - if (!prevLineText?.includes(newFlag)) { |
459 |
| - context.report({ |
460 |
| - node: _node, |
461 |
| - messageId: |
462 |
| - 'will be noted as local dependency causing a selector to not be cached globally', |
463 |
| - fix(fixer) { |
464 |
| - return prevLineText.includes(LINT_COMMENT_PREFIX) |
465 |
| - ? fixer.replaceTextRange(getPrevLineRange(context, _node), `${newComment}`) |
466 |
| - : fixer.insertTextBeforeRange( |
467 |
| - getCurrentLineRange(context, _node), |
468 |
| - `${newComment}\n` |
469 |
| - ) |
470 |
| - }, |
471 |
| - }) |
472 |
| - } |
473 |
| - } |
| 443 | + // // CHANGE V3 TODO |
| 444 | + // let _node = dependencyNode |
| 445 | + // let currentLine = _node.loc.start.line |
| 446 | + // let prevLineText = context.getSourceCode().getLines()[currentLine - 2] |
| 447 | + // if ( |
| 448 | + // dependencyNode.type === 'MemberExpression' && |
| 449 | + // dependencyNode.property.type === 'Identifier' && |
| 450 | + // dependencyNode.property.name === 'current' |
| 451 | + // ) { |
| 452 | + // const existingComment = prevLineText?.includes(LINT_COMMENT_PREFIX) ? prevLineText : '' |
| 453 | + // const newFlag = `${_node.object.name}.${_node.property.name} - ${SELECTOR_LOCAL_REF_DEPENDECY_COMMENT}` |
| 454 | + // const newComment = getUpdatedLintComment(newFlag, existingComment) |
| 455 | + // if (!prevLineText?.includes(newFlag)) { |
| 456 | + // context.report({ |
| 457 | + // node: _node, |
| 458 | + // messageId: |
| 459 | + // 'will be noted as local dependency causing a selector to not be cached globally', |
| 460 | + // fix(fixer) { |
| 461 | + // return prevLineText.includes(LINT_COMMENT_PREFIX) |
| 462 | + // ? fixer.replaceTextRange(getPrevLineRange(context, _node), `${newComment}`) |
| 463 | + // : fixer.insertTextBeforeRange( |
| 464 | + // getCurrentLineRange(context, _node), |
| 465 | + // `${newComment}\n` |
| 466 | + // ) |
| 467 | + // }, |
| 468 | + // }) |
| 469 | + // } |
| 470 | + // } |
474 | 471 | // else if (prevLineText?.includes('ref dependency')) {
|
475 | 472 | // context.report({
|
476 | 473 | // node: _node,
|
@@ -1355,49 +1352,49 @@ function collectRecommendations({
|
1355 | 1352 | isNodeTypeIncludesFunction(context, value.references[0].identifier)
|
1356 | 1353 | )
|
1357 | 1354 | ),
|
1358 |
| - ] |
| 1355 | + ] |
1359 | 1356 | : [_dependencies, new Map()]
|
1360 | 1357 |
|
1361 |
| - if (isHookIncludeAllDeps && functionDeps.size > 0) { |
1362 |
| - Array.from(_dependencies) |
1363 |
| - .filter(([key, value]) => isNodeTypeIncludesFunction(context, value.references[0].identifier)) |
1364 |
| - .forEach(([key, value]) => { |
1365 |
| - // CHANGE V3 |
1366 |
| - |
1367 |
| - let _node = value.references[0].identifier |
1368 |
| - if (!_node.name.endsWith('__global')) { |
1369 |
| - let currentLine = _node.loc.start.line |
1370 |
| - let prevLineText = context.getSourceCode().getLines()[currentLine - 2] |
1371 |
| - const existingComment = prevLineText?.includes(LINT_COMMENT_PREFIX) ? prevLineText : '' |
1372 |
| - const newFlag = `${_node.name} - ${SELECTOR_LOCAL_FUNCTION_DEPENDECY_COMMENT}` |
1373 |
| - const newComment = getUpdatedLintComment(newFlag, existingComment) |
1374 |
| - if (!prevLineText?.includes(newFlag)) { |
1375 |
| - context.report({ |
1376 |
| - node: _node, |
1377 |
| - messageId: 'will be noted as local dependency causing a selector to not be cached globally', |
1378 |
| - fix(fixer) { |
1379 |
| - return prevLineText.includes(LINT_COMMENT_PREFIX) |
1380 |
| - ? fixer.replaceTextRange(getPrevLineRange(context, _node), `${newComment}`) |
1381 |
| - : fixer.insertTextBeforeRange( |
1382 |
| - getCurrentLineRange(context, _node), |
1383 |
| - `${newComment}\n` |
1384 |
| - ) |
1385 |
| - }, |
1386 |
| - }) |
1387 |
| - } |
1388 |
| - } |
1389 |
| - // else if (prevLineText?.includes('function dependency')) { |
1390 |
| - // console.log('2') |
1391 |
| - // context.report({ |
1392 |
| - // node: _node, |
1393 |
| - // messageId: 'will be noted as local dependency causing a selector to not be cached globally', |
1394 |
| - // fix(fixer) { |
1395 |
| - // return fixer.removeRange(getPrevLineRange(context, _node)) |
1396 |
| - // }, |
1397 |
| - // }) |
1398 |
| - // } |
1399 |
| - }) |
1400 |
| - } |
| 1358 | + // if (isHookIncludeAllDeps && functionDeps.size > 0) { |
| 1359 | + // Array.from(_dependencies) |
| 1360 | + // .filter(([key, value]) => isNodeTypeIncludesFunction(context, value.references[0].identifier)) |
| 1361 | + // .forEach(([key, value]) => { |
| 1362 | + // // CHANGE V3 |
| 1363 | + |
| 1364 | + // // let _node = value.references[0].identifier |
| 1365 | + // // if (!_node.name.endsWith('__global')) { |
| 1366 | + // // let currentLine = _node.loc.start.line |
| 1367 | + // // let prevLineText = context.getSourceCode().getLines()[currentLine - 2] |
| 1368 | + // // const existingComment = prevLineText?.includes(LINT_COMMENT_PREFIX) ? prevLineText : '' |
| 1369 | + // // const newFlag = `${_node.name} - ${SELECTOR_LOCAL_FUNCTION_DEPENDECY_COMMENT}` |
| 1370 | + // // const newComment = getUpdatedLintComment(newFlag, existingComment) |
| 1371 | + // // if (!prevLineText?.includes(newFlag)) { |
| 1372 | + // // context.report({ |
| 1373 | + // // node: _node, |
| 1374 | + // // messageId: 'will be noted as local dependency causing a selector to not be cached globally', |
| 1375 | + // // fix(fixer) { |
| 1376 | + // // return prevLineText.includes(LINT_COMMENT_PREFIX) |
| 1377 | + // // ? fixer.replaceTextRange(getPrevLineRange(context, _node), `${newComment}`) |
| 1378 | + // // : fixer.insertTextBeforeRange( |
| 1379 | + // // getCurrentLineRange(context, _node), |
| 1380 | + // // `${newComment}\n` |
| 1381 | + // // ) |
| 1382 | + // // }, |
| 1383 | + // // }) |
| 1384 | + // // } |
| 1385 | + // // } |
| 1386 | + // // else if (prevLineText?.includes('function dependency')) { |
| 1387 | + // // console.log('2') |
| 1388 | + // // context.report({ |
| 1389 | + // // node: _node, |
| 1390 | + // // messageId: 'will be noted as local dependency causing a selector to not be cached globally', |
| 1391 | + // // fix(fixer) { |
| 1392 | + // // return fixer.removeRange(getPrevLineRange(context, _node)) |
| 1393 | + // // }, |
| 1394 | + // // }) |
| 1395 | + // // } |
| 1396 | + // }) |
| 1397 | + // } |
1401 | 1398 |
|
1402 | 1399 | // console.log({
|
1403 | 1400 | // realfndep: functionDeps.get('realfn')?.references?.[0],
|
|
0 commit comments