eslint-plugin icon indicating copy to clipboard operation
eslint-plugin copied to clipboard

no-unused-expressions

Open g-plane opened this issue 6 years ago • 5 comments

文档:https://eslint.org/docs/rules/no-unused-expressions

直接移除 node。 但如果子节点中包含 MemberExpression,则不修复。因为会有以下情况:

var obj = Object.defineProperty({}, 'prop', {
  get() { /* 产生副作用 */ }
})

obj.prop

当然也不排除这个 fix 过于激进,所以也可以考虑不实现这个 fix。

g-plane avatar Feb 13 '19 15:02 g-plane

严格来说,全局变量也有这种情况(比较少见):

var obj = Object.defineProperty(window, 'prop', {
  get() { /* 产生副作用 */ }
});

prop; // window.prop

aladdin-add avatar Feb 13 '19 15:02 aladdin-add

那就考虑采用「白名单」的方式,例如只修复 BinaryExpression 等。

g-plane avatar Feb 13 '19 15:02 g-plane

一般get函数是没有副作用的,所以移除掉的话也算合理。

aladdin-add avatar Feb 13 '19 15:02 aladdin-add

what if cb && cb();?

aladdin-add avatar Jun 10 '19 01:06 aladdin-add

The hasSideEffect function will be improved in the future to detect more cases.

Once the improvement completed, some rules besides no-unused-expressions can be done.

g-plane avatar Jun 10 '19 04:06 g-plane