// OnStart checks the file.
OnStart checks the file.
// OnStart checks the file .
func (v *fileNamesLowerSnakeCaseVisitor) OnStart(proto *parser.Proto) error {
	path := proto.Meta.Filename
	if stringsutil.ContainsStringInSlice(path, v.excluded) {
		return nil
	}
	filename := filepath.Base(path)
	ext := filepath.Ext(filename)
	base := strings.TrimSuffix(filename, ext)
	if ext != ".proto" || !strs.IsLowerSnakeCase(base) {
		expected := strs.ToLowerSnakeCase(base) + ext
		v.AddFailurefWithProtoMeta(proto.Meta, "File name %q should be lower_snake_case.proto like %q.", filename, expected)
		if v.fixMode {
			dir := filepath.Dir(path)
			newPath := filepath.Join(dir, expected)
			if _, err := os.Stat(newPath); !os.IsNotExist(err) {
				v.AddFailurefWithProtoMeta(proto.Meta, "Failed to rename %q because %q already exists.", filename, expected)
				return nil
			}
			err := os.Rename(path, newPath)
			if err != nil {
				return err
			}
			proto.Meta.Filename = newPath
		}
	}
	return nil
}
func ( v * fileNamesLowerSnakeCaseVisitor ) OnStart ( proto * parser . Proto ) error { path := proto . Meta . Filename if stringsutil . ContainsStringInSlice ( path , v . excluded ) { return nil } filename := filepath . Base ( path ) ext := filepath . Ext ( filename ) base := strings . TrimSuffix ( filename , ext ) if ext != " " || ! strs . IsLowerSnakeCase ( base ) { expected := strs . ToLowerSnakeCase ( base ) + ext v . AddFailurefWithProtoMeta ( proto . Meta , " " , filename , expected ) if v . fixMode { dir := filepath . Dir ( path ) newPath := filepath . Join ( dir , expected ) if _ , err := os . Stat ( newPath ) ; ! os . IsNotExist ( err ) { v . AddFailurefWithProtoMeta ( proto . Meta , " " , filename , expected ) return nil } err := os . Rename ( path , newPath ) if err != nil { return err } proto . Meta . Filename = newPath } } return nil }
OnStart checks the file.
OnStart checks the file .
// Notify the upstream this new filename by updating the proto.