no-useless-rename

不允许将导入、导出和解构的分配重命名为相同的名称

一些该规则报告的问题可以通过 --fix 命令行选项 自动修复

ES2015 允许重命名 import 和 export 语句中的引用以及解构赋值。这为程序员在重命名这些引用时执行这些操作提供了简洁的语法:

import { foo as bar } from "baz";
export { foo as bar };
let { foo: bar } = baz;

使用此语法,可以将引用重命名为相同名称。这是一个完全多余的操作,因为这与根本不重命名是一样的。例如,这个:

import { foo as foo } from "bar";
export { foo as foo };
let { foo: foo } = bar;

是相同的:

import { foo } from "bar";
export { foo };
let { foo } = bar;

规则详情

VYi1Fd/b5KjfwHRexxQAsH7QdDLAe8cmE70+QyXENW5BCB0op8hR4kSXplVe2gMwGUkeM5HTfQo/wfTF83JHQTizSeHj7TwdhoH7oBgHEso=

选项

9XrH4x9N7wWmOvzUjVwMra3h7TDRWZPkOIC3hep+HyBv2llV5UhrNE9qhwi3no3eyU2wiqFPiXsczwpx4C890w==

    W13ISgp0VfanKSIEnd+AYwcYcMRrLH4XWeMuFtx+iKWnuqoUP2M68V2pIbPke0NG0kjm+2rzYsBvVEd/KmNH3gfxN+ahT8GV569VWYOD8VMvB8LscNZdcuIXkO4XGbuCFZa3icldzidXsTjeHSoT732nHc7rQ2aWL4FsjvO+m03MpXwL9ViXjygdJsrWsAO79x3P1MNyevkD0SdqJNWF6sgIzYpn5+WSkYfW3Y15LytdxhMDolxDZhWjgZTJ39HamYYRmjy2DWuOtSS3ZYj78qi1jRXp0EihGZ8xWcgYWRCFUvAK5lnpTEsEZuNWpEkKyN49OdpMFEtR7cvt7MJoPIbs+DqPYeqQ+AgF7dhClB8K2O+c7nNyAGOImtTWZfoVSa1atW4YseALRv0Ay2UoHA==

c2gFciP9YPVZ5YHHVWv+GtGg5Y5UVMO1HUROp1Uqg9jfmoPFl7NeX6Dl88T6JRMdgy9jEXDo5U6YrHkPvOAk5p+/vUnKxXS8RvPoAYl1FmQ=

"no-useless-rename": ["error", {
    "ignoreDestructuring": false,
    "ignoreImport": false,
    "ignoreExport": false
}]

c2gFciP9YPVZ5YHHVWv+GrC7+gOM6FTLzp0c0wfITI1qYKq5yry1yMazDAvHI2K/JwlsWESVdNNzzbw3d4smOg==

/*eslint no-useless-rename: "error"*/

import { foo as foo } from "bar";
import { "foo" as foo } from "bar";
export { foo as foo };
export { foo as "foo" };
export { foo as foo } from "bar";
export { "foo" as "foo" } from "bar";
let { foo: foo } = bar;
let { 'foo': foo } = bar;
function foo({ bar: bar }) {}
({ foo: foo }) => {}

XzI939IK+dLd3EupmpNvSYxAStxuhc/vaV27VKtNflliblmfNV1ebos8HldHJkh0oWAuBMI0vduIUojJFwMchA==

/*eslint no-useless-rename: "error"*/

import * as foo from "foo";
import { foo } from "bar";
import { foo as bar } from "baz";
import { "foo" as bar } from "baz";

export { foo };
export { foo as bar };
export { foo as "bar" };
export { foo as bar } from "foo";
export { "foo" as "bar" } from "foo";

let { foo } = bar;
let { foo: bar } = baz;
let { [foo]: foo } = bar;

function foo({ bar }) {}
function foo({ bar: baz }) {}

({ foo }) => {}
({ foo: bar }) => {}

DzO9VpSFHJiTjGCgt1KSooNhAIn1o64th84QTOygwWS+oNcyespxh/JIJqb1rVeSRCAu7CaXzUihXr513J/WaKcZ8KjxsDUnlbwAKMbmhjAXVPMKo3e8w9cBXcP5zmbH

/*eslint no-useless-rename: ["error", { ignoreImport: true }]*/

import { foo as foo } from "bar";

DzO9VpSFHJiTjGCgt1KSooNhAIn1o64th84QTOygwWS+oNcyespxh/JIJqb1rVeSdIEIvejnKCw/WJvwkT7b1o56fxXfK57M4Qg9baV5c3AZPKznhP1pjf87dOfZouOz

/*eslint no-useless-rename: ["error", { ignoreExport: true }]*/

export { foo as foo };
export { foo as foo } from "bar";

DzO9VpSFHJiTjGCgt1KSooNhAIn1o64th84QTOygwWS+oNcyespxh/JIJqb1rVeS5hSMCKW7dFRWnl5YXiUwZ8WZhgC3yP5MXt8F/fbBwy0Q2BhdHCQ5j3NghaxnLVM7

/*eslint no-useless-rename: ["error", { ignoreDestructuring: true }]*/

let { foo: foo } = bar;
function foo({ bar: bar }) {}
({ foo: foo }) => {}

何时不使用

uYEZVMMeEUwUwbTo3rC6SNlI0U66k8yUG9L+rO6ArXoCkyj2bR6qSgZ511w9WWGgWKRDo9w4HN33aRLqBlVDd1PyBBsTW82+WTEZlowX+9KG+YlVKQQ3HipFfQN8a7c+qZtq/Uiriup5AQAEX6D0rA==

兼容性

    A2arLA16BaFzoOfXvkJXZFrw4NcT3SGVL3d8aXz3etEghCM0aZcKGjS9RsJLIre0kCc52vjF22XMCzrEV5dinVw+Xxg9IIZ7MRbDIuXNkcoNWzIsZZ+ZpcQlEWsCAfGp9zZ3SDBU2YmoXfYqrsSn8Q4MeKHJY3IOw0GfigfgG6Y=