diff --git a/package.json b/package.json index 4de96ae..b4e5918 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ ], "scripts": { "build": "rm -rf dist && tsc", + "prepack": "yarn build", "test": "jest", "test:ci": "jest --ci" }, diff --git a/src/__test__/analyze.test.ts b/src/__test__/analyze.test.ts index 34663cd..ac3016e 100644 --- a/src/__test__/analyze.test.ts +++ b/src/__test__/analyze.test.ts @@ -53,6 +53,33 @@ describe("analyze", () => { ]); }); + it("should ignore private if not wanted", () => { + const project = new Project({ useInMemoryFileSystem: true }); + project.createSourceFile( + "foo.ts", + ` + class A { + x = 1, + + fn() { + return this.x; + } + } + ` + ); + getConfigMock.mockReturnValue({ + ignoreCouldBePrivate: true + }); + assertResults(analyze(project), [ + { + class: "A", + member: "fn", + reason: "unused", + }, + ]); + }); + + it("should check references in all files", () => { const project = new Project({ useInMemoryFileSystem: true }); project.createSourceFile( diff --git a/src/analyze.ts b/src/analyze.ts index 5f1671d..9b7f0f7 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -220,7 +220,10 @@ export const analyze = (project: t.Project): IOffendingMembers[] => { // At this point, we knew the member is referenced somewhere, so if // it's already private then there's nothing to do here. - if (member.getScope() === t.Scope.Private) { + if ( + member.getScope() === t.Scope.Private || + config.ignoreCouldBePrivate + ) { continue; } diff --git a/src/config.ts b/src/config.ts index 162b0f5..38adccf 100644 --- a/src/config.ts +++ b/src/config.ts @@ -6,6 +6,7 @@ interface ICliConfig { fix?: boolean | undefined; path?: string; ignoreFileRegex?: string; + ignoreCouldBePrivate?: boolean | undefined; } interface IConfig extends ICliConfig { @@ -33,6 +34,10 @@ const cliConfig = yargs(process.argv.slice(2)) type: "string", describe: "Regex pattern for excluding files", }, + ignoreCouldBePrivate: { + type: "boolean", + describe: "Don't report members that are public but could be private", + } }) .hide("fix") .help().argv;