Skip to content

Conversation

@mikelolasagasti
Copy link
Collaborator

This new rule warns when the same target is defined multiple times, which can cause recipe overrides in GNU Make or unintended merges in BSD Make. The rule supports an optional ignore configuration key to skip specific targets.

Copy link
Collaborator

@obnoxxx obnoxxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice rule addition.

The ci is failing on the pre-commit check
and it seems to be due to #172.

So this should be good if we can fix that issue first.

Additionally, my request is to document the new rule in the manpage in this PR.

Copy link
Collaborator

@obnoxxx obnoxxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more suggestion/request:

Should we rename the new rule?

Exesting rules have names that (positively) specify something that a Makefile has to fulfill to pass

This new rule's name (negatively) specifies something that a Makefile must not fulfill to pass.

how about a name like uniqueargets? I think it would be more consistent with the existing rule names.

@mikelolasagasti mikelolasagasti changed the title rules: add duplicatetargets rule to detect repeated Makefile targets rules: add uniquetargets rule to detect repeated Makefile targets Oct 17, 2025
@obnoxxx obnoxxx force-pushed the rule-duplicatetargets branch from d22a009 to 2ec7fbe Compare October 17, 2025 16:23
Copy link
Collaborator

@obnoxxx obnoxxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update!

even after #173 merged, some adjustments to the fixtures are needed to let the ci pass.

Also note that list0rulesdoes not list uniquetargets. -- please fix.

@obnoxxx obnoxxx force-pushed the rule-duplicatetargets branch from 2ec7fbe to 5213ecd Compare October 17, 2025 17:20
This new rule warns when the same target is defined multiple times,
which can cause recipe overrides in GNU Make or unintended merges in
BSD Make. The rule supports an optional `ignore` configuration key to
skip specific targets.

Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
@mikelolasagasti
Copy link
Collaborator Author

I removed fixtures from the PR, as I used them during the development but are not required by uniquetargets_test.go. They could be used to test CLI in cmd/checkmake/main_test.go but may be overkill.

@mikelolasagasti
Copy link
Collaborator Author

$ make clean && make binaries
$ ./checkmake list-rules
       NAME                    DESCRIPTION            
 maxbodylength      Target bodies should be kept      
                    simple and short (no more than 8  
                    lines).                           
 minphony           Minimum required phony targets    
                    must be present (all,clean,test). 
 phonydeclared      Every target without a body needs 
                    to be marked PHONY                
 timestampexpanded  timestamp variables should be     
                    simply expanded                   
 uniquetargets      Targets should be uniquely        <-- the new rule
                    defined; duplicates can cause     
                    recipe overrides or unintended    
                    merges.                           

What would be missing to document the rule somewhere, but I think that's missing for all rules.

@obnoxxx
Copy link
Collaborator

obnoxxx commented Oct 20, 2025

@mikelolasagasti wrote:

What would be missing to document the rule somewhere, but I think that's missing for all rules.

yes. I think we should add rule descriptions to the manpage:
https://github.com/checkmake/checkmake/blob/main/man/man1/checkmake.1.md

Maybe even add a new section for rules to the manpage.
The latter should be a separate PR though.

@obnoxxx
Copy link
Collaborator

obnoxxx commented Oct 20, 2025

@mikelolasagasti wrote:

I removed fixtures from the PR, as I used them during the development but are not required by uniquetargets_test.go.

Sounds good.

They could be used to test CLI in cmd/checkmake/main_test.go but may be overkill.

Agreed. The go test file is meant to hold unit tests, not end-to-end CLI tests.

Copy link
Collaborator

@obnoxxx obnoxxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.


// Validate let's you validate a passed in Makefile with the provided config
func Validate(makefile parser.Makefile, cfg *config.Config) (ret rules.RuleViolationList) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not quite sure why the patch removes this empty line
as it does not seem to be related to what the PR does.

I guess it was done by your editor/IDE automatically
and added to the commit by accident.
I'll therefore ignore it as it does not harm either.

@obnoxxx obnoxxx merged commit 616629c into checkmake:main Oct 20, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants