Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Commit

Permalink
feat: adds setting to ignore based on paths
Browse files Browse the repository at this point in the history
Introduces a configuration option to ignore a path based on a regex.
  • Loading branch information
thisislawatts committed Apr 21, 2020
1 parent 5b1c6a0 commit 748c178
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
"type": "object",
"title": "Snyk vulnerability cost configuration",
"properties": {
"vulnCost.ignorePaths": {
"type": "array",
"default": [],
"description:": "Paths which should not be scanned"
},
"vulnCost.typescriptExtensions": {
"type": "array",
"default": [
Expand Down
20 changes: 19 additions & 1 deletion src/getImports/babelParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import traverse from '@babel/traverse';
import * as t from '@babel/types';
import * as fs from 'fs';
import * as path from 'path';
import { workspace } from 'vscode';
import { parse as jsParse } from '@babel/parser';
import { TYPESCRIPT } from './parser';
import logger from '../logger';
Expand Down Expand Up @@ -29,10 +30,27 @@ export function getPackages(fileName, source, language) {
const packages = [];
const visitor = {
ImportDeclaration({ node }) {
const configuration = workspace.getConfiguration('vulnCost');
let pathIgnored = false;

for (let i = 0; i < configuration.ignorePaths.length; i++) {
const path = configuration.ignorePaths[i];
pathIgnored = new RegExp(path).test(node.source.value);

if (pathIgnored) {
continue;
}
}

if (pathIgnored) {
logger.log(`Import ${node.source.value} matched ignored path: ${path}`);
return;
}

const target = path.dirname(fileName) + path.sep + node.source.value;
const fileExists =
fs.existsSync(target) ||
fs.existsSync(target + '.js' ) ||
fs.existsSync(target + '.js') ||
fs.existsSync(target + path.sep + 'index.js');

if (!fileExists) {
Expand Down

0 comments on commit 748c178

Please sign in to comment.