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

@line/ts-remove-unused

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@line/ts-remove-unused - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

15

dist/index.js

@@ -10,10 +10,15 @@ #!/usr/bin/env node

.option('--skip <regexp_pattern>', 'Specify the regexp pattern to match files that should be skipped from transforming')
.option('--include-d-ts', 'Include .d.ts files in target for transformation')
.action((options) => {
const skip = options.skip && Array.isArray(options.skip)
? options.skip
: typeof options.skip === 'string'
? [options.skip]
: [];
if (!options['includeD-ts']) {
skip.push('\\.d\\.ts');
}
execute({
tsConfigFilePath: options.project || './tsconfig.json',
skip: options.skip && Array.isArray(options.skip)
? options.skip
: typeof options.skip === 'string'
? [options.skip]
: [],
skip,
});

@@ -20,0 +25,0 @@ });

import { Project } from 'ts-morph';
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { removeUnusedFunctionExport } from './removeUnusedFunctionExport.js';

@@ -14,3 +16,3 @@ describe('removeUnusedFunctionExport', () => {

const result = file.getFullText();
expect(result.trim()).toBe(`export function hello() {};`);
assert.equal(result.trim(), `export function hello() {};`);
});

@@ -21,3 +23,3 @@ it('should remove export for function if its not used in some other file', () => {

const result = file.getFullText();
expect(result.trim()).toBe(`function world() {};`);
assert.equal(result.trim(), `function world() {};`);
});

@@ -29,5 +31,5 @@ it('should not remove export if it has a comment to ignore', () => {

const result = file.getFullText();
expect(result.trim()).toBe(`// ts-remove-unused-skip
assert.equal(result.trim(), `// ts-remove-unused-skip
export function world() {};`);
});
});
import { Project } from 'ts-morph';
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { removeUnusedInterfaceExport } from './removeUnusedInterfaceExport.js';

@@ -14,3 +16,3 @@ describe('removeUnusedInterfaceExport', () => {

const result = file.getFullText();
expect(result.trim()).toBe(`export interface Hello { hello: 'hello' }`);
assert.equal(result.trim(), `export interface Hello { hello: 'hello' }`);
});

@@ -21,3 +23,3 @@ it('should remove export for interface if its not used in some other file', () => {

const result = file.getFullText();
expect(result.trim()).toBe(`interface World { world: 'world' }`);
assert.equal(result.trim(), `interface World { world: 'world' }`);
});

@@ -29,3 +31,3 @@ it('should not remove export if it has a comment to ignore', () => {

const result = file.getFullText();
expect(result.trim()).toBe(`// ts-remove-unused-skip
assert.equal(result.trim(), `// ts-remove-unused-skip
export interface World { world: 'world' }`);

@@ -37,4 +39,4 @@ });

const result = file.getFullText();
expect(result.trim()).toBe(`interface World { world: 'world' }; export default World;`);
assert.equal(result.trim(), `interface World { world: 'world' }; export default World;`);
});
});
import { Project } from 'ts-morph';
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { removeUnusedTypeExport } from './removeUnusedTypeExport.js';

@@ -14,3 +16,3 @@ describe('removeUnusedTypeExport', () => {

const result = file.getFullText();
expect(result.trim()).toBe(`export type Hello = 'hello';`);
assert.equal(result.trim(), `export type Hello = 'hello';`);
});

@@ -21,3 +23,3 @@ it('should remove export for type if its not used in some other file', () => {

const result = file.getFullText();
expect(result.trim()).toBe(`type World = 'world';`);
assert.equal(result.trim(), `type World = 'world';`);
});

@@ -29,3 +31,3 @@ it('should not remove export if it has a comment to ignore', () => {

const result = file.getFullText();
expect(result.trim()).toBe(`// ts-remove-unused-skip
assert.equal(result.trim(), `// ts-remove-unused-skip
export type World = 'world';`);

@@ -37,4 +39,4 @@ });

const result = file.getFullText();
expect(result.trim()).toBe(`type World = 'world'; export default World;`);
assert.equal(result.trim(), `type World = 'world'; export default World;`);
});
});
import { Project } from 'ts-morph';
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { removeUnusedVariableExport } from './removeUnusedVariableExport.js';

@@ -14,3 +16,3 @@ describe('removeUnusedVariableExport', () => {

const result = file.getFullText();
expect(result.trim()).toBe(`export const hello = 'hello';`);
assert.equal(result.trim(), `export const hello = 'hello';`);
});

@@ -21,3 +23,3 @@ it('should remove export for variable if its not used in some other file', () => {

const result = file.getFullText();
expect(result.trim()).toBe(`const world = 'world';`);
assert.equal(result.trim(), `const world = 'world';`);
});

@@ -29,3 +31,3 @@ it('should not remove export if it has a comment to ignore', () => {

const result = file.getFullText();
expect(result.trim()).toBe(`// ts-remove-unused-skip
assert.equal(result.trim(), `// ts-remove-unused-skip
export const world = 'world';`);

@@ -37,4 +39,4 @@ });

const result = file.getFullText();
expect(result.trim()).toBe(`const world = 'world'; export default world;`);
assert.equal(result.trim(), `const world = 'world'; export default world;`);
});
});
import { Node, Project } from 'ts-morph';
import { isReferredInMultipleFiles } from './isReferredInMultipleFiles.js';
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
describe('isReferredInMultipleFiles', () => {

@@ -18,5 +20,5 @@ // todo: issue in ts-morph, think of alternative solution

}
expect(isReferredInMultipleFiles(declaration)).toBe(true);
assert.equal(isReferredInMultipleFiles(declaration), true);
});
});
});
import { Project } from 'ts-morph';
import { isUsedFile } from './isUsedFile.js';
import { IGNORE_COMMENT } from './shouldIgnore.js';
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
describe('isUsedFile', () => {

@@ -14,6 +16,6 @@ it('should return true if some exports are used in some other file', () => {

const e = project.createSourceFile('./e.ts', `export function b() {}; export const c = 1; export type D = number; export interface E {};`);
expect(isUsedFile(b)).toBe(true);
expect(isUsedFile(c)).toBe(true);
expect(isUsedFile(d)).toBe(true);
expect(isUsedFile(e)).toBe(true);
assert.equal(isUsedFile(b), true);
assert.equal(isUsedFile(c), true);
assert.equal(isUsedFile(d), true);
assert.equal(isUsedFile(e), true);
});

@@ -25,3 +27,3 @@ it('should return false if all exports are not used in any other file', () => {

const b = project.createSourceFile('./b.ts', `export function b() {}; export const c = 1; export type D = number; export interface E {};`);
expect(isUsedFile(b)).toBe(false);
assert.equal(isUsedFile(b), false);
});

@@ -43,6 +45,6 @@ it('should return true if some exports are marked with a skip comment', () => {

export interface E {};`);
expect(isUsedFile(b)).toBe(true);
expect(isUsedFile(c)).toBe(true);
expect(isUsedFile(d)).toBe(true);
expect(isUsedFile(e)).toBe(true);
assert.equal(isUsedFile(b), true);
assert.equal(isUsedFile(c), true);
assert.equal(isUsedFile(d), true);
assert.equal(isUsedFile(e), true);
});

@@ -59,9 +61,9 @@ it('should return true if the file has a default export', () => {

const eAlt = project.createSourceFile('./eAlt.ts', `function b() {}; export const c = 1; export type D = number; interface E {}; export default E;`);
expect(isUsedFile(b)).toBe(true);
expect(isUsedFile(bAlt)).toBe(true);
expect(isUsedFile(c)).toBe(true);
expect(isUsedFile(d)).toBe(true);
expect(isUsedFile(e)).toBe(true);
expect(isUsedFile(eAlt)).toBe(true);
assert.equal(isUsedFile(b), true);
assert.equal(isUsedFile(bAlt), true);
assert.equal(isUsedFile(c), true);
assert.equal(isUsedFile(d), true);
assert.equal(isUsedFile(e), true);
assert.equal(isUsedFile(eAlt), true);
});
});
{
"name": "@line/ts-remove-unused",
"version": "0.1.0",
"version": "0.2.0",
"description": "Remove unused code from your TypeScript project",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/line/ts-remove-unused"
},
"license": "Apache-2.0",

@@ -14,7 +18,8 @@ "bin": "dist/index.js",

"build": "rm -rf dist && tsc --outDir dist",
"type-check": "tsc --noEmit",
"prepublishOnly": "npm run build",
"test": "jest src"
"test": "glob -c 'node --loader ts-node/esm --test' 'src/**/*.test.ts'"
},
"devDependencies": {
"@types/jest": "^29.5.0",
"@types/node": "^20.6.3",
"@typescript-eslint/eslint-plugin": "^6.4.1",

@@ -25,5 +30,5 @@ "@typescript-eslint/parser": "^6.4.1",

"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.5.0",
"glob": "^10.3.5",
"prettier": "^3.0.2",
"ts-jest": "^29.1.0"
"ts-node": "^10.9.1"
},

@@ -30,0 +35,0 @@ "dependencies": {

@@ -27,2 +27,3 @@ # ts-remove-unused

--skip <regexp_pattern> Specify the regexp pattern to match files that should be skipped from transforming
--include-d-ts Include .d.ts files in target for transformation
-h, --help Display this message

@@ -50,2 +51,4 @@ -v, --version Display version number

By default, .d.ts files are skipped. If you want to include .d.ts files, use the --include-d-ts option.
## Known Issue

@@ -58,2 +61,3 @@

npx prettier --write . ## fix the format
git add .
git commit ## commit first

@@ -60,0 +64,0 @@ git checkout HEAD~1 -- . && git diff HEAD~1 HEAD --ignore-blank-lines | git apply && git reset ## this will try to restore irrelevant changes of empty lines caused by the first commit

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