Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option to reduce false positives for index.ts #316

Open
tanquar opened this issue Dec 12, 2024 · 0 comments
Open

New option to reduce false positives for index.ts #316

tanquar opened this issue Dec 12, 2024 · 0 comments

Comments

@tanquar
Copy link

tanquar commented Dec 12, 2024

Hi, I am working with Deno Fresh project, where "index.js" "index.ts" are typically present in import paths:

import { t } from "/utils/i18n/index.ts";

In this case, current ts-unused-exports will produce false positives, when the exporting file name is "index.ts".

2 modules with unused exports
/Users/me/my-project/utils/i18n/index.ts: Languages, t

To remove false positives in Deno projects, I suggest to add a new option.
This will prevent removing "index.ts" from the file name during parsing.

argsParser.js:

...
        switch (optionName) {
            case '--allowUnusedEnums':
                newOptions.allowUnusedEnums = true;
                break;
...
            case '--keepIndex':
                newOptions.keepIndexInFileNames = true;
                break;
...

parser/index.js:

...
var pathWithoutExtension = function (pathIn, extraOptions) {
    var parsed = path.parse(pathIn);
    if (!extraOptions.keepIndexInFileNames) {
      if (util_1.indexCandidates.some(function (i) { return pathIn.endsWith(i); }))
          return parsed.dir;
    }
    return path.join(parsed.dir, cleanFilename(pathIn));
};
...
    return {
        path: pathWithoutExtension(path, extraOptions),
        fullPath: path,
        imports: imports,
        exports: exportNames,
        exportLocations: exportLocations,
    };

I'm not sure if this change is the best way, but at least in my Deno project just commentting out

      if (util_1.indexCandidates.some(function (i) { return pathIn.endsWith(i); }))
          return parsed.dir;

part works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant