Open brettz9 opened 5 years ago
Go for it. Sounds like a useful addition.
I think it would also be interesting if config could allow reading of outside variables but prevent setting of them.
The rule in the MIT-based library at https://github.com/yannickcr/eslint-plugin-react/blob/master/lib/rules/prefer-stateless-function.js might be useful as a starting point for this rule. (https://github.com/purely-functional/eslint-plugin-pure/blob/master/docs/rules/pure.md might be of interest, but probably not of real use for our particular needs here.)
While many of us use and enjoy using closures all over the place (or non-"pure" functions), taking advantage of their ability to borrow from their surrounding context, without any rule enforcement, such code can become a non-modular, non-unit-testable, non-externally-reusable spaghetti of functions, with too many contextual dependencies and preventing closures from being moved externally if necessary and may cause memory leaks/prevent garbage collection.
I'd like to see a non-standard JSDoc tag (akin to PHP's "use" language construct) to help with this, as well as to make
no-shadow
less unpleasant as detailed in the ESLint report.I detailed such an idea at https://github.com/eslint/eslint/issues/11061 though it was rejected from ESLint proper.
While I don't think this should be a recommended rule, I think it could provide some useful linting qualities and wanted to get your thoughts.
Update: Would be nice to also support other tags for enforcing the degree of function purity like
@setsProperty {type} target name
,@addsProperty {type} target name
,@removesProperty
.