Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Utility library to manipulate ASTs
$ npm install --save ast-utils
const astUtils = require('ast-utils');
Checks whether node
is a call to CommonJS's require
function.
Returns true
if and only if:
CallExpression
node
's callee is an Identifier
named require
node
has exactly 1 Literal
argument whose value is a string
Example:
require('lodash');
// => true
require(foo);
// => false
foo('lodash');
// => false
Usage example (in the context of an ESLint rule):
function create(context) {
return {
CallExpression(node) {
if (astUtils.isStaticRequire(node)) {
context.report({
node: node,
message: 'Use import syntax rather than `require`'
});
}
}
};
}
Gets the source of a require()
call. If node
is not a require
call (in the definition of isStaticRequire
), it will return undefined
.
Example:
require('lodash');
// => 'lodash'
require('./foo');
// => './foo'
Usage example (in the context of an ESLint rule):
function create(context) {
return {
CallExpression(node) {
if (astUtils.isStaticRequire(node) && astUtils.getRequireSource(node) === 'underscore') {
context.report({
node: node,
message: 'Use `lodash` instead of `underscore`'
});
}
}
};
}
Checks if there is a reference to a variable named name
inside of node
.
Returns true if and only if:
Identifier
named name
inside of node
Identifier
is a variable (i.e. not a static property name for instance)Identifier
does not reference a different variable named name
introduced in a sub-scope of node
.Example:
foo(a);
// containsIdentifier('a', node) // => true
// containsIdentifier('b', node) // => true
function foo(fn) {
return function(a) {
return fn(a);
};
}
// containsIdentifier('a', node) // => false
Usage example (in the context of an ESLint rule):
function create(context) {
return {
FunctionDeclaration(node) {
node.params.forEach(param => {
if (param.type === 'Identifier' && !astUtils.containsIdentifier(param.name, node.body)) {
context.report({
node: node,
message: `${name} is never used`
});
}
});
}
};
}
Checks if there is a reference to a variable named name
inside any node of the nodes
array. Will return false
if nodes
is not an array.
This is a shorthand version of containsIdentifier
that works for arrays. The following are equivalent:
[node1, node2, node3].some(node => astUtils.containsIdentifier('a', node));
// equivalent to
astUtils.someContainIdentifier('a', [node1, node2, node3]);
MIT © Jeroen Engels
FAQs
Utility library to manipulate ASTs
The npm package ast-utils receives a total of 531 weekly downloads. As such, ast-utils popularity was classified as not popular.
We found that ast-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.