pzavolinsky / ts-unused-exports

ts-unused-exports finds unused exported symbols in your Typescript project
MIT License
738 stars 46 forks source link

Use own keys for unused exports and unused files #309

Open aryzing opened 2 months ago

aryzing commented 2 months ago

Would be great if the result returned by programmatic API organized the results organized in their own keys. Currently, file names with unused exports are top level properties alongside the unusedFiles property,

const result = {
  "filePath1": { /* ... */ },
  "filePath2": { /* ... */ },
  /* ... */
  unusedFiles: { /* ... */ },
};

It's not straightforward to get a list of files, having to handle the unusedFiles prop separately. Perhaps the result value could be updated to look more like one the following,

const result1 = {
  unusedExports: [
    {
      ["path/to/file"]: [
        {
          exportName: "someFunction",
          location: {
            line: 1,
            character: 1
          }
        }
      ]
    }
  ],
  unusedFiles: [
    {
      filePath: "..."
    }
  ],
};

or

const result2 = {
  unusedExports: [
    {
      filePath: "...",
      exports: [
        {
          name: "someFunction",
          location: {
            line: 1,
            character: 1
          }
        }
      ]
    }
  ],
  unusedFiles: [
    {
      filePath: "..."
    }
  ],
};