<commit_before>package rules

import (
	"fmt"
	"github.com/golang/protobuf/v2/proto"
	descriptorpb "github.com/golang/protobuf/v2/types/descriptor"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
)

func protoDescriptorProtoFromSource(source string) (*descriptorpb.FileDescriptorProto, error) {
	tmpDir := os.TempDir()

	f, err := ioutil.TempFile(tmpDir, "proto*")

	if err != nil {
		return nil, err
	}

	defer func() {
		err := closeAndRemoveFile(f)

		if err != nil {
			log.Fatalf("Error removing proto file: %v", err)
		}
	}()

	_, err = f.Write([]byte(source))

	if err != nil {
		return nil, err
	}

	descSetF, err := ioutil.TempFile(tmpDir, "descset*")

	if err != nil {
		return nil, err
	}

	defer func() {
		err := closeAndRemoveFile(descSetF)

		if err != nil {
			log.Fatalf("Error removing descriptor set file: %v", err)
		}
	}()

	cmd := exec.Command(
		"protoc",
		"--include_source_info",
		fmt.Sprintf("--proto_path=%s", tmpDir),
		fmt.Sprintf("--descriptor_set_out=%s", descSetF.Name()),
		f.Name(),
	)

	cmd.Stderr = os.Stderr

	err = cmd.Run()

	if err != nil {
		return nil, err
	}

	descSet, err := ioutil.ReadFile(descSetF.Name())

	if err != nil {
		return nil, err
	}

	protoset := &descriptorpb.FileDescriptorSet{}
	if err := proto.Unmarshal(descSet, protoset); err != nil {
		log.Fatalf("Unable to parse %T from source: %v.", protoset, err)
	}

	return protoset.GetFile()[0], nil
}

func closeAndRemoveFile(f *os.File) error {
	err := f.Close()

	if err != nil {
		return err
	}

	err = os.Remove(f.Name())

	if err != nil {
		return err
	}

	return nil
}<commit_msg>Inline all err := with if<commit_after>package rules

import (
	"fmt"
	"github.com/golang/protobuf/v2/proto"
	descriptorpb "github.com/golang/protobuf/v2/types/descriptor"
	"io/ioutil"
	"log"
	"os"
	"os/exec"
)

func protoDescriptorProtoFromSource(source string) (*descriptorpb.FileDescriptorProto, error) {
	tmpDir := os.TempDir()

	f, err := ioutil.TempFile(tmpDir, "proto*")

	if err != nil {
		return nil, err
	}

	defer func() {
		if err := closeAndRemoveFile(f); err != nil {
			log.Fatalf("Error removing proto file: %v", err)
		}
	}()

	if _, err = f.Write([]byte(source)); err != nil {
		return nil, err
	}

	descSetF, err := ioutil.TempFile(tmpDir, "descset*")

	if err != nil {
		return nil, err
	}

	defer func() {
		if err := closeAndRemoveFile(descSetF); err != nil {
			log.Fatalf("Error removing descriptor set file: %v", err)
		}
	}()

	cmd := exec.Command(
		"protoc",
		"--include_source_info",
		fmt.Sprintf("--proto_path=%s", tmpDir),
		fmt.Sprintf("--descriptor_set_out=%s", descSetF.Name()),
		f.Name(),
	)

	cmd.Stderr = os.Stderr

	if err = cmd.Run(); err != nil {
		return nil, err
	}

	descSet, err := ioutil.ReadFile(descSetF.Name())

	if err != nil {
		return nil, err
	}

	protoset := &descriptorpb.FileDescriptorSet{}
	if err := proto.Unmarshal(descSet, protoset); err != nil {
		log.Fatalf("Unable to parse %T from source: %v.", protoset, err)
	}

	return protoset.GetFile()[0], nil
}

func closeAndRemoveFile(f *os.File) error {
	if err := f.Close(); err != nil {
		return err
	}

	if err := os.Remove(f.Name()); err != nil {
		return err
	}

	return nil
}
{'fraction_non_alphanumeric': 0.1679798298140561, 'fraction_numerical': 0.0018909549322407816, 'mean_word_length': 3.5734870317002883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '873280', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1203, 'n_words': 286}