Skip to content

Commit

Permalink
fix: skip import type nodes in no-unpublished-import rule (eslint-com…
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal authored and aladdin-add committed Mar 3, 2023
1 parent e43d4ea commit f7d81f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/no-unpublished-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = {
return {}
}

return visitImport(context, {}, targets => {
return visitImport(context, { excludeTypeImport: true }, targets => {
checkPublish(context, filePath, targets)
})
},
Expand Down
12 changes: 11 additions & 1 deletion lib/util/visit-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ const stripImportPathParams = require("./strip-import-path-params")
* @param {Object} [options] - The flag to include core modules.
* @param {boolean} [options.includeCore] - The flag to include core modules.
* @param {number} [options.optionIndex] - The index of rule options.
* @param {boolean} [options.excludeTypeImport] - The flag to exclude typescript type imports.
* @param {function(ImportTarget[]):void} callback The callback function to get result.
* @returns {ImportTarget[]} A list of found target's information.
*/
module.exports = function visitImport(
context,
{ includeCore = false, optionIndex = 0 } = {},
{ includeCore = false, optionIndex = 0, excludeTypeImport = false } = {},
callback
) {
const targets = []
Expand All @@ -52,6 +53,15 @@ module.exports = function visitImport(
return
}

// skip `import type { foo } from 'bar'` (for eslint-typescript)
if (
excludeTypeImport &&
node.type === "ImportDeclaration" &&
node.importKind === "type"
) {
return
}

const name = sourceNode && stripImportPathParams(sourceNode.value)
// Note: "999" arbitrary to check current/future Node.js version
if (name && (includeCore || !isCoreModule(name, "999"))) {
Expand Down

0 comments on commit f7d81f9

Please sign in to comment.