Skip to content

Commit

Permalink
Move JSDoc imports to before real imports.
Browse files Browse the repository at this point in the history
While issues have not yet been discovered in this project, JSDoc type imports have to be before the real module imports to workaround this TypeScript bug where sometimes the type imports are falsely considered unused:

microsoft/TypeScript#58368 (comment)
microsoft/TypeScript#58969
  • Loading branch information
jaydenseric committed Oct 9, 2024
1 parent 317780e commit e6a9851
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Patch

- Updated dependencies.
- Moved JSDoc comments containing `@import` to before real imports.

## 7.0.0

Expand Down
4 changes: 2 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @ts-check

/** @import { Linter } from "eslint" */

import eslintJs from "@eslint/js";
import eslintPluginJsdoc from "eslint-plugin-jsdoc";
import eslintPluginSimpleImportSort from "eslint-plugin-simple-import-sort";
import globals from "globals";

/** @import { Linter } from "eslint" */

/**
* Globs for ESM files.
* @satisfies {Array<string>}
Expand Down
4 changes: 2 additions & 2 deletions findUnusedExports.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @ts-check

/** @import { ModuleExports, ModuleScan } from "./scanModuleCode.mjs" */

import { readFile } from "node:fs/promises";
import { dirname, extname, join, resolve, sep } from "node:path";

Expand All @@ -9,8 +11,6 @@ import isDirectoryPath from "./isDirectoryPath.mjs";
import MODULE_GLOB from "./MODULE_GLOB.mjs";
import scanModuleCode from "./scanModuleCode.mjs";

/** @import { ModuleExports, ModuleScan } from "./scanModuleCode.mjs" */

/**
* Finds unused
* [ECMAScript module exports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export)
Expand Down
4 changes: 2 additions & 2 deletions scanModuleCode.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// @ts-check

/** @import { ParserPlugin } from "@babel/parser" */

// Use `@babel/core` instead of `@babel/parser` and `@babel/traverse` directly
// so that project Babel config will be respected when parsing code.
import babel from "@babel/core";

import getVariableDeclarationIdentifierNames from "./getVariableDeclarationIdentifierNames.mjs";

/** @import { ParserPlugin } from "@babel/parser" */

// Babel seems to also support non-standard string literals in place of named
// import and export identifiers, perhaps because CJS can have export names
// containing dashes, etc. such as `exports["a-b-c"]` and they want to support
Expand Down

0 comments on commit e6a9851

Please sign in to comment.