Skip to content

Commit

Permalink
Rename "unused" to "unreferenced" in code
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 7, 2022
1 parent 48a7acf commit 31ba4fa
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 43 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,16 @@ can be tweaked further to the project structure.

```
$ exportman --config ./exportman.json
--- UNUSED FILES (2)
--- UNREFERENCED FILES (2)
src/chat/helpers.ts
src/components/SideBar.tsx
--- UNUSED EXPORTS (5)
--- UNREFERENCED EXPORTS (5)
lowercaseFirstLetter src/common/src/string/index.ts
RegistrationBox src/components/Registration.tsx
clamp src/css.ts
restoreSession src/services/authentication.ts
PREFIX src/services/authentication.ts
--- UNUSED TYPES (4)
--- UNREFERENCED TYPES (4)
enum RegistrationServices src/components/Registration/registrationMachine.ts
type RegistrationAction src/components/Registration/registrationMachine.ts
type ComponentProps src/components/Registration.tsx
Expand All @@ -201,15 +201,15 @@ ProductsList, default src/components/Products.tsx

```
$ exportman --config ./exportman.json --reporter compact
--- UNUSED FILES (2)
--- UNREFERENCED FILES (2)
src/chat/helpers.ts
src/components/SideBar.tsx
--- UNUSED EXPORTS (4)
--- UNREFERENCED EXPORTS (4)
src/common/src/string/index.ts: lowercaseFirstLetter
src/components/Registration.tsx: RegistrationBox
src/css.ts: clamp
src/services/authentication.ts: restoreSession, PREFIX
--- UNUSED TYPES (3)
--- UNREFERENCED TYPES (3)
src/components/Registration/registrationMachine.ts: RegistrationServices, RegistrationAction
src/components/Registration.tsx: ComponentProps
src/types/Product.ts: ProductDetail
Expand Down
2 changes: 1 addition & 1 deletion src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const printHelp = () => {
Options:
-c/--config [file] Configuration file path (default: ./exportman.json or package.json#exportman)
--cwd Working directory (default: current working directory)
--maxIssues Maximum number of unused files until non-zero exit code (default: 1)
--maxIssues Maximum number of unreferenced files until non-zero exit code (default: 1)
--only Report only listed issue group(s): files, exports, types, members, duplicates
--exclude Exclude issue group(s) from report: files, exports, types, members, duplicates
--noProgress Don't show dynamic progress updates
Expand Down
20 changes: 10 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ export async function run(configuration: Configuration) {
const project = await createProject(cwd, configuration.filePatterns);
const projectFiles = project.getSourceFiles();

// Slice & dice used & unused files
const [usedProductionFiles, unusedProductionFiles] = partitionSourceFiles(projectFiles, productionFiles);
// Slice & dice used & unreferenced files
const [usedProductionFiles, unreferencedProductionFiles] = partitionSourceFiles(projectFiles, productionFiles);
const [, usedNonEntryFiles] = partitionSourceFiles(usedProductionFiles, entryFiles);

// Set up the results
const issues: Issues = {
files: new Set(unusedProductionFiles.map(file => file.getFilePath())),
files: new Set(unreferencedProductionFiles.map(file => file.getFilePath())),
exports: {},
types: {},
duplicates: {},
members: {}
members: {},
};

const counters = {
Expand All @@ -40,17 +40,17 @@ export async function run(configuration: Configuration) {
types: 0,
duplicates: 0,
members: 0,
processed: issues.files.size
processed: issues.files.size,
};

// OK, this looks ugly
const updateProcessingOutput = (item: Issue) => {
if (!isShowProgress) return;
const counter = unusedProductionFiles.length + counters.processed;
const total = unusedProductionFiles.length + usedNonEntryFiles.length;
const counter = unreferencedProductionFiles.length + counters.processed;
const total = unreferencedProductionFiles.length + usedNonEntryFiles.length;
const percentage = Math.floor((counter / total) * 100);
const messages = [getLine(`${percentage}%`, `of files processed (${counter} of ${total})`)];
include.files && messages.push(getLine(unusedProductionFiles.length, 'unused files'));
include.files && messages.push(getLine(unreferencedProductionFiles.length, 'unused files'));
include.exports && messages.push(getLine(counters.exports, 'unused exports'));
include.types && messages.push(getLine(counters.types, 'unused types'));
include.members && messages.push(getLine(counters.members, 'unused namespace members'));
Expand All @@ -71,7 +71,7 @@ export async function run(configuration: Configuration) {
if (isShowProgress) updateProcessingOutput(issue);
};

// Skip when only interested in unused files
// Skip when only interested in unreferenced files
if (include.exports || include.types || include.members || include.duplicates) {
usedNonEntryFiles.forEach(sourceFile => {
const filePath = sourceFile.getFilePath();
Expand Down Expand Up @@ -138,7 +138,7 @@ export async function run(configuration: Configuration) {

if (!isReferencedOnlyBySelf) return; // This identifier is used somewhere else

// No more reasons left to think this identifier is used somewhere else, report it as unused
// No more reasons left to think this identifier is used somewhere else, report it as unreferenced
if (findReferencingNamespaceNodes(sourceFile).length > 0) {
addIssue('members', { filePath, symbol: identifierText });
} else if (type) {
Expand Down
20 changes: 10 additions & 10 deletions src/reporters/compact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,38 @@ export default ({ issues, config, cwd }: { issues: Issues; config: Configuration
const reportMultipleGroups = Object.values(include).filter(Boolean).length > 1;

if (include.files) {
const unusedFiles = Array.from(issues.files);
logIssueGroupResult(unusedFiles, cwd, reportMultipleGroups && 'UNUSED FILES');
const unreferencedFiles = Array.from(issues.files);
logIssueGroupResult(unreferencedFiles, cwd, reportMultipleGroups && 'UNREFERENCED FILES');
}

if (include.exports) {
const unusedExports = Object.values(issues.exports).map(issues => {
const unreferencedExports = Object.values(issues.exports).map(issues => {
const items = Object.values(issues);
return { ...items[0], symbols: items.map(i => i.symbol) };
});
logIssueGroupResults(unusedExports, cwd, reportMultipleGroups && 'UNUSED EXPORTS');
logIssueGroupResults(unreferencedExports, cwd, reportMultipleGroups && 'UNREFERENCED EXPORTS');
}

if (include.types) {
const unusedTypes = Object.values(issues.types).map(issues => {
const unreferencedTypes = Object.values(issues.types).map(issues => {
const items = Object.values(issues);
return { ...items[0], symbols: items.map(i => i.symbol) };
});
logIssueGroupResults(unusedTypes, cwd, reportMultipleGroups && 'UNUSED TYPES');
logIssueGroupResults(unreferencedTypes, cwd, reportMultipleGroups && 'UNREFERENCED TYPES');
}

if (include.members) {
const unusedMembers = Object.values(issues.members).map(issues => {
const unreferencedMembers = Object.values(issues.members).map(issues => {
const items = Object.values(issues);
return { ...items[0], symbols: items.map(i => i.symbol) };
});
logIssueGroupResults(unusedMembers, cwd, reportMultipleGroups && 'UNUSED NAMESPACE MEMBERS');
logIssueGroupResults(unreferencedMembers, cwd, reportMultipleGroups && 'UNREFERENCED NAMESPACE MEMBERS');
}

if (include.duplicates) {
const unusedDuplicates = Object.values(issues.duplicates)
const unreferencedDuplicates = Object.values(issues.duplicates)
.map(issues => Object.values(issues))
.flat();
logIssueGroupResults(unusedDuplicates, cwd, reportMultipleGroups && 'DUPLICATE EXPORTS');
logIssueGroupResults(unreferencedDuplicates, cwd, reportMultipleGroups && 'DUPLICATE EXPORTS');
}
};
26 changes: 10 additions & 16 deletions src/reporters/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,27 @@ export default ({ issues, config, cwd }: { issues: Issues; config: Configuration
const reportMultipleGroups = Object.values(include).filter(Boolean).length > 1;

if (include.files) {
const unusedFiles = Array.from(issues.files);
logIssueGroupResult(unusedFiles, cwd, reportMultipleGroups && 'UNUSED FILES');
const unreferencedFiles = Array.from(issues.files);
logIssueGroupResult(unreferencedFiles, cwd, reportMultipleGroups && 'UNUSED FILES');
}

if (include.exports) {
const unusedExports = Object.values(issues.exports).map(Object.values).flat();
logIssueGroupResults(unusedExports, cwd, reportMultipleGroups && 'UNUSED EXPORTS');
const unreferencedExports = Object.values(issues.exports).map(Object.values).flat();
logIssueGroupResults(unreferencedExports, cwd, reportMultipleGroups && 'UNUSED EXPORTS');
}

if (include.types) {
const unusedTypes = Object.values(issues.types)
.map(issues => Object.values(issues))
.flat();
logIssueGroupResults(unusedTypes, cwd, reportMultipleGroups && 'UNUSED TYPES');
const unreferencedTypes = Object.values(issues.types).map(Object.values).flat();
logIssueGroupResults(unreferencedTypes, cwd, reportMultipleGroups && 'UNUSED TYPES');
}

if (include.members) {
const unusedExports = Object.values(issues.members)
.map(issues => Object.values(issues))
.flat();
logIssueGroupResults(unusedExports, cwd, reportMultipleGroups && 'UNUSED NAMESPACE MEMBERS');
const unreferencedExports = Object.values(issues.members).map(Object.values).flat();
logIssueGroupResults(unreferencedExports, cwd, reportMultipleGroups && 'UNUSED NAMESPACE MEMBERS');
}

if (include.duplicates) {
const unusedDuplicates = Object.values(issues.duplicates)
.map(issues => Object.values(issues))
.flat();
logIssueGroupResults(unusedDuplicates, cwd, reportMultipleGroups && 'DUPLICATE EXPORTS');
const unreferencedDuplicates = Object.values(issues.duplicates).map(Object.values).flat();
logIssueGroupResults(unreferencedDuplicates, cwd, reportMultipleGroups && 'DUPLICATE EXPORTS');
}
};

0 comments on commit 31ba4fa

Please sign in to comment.