-
Notifications
You must be signed in to change notification settings - Fork 1k
Conversation
[NOT A REVIEW] And also, I think we would like to have this warning in |
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.
Looks to be in the right direction.
We would also need integration tests for this.
manifest.go
Outdated
@@ -33,6 +33,7 @@ var ( | |||
errInvalidMetadata = errors.New("metadata should be a TOML table") | |||
|
|||
errInvalidProjectRoot = errors.New("ProjectRoot name validation failed") | |||
errInefficientRules = errors.New("Inefficient rules found in the manifest") |
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.
errors should start with lowercase, unless they are some special term, like ProjectRoot
.
manifest.go
Outdated
@@ -324,6 +325,78 @@ func ValidateProjectRoots(c *Ctx, m *Manifest, sm gps.SourceManager) error { | |||
return valErr | |||
} | |||
|
|||
// ValidatePackageRules ensure that there are no ineffectual package declarations | |||
// in the constraints, overrides, required, and ignored rules in the manifest. |
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.
I don't think we should do this with required
and ignored
, because they can be used to include and ignore packages that are not part of root project code or not directly reachable by the root project.
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.
I reread the spec for required
and I agree it shouldn't/ be applied in this case.
But for ignored
I can see value in letting you know that one of the packages in that rule isn't being imported.
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.
Let me know where we'd like to go with this when you get a chance!
manifest.go
Outdated
} | ||
} | ||
|
||
// Check overrides as well |
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.
Let's have proper sentences with a period at the end for all the comments :) We are doing it as much as possible for all the new code.
- casing in error message - whole sentences in comments - remove merging or required packages - omit underscore values in ranges
ee72b5f
to
29857b2
Compare
I'd like one more persons feedback before I get started on the tests please 😄 |
manifest.go
Outdated
@@ -324,6 +325,71 @@ func ValidateProjectRoots(c *Ctx, m *Manifest, sm gps.SourceManager) error { | |||
return valErr | |||
} | |||
|
|||
// ValidatePackageRules ensure that there are no ineffectual package declarations | |||
// in the constraints, overrides, and ignored rules in the manifest. | |||
func ValidatePackageRules(c *Ctx, proj *Project, sm gps.SourceManager) (err error) { |
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.
What about separating responsibilities here by dropping the c *Ctx
argument and instead returning an extended errInefficientRules
error that knows how to print itself the same way?
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.
I like the idea, of dropping Ctx
, but to clarify do you mean appending more lines to the errInefficentRules
before returning it?
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.
I was thinking expand var errInefficentRules error
from a single static error instance to something like type errInefficentRules struct{constraints, ignores []gps.ProjectRoot}
with an Error() string
method (which e.g. builds a string via bytes.Buffer
rather than logging). So, essentially the same result as adding lines to errInefficentRules
before returning, but underneath it would actually be deferred until the error
is printed.
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.
^ This would also set us up to potentially export errInefficentRules
and its fields later on, giving callers even more flexibility when interpreting and handling the error.
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.
Yeah that sounds pretty good to me, will do
manifest.go
Outdated
|
||
// FindIneffectualConstraints looks for constraints decleared in the project | ||
// manifest that aren't directly used in the project. | ||
func FindIneffectualConstraints(m *Manifest, directDeps map[string]bool) []gps.ProjectRoot { |
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.
It looks like the FindIneffectual*
functions don't need to be exported, is there a compelling reason to export them?
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.
They don't need to be, I'll fix that
- move display string logic in errInefficientRules.Error() - remove Ctx from ValidatePackageRules - unexport FindIneffectual* funcs
@darkowlzz @jmank88 should we get rid of checking for ignores as a part of the validation? Also I'll have to open up a new PR to fix the current integration tests, many of them call |
Sorry for the delay. I have new thoughts now: About ineffectual If a project is a transitive dependency, the project would have an entry in the lock file with all the subpackages of it that are needed for the main project to build. Adding a [[projects]]
name = "github.com/golang/dep"
packages = [
".",
"cmd/dep",
"internal/feedback",
"internal/fs",
"internal/gps",
"internal/gps/internal/pb",
"internal/gps/paths",
"internal/gps/pkgtree",
"internal/importers",
"internal/importers/base",
"internal/importers/glide",
"internal/importers/godep",
"internal/importers/govend",
"internal/importers/gvt",
"internal/importers/vndr"
]
revision = "8ddfc8afb2d520d41997ebddd921b52152706c01"
version = "v0.3.2" Also, given a manifest and lock, it's difficult to tell if a given project is in the lock due to the Addressing one of your old comments:
yes, let's not do it and focus on ineffectual constraints only. Also, let's change
I would recommend building clean sets of changes as multiple commits and squashing your existing commits to cleanup. Keeping new implementation, old test fixes and new test changes into cleanly separated commits would help while reviewing and avoid failing tests across PRs. I like commits that build stories :) |
Thoughts about ineffectual ignores:
Another way in which an ignore would be ineffectual is if the ignored package is not part of root project, direct dependency or transitive dependency. A totally unrelated package would also be an ineffectual ignore. Leaving the idea here, we can do it as a separate PR in the future. |
@darkowlzz sounds good, thanks for explaining! |
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.
sorry, there's a couple too many things here - in particular, getDirectDependencies
is actually the wrong implementation to be using here - that should only be used by init, as-written.
i'm going to close this in favor of my PR, #1534
return nil | ||
} | ||
|
||
// findIneffectualConstraints looks for constraints decleared in the project |
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.
decleared
@@ -324,6 +324,90 @@ func ValidateProjectRoots(c *Ctx, m *Manifest, sm gps.SourceManager) error { | |||
return valErr | |||
} | |||
|
|||
type errInefficientRules struct { |
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.
ineffectual, not inefficient
return ineffectuals | ||
} | ||
|
||
// findIneffectualIgnores looks for ignored packages decleared in the project |
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.
declared
|
||
// findIneffectualIgnores looks for ignored packages decleared in the project | ||
// manifest that aren't directly used in the project. | ||
func findIneffectualIgnores(m *Manifest, directDeps map[string]bool) []gps.ProjectRoot { |
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.
not possible to determine if ignores are ineffectual at this point
What does this do / why do we need it?
Report ineffectual rules found in the manifest. This happens on
dep ensure
.Did this by:
getDirectDependinces
method to be a part of theProject
structensure
andcommandsstatus
Would like some intermediate feedback before I start writing the tests and fixing a bunch of tests
What should your reviewer look out for in this PR?
Do you need help or clarification on anything?
Which issue(s) does this PR fix?
fixes #302