Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(
prefer-modern-dom-apis
): Switch to whitelist for determining wh…
…ere node return values are expected safe not to be used. For `prefer-modern-dom-apis`, the change will avoid fixers in more cases than just `VariableDeclarator` and `AssignmentExpression` parent types (as previously); will now avoid whenever parent is not an `ExpressionStatement` since many other parents, e.g., `ArrayExpression`, `IfStatement`, `'MemberExpression`, `Property`, `ReturnStatement`, etc. can use a return value. For `prefer-node-*` rules, rather than blacklisting an albeit more extensive set of parents, will also switch to a whitelist, potentially avoiding fixers on other contexts not previously avoided, e.g., `AwaitExpression`. The previous avoidance by `prefer-node-*` of fixers with `ExpressionStatement` grandparents is not currently required. Also: 1. provides minor optimization to avoid declaring fixer with value when not needed. 2. fixes a test which made a fix which would break because of an inability of the replacement API to return a value.
- Loading branch information
Showing
3 changed files
with
95 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,7 @@ | ||
'use strict'; | ||
|
||
const ignoredParentTypes = [ | ||
'ArrayExpression', | ||
'AssignmentExpression', | ||
'IfStatement', | ||
'MemberExpression', | ||
'Property', | ||
'ReturnStatement', | ||
'VariableDeclarator' | ||
]; | ||
|
||
const ignoredGrandparentTypes = [ | ||
'ExpressionStatement' | ||
]; | ||
|
||
module.exports = function (node) { | ||
const {parent} = node; | ||
const { | ||
parent: grandparent | ||
} = (parent || {}); | ||
|
||
return (parent && ignoredParentTypes.includes(parent.type)) || | ||
(grandparent && ignoredGrandparentTypes.includes(grandparent.type)); | ||
return parent && parent.type !== 'ExpressionStatement'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters