tools icon indicating copy to clipboard operation
tools copied to clipboard

fix(rome_js_analyze): improve the detection of invalid cases in `noArrayIndexKey`

Open lucasweng opened this issue 1 year ago • 1 comments

Summary

  • Resolves https://github.com/rome/tools/issues/3670
  • Improves the detection of the following cases
    // Return statement
    return array.map((_, index) => <Component key={index} />);
    
    // Assignment expression
    let element = null
    if (condition) {
        elements = array.map((_, index) => <Component key={index} />);
    }
    
    // Parenthesized expression
    function App({things}) {
        const elements = useMemo(() => (
            things.map((_, index) => <Component key={index} />)
        ), [things]);
        return elements;
     }
    function App() {
        return (
            <HoC>
                {({things}) => (
                    things.map((_, index) => <Component key={index} />)
                )}
            </HoC>
        )
    }
    
    // Call expression
    const Component = () => array.map((_, index) => <Component key={index} />);
    
    // Variable declaration
    let elements = array.map((_, index) => <Component key={index} />);
    

Test Plan

Added new test cases

lucasweng avatar Nov 11 '22 22:11 lucasweng

Deploy Preview for docs-rometools canceled.

Built without sensitive environment variables

Name Link
Latest commit 87911ad836b52f84c3fc7d53ad08fdbd92cca74f
Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/636f420ff96361000980c31d

netlify[bot] avatar Nov 11 '22 22:11 netlify[bot]