11/**
22 * @name Useless assignment to property
3- * @description An assignment to a property whose value is always overwritten, has no effect.
3+ * @description An assignment to a property whose value is always overwritten has no effect.
44 * @kind problem
55 * @problem.severity warning
66 * @id js/useless-assignment-to-property
@@ -15,7 +15,7 @@ import DeadStore
1515/**
1616 * Holds if `assign` definitely assigns property `name` of `base`.
1717 */
18- predicate unambigiousPropWrite ( DataFlow:: SourceNode base , string name , Assignment assign ) {
18+ predicate unambiguousPropWrite ( DataFlow:: SourceNode base , string name , Assignment assign ) {
1919 exists ( DataFlow:: PropWrite lhs |
2020 assign .getLhs ( ) .flow ( ) = lhs and
2121 base .getAPropertyWrite ( name ) = lhs and
@@ -33,8 +33,8 @@ predicate postDominatedPropWrite(string name, Assignment assign1, Assignment ass
3333 exists ( DataFlow:: SourceNode base , ReachableBasicBlock block1 , ReachableBasicBlock block2 |
3434 block1 = assign1 .getBasicBlock ( ) and
3535 block2 = assign2 .getBasicBlock ( ) and
36- unambigiousPropWrite ( base , name , assign1 ) and
37- unambigiousPropWrite ( base , name , assign2 ) and
36+ unambiguousPropWrite ( base , name , assign1 ) and
37+ unambiguousPropWrite ( base , name , assign2 ) and
3838 block2 .postDominates ( block1 ) and
3939 ( block1 = block2 implies
4040 exists ( int i1 , int i2 |
@@ -61,13 +61,13 @@ predicate maybeAccessesProperty(Expr e, string name) {
6161 */
6262predicate isDeadAssignment ( string name , Assignment assign1 , Assignment assign2 ) {
6363 postDominatedPropWrite ( name , assign1 , assign2 ) and
64- maybeHasPropAccessBetween ( name , assign1 , assign2 ) and
64+ noPropAccessBetween ( name , assign1 , assign2 ) and
6565 not isDOMProperty ( name )
6666}
6767
6868/**
6969 * Holds if `assign` assigns a property `name` that may be accessed somewhere else in the same block,
70- * `after` indicates if the if the access happens before or after the node for `assign`.
70+ * `after` indicates if the access happens before or after the node for `assign`.
7171 */
7272bindingset [ name]
7373predicate maybeAccessesAssignedPropInBlock ( string name , Assignment assign , boolean after ) {
@@ -86,12 +86,12 @@ predicate maybeAccessesAssignedPropInBlock(string name, Assignment assign, boole
8686 * Holds if `assign1` and `assign2` both assign property `name`, and the assigned property may be accessed between the two assignments.
8787 */
8888bindingset [ name]
89- predicate maybeHasPropAccessBetween ( string name , Assignment assign1 , Assignment assign2 ) {
89+ predicate noPropAccessBetween ( string name , Assignment assign1 , Assignment assign2 ) {
9090 exists ( ReachableBasicBlock block1 , ReachableBasicBlock block2 |
9191 assign1 .getBasicBlock ( ) = block1 and
9292 assign2 .getBasicBlock ( ) = block2 and
9393 if block1 = block2 then
94- // same block: check for read between
94+ // same block: check for access between
9595 not exists ( int i1 , int iMid , Expr mid , int i2 |
9696 assign1 = block1 .getNode ( i1 ) and
9797 assign2 = block2 .getNode ( i2 ) and
@@ -102,15 +102,15 @@ predicate maybeHasPropAccessBetween(string name, Assignment assign1, Assignment
102102 else
103103 // other block:
104104 not (
105- // check for read after in start block
105+ // check for an access after the first write node
106106 maybeAccessesAssignedPropInBlock ( name , assign1 , true ) or
107- // check for read after in other block
107+ // check for an access between the two write blocks
108108 exists ( ReachableBasicBlock mid |
109109 block1 .getASuccessor + ( ) = mid and
110110 mid .getASuccessor + ( ) = block2 |
111111 maybeAccessesProperty ( mid .getANode ( ) , name )
112112 ) or
113- // check for read before in end block
113+ // check for an access before the second write node
114114 maybeAccessesAssignedPropInBlock ( name , assign2 , false )
115115 )
116116 )
0 commit comments