Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return stackTrace.parse(error).map(call => {
const fileName = call.getFileName();
const functionName = call.getFunctionName();
const lineNumber = call.getLineNumber();
const columnNumber = call.getColumnNumber();
if (isString(fileName)) {
const absolute = isAbsolute(fileName);
const resolvedFileName = path.resolve(cwd, fileName);
if (
subdir(cwd, fileName) &&
!subdir(path.join(cwd, 'node_modules'), resolvedFileName) &&
(absolute || (
builtins.indexOf(path.basename(fileName, '.js')) === -1 &&
pathExists.sync(resolvedFileName)
))
) {
// absolute and within CWD (but not in node_modules folder)
// - highlight this line
return (
(functionName ? grey(' at ') + functionName : ' ') +
grey(' in ') + path.join('./', path.relative(cwd, fileName)) +
(lineNumber ? grey(':' + lineNumber + ':' + columnNumber) : '')
);
}
// anywhere else - dim this line
return grey(
(functionName ? ' at ' + functionName : ' ') +
' in ' + path.relative(cwd, fileName) +
.filter((dep) =>
// built in modules
builtinModules.indexOf(dep) === -1
// react-intl locale imports
&& !dep.includes('react-intl/locale-data')
// local references
&& dep[0] !== '.')
.sort();
module.exports = function (str) {
if (typeof str !== 'string') {
throw new TypeError('Expected a string');
}
return builtinModules.indexOf(str) !== -1;
};
function walk(ctx: Lint.WalkContext) {
const { options } = ctx;
let dependencies: Set | undefined;
const whitelist = new Set(options.whitelist);
for (const name of findImports(ctx.sourceFile, ImportKind.All)) {
if (!ts.isExternalModuleNameRelative(name.text)) {
const packageName = getPackageName(name.text, whitelist);
if (
!whitelist.has(packageName) &&
builtins.indexOf(packageName) === -1 &&
!hasDependency(packageName)
) {
ctx.addFailureAtNode(name, Rule.FAILURE_STRING_FACTORY(packageName));
}
}
}
function hasDependency(module: string): boolean {
if (dependencies === undefined) {
dependencies = getDependencies(ctx.sourceFile.fileName, options);
}
return dependencies.has(module);
}
}
module.exports = function (str) {
if (typeof str !== 'string') {
throw new TypeError('Expected a string');
}
return builtinModules.indexOf(str) !== -1;
};
function testModulePath(value, fileDir, aliases = {}, extensions = []) {
if (builtinModules.indexOf(value) >= 0) {
return;
}
if (aliases[value] !== undefined) {
value = aliases[value];
} else {
for (const key of Object.keys(aliases)) {
if (value.startsWith(`${key}/`)) {
value = value.replace(`${key}/`, `${aliases[key]}/`);
break;
}
}
}
try {
resolve.sync(value, {
function ( err, resolved ) {
if ( err ) {
if ( skip === true ) accept( false );
else reject( Error( ("Could not resolve '" + importee + "' from " + (normalize( importer ))) ) );
} else {
if ( resolved === COMMONJS_BROWSER_EMPTY ) {
accept( ES6_BROWSER_EMPTY );
} else if ( ~builtins.indexOf( resolved ) ) {
accept( null );
} else if ( ~builtins.indexOf( importee ) && preferBuiltins ) {
if ( !isPreferBuiltinsSet ) {
onwarn(
"preferring built-in module '" + importee + "' over local alternative " +
"at '" + resolved + "', pass 'preferBuiltins: false' to disable this " +
"behavior or 'preferBuiltins: true' to disable this warning"
);
}
accept( null );
} else {
accept( resolved );
}
}
}
);
module.exports = function (str) {
if (typeof str !== 'string') {
throw new TypeError('Expected a string');
}
return builtinModules.indexOf(str) !== -1;
};
module.exports = function (str) {
if (typeof str !== 'string') {
throw new TypeError('Expected a string');
}
return builtinModules.indexOf(str) !== -1;
};
function ( err, resolved ) {
if ( err ) {
if ( skip === true ) accept( false );
else reject( Error( ("Could not resolve '" + importee + "' from " + (normalize( importer ))) ) );
} else {
if ( resolved === COMMONJS_BROWSER_EMPTY ) {
accept( ES6_BROWSER_EMPTY );
} else if ( ~builtins.indexOf( resolved ) ) {
accept( null );
} else if ( ~builtins.indexOf( importee ) && preferBuiltins ) {
if ( !isPreferBuiltinsSet ) {
onwarn(
"preferring built-in module '" + importee + "' over local alternative " +
"at '" + resolved + "', pass 'preferBuiltins: false' to disable this " +
"behavior or 'preferBuiltins: true' to disable this warning"
);
}
accept( null );
} else {
accept( resolved );
}
}
}
);