-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Hi.
Thanks for this great plugin!
I'm interested in sending a PR to add a new rule.
Wanted your take\input before I take the time to work on it.
The goal of this rule is to catch cases where one of the parameters in the module function is reassigned.
It's easy to miss that the variable you think refers to the dependency now refers to something else.
Please LMK if you think you'd be interested in something like this,
and if so, some pointers on what I should pay attention to to increase changes of accepting the PR.
Thanks!
Invalid code example (only the assignment of a is invalid):
define(['path/to/a', 'path/to/b'], function(a, b) {
a = 1;
var c = b;
c = 2;
});Rule implementation (wip)
function create(context) {
const params = [];
return {
CallExpression(node) {
if (!isAmdWithCallback(node)) return;
const moduleFunction = getModuleFunction(node);
params = moduleFunction.params.map(x => x.name);
},
AssignmentExpression(node) {
if (node.left.type !== "Identifier") return;
const name = node.left.name;
if (params.some(x => x === name)) {
context.report(node, `Cannot assign to a module dependency named ${name}`);
}
}
};
}Reactions are currently unavailable