Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-unused-expressions #32

Open
g-plane opened this issue Feb 13, 2019 · 5 comments
Open

no-unused-expressions #32

g-plane opened this issue Feb 13, 2019 · 5 comments

Comments

@g-plane
Copy link
Collaborator

g-plane commented Feb 13, 2019

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

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

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

obj.prop

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

@aladdin-add
Copy link
Owner

aladdin-add commented Feb 13, 2019

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

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

prop; // window.prop

@g-plane
Copy link
Collaborator Author

g-plane commented Feb 13, 2019

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

@aladdin-add
Copy link
Owner

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

@aladdin-add
Copy link
Owner

what if cb && cb();?

@g-plane
Copy link
Collaborator Author

g-plane commented Jun 10, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants