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

knip

Package Overview
Dependencies
Maintainers
1
Versions
423
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knip - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

dist/reporters/codeowners.d.ts

5

dist/cli.js

@@ -13,3 +13,3 @@ #!/usr/bin/env node

const errors_1 = require("./util/errors");
const { values: { help, dir, config: configFilePath = 'knip.json', tsConfig: tsConfigFilePath, include = [], exclude = [], ignore = [], 'no-gitignore': isNoGitIgnore = false, dev: isDev = false, 'no-progress': noProgress = false, reporter = 'symbols', 'max-issues': maxIssues = '0', jsdoc: jsDoc = [], debug: isDebug = false, 'debug-level': debugLevel = '1', }, } = (0, node_util_1.parseArgs)({
const { values: { help, dir, config: configFilePath = 'knip.json', tsConfig: tsConfigFilePath, include = [], exclude = [], ignore = [], 'no-gitignore': isNoGitIgnore = false, dev: isDev = false, 'no-progress': noProgress = false, reporter = 'symbols', 'reporter-options': reporterOptions = '', 'max-issues': maxIssues = '0', jsdoc: jsDoc = [], debug: isDebug = false, 'debug-level': debugLevel = '1', }, } = (0, node_util_1.parseArgs)({
options: {

@@ -28,2 +28,3 @@ help: { type: 'boolean' },

reporter: { type: 'string' },
'reporter-options': { type: 'string' },
jsdoc: { type: 'string', multiple: true },

@@ -61,3 +62,3 @@ debug: { type: 'boolean' },

});
printReport({ report, issues, workingDir, isDev });
printReport({ report, issues, cwd, workingDir, isDev, options: reporterOptions });
const reportGroup = report.files ? 'files' : Object.keys(report).find(key => report[key]);

@@ -64,0 +65,0 @@ const counterGroup = reportGroup === 'unlisted' ? 'unresolved' : reportGroup;

4

dist/help.js

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

--max-issues Maximum number of issues before non-zero exit code (default: 0)
--reporter Select reporter: symbols, compact (default: symbols)
--reporter Select reporter: symbols, compact, codeowners (default: symbols)
--reporter-options Pass extra options to the reporter (as JSON string, see example)
--jsdoc Enable JSDoc parsing, with options: public

@@ -32,2 +33,3 @@ --debug Show debug output

$ knip --ignore 'lib/**/*.ts' --ignore build
$ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'

@@ -34,0 +36,0 @@ More info: https://github.com/webpro/knip`);

@@ -1,8 +0,3 @@

import type { Issues, Report } from '../types';
declare const _default: ({ report, issues, workingDir, isDev, }: {
report: Report;
issues: Issues;
workingDir: string;
isDev: boolean;
}) => void;
import type { ReporterOptions } from '../types';
declare const _default: ({ report, issues, workingDir, isDev }: ReporterOptions) => void;
export default _default;

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

};
exports.default = ({ report, issues, workingDir, isDev, }) => {
exports.default = ({ report, issues, workingDir, isDev }) => {
const reportMultipleGroups = Object.values(report).filter(Boolean).length > 1;

@@ -32,0 +32,0 @@ if (report.files) {

declare const _default: {
symbols: ({ report, issues, workingDir, isDev, }: {
report: import("../types").Report;
issues: import("../types").Issues;
workingDir: string;
isDev: boolean;
}) => void;
compact: ({ report, issues, workingDir, isDev, }: {
report: import("../types").Report;
issues: import("../types").Issues;
workingDir: string;
isDev: boolean;
}) => void;
symbols: ({ report, issues, workingDir, isDev }: import("../types").ReporterOptions) => void;
compact: ({ report, issues, workingDir, isDev }: import("../types").ReporterOptions) => void;
codeowners: ({ report, issues, cwd, isDev, options }: import("../types").ReporterOptions) => void;
};
export default _default;

@@ -8,5 +8,7 @@ "use strict";

const compact_1 = __importDefault(require("./compact"));
const codeowners_1 = __importDefault(require("./codeowners"));
exports.default = {
symbols: symbols_1.default,
compact: compact_1.default,
codeowners: codeowners_1.default,
};

@@ -1,8 +0,3 @@

import type { Issues, Report } from '../types';
declare const _default: ({ report, issues, workingDir, isDev, }: {
report: Report;
issues: Issues;
workingDir: string;
isDev: boolean;
}) => void;
import type { ReporterOptions } from '../types';
declare const _default: ({ report, issues, workingDir, isDev }: ReporterOptions) => void;
export default _default;

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

};
exports.default = ({ report, issues, workingDir, isDev, }) => {
exports.default = ({ report, issues, workingDir, isDev }) => {
const reportMultipleGroups = Object.values(report).filter(Boolean).length > 1;

@@ -34,0 +34,0 @@ if (report.files) {

@@ -79,2 +79,11 @@ import { SourceFile } from 'ts-morph';

};
export declare type ReporterOptions = {
report: Report;
issues: Issues;
cwd: string;
workingDir: string;
isDev: boolean;
options: string;
};
export declare type Reporter = (options: ReporterOptions) => void;
export {};

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

export declare const isFile: (filePath: string) => Promise<boolean>;
export declare const findFile: (cwd: string, fileName: string) => Promise<string | undefined>;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.findFile = exports.isFile = void 0;
exports.findFile = void 0;
const promises_1 = __importDefault(require("node:fs/promises"));

@@ -19,6 +19,5 @@ const node_path_1 = __importDefault(require("node:path"));

};
exports.isFile = isFile;
const findFile = async (cwd, fileName) => {
const filePath = node_path_1.default.join(cwd, fileName);
if (await (0, exports.isFile)(filePath)) {
if (await isFile(filePath)) {
return filePath;

@@ -25,0 +24,0 @@ }

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

export declare const prependDirToPattern: (workingDir: string, pattern: string) => string;
export declare const resolvePaths: ({ cwd, workingDir, patterns, ignore, gitignore, }: {

@@ -3,0 +2,0 @@ cwd: string;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.resolvePaths = exports.prependDirToPattern = void 0;
exports.resolvePaths = void 0;
const node_path_1 = __importDefault(require("node:path"));

@@ -22,4 +22,3 @@ let _globby;

};
exports.prependDirToPattern = prependDirToPattern;
const resolvePaths = async ({ cwd, workingDir, patterns, ignore, gitignore, }) => glob(patterns.map(pattern => (0, exports.prependDirToPattern)(node_path_1.default.relative(cwd, workingDir), pattern)), {
const resolvePaths = async ({ cwd, workingDir, patterns, ignore, gitignore, }) => glob(patterns.map(pattern => prependDirToPattern(node_path_1.default.relative(cwd, workingDir), pattern)), {
cwd,

@@ -26,0 +25,0 @@ ignore,

{
"name": "knip",
"version": "0.6.0",
"version": "0.7.0",
"description": "Find unused files, dependencies and exports in your TypeScript and JavaScript project",

@@ -43,2 +43,3 @@ "keywords": [

"dependencies": {
"@snyk/github-codeowners": "1.0.0",
"globby": "13.1.2",

@@ -45,0 +46,0 @@ "is-builtin-module": "3.2.0",

@@ -23,2 +23,3 @@ # ✂️ Knip

- [x] Supports JavaScript-only projects using ESM (without a `tsconfig.json`)
- [x] Features multiple [reporters](#reporters) and supports [custom reporters](#custom-reporters).

@@ -95,3 +96,4 @@ Knip really shines in larger projects where you have non-production files (such as `/docs`, `/tools` and `/scripts`).

--max-issues Maximum number of issues before non-zero exit code (default: 0)
--reporter Select reporter: symbols, compact (default: symbols)
--reporter Select reporter: symbols, compact, codeowners (default: symbols)
--reporter-options Pass extra options to the reporter (as JSON string, see example)
--jsdoc Enable JSDoc parsing, with options: public

@@ -109,2 +111,3 @@ --debug Show debug output

$ knip --ignore 'lib/**/*.ts' --ignore build
$ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'

@@ -251,7 +254,36 @@ More info: https://github.com/webpro/knip

## Example Output
## Reporters
### Default reporter
For starters, Knip already contains a few useful reporters:
- `symbol` (default)
- `compact`
- `codeowners`
### Custom Reporters
When a `--reporter ./my-reporter` is passed, the default export of that module should have this interface:
```ts
type Reporter = (options: ReporterOptions) => void;
type ReporterOptions = {
report: Report;
issues: Issues;
cwd: string;
workingDir: string;
isDev: boolean;
options: string;
};
```
The data can then be used to write issues to `stdout`, a JSON or CSV file, or sent to a service, anything really!
### Example Output
#### Symbol (default)
The default reporter shows the sorted symbols first:
```
$ knip

@@ -281,4 +313,6 @@ --- UNUSED FILES (2)

### Compact
#### Compact
The compact reporter shows the sorted files first, and then a list of symbols:
```

@@ -307,2 +341,33 @@ $ knip --reporter compact

#### Code Owners
The `codeowners` reporter is like `compact`, but shows the sorted code owners (according to `.github/CODEOWNERS`) first:
```
$ knip --reporter codeowners
--- UNUSED FILES (2)
@org/team src/chat/helpers.ts
@org/owner src/components/SideBar.tsx
--- UNUSED DEPENDENCIES (1)
@org/admin moment
--- UNLISTED DEPENDENCIES (1)
@org/owner src/components/Registration.tsx react
--- UNUSED EXPORTS (4)
@org/team src/common/src/string/index.ts: lowercaseFirstLetter
@org/owner src/components/Registration.tsx: RegistrationBox
@org/owner src/css.ts: clamp
@org/owner src/services/authentication.ts: restoreSession, PREFIX
--- UNUSED TYPES (3)
@org/owner src/components/Registration/registrationMachine.ts: RegistrationServices, RegistrationAction
@org/owner src/components/Registration.tsx: ComponentProps
@org/owner src/types/Product.ts: ProductDetail
--- DUPLICATE EXPORTS (2)
@org/owner src/components/Registration.tsx: Registration, default
@org/owner src/components/Products.tsx: ProductsList, default
```
The owner of `package.json` is considered the owner of unused (dev) dependencies.
Use `--reporter-options '{"path":".github/CODEOWNERS"}'` to pass another location for the code owners file.
## Why Yet Another unused file/dependency/export finder?

@@ -309,0 +374,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