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 3 years 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 failed.

Name Link
Latest commit
Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/637781eff15ce21882c2c3d7

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

!bench_analyzer

MichaReiser avatar Nov 18 '22 08:11 MichaReiser

Analyzer Benchmark Results

group                     main                                   pr
-----                     ----                                   --
analyzer/css.js           1.03      2.8±0.06ms     4.1 MB/sec    1.00      2.7±0.13ms     4.3 MB/sec
analyzer/index.js         1.06      8.1±0.33ms     4.0 MB/sec    1.00      7.7±0.33ms     4.3 MB/sec
analyzer/lint.ts          1.00      3.8±0.09ms    10.9 MB/sec    1.01      3.8±0.07ms    10.8 MB/sec
analyzer/parser.ts        1.05      9.4±0.25ms     5.2 MB/sec    1.00      8.9±0.22ms     5.5 MB/sec
analyzer/router.ts        1.01      6.3±0.22ms    10.0 MB/sec    1.00      6.2±0.18ms    10.1 MB/sec
analyzer/statement.ts     1.04      9.1±0.28ms     3.9 MB/sec    1.00      8.8±0.21ms     4.0 MB/sec
analyzer/typescript.ts    1.03     13.8±0.41ms     3.9 MB/sec    1.00     13.5±0.49ms     4.0 MB/sec

github-actions[bot] avatar Nov 18 '22 08:11 github-actions[bot]

Analyzer Benchmark Results

group                     main                                   pr
-----                     ----                                   --
analyzer/css.js           1.03      2.8±0.06ms     4.1 MB/sec    1.00      2.7±0.13ms     4.3 MB/sec
analyzer/index.js         1.06      8.1±0.33ms     4.0 MB/sec    1.00      7.7±0.33ms     4.3 MB/sec
analyzer/lint.ts          1.00      3.8±0.09ms    10.9 MB/sec    1.01      3.8±0.07ms    10.8 MB/sec
analyzer/parser.ts        1.05      9.4±0.25ms     5.2 MB/sec    1.00      8.9±0.22ms     5.5 MB/sec
analyzer/router.ts        1.01      6.3±0.22ms    10.0 MB/sec    1.00      6.2±0.18ms    10.1 MB/sec
analyzer/statement.ts     1.04      9.1±0.28ms     3.9 MB/sec    1.00      8.8±0.21ms     4.0 MB/sec
analyzer/typescript.ts    1.03     13.8±0.41ms     3.9 MB/sec    1.00     13.5±0.49ms     4.0 MB/sec

Nice!

MichaReiser avatar Nov 18 '22 08:11 MichaReiser

And there are now errors that Rome detects in the playground because of your fixes :D Awesome job

MichaReiser avatar Nov 18 '22 08:11 MichaReiser