import-js/eslint-plugin-import

no-duplicates should remove duplicate elements

開放

#1,812 建立於 2020年6月8日

 (4 則留言) (2 個反應) (0 位負責人)JavaScript (1,548 個分叉)batch import
bughelp wanted

倉庫指標

星標
 (5,940 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

no-duplicates should remove duplicate Imported values.

This case is most commonly seen when resolving merge conflicts where identical imports can be copied. It would be helpful if the fix were able to de-duplicate the imported values themselves not only the paths.

// bad
import { foo } from '../foo'
import { bar } from '../bar'
import { foo } from '../foo'

// current fix
import { foo, foo } from '../foo' // <-- creates duplicate imported values
import { bar } from '../bar'

// idealized fix
import { foo } from '../foo' // <-- removed duplicated value
import { bar } from '../bar'

Edge cases

// used with `as` with same naming
import { foo as newFoo } from '../foo'
import { bar } from '../bar'
import { foo as newFoo } from '../foo'

// current fix
import { foo as newFoo, foo as newFoo } from '../foo' // <-- removed duplicated value
import { bar } from '../bar'

// idealized fix
import { foo as newFoo } from '../foo' // <-- removed duplicated value
import { bar } from '../bar'
// used with `as` with different naming
import { foo as foo1 } from '../foo'
import { bar } from '../bar'
import { foo as foo2 } from '../foo'

// current and idealized fix to avoid naming collisions 
import { foo as foo1, foo as foo2 } from '../foo' // <-- removed duplicated value
import { bar } from '../bar'

貢獻者指南