Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Disallow import internal root package #1681

Merged
merged 3 commits into from
Jun 4, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/goPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

@ramya-rao-a ramya-rao-a Jun 4, 2018

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;
}

?

Copy link
Contributor Author

@uudashr uudashr Jun 4, 2018

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

internalPkgFound = pkgPath.match(/^internal\b/);
}

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;
Copy link
Contributor

@ramya-rao-a ramya-rao-a Jun 4, 2018

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

Copy link
Contributor Author

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.

}
return true;
}