-
Notifications
You must be signed in to change notification settings - Fork 645
Disallow import internal root package #1681
Conversation
src/goPackages.ts
Outdated
@@ -278,9 +278,13 @@ export function getNonVendorPackages(folderPath: string): Promise<string[]> { | |||
// see: https://golang.org/s/go14internal | |||
function isAllowToImportPackage(toDirPath: string, currentWorkspace: string, pkgPath: string) { | |||
let internalPkgFound = pkgPath.match(/\/internal\/|\/internal$/); | |||
if (internalPkgFound) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldnt this be if(!internalPkgFound)
?
Your case is that pkgPath
has a value like internal/nettrace
for which internalPkgFound
would be null at this point.
Why not exit early with
if (pkgPath.startsWith('internal/') {
return false;
}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank for the correction.. will fix soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uudashr I've left a comment on why this change wouldn't work as expected. Please take a look.
Also, am curious. If no one can import such packages, how do they get used? |
based on https://golang.org/s/go14internal
It can be used by all the source reside on GOROOT |
@ramya-rao-a please check |
src/goPackages.ts
Outdated
if (internalPkgFound) { | ||
let rootProjectForInternalPkg = path.join(currentWorkspace, pkgPath.substr(0, internalPkgFound.index)); | ||
return toDirPath.startsWith(rootProjectForInternalPkg + path.sep) || toDirPath === rootProjectForInternalPkg; | ||
return (rootProjectForInternalPkg !== currentWorkspace && toDirPath.startsWith(rootProjectForInternalPkg + path.sep)) || toDirPath === rootProjectForInternalPkg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this return true
for pkgPath which is say internal/something
and user is working on a file directly under GOPATH/src
?
I would still say, exiting early with if (pkgPath.startsWith('internal/') return false;
is cleaner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Impossible to work under GOPATH/src
Ahh.. yes.. correct.
More simple with your way |
This should ignore any import of internal packages on the root such as: