sindresorhus/eslint-plugin-unicorn
Rule proposal: `no-unnecessary-rename`
Chiusa
#1313 aperta il 24 mag 2021
help wantednew rule
Metriche repository
- Star
- (5022 stelle)
- Metriche merge PR
- (Merge medio 4h 30m) (26 PR mergiate in 30 g)
Descrizione
Sometimes, when we import a module or destructuring an object, the property name are not available, we have to rename it. But during refactor, the property name is available again, we may want to avoid rename.
- const foo = 1;
const {foo: anotherFoo} = bar;
Since we removed foo, I want to use foo instead of anotherFoo now.
Or
const foo = 1;
+ if (bar) {
const {foo: anotherFoo} = bar; // `foo` is available in the new scope now, and I don't need access to the outer `foo`.
+ }
Fail
const {foo: anotherFoo} = bar;
// `foo` is avaiable
import {fromPairs as lodashFromPairs} from 'lodash-es';
// No other variable `fromPairs`
Pass
const foo = 1;
const {foo: anotherFoo} = bar;
import {fromPairs as lodashFromPairs} from 'lodash-es';
function fromPairs() {
// Do something different from `lodash.fromPairs`
}