Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
eslint-plugin-valtio
Advanced tools
Valtio linting plugin for better development.
npm install eslint-plugin-valtio --save-dev
for yarn users:
yarn add -D eslint-plugin-valtio
Add valtio
to the extends
section of your .eslintrc
configuration file.
{
"extends": [
"plugin:valtio/recommended"
]
}
Alternatively, you can enable rules in the plugin, selectively.
{
"rules": {
"valtio/state-snapshot-rule": "warn",
"valtio/avoid-this-in-proxy" :"warn",
}
}
This plugin helps you catch common mistakes that can occur in valtio. Here are some cases that this plugin catches.
We shouldn't use snapshots in callbacks, because snapshots can be stale there.
const state = proxy({ count: 0 })
function App() {
const snap = useSnapshot(state)
const handleClick = () => {
console.log(snap.count) // This is not recommended as it can be stale.
}
return (
<div>
{snap.count} <button onClick={handleClick}>click</button>
</div>
)
}
In render phase, it's better to use snapshots (as they're made to be compatible with react's reactivity) instead of states directly.
const state = proxy({ count: 0 })
function App() {
return (
<div>
{state.count} // This is not recommended as it is not reactive.
</div>
)
}
Snapshots are made to be used in the react render phase, and not mutable. So, we need to mutate proxy states directly.
const state = proxy({ count: 0 })
function App() {
const snap = useSnapshot(state)
const handleClick = () => {
++snap.count // This doesn't work. Use proxy state instead.
}
return <button onClick={handleClick}>mutate</button>
}
In the way valtio treats objects in proxyWithComputed
, the order of fields matters; for example, quadrupled
comes before doubled
, but it depends on doubled
, so the order is wrong! So we need to bring doubled
first.
const state = proxyWithComputed({
count: 0,
}, {
quadrupled: (snap) => snap.doubled * 2, // Not found, If a computed field deriving value is created from another computed, the computed source should be declared first.
doubled: (snap) => snap.count * 2,
})
this
in proxy (valtio/avoid-this-in-proxy
)When working with proxy
using this
in it's context as long as taken care of will work as expected but since the implementation differs from a simple proxy
to a snapshot
version of the proxy, using this
could get confusing. This rule is specifically for beginners that are adapting to the structure/differences in valtio.
const state = proxy({
count: 0,
inc() {
++state.count; // works as the state is being modified
},
});
const state = proxy({
count: 0,
inc() {
++this.count; // works as the context belongs to proxy
},
});
const state = snapshot(
proxy({
count: 0,
inc() {
++this.count; // won't work since the params are now frozen since you are in a snapshot.
},
})
);
FAQs
An eslint plugin for better valtio experience
The npm package eslint-plugin-valtio receives a total of 10,554 weekly downloads. As such, eslint-plugin-valtio popularity was classified as popular.
We found that eslint-plugin-valtio demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.