Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
added basic ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Fritsch-Tech committed Sep 30, 2023
1 parent 70ef403 commit a2a56ea
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 8 deletions.
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"file-entry-cache": "^6.0.1",
"flow-remove-types": "2.156.0",
"glob": "^7.1.6",
"ignore": "^5.2.4",
"json5": "^2.2.0",
"ora": "^5.3.0",
"read-pkg-up": "^7.0.1",
Expand Down
5 changes: 4 additions & 1 deletion src/__tests__/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,8 @@ export default promise
"ignoreUnresolved": [],
"ignoreUnimported": ["src/setup{Proxy,Tests}.js"],
"ignoreUnused": [],
"ignorePatterns": ["**/node_modules/**", "**/*.d.ts"]
"ignorePatterns": ["**/node_modules/**", "**/*.d.ts"],
"respectGitignore": true
}`,
},
{ name: 'src/index.tsx', content: `import './imported';` },
Expand Down Expand Up @@ -1118,6 +1119,7 @@ cases(
ignoreUnresolved: [],
ignoreUnimported: [],
ignoreUnused: [],
respectGitignore: true,
},
},
{
Expand Down Expand Up @@ -1151,6 +1153,7 @@ cases(
ignoreUnresolved: [],
ignoreUnimported: [],
ignoreUnused: ['@babel/runtime', 'meteor-node-stubs'],
respectGitignore: true,
},
},
],
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('printResults', () => {
ignoreUnimported: [],
ignoreUnused: [],
ignoreUnresolved: [],
respectGitignore: false,
},
showUnresolvedImports: false,
showUnusedDeps: false,
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('processResults', () => {
ignoreUnimported: [],
ignoreUnused: [],
ignoreUnresolved: [],
respectGitignore: false,
},
showUnusedFiles: false,
showUnusedDeps: false,
Expand Down Expand Up @@ -64,6 +65,7 @@ describe('processResults', () => {
ignoreUnimported: [],
ignoreUnused: [],
ignoreUnresolved: [],
respectGitignore: false,
},
showUnusedFiles: false,
showUnusedDeps: false,
Expand Down Expand Up @@ -104,6 +106,7 @@ describe('processResults', () => {
ignoreUnimported: [],
ignoreUnused: [],
ignoreUnresolved: [],
respectGitignore: false,
},
showUnusedFiles: false,
showUnusedDeps: true,
Expand Down Expand Up @@ -154,6 +157,7 @@ describe('processResults', () => {
ignoreUnimported: [],
ignoreUnused: [],
ignoreUnresolved: [],
respectGitignore: false,
},
showUnusedFiles: true,
showUnusedDeps: false,
Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface UnimportedConfig {
ignoreUnresolved: string[];
ignoreUnimported: string[];
ignoreUnused: string[];
respectGitignore?: boolean;
moduleDirectory?: string[];
rootDir?: string;
extensions?: string[];
Expand Down Expand Up @@ -70,6 +71,7 @@ export interface Config {
ignoreUnresolved: string[];
ignoreUnimported: string[];
ignoreUnused: string[];
respectGitignore: boolean;
moduleDirectory?: string[];
rootDir?: string;
extensions: string[];
Expand Down Expand Up @@ -157,6 +159,7 @@ export async function getConfig(args?: CliArguments): Promise<Config> {
),
ignoreUnused: configFile?.ignoreUnused ?? preset?.ignoreUnused ?? [],
ignorePatterns: configFile?.ignorePatterns ?? preset?.ignorePatterns ?? [],
respectGitignore: configFile?.respectGitignore ?? true,
moduleDirectory: configFile?.moduleDirectory ?? preset?.moduleDirectory,
entryFiles: [],
extensions: [],
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export async function main(args: CliArguments): Promise<void> {
ignoreUnimported: config.ignoreUnimported,
ignoreUnused: config.ignoreUnused,
ignoreUnresolved: config.ignoreUnresolved,
respectGitignore: config.respectGitignore,
});

spinner.stop();
Expand Down
17 changes: 16 additions & 1 deletion src/process.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import ignore from 'ignore';
import { TraverseResult } from './traverse';
import { Context } from './index';
import { ensureArray } from './ensureArray';
import path from 'path';
import { exists, readText } from './fs';

export interface ProcessedResult {
unresolved: [string, string[]][];
Expand Down Expand Up @@ -41,11 +44,23 @@ export async function processResults(
!ignoreUnusedIdx[x],
);

const unimported = files
let unimported = files
.filter((x) => !traverseResult.files.has(x))
.map((x) => x.replace(context.cwd + '/', ''))
.filter((x) => !ignoreUnimportedIdx[x]);

if (context.config.respectGitignore && (await exists('.gitignore'))) {
const gitignore = (await readText('.gitignore')).split('\n');
const ig = ignore().add(gitignore);
unimported = ig
.filter(
unimported.map((x) =>
path.relative(context.cwd, path.resolve(context.cwd, x)),
),
)
.map((x) => path.join(context.cwd, x));
}

const formatTypeResultMap: { [P in FormatTypes]: boolean } = {
showUnusedFiles: !unimported.length,
showUnusedDeps: !unused.length,
Expand Down

0 comments on commit a2a56ea

Please sign in to comment.