( config *config, ruleID string, fileLocation descriptor.FileLocation, )
| 782 | } |
| 783 | |
| 784 | func 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. |
no test coverage detected
searching dependent graphs…