<commit_before>// Package rule1 implements the ruleset for making sure all targets that don't
// have a rule body are marked PHONY
package rule1

import (
	"fmt"
	"github.com/mrtazz/checkmake/parser"
	"github.com/mrtazz/checkmake/rules"
	"strings"
)

func init() {
	rules.RegisterRule(rules.Rule{
		Name:        "rule1",
		Description: "Every target without a body needs to be marked PHONY",
		Rule:        ruleset})
}

func ruleset(makefile parser.Makefile, config rules.RuleConfig) rules.RuleViolationList {
	ret := rules.RuleViolationList{}

	ruleIndex := make(map[string]bool)

	for _, variable := range makefile.Variables {
		if variable.Name == "PHONY" {
			for _, phony := range strings.Split(variable.Assignment, " ") {
				ruleIndex[phony] = true
			}
		}
	}

	for _, rule := range makefile.Rules {
		_, ok := ruleIndex[rule.Target]
		if len(rule.Body) == 0 && ok == false {
			ret = append(ret, rules.RuleViolation{
				Rule:      "rule1",
				Violation: fmt.Sprintf("Target '%s' should be marked PHONY.", rule.Target),
			})
		}<commit_msg>track line number for violations in rule1<commit_after>// Package rule1 implements the ruleset for making sure all targets that don't
// have a rule body are marked PHONY
package rule1

import (
	"fmt"
	"github.com/mrtazz/checkmake/parser"
	"github.com/mrtazz/checkmake/rules"
	"strings"
)

func init() {
	rules.RegisterRule(rules.Rule{
		Name:        "rule1",
		Description: "Every target without a body needs to be marked PHONY",
		Rule:        ruleset})
}

func ruleset(makefile parser.Makefile, config rules.RuleConfig) rules.RuleViolationList {
	ret := rules.RuleViolationList{}

	ruleIndex := make(map[string]bool)

	for _, variable := range makefile.Variables {
		if variable.Name == "PHONY" {
			for _, phony := range strings.Split(variable.Assignment, " ") {
				ruleIndex[phony] = true
			}
		}
	}

	for _, rule := range makefile.Rules {
		_, ok := ruleIndex[rule.Target]
		if len(rule.Body) == 0 && ok == false {
			ret = append(ret, rules.RuleViolation{
				Rule:       "rule1",
				Violation:  fmt.Sprintf("Target '%s' should be marked PHONY.", rule.Target),
				LineNumber: rule.LineNumber,
			})
		}
{'fraction_non_alphanumeric': 0.1279445727482679, 'fraction_numerical': 0.005080831408775982, 'mean_word_length': 3.569620253164557, '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': '7446382', 'n_tokens_mistral': 775, 'n_tokens_neox': 719, 'n_words': 192}