New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ts-unused-exports

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-unused-exports - npm Package Compare versions

Comparing version 9.0.4 to 9.0.5

lib/parser/blacklists.d.ts

4

CHANGELOG.md

@@ -0,1 +1,5 @@

## [9.0.5] - 24 Jun 2023
- Add --ignoreLocallyUsed flag which means that exports which are used in the same file they are defined in won't be reported as unused
## [9.0.4] - 12 Feb 2023

@@ -2,0 +6,0 @@

@@ -72,2 +72,6 @@ "use strict";

break;
case '--ignoreLocallyUsed': {
newOptions.ignoreLocallyUsed = true;
break;
}
case '--maxIssues':

@@ -74,0 +78,0 @@ {

4

lib/parser/dynamic.js

@@ -7,6 +7,6 @@ "use strict";

var util_1 = require("./util");
var namespaceBlacklist_1 = require("./namespaceBlacklist");
var blacklists_1 = require("./blacklists");
// Parse Dynamic Imports
exports.mayContainDynamicImports = function (node) {
return !namespaceBlacklist_1.namespaceBlacklist.includes(node.kind) && node.getText().includes('import(');
return !blacklists_1.namespaceBlacklist.includes(node.kind) && node.getText().includes('import(');
};

@@ -13,0 +13,0 @@ function isWithExpressionBoolean(node) {

@@ -36,9 +36,10 @@ "use strict";

: common_1.STAR;
var from = common_1.getFrom(moduleSpecifier);
return {
exported: {
from: common_1.getFrom(moduleSpecifier),
from: from,
what: whatExported,
},
imported: {
from: common_1.getFrom(moduleSpecifier),
from: from,
what: whatImported,

@@ -45,0 +46,0 @@ isExportStarAs: (exportClause === null || exportClause === void 0 ? void 0 : exportClause.kind) === ts.SyntaxKind.NamespaceExport,

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addImportsFromNamespace = void 0;
var namespaceBlacklist_1 = require("./namespaceBlacklist");
var blacklists_1 = require("./blacklists");
var getPossibleImportedNamespaces = function (imports) {

@@ -46,3 +46,3 @@ var keys = Object.keys(imports);

.getChildren()
.filter(function (c) { return !namespaceBlacklist_1.namespaceBlacklist.includes(c.kind); })
.filter(function (c) { return !blacklists_1.namespaceBlacklist.includes(c.kind); })
.forEach(recurseIntoChildren);

@@ -49,0 +49,0 @@ };

@@ -11,3 +11,4 @@ "use strict";

var import_1 = require("./import");
var namespaceBlacklist_1 = require("./namespaceBlacklist");
var blacklists_1 = require("./blacklists");
var util_1 = require("./util");
var hasModifier = function (node, mod) {

@@ -101,2 +102,11 @@ return node.modifiers && node.modifiers.filter(function (m) { return m.kind === mod; }).length > 0;

}
if ((extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.ignoreLocallyUsed) &&
kind === ts.SyntaxKind.Identifier &&
node.parent.kind !== ts.SyntaxKind.VariableDeclaration &&
node.parent.kind !== ts.SyntaxKind.FunctionDeclaration) {
addImport({
from: util_1.removeTsFileExtension(node.getSourceFile().fileName),
what: [node.getText()],
});
}
if (hasModifier(node, ts.SyntaxKind.ExportKeyword)) {

@@ -109,7 +119,10 @@ var nsHolder = {

}
if (namespace.length > 0) {
if (namespace.length > 0 || (extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.ignoreLocallyUsed)) {
// In namespace: need to process children, in case they *import* any types
// If ignoreLocallyUsed: need to iterate through whole AST to find local uses of exported variables
var blacklist_1 = (extraOptions === null || extraOptions === void 0 ? void 0 : extraOptions.ignoreLocallyUsed) ? blacklists_1.ignoreLocalBlacklist
: blacklists_1.namespaceBlacklist;
node
.getChildren()
.filter(function (c) { return !namespaceBlacklist_1.namespaceBlacklist.includes(c.kind); })
.filter(function (c) { return !blacklist_1.includes(c.kind); })
.forEach(function (c) {

@@ -116,0 +129,0 @@ processSubNode(c, namespace);

@@ -6,2 +6,4 @@ import ts = require('typescript');

export declare function removeFileExtensionToAllowForJs(path: string): string;
export declare function removeTsFileExtension(path: string): string;
export declare function stripExtensionsFromPath(extensions: string[], path: string): string;
export declare function removeExportStarPrefix(path: string): string;

@@ -8,0 +10,0 @@ export declare function recurseIntoChildren(next: ts.Node, fun: (node: ts.Node) => boolean): boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findFirstChildOfKind = exports.findAllChildrenOfKind = exports.recurseIntoChildren = exports.removeExportStarPrefix = exports.removeFileExtensionToAllowForJs = exports.indexCandidateExtensions = exports.indexCandidates = exports.isUnique = void 0;
exports.findFirstChildOfKind = exports.findAllChildrenOfKind = exports.recurseIntoChildren = exports.removeExportStarPrefix = exports.stripExtensionsFromPath = exports.removeTsFileExtension = exports.removeFileExtensionToAllowForJs = exports.indexCandidateExtensions = exports.indexCandidates = exports.isUnique = void 0;
var ts = require("typescript");
var namespaceBlacklist_1 = require("./namespaceBlacklist");
var blacklists_1 = require("./blacklists");
function isUnique(value, index, self) {

@@ -32,10 +32,20 @@ return self.indexOf(value) === index;

var extensionsToStrip = ['.js', '.cjs', '.mjs'];
for (var i = 0; i < extensionsToStrip.length; i++) {
var ext = extensionsToStrip[i];
if (path.endsWith(ext))
return path.substring(0, path.length - ext.length);
return stripExtensionsFromPath(extensionsToStrip, path);
}
exports.removeFileExtensionToAllowForJs = removeFileExtensionToAllowForJs;
function removeTsFileExtension(path) {
var ext = ['.ts'];
return stripExtensionsFromPath(ext, path);
}
exports.removeTsFileExtension = removeTsFileExtension;
function stripExtensionsFromPath(extensions, path) {
for (var _i = 0, extensions_1 = extensions; _i < extensions_1.length; _i++) {
var extension = extensions_1[_i];
if (path.endsWith(extension)) {
return path.substring(0, path.length - extension.length);
}
}
return path;
}
exports.removeFileExtensionToAllowForJs = removeFileExtensionToAllowForJs;
exports.stripExtensionsFromPath = stripExtensionsFromPath;
function removeExportStarPrefix(path) {

@@ -61,3 +71,3 @@ if (path.startsWith('*:'))

.getChildren()
.filter(function (c) { return !namespaceBlacklist_1.namespaceBlacklist.includes(c.kind) || whitelist.includes(c.kind); })
.filter(function (c) { return !blacklists_1.namespaceBlacklist.includes(c.kind) || whitelist.includes(c.kind); })
.forEach(function (node) {

@@ -64,0 +74,0 @@ fun(node);

@@ -42,2 +42,3 @@ export interface Imports {

ignoreFilesRegex?: string[];
ignoreLocallyUsed?: boolean;
maxIssues?: number;

@@ -44,0 +45,0 @@ pathsToExcludeFromReport?: string[];

{
"name": "ts-unused-exports",
"version": "9.0.4",
"version": "9.0.5",
"description": "ts-unused-exports finds unused exported symbols in your Typescript project",

@@ -5,0 +5,0 @@ "main": "lib/app.js",

@@ -53,2 +53,3 @@ # ts-unused-exports

| `ignoreTestFiles` | Only scan **production** files (ignore all test files, like `spec.ts(x)` or `test.ts(x)` or `TestUtils.ts`). Use this to detect production code that is only used in tests (so is dead code). Note: this will NOT detect unused exports in test code - for that, you can run `ts-unused-exports` separately with the `--ignoreProductionFiles` option. | `--ignoreTestFiles` |
| `ignoreLocallyUsed` | Exports which are used in the same file they are defined in won't be reported as unused. Note that this may have an impact on performance in larger codebases. | `--ignoreLocallyUsed` |
| `maxIssues` | Return successfully for up to a given number of modules with unused exports. | `--maxIssues=7` |

@@ -55,0 +56,0 @@ | `searchNamespaces` | Enable searching for unused exports within namespaces. Note: this can affect performance on large codebases. | `--searchNamespaces` |

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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