mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
QL code and tests for C#/C++/JavaScript.
This commit is contained in:
19
javascript/ql/src/React/DirectStateMutation.ql
Normal file
19
javascript/ql/src/React/DirectStateMutation.ql
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @name Direct state mutation
|
||||
* @description Mutating the state of a React component directly may lead to
|
||||
* lost updates.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @id js/react/direct-state-mutation
|
||||
* @tags reliability
|
||||
* frameworks/react
|
||||
* @precision very-high
|
||||
*/
|
||||
|
||||
import semmle.javascript.frameworks.React
|
||||
|
||||
from DataFlow::PropWrite pwn, ReactComponent c
|
||||
where pwn.getBase() = c.getAStateAccess() and
|
||||
// writes in constructors are ok
|
||||
not pwn.getContainer() instanceof Constructor
|
||||
select pwn, "Use `setState` instead of directly modifying component state."
|
||||
Reference in New Issue
Block a user