Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@boll/rules-typescript

Package Overview
Dependencies
Maintainers
3
Versions
1227
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@boll/rules-typescript - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

18

dist/cross-package-dependency-detector.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -17,3 +21,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -37,3 +41,3 @@ return result;

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -100,3 +104,3 @@ if (y = 0, t) op = [op[0] & 2, t.value];

lineNumber = lineNumber + totalLines - 1;
if (typescript_1.isImportDeclaration(n)) {
if ((0, typescript_1.isImportDeclaration)(n)) {
var path_1 = _this.getPathFromNode(n);

@@ -115,3 +119,3 @@ if (path_1.startsWith(".")) {

if (!resolvedPath.startsWith(packageRoot + path.sep)) {
var result = new core_1.Failure(ruleName, sourceFilePath, core_1.asBollLineNumber(i.lineNumber), "Imports " + resolvedPath + ", which spans a package boundary.");
var result = new core_1.Failure(ruleName, sourceFilePath, (0, core_1.asBollLineNumber)(i.lineNumber), "Imports ".concat(resolvedPath, ", which spans a package boundary."));
results.push(result);

@@ -126,7 +130,7 @@ }

CrossPackageDependencyDetector.prototype.getPathFromNode = function (n) {
if (typescript_1.isStringLiteral(n.moduleSpecifier)) {
if ((0, typescript_1.isStringLiteral)(n.moduleSpecifier)) {
var moduleSpecifier = n.moduleSpecifier.getText();
return moduleSpecifier.slice(1, moduleSpecifier.length - 1);
}
throw new Error("Don't know how to parse import statement " + n.getText());
throw new Error("Don't know how to parse import statement ".concat(n.getText()));
};

@@ -133,0 +137,0 @@ return CrossPackageDependencyDetector;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -10,3 +14,3 @@ if (k2 === undefined) k2 = k;

var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};

@@ -13,0 +17,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

@@ -17,3 +17,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -73,3 +73,3 @@ if (y = 0, t) op = [op[0] & 2, t.value];

return l.line.includes("node_modules") &&
results.push(new core_1.Failure(ruleName, fileName, core_1.asBollLineNumber(l.lineNumber), "Explicit reference to \"node_modules\" directory: " + l));
results.push(new core_1.Failure(ruleName, fileName, (0, core_1.asBollLineNumber)(l.lineNumber), "Explicit reference to \"node_modules\" directory: ".concat(l)));
});

@@ -76,0 +76,0 @@ if (results.length > 0) {

@@ -17,3 +17,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -74,3 +74,3 @@ if (y = 0, t) op = [op[0] & 2, t.value];

.map(function (i) {
return new core_1.Failure(ruleName, fileName, core_1.asBollLineNumber(i.lineNumber), "Already used as an import source; please combine import statements");
return new core_1.Failure(ruleName, fileName, (0, core_1.asBollLineNumber)(i.lineNumber), "Already used as an import source; please combine import statements");
});

@@ -88,3 +88,3 @@ if (results.length > 0) {

lineNumber = lineNumber + totalLines - 1;
if (typescript_1.isImportDeclaration(n)) {
if ((0, typescript_1.isImportDeclaration)(n)) {
importPaths.push({

@@ -91,0 +91,0 @@ path: n.moduleSpecifier.getText(),

@@ -17,3 +17,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -74,3 +74,3 @@ if (y = 0, t) op = [op[0] & 2, t.value];

.map(function (i) {
return new core_1.Failure(ruleName, fileName, core_1.asBollLineNumber(i.lineNumber), "Import includes 'src', but should not. Import from root package instead.");
return new core_1.Failure(ruleName, fileName, (0, core_1.asBollLineNumber)(i.lineNumber), "Import includes 'src', but should not. Import from root package instead.");
});

@@ -88,3 +88,3 @@ if (results.length > 0) {

lineNumber = lineNumber + totalLines - 1;
if (typescript_1.isImportDeclaration(n)) {
if ((0, typescript_1.isImportDeclaration)(n)) {
importPaths.push({

@@ -91,0 +91,0 @@ path: n.moduleSpecifier.getText(),

@@ -10,2 +10,2 @@ "use strict";

var unused_dependency_detector_test_1 = require("./unused-dependency-detector.test");
test_internal_1.suite(cross_package_dep_detector_test_1.test, node_modules_reference_detector_test_1.test, redundant_imports_detector_test_1.test, src_detector_test_1.test, transitive_dependency_detector_test_1.test, unused_dependency_detector_test_1.test);
(0, test_internal_1.suite)(cross_package_dep_detector_test_1.test, node_modules_reference_detector_test_1.test, redundant_imports_detector_test_1.test, src_detector_test_1.test, transitive_dependency_detector_test_1.test, unused_dependency_detector_test_1.test);
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -17,3 +21,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -37,3 +41,3 @@ return result;

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -69,4 +73,4 @@ if (y = 0, t) op = [op[0] & 2, t.value];

var test_internal_1 = require("@boll/test-internal");
exports.test = baretest_1.default("Cross package dependency detector");
exports.test("Should pass if no cross-package dependencies detected", function () { return __awaiter(void 0, void 0, void 0, function () {
exports.test = (0, baretest_1.default)("Cross package dependency detector");
(0, exports.test)("Should pass if no cross-package dependencies detected", function () { return __awaiter(void 0, void 0, void 0, function () {
var importPaths, sut, result;

@@ -79,3 +83,3 @@ return __generator(this, function (_a) {

sut = new cross_package_dependency_detector_1.CrossPackageDependencyDetector();
result = sut.checkImportPaths(core_1.asBollDirectory("/a/b/c"), core_1.asBollFile("/a/b/c/baz.ts"), importPaths);
result = sut.checkImportPaths((0, core_1.asBollDirectory)("/a/b/c"), (0, core_1.asBollFile)("/a/b/c/baz.ts"), importPaths);
assert.strictEqual(1, result.length);

@@ -86,3 +90,3 @@ assert.strictEqual(core_1.ResultStatus.success, result[0].status);

}); });
exports.test("Should fail if cross-package dependency detected", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should fail if cross-package dependency detected", function () { return __awaiter(void 0, void 0, void 0, function () {
var importPaths, sut, result;

@@ -96,3 +100,3 @@ return __generator(this, function (_a) {

sut = new cross_package_dependency_detector_1.CrossPackageDependencyDetector();
result = sut.checkImportPaths(core_1.asBollDirectory("/a/b/c"), core_1.asBollFile("/a/b/c/baz.ts"), importPaths);
result = sut.checkImportPaths((0, core_1.asBollDirectory)("/a/b/c"), (0, core_1.asBollFile)("/a/b/c/baz.ts"), importPaths);
assert.strictEqual(1, result.length);

@@ -103,6 +107,6 @@ assert.strictEqual(core_1.ResultStatus.failure, result[0].status);

}); });
exports.test("Should fail for missing imports if few imports are declared in devDependencies and devDeps mode is enabled", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should fail for missing imports if few imports are declared in devDependencies and devDeps mode is enabled", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, test_internal_1.inFixtureDir("cross-package-dep-detector", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
case 0: return [4 /*yield*/, (0, test_internal_1.inFixtureDir)("cross-package-dep-detector", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, result, _a, _b, failure, failure1, failure2;

@@ -114,3 +118,3 @@ return __generator(this, function (_c) {

_b = (_a = sut).check;
return [4 /*yield*/, core_1.getSourceFile(core_1.asBollDirectory("."), "cross-package-dep-detector.ts", new core_1.Package({}, {}))];
return [4 /*yield*/, (0, core_1.getSourceFile)((0, core_1.asBollDirectory)("."), "cross-package-dep-detector.ts", {})];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()])];

@@ -117,0 +121,0 @@ case 2:

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -17,3 +21,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -37,3 +41,3 @@ return result;

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -69,6 +73,6 @@ if (y = 0, t) op = [op[0] & 2, t.value];

var test_internal_1 = require("@boll/test-internal");
exports.test = baretest_1.default("Node modules reference detector");
exports.test("Should pass if no references to node_modules exist in source code", function () { return __awaiter(void 0, void 0, void 0, function () {
exports.test = (0, baretest_1.default)("Node modules reference detector");
(0, exports.test)("Should pass if no references to node_modules exist in source code", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
test_internal_1.inFixtureDir("node-modules-references", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
(0, test_internal_1.inFixtureDir)("node-modules-references", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, result, _a, _b;

@@ -80,3 +84,3 @@ return __generator(this, function (_c) {

_b = (_a = sut).check;
return [4 /*yield*/, core_1.getSourceFile(core_1.asBollDirectory("."), "node-modules-reference-none.ts", new core_1.Package({}, {}))];
return [4 /*yield*/, (0, core_1.getSourceFile)((0, core_1.asBollDirectory)("."), "node-modules-reference-none.ts", {})];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()])];

@@ -94,5 +98,5 @@ case 2:

}); });
exports.test("Should fail if references to node_modules exist in source code", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should fail if references to node_modules exist in source code", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
test_internal_1.inFixtureDir("node-modules-references", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
(0, test_internal_1.inFixtureDir)("node-modules-references", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, result, _a, _b, failure, failure1;

@@ -104,3 +108,3 @@ return __generator(this, function (_c) {

_b = (_a = sut).check;
return [4 /*yield*/, core_1.getSourceFile(core_1.asBollDirectory("."), "node-modules-reference.ts", new core_1.Package({}, {}))];
return [4 /*yield*/, (0, core_1.getSourceFile)((0, core_1.asBollDirectory)("."), "node-modules-reference.ts", {})];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()])];

@@ -107,0 +111,0 @@ case 2:

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -17,3 +21,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -37,3 +41,3 @@ return result;

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -69,4 +73,4 @@ if (y = 0, t) op = [op[0] & 2, t.value];

var test_internal_1 = require("@boll/test-internal");
exports.test = baretest_1.default("Redunant imports detector");
exports.test("Should pass if no redundant import paths", function () { return __awaiter(void 0, void 0, void 0, function () {
exports.test = (0, baretest_1.default)("Redunant imports detector");
(0, exports.test)("Should pass if no redundant import paths", function () { return __awaiter(void 0, void 0, void 0, function () {
var importPaths, sut, result;

@@ -80,3 +84,3 @@ return __generator(this, function (_a) {

sut = new redundant_imports_detector_1.RedundantImportsDetector();
result = sut.checkImportPaths(core_1.asBollFile("a"), importPaths);
result = sut.checkImportPaths((0, core_1.asBollFile)("a"), importPaths);
assert.strictEqual(core_1.ResultStatus.success, result[0].status);

@@ -86,3 +90,3 @@ return [2 /*return*/];

}); });
exports.test("Should fail if there are redundant import paths", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should fail if there are redundant import paths", function () { return __awaiter(void 0, void 0, void 0, function () {
var importPaths, sut, result;

@@ -96,3 +100,3 @@ return __generator(this, function (_a) {

sut = new redundant_imports_detector_1.RedundantImportsDetector();
result = sut.checkImportPaths(core_1.asBollFile("a"), importPaths);
result = sut.checkImportPaths((0, core_1.asBollFile)("a"), importPaths);
assert.strictEqual(core_1.ResultStatus.failure, result[0].status);

@@ -102,6 +106,6 @@ return [2 /*return*/];

}); });
exports.test("Should fail for missing imports if few imports are declared in devDependencies and devDeps mode is enabled", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should fail for missing imports if few imports are declared in devDependencies and devDeps mode is enabled", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, test_internal_1.inFixtureDir("redundant-imports-detector", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
case 0: return [4 /*yield*/, (0, test_internal_1.inFixtureDir)("redundant-imports-detector", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, result, _a, _b, failure, failure1;

@@ -113,3 +117,3 @@ return __generator(this, function (_c) {

_b = (_a = sut).check;
return [4 /*yield*/, core_1.getSourceFile(core_1.asBollDirectory("."), "redundant-imports-detector.ts", new core_1.Package({}, {}))];
return [4 /*yield*/, (0, core_1.getSourceFile)((0, core_1.asBollDirectory)("."), "redundant-imports-detector.ts", {})];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()])];

@@ -116,0 +120,0 @@ case 2:

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -17,3 +21,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -37,3 +41,3 @@ return result;

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -69,4 +73,4 @@ if (y = 0, t) op = [op[0] & 2, t.value];

var test_internal_1 = require("@boll/test-internal");
exports.test = baretest_1.default("Source detector");
exports.test("Should pass if no `src` detected in imports", function () { return __awaiter(void 0, void 0, void 0, function () {
exports.test = (0, baretest_1.default)("Source detector");
(0, exports.test)("Should pass if no `src` detected in imports", function () { return __awaiter(void 0, void 0, void 0, function () {
var importPaths, sut, result;

@@ -79,3 +83,3 @@ return __generator(this, function (_a) {

sut = new src_detector_1.SrcDetector();
result = sut.checkImportPaths(core_1.asBollFile("a"), importPaths);
result = sut.checkImportPaths((0, core_1.asBollFile)("a"), importPaths);
assert.strictEqual(core_1.ResultStatus.success, result[0].status);

@@ -85,3 +89,3 @@ return [2 /*return*/];

}); });
exports.test("Should fail if `src` detected in imports", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should fail if `src` detected in imports", function () { return __awaiter(void 0, void 0, void 0, function () {
var importPaths, sut, result;

@@ -94,3 +98,3 @@ return __generator(this, function (_a) {

sut = new src_detector_1.SrcDetector();
result = sut.checkImportPaths(core_1.asBollFile("a"), importPaths);
result = sut.checkImportPaths((0, core_1.asBollFile)("a"), importPaths);
assert.strictEqual(core_1.ResultStatus.failure, result[0].status);

@@ -100,5 +104,5 @@ return [2 /*return*/];

}); });
exports.test("Should fail if references to `src` detected in imports", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should fail if references to `src` detected in imports", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
test_internal_1.inFixtureDir("src-detector", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
(0, test_internal_1.inFixtureDir)("src-detector", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, result, _a, _b, failure, failure1;

@@ -110,3 +114,3 @@ return __generator(this, function (_c) {

_b = (_a = sut).check;
return [4 /*yield*/, core_1.getSourceFile(core_1.asBollDirectory("."), "src-detector.ts", new core_1.Package({}, {}))];
return [4 /*yield*/, (0, core_1.getSourceFile)((0, core_1.asBollDirectory)("."), "src-detector.ts", {})];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()])];

@@ -113,0 +117,0 @@ case 2:

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -17,3 +21,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -37,3 +41,3 @@ return result;

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -69,7 +73,7 @@ if (y = 0, t) op = [op[0] & 2, t.value];

var test_internal_1 = require("@boll/test-internal");
exports.test = baretest_1.default("Transitive dep detector");
exports.test("(dependencies only mode) Should fail if any references to packages not referenced in package", function () { return __awaiter(void 0, void 0, void 0, function () {
exports.test = (0, baretest_1.default)("Transitive dep detector");
(0, exports.test)("(dependencies only mode) Should fail if any references to packages not referenced in package", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, test_internal_1.inFixtureDir("transitive-reference", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
case 0: return [4 /*yield*/, (0, test_internal_1.inFixtureDir)("transitive-reference", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, result, _a, _b, expected, containsExpected;

@@ -81,3 +85,3 @@ return __generator(this, function (_c) {

_b = (_a = sut).check;
return [4 /*yield*/, core_1.getSourceFile(core_1.asBollDirectory("."), "foo.ts", new core_1.Package({}, {}))];
return [4 /*yield*/, (0, core_1.getSourceFile)((0, core_1.asBollDirectory)("."), "foo.ts", {})];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()])];

@@ -90,3 +94,3 @@ case 2:

containsExpected = result[0].formattedMessage.includes(expected);
assert.ok(containsExpected, "Expected \"" + result[0].formattedMessage + "\" to contain \"" + expected + "\", but didn't.");
assert.ok(containsExpected, "Expected \"".concat(result[0].formattedMessage, "\" to contain \"").concat(expected, "\", but didn't."));
return [2 /*return*/];

@@ -102,3 +106,3 @@ }

}); });
exports.test("Should allow any modules given to the constructor", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should allow any modules given to the constructor", function () { return __awaiter(void 0, void 0, void 0, function () {
var sut;

@@ -112,6 +116,6 @@ return __generator(this, function (_a) {

}); });
exports.test("Should succeed if all imports are declared in dependencies", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should succeed if all imports are declared in dependencies", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, test_internal_1.inFixtureDir("transitive-reference", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
case 0: return [4 /*yield*/, (0, test_internal_1.inFixtureDir)("transitive-reference", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, result, _a, _b;

@@ -123,3 +127,3 @@ return __generator(this, function (_c) {

_b = (_a = sut).check;
return [4 /*yield*/, core_1.getSourceFile(core_1.asBollDirectory("."), "foo.ts", new core_1.Package({ "@some/other-package": "0" }, {}))];
return [4 /*yield*/, (0, core_1.getSourceFile)((0, core_1.asBollDirectory)("."), "foo.ts", { dependencies: { "@some/other-package": "0" } })];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()])];

@@ -139,6 +143,6 @@ case 2:

}); });
exports.test("Should succeed if all imports are declared in devDependencies and devDeps mode is enabled", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should succeed if all imports are declared in devDependencies and devDeps mode is enabled", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, test_internal_1.inFixtureDir("transitive-reference", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
case 0: return [4 /*yield*/, (0, test_internal_1.inFixtureDir)("transitive-reference", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, result, _a, _b;

@@ -150,3 +154,3 @@ return __generator(this, function (_c) {

_b = (_a = sut).check;
return [4 /*yield*/, core_1.getSourceFile(core_1.asBollDirectory("."), "foo.ts", new core_1.Package({}, { "@some/other-package": "0" }))];
return [4 /*yield*/, (0, core_1.getSourceFile)((0, core_1.asBollDirectory)("."), "foo.ts", { devDependencies: { "@some/other-package": "0" } })];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()])];

@@ -166,6 +170,6 @@ case 2:

}); });
exports.test("Should fail if all imports are declared in devDependencies and devDeps mode is disabled", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should fail if all imports are declared in devDependencies and devDeps mode is disabled", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, test_internal_1.inFixtureDir("transitive-reference", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
case 0: return [4 /*yield*/, (0, test_internal_1.inFixtureDir)("transitive-reference", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, result, _a, _b, failure;

@@ -177,3 +181,3 @@ return __generator(this, function (_c) {

_b = (_a = sut).check;
return [4 /*yield*/, core_1.getSourceFile(core_1.asBollDirectory("."), "foo.ts", new core_1.Package({}, { "@some/other-package": "0" }))];
return [4 /*yield*/, (0, core_1.getSourceFile)((0, core_1.asBollDirectory)("."), "foo.ts", { devDependencies: { "@some/other-package": "0" } })];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()])];

@@ -196,6 +200,6 @@ case 2:

}); });
exports.test("Should fail for missing imports if few imports are declared in devDependencies and devDeps mode is enabled", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should fail for missing imports if few imports are declared in devDependencies and devDeps mode is enabled", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, test_internal_1.inFixtureDir("transitive-reference", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
case 0: return [4 /*yield*/, (0, test_internal_1.inFixtureDir)("transitive-reference", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, result, _a, _b, failure, failure1, failure2;

@@ -207,3 +211,5 @@ return __generator(this, function (_c) {

_b = (_a = sut).check;
return [4 /*yield*/, core_1.getSourceFile(core_1.asBollDirectory("."), "transitive-reference.ts", new core_1.Package({}, { "@some/other-package": "0" }))];
return [4 /*yield*/, (0, core_1.getSourceFile)((0, core_1.asBollDirectory)("."), "transitive-reference.ts", {
devDependencies: { "@some/other-package": "0" }
})];
case 1: return [4 /*yield*/, _b.apply(_a, [_c.sent()])];

@@ -210,0 +216,0 @@ case 2:

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -17,3 +21,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -37,3 +41,3 @@ return result;

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -70,4 +74,7 @@ if (y = 0, t) op = [op[0] & 2, t.value];

var test_internal_1 = require("@boll/test-internal");
exports.test = baretest_1.default("Unused dep detector");
exports.test("Should succeed because all declared dependencies are imported in code", function () { return __awaiter(void 0, void 0, void 0, function () {
var fs = __importStar(require("fs"));
var util_1 = require("util");
var readFileAsync = (0, util_1.promisify)(fs.readFile);
exports.test = (0, baretest_1.default)("Unused dep detector");
(0, exports.test)("Should succeed because all declared dependencies are imported in code", function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, results;

@@ -89,3 +96,3 @@ return __generator(this, function (_a) {

}); });
exports.test("Should succeed because all declared dependencies are imported in code (with more deps)", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should succeed because all declared dependencies are imported in code (with more deps)", function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, results;

@@ -118,3 +125,3 @@ return __generator(this, function (_a) {

}); });
exports.test("Should succeed because `baz` is excluded", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should succeed because `baz` is excluded", function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, results;

@@ -142,3 +149,3 @@ return __generator(this, function (_a) {

}); });
exports.test("Should succeed because all declared dependencies are imported in code and devDependencies are ignored", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should succeed because all declared dependencies are imported in code and devDependencies are ignored", function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, results;

@@ -161,3 +168,3 @@ return __generator(this, function (_a) {

}); });
exports.test("Should fail because baz is not used as an import", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should fail because baz is not used as an import", function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, results;

@@ -184,3 +191,3 @@ return __generator(this, function (_a) {

}); });
exports.test("Should fail because multiple deps are not used", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Should fail because multiple deps are not used", function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, results;

@@ -222,15 +229,17 @@ return __generator(this, function (_a) {

}); });
exports.test("Fixture test should succeed because all declared dependencies are imported in code", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Fixture test should succeed because all declared dependencies are imported in code", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, test_internal_1.inFixtureDir("unused-deps/succeed", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, results;
case 0: return [4 /*yield*/, (0, test_internal_1.inFixtureDir)("unused-deps/succeed", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var pkgJson, sut, results;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
case 0: return [4 /*yield*/, readFileAsync((0, core_1.asBollFile)("package.json"))];
case 1:
pkgJson = (_a.sent()).toString();
sut = new unused_dependency_detector_1.UnusedDependencyDetector();
return [4 /*yield*/, sut.check(["a.ts", "b.ts", "c.ts"].map(function (f) {
return new core_1.FileContext(core_1.asBollDirectory("."), core_1.Package.parse(core_1.asBollFile("package.json")), core_1.asBollFile(f), fs_1.readFileSync(core_1.asBollFile(f)).toString());
return new core_1.FileContext((0, core_1.asBollDirectory)("."), (0, core_1.parse)(pkgJson), (0, core_1.asBollFile)(f), (0, fs_1.readFileSync)((0, core_1.asBollFile)(f)).toString());
}))];
case 1:
case 2:
results = _a.sent();

@@ -249,7 +258,7 @@ assert.deepStrictEqual(results.length, 1);

}); });
exports.test("Fixture test should succeed because unused dependencies are excluded", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Fixture test should succeed because unused dependencies are excluded", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, test_internal_1.inFixtureDir("unused-deps/succeed-exclude", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, results;
case 0: return [4 /*yield*/, (0, test_internal_1.inFixtureDir)("unused-deps/succeed-exclude", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, pkgJson, results;
return __generator(this, function (_a) {

@@ -259,6 +268,9 @@ switch (_a.label) {

sut = new unused_dependency_detector_1.UnusedDependencyDetector({ exclude: ["baz"] });
return [4 /*yield*/, readFileAsync((0, core_1.asBollFile)("package.json"))];
case 1:
pkgJson = (_a.sent()).toString();
return [4 /*yield*/, sut.check(["a.ts", "b.ts", "c.ts"].map(function (f) {
return new core_1.FileContext(core_1.asBollDirectory("."), core_1.Package.parse(core_1.asBollFile("package.json")), core_1.asBollFile(f), fs_1.readFileSync(core_1.asBollFile(f)).toString());
return new core_1.FileContext((0, core_1.asBollDirectory)("."), (0, core_1.parse)(pkgJson), (0, core_1.asBollFile)(f), (0, fs_1.readFileSync)((0, core_1.asBollFile)(f)).toString());
}))];
case 1:
case 2:
results = _a.sent();

@@ -277,6 +289,6 @@ assert.deepStrictEqual(results.length, 1);

}); });
exports.test("Fixture test should succeed because devDependencies are ignored", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Fixture test should succeed because devDependencies are ignored", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, test_internal_1.inFixtureDir("unused-deps/succeed-ignore-dev-deps", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
case 0: return [4 /*yield*/, (0, test_internal_1.inFixtureDir)("unused-deps/succeed-ignore-dev-deps", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, results;

@@ -288,3 +300,3 @@ return __generator(this, function (_a) {

return [4 /*yield*/, sut.check(["a.ts", "b.ts", "c.ts"].map(function (f) {
return new core_1.FileContext(core_1.asBollDirectory("."), core_1.Package.parse(core_1.asBollFile("package.json")), core_1.asBollFile(f), fs_1.readFileSync(core_1.asBollFile(f)).toString());
return new core_1.FileContext((0, core_1.asBollDirectory)("."), (0, core_1.parse)((0, core_1.asBollFile)("package.json")), (0, core_1.asBollFile)(f), (0, fs_1.readFileSync)((0, core_1.asBollFile)(f)).toString());
}))];

@@ -305,15 +317,17 @@ case 1:

}); });
exports.test("Fixture test should fail because a dependency is not imported in code", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Fixture test should fail because a dependency is not imported in code", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, test_internal_1.inFixtureDir("unused-deps/fail-unused-dep", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, results;
case 0: return [4 /*yield*/, (0, test_internal_1.inFixtureDir)("unused-deps/fail-unused-dep", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var pkgJson, sut, results;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
case 0: return [4 /*yield*/, readFileAsync((0, core_1.asBollFile)("package.json"))];
case 1:
pkgJson = (_a.sent()).toString();
sut = new unused_dependency_detector_1.UnusedDependencyDetector();
return [4 /*yield*/, sut.check(["a.ts", "b.ts", "c.ts"].map(function (f) {
return new core_1.FileContext(core_1.asBollDirectory("."), core_1.Package.parse(core_1.asBollFile("package.json")), core_1.asBollFile(f), fs_1.readFileSync(core_1.asBollFile(f)).toString());
return new core_1.FileContext((0, core_1.asBollDirectory)("."), (0, core_1.parse)(pkgJson), (0, core_1.asBollFile)(f), (0, fs_1.readFileSync)((0, core_1.asBollFile)(f)).toString());
}))];
case 1:
case 2:
results = _a.sent();

@@ -333,7 +347,7 @@ assert.deepStrictEqual(results.length, 1);

}); });
exports.test("Fixture test should fail because several dependencies are not imported in code", function () { return __awaiter(void 0, void 0, void 0, function () {
(0, exports.test)("Fixture test should fail because several dependencies are not imported in code", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, test_internal_1.inFixtureDir("unused-deps/fail-unused-deps", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, results;
case 0: return [4 /*yield*/, (0, test_internal_1.inFixtureDir)("unused-deps/fail-unused-deps", __dirname, function () { return __awaiter(void 0, void 0, void 0, function () {
var sut, pkgJson, results;
return __generator(this, function (_a) {

@@ -343,6 +357,9 @@ switch (_a.label) {

sut = new unused_dependency_detector_1.UnusedDependencyDetector();
return [4 /*yield*/, readFileAsync((0, core_1.asBollFile)("package.json"))];
case 1:
pkgJson = (_a.sent()).toString();
return [4 /*yield*/, sut.check(["a.ts", "b.ts", "c.ts"].map(function (f) {
return new core_1.FileContext(core_1.asBollDirectory("."), core_1.Package.parse(core_1.asBollFile("package.json")), core_1.asBollFile(f), fs_1.readFileSync(core_1.asBollFile(f)).toString());
return new core_1.FileContext((0, core_1.asBollDirectory)("."), (0, core_1.parse)(pkgJson), (0, core_1.asBollFile)(f), (0, fs_1.readFileSync)((0, core_1.asBollFile)(f)).toString());
}))];
case 1:
case 2:
results = _a.sent();

@@ -349,0 +366,0 @@ assert.deepStrictEqual(results.length, 4);

@@ -1,2 +0,2 @@

import { DependencyMap, FileContext, ImportPathAndLineNumber, PackageRule, Result } from "@boll/core";
import { Package, FileContext, ImportPathAndLineNumber, PackageRule, Result } from "@boll/core";
import { SourceFile } from "typescript";

@@ -24,5 +24,5 @@ export interface Options {

check(file: FileContext): Promise<Result[]>;
isValidImport(packageDependencies: DependencyMap, packageDevDependencies: DependencyMap, importPath: string): any;
isValidImport(packageDependencies: Package["dependencies"], packageDevDependencies: Package["devDependencies"], importPath: string): any;
getModuleImports(sourceFile: SourceFile): ImportPathAndLineNumber[];
private getPathFromNode;
}

@@ -28,3 +28,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -73,3 +73,2 @@ if (y = 0, t) op = [op[0] & 2, t.value];

function TransitiveDependencyDetector() {
var _this = this;
var options = [];

@@ -79,2 +78,3 @@ for (var _i = 0; _i < arguments.length; _i++) {

}
var _this = this;
this.options = __assign({}, defaultOptions);

@@ -94,11 +94,12 @@ options.forEach(function (o) {

return __awaiter(this, void 0, void 0, function () {
var imports;
var imports, errors;
var _this = this;
return __generator(this, function (_a) {
imports = this.getModuleImports(file.source);
return [2 /*return*/, imports
.filter(function (i) { return !_this.isValidImport(file.packageDependencies, file.packageDevDependencies, i.path); })
.map(function (i) {
return new core_1.Failure(ruleName, file.filename, core_1.asBollLineNumber(i.lineNumber), "\"" + i.path + "\" is used as a module import, but not listed as a dependency. (Either add as a direct dependency or remove usage.)");
})];
errors = imports
.filter(function (i) { return !_this.isValidImport(file.packageDependencies, file.packageDevDependencies, i.path); })
.map(function (i) {
return new core_1.Failure(ruleName, file.filename, (0, core_1.asBollLineNumber)(i.lineNumber), "\"".concat(i.path, "\" is used as a module import, but not listed as a dependency. (Either add as a direct dependency or remove usage.)"));
});
return [2 /*return*/, errors];
});

@@ -108,7 +109,7 @@ });

TransitiveDependencyDetector.prototype.isValidImport = function (packageDependencies, packageDevDependencies, importPath) {
var validImports = Object.keys(packageDependencies).concat(this.options.ignorePackages);
var validImports = Object.keys(packageDependencies || {}).concat(this.options.ignorePackages);
if (this.options.allowDevDependencies) {
validImports = validImports.concat(Object.keys(packageDevDependencies));
validImports = validImports.concat(Object.keys(packageDevDependencies || {}));
}
return validImports.some(function (moduleName) { return importPath === moduleName || importPath.startsWith(moduleName + "/"); });
return validImports.some(function (moduleName) { return importPath === moduleName || importPath.startsWith("".concat(moduleName, "/")); });
};

@@ -122,3 +123,3 @@ TransitiveDependencyDetector.prototype.getModuleImports = function (sourceFile) {

lineNumber = lineNumber + totalLines - 1;
if (typescript_1.isImportDeclaration(n)) {
if ((0, typescript_1.isImportDeclaration)(n)) {
var path = _this.getPathFromNode(n);

@@ -133,7 +134,7 @@ if (!path.startsWith(".")) {

TransitiveDependencyDetector.prototype.getPathFromNode = function (n) {
if (typescript_1.isStringLiteral(n.moduleSpecifier)) {
if ((0, typescript_1.isStringLiteral)(n.moduleSpecifier)) {
var moduleSpecifier = n.moduleSpecifier.getText();
return moduleSpecifier.slice(1, moduleSpecifier.length - 1);
}
throw new Error("Don't know how to parse import statement " + n.getText());
throw new Error("Don't know how to parse import statement ".concat(n.getText()));
};

@@ -140,0 +141,0 @@ return TransitiveDependencyDetector;

@@ -6,3 +6,3 @@ import { FileContext, Result, PackageMetaRule, Package } from "@boll/core";

ignoreDevDependencies: boolean;
packageContextOverride: Package;
packageContextOverride: Partial<Package>;
}

@@ -9,0 +9,0 @@ /**

@@ -17,3 +17,3 @@ "use strict";

if (f) throw new TypeError("Generator is already executing.");
while (_) try {
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;

@@ -39,8 +39,10 @@ if (y = 0, t) op = [op[0] & 2, t.value];

};
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};

@@ -60,3 +62,3 @@ Object.defineProperty(exports, "__esModule", { value: true });

this.options = options;
this._exclude = options && options.exclude ? new Set(__spreadArrays(exclude, options.exclude)) : new Set(exclude);
this._exclude = options && options.exclude ? new Set(__spreadArray(__spreadArray([], exclude, true), options.exclude, true)) : new Set(exclude);
}

@@ -82,3 +84,3 @@ Object.defineProperty(UnusedDependencyDetector.prototype, "name", {

sourceFile.forEachChild(function (n) {
if (typescript_1.isImportDeclaration(n)) {
if ((0, typescript_1.isImportDeclaration)(n)) {
var path = _this.getPathFromNode(n);

@@ -102,9 +104,9 @@ if (!path.startsWith(".")) {

});
var results = __spreadArrays(Object.keys(dependencies)
var results = __spreadArray(__spreadArray([], Object.keys(dependencies)
.filter(function (d) { return dependencies[d] === 0 && !_this.isExcluded(d); })
.map(function (d) {
return new core_1.Failure(ruleName, core_1.asBollFile("package.json"),
return new core_1.Failure(ruleName, (0, core_1.asBollFile)("package.json"),
// TODO: Determine how to properly parse line number for package.json
core_1.asBollLineNumber(0), d + " is declared as a dependency in package.json but is not imported in code.");
}), Object.keys(devDependencies)
(0, core_1.asBollLineNumber)(0), "".concat(d, " is declared as a dependency in package.json but is not imported in code."));
}), true), Object.keys(devDependencies)
.filter(function (d) {

@@ -116,14 +118,14 @@ return devDependencies[d] === 0 &&

.map(function (d) {
return new core_1.Failure(ruleName, core_1.asBollFile("package.json"),
return new core_1.Failure(ruleName, (0, core_1.asBollFile)("package.json"),
// TODO: Determine how to properly parse line number for package.json
core_1.asBollLineNumber(0), d + " is declared as a devDependency in package.json but is not imported in code.");
}));
(0, core_1.asBollLineNumber)(0), "".concat(d, " is declared as a devDependency in package.json but is not imported in code."));
}), true);
return results.length ? results : [new core_1.Success(ruleName)];
};
UnusedDependencyDetector.prototype.getPathFromNode = function (n) {
if (typescript_1.isStringLiteral(n.moduleSpecifier)) {
if ((0, typescript_1.isStringLiteral)(n.moduleSpecifier)) {
var moduleSpecifier = n.moduleSpecifier.getText();
return moduleSpecifier.slice(1, moduleSpecifier.length - 1);
}
throw new Error("Don't know how to parse import statement " + n.getText());
throw new Error("Don't know how to parse import statement ".concat(n.getText()));
};

@@ -144,4 +146,4 @@ UnusedDependencyDetector.prototype.isExcluded = function (dep) {

if (this.options && this.options.packageContextOverride) {
Object.keys(this.options.packageContextOverride.dependencies).forEach(function (d) { return (dependencies[d] = 0); });
Object.keys(this.options.packageContextOverride.devDependencies).forEach(function (d) { return (devDependencies[d] = 0); });
Object.keys(this.options.packageContextOverride.dependencies || {}).forEach(function (d) { return (dependencies[d] = 0); });
Object.keys(this.options.packageContextOverride.devDependencies || {}).forEach(function (d) { return (devDependencies[d] = 0); });
}

@@ -151,4 +153,4 @@ else {

var file = files[0];
Object.keys(file.packageDependencies).forEach(function (d) { return (dependencies[d] = 0); });
Object.keys(file.packageDevDependencies).forEach(function (d) { return (devDependencies[d] = 0); });
Object.keys(file.packageDependencies || {}).forEach(function (d) { return (dependencies[d] = 0); });
Object.keys(file.packageDevDependencies || {}).forEach(function (d) { return (devDependencies[d] = 0); });
}

@@ -155,0 +157,0 @@ return { dependencies: dependencies, devDependencies: devDependencies };

@@ -7,4 +7,4 @@ {

"dependencies": {
"@boll/core": "2.0.0",
"typescript": "^3.9.7"
"@boll/core": "3.0.0",
"typescript": "^4.9.4"
},

@@ -16,3 +16,3 @@ "description": "@boll rules for typescript source files",

"baretest": "^2.0.0",
"prettier": "^2.0.5",
"prettier": "^2.8.1",
"rimraf": "^3.0.2",

@@ -44,3 +44,3 @@ "ts-node-dev": "^1.0.0-pre.58",

},
"version": "1.0.0"
"version": "2.0.0"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc