MCPcopy Create free account
hub / github.com/bufbuild/buf / ignoreFileLocation

Function ignoreFileLocation

private/bufpkg/bufcheck/client.go:784–837  ·  view source on GitHub ↗
(
	config *config,
	ruleID string,
	fileLocation descriptor.FileLocation,
)

Source from the content-addressed store, hash-verified

782}
783
784func ignoreFileLocation(
785 config *config,
786 ruleID string,
787 fileLocation descriptor.FileLocation,
788) (bool, error) {
789 fileDescriptor := fileLocation.FileDescriptor()
790 if config.ExcludeImports && fileDescriptor.IsImport() {
791 return true, nil
792 }
793
794 protoreflectFileDescriptor := fileDescriptor.ProtoreflectFileDescriptor()
795 path := protoreflectFileDescriptor.Path()
796 if normalpath.MapHasEqualOrContainingPath(config.IgnoreRootPaths, path, normalpath.Relative) {
797 return true, nil
798 }
799 // If the config says to ignore this specific rule for this path, ignore this location, otherwise we look for other forms of ignores.
800 if ignoreRootPaths, ok := config.IgnoreRuleIDToRootPaths[ruleID]; ok && normalpath.MapHasEqualOrContainingPath(ignoreRootPaths, path, normalpath.Relative) {
801 return true, nil
802 }
803
804 // Not a great design, but will never be triggered by lint since this is never set.
805 if config.IgnoreUnstablePackages {
806 if packageVersion, ok := protoversion.NewPackageVersionForPackage(string(protoreflectFileDescriptor.Package())); ok {
807 if packageVersion.StabilityLevel() != protoversion.StabilityLevelStable {
808 return true, nil
809 }
810 }
811 }
812
813 // Not a great design, but will never be triggered by breaking since this is never set.
814 // Therefore, never called for an againstLocation (since lint never has againstLocations).
815 if config.AllowCommentIgnores && config.CommentIgnorePrefix != "" {
816 sourcePath := fileLocation.SourcePath()
817 if len(sourcePath) == 0 {
818 return false, nil
819 }
820 associatedSourcePaths, err := protosourcepath.GetAssociatedSourcePaths(sourcePath)
821 if err != nil {
822 return false, err
823 }
824 sourceLocations := protoreflectFileDescriptor.SourceLocations()
825 for _, associatedSourcePath := range associatedSourcePaths {
826 sourceLocation := sourceLocations.ByPath(associatedSourcePath)
827 if leadingComments := sourceLocation.LeadingComments; leadingComments != "" {
828 for _, line := range xstrings.SplitTrimLinesNoEmpty(leadingComments) {
829 if checkCommentLineForCheckIgnore(line, config.CommentIgnorePrefix, ruleID) {
830 return true, nil
831 }
832 }
833 }
834 }
835 }
836 return false, nil
837}
838
839// checkCommentLineForCheckIgnore checks that the comment line starts with the configured
840// comment ignore prefix, a space and the ruleID of the check.

Callers 1

ignoreAnnotationFunction · 0.85

Calls 10

GetAssociatedSourcePathsFunction · 0.92
FileDescriptorMethod · 0.65
IsImportMethod · 0.65
PathMethod · 0.65
PackageMethod · 0.65
StabilityLevelMethod · 0.65
SourcePathMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…