Skip to content

Add support for .lr and .lr.go files#85

Merged
CalebAlbers merged 1 commit into
hashicorp:mainfrom
czunker:christian/support_lr
Nov 13, 2023
Merged

Add support for .lr and .lr.go files#85
CalebAlbers merged 1 commit into
hashicorp:mainfrom
czunker:christian/support_lr

Conversation

@czunker
Copy link
Copy Markdown
Contributor

@czunker czunker commented Aug 23, 2023

🛠️ Description

Add new file extensions to also support license headers for .lr and .lr.go files.

🔗 External Links

We use it in this repo: https://github.com/mondoohq/cnquery

👍 Definition of Done

  • New functionality works?
  • Tests added?

🤔 Can be merged upon approval?

@czunker czunker requested a review from a team August 23, 2023 10:40
@hashicorp-cla
Copy link
Copy Markdown

hashicorp-cla commented Aug 23, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@CalebAlbers CalebAlbers left a comment

Choose a reason for hiding this comment

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

Hey, @czunker 👋

Thanks a ton for the contribution! I'm glad to see copywrite gaining use in the community.

I left a few small notes on this I'd like addressed, but happy to merge after that.

Cheers!

Comment thread addlicense/main.go Outdated
case ".js", ".mjs", ".cjs", ".jsx", ".tsx", ".css", ".scss", ".sass", ".ts":
lic, err = executeTemplate(tmpl, data, "/**", " * ", " */")
case ".cc", ".cpp", ".cs", ".go", ".hh", ".hpp", ".m", ".mm", ".proto", ".rs", ".swift", ".dart", ".groovy", ".v", ".sv":
case ".cc", ".cpp", ".cs", ".go", ".hh", ".hpp", ".m", ".mm", ".proto", ".rs", ".swift", ".dart", ".groovy", ".v", ".sv", ".lr.go", ".lr":
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe the .lr.go case should be taken care of automatically given it ends in .go. The module uses Go's filepath.Ext() function, which should look only at the last suffix according to the docs:

Ext returns the file name extension used by path. The extension is the suffix beginning at the final dot in the final element of path; it is empty if there is no dot.

Suggested change
case ".cc", ".cpp", ".cs", ".go", ".hh", ".hpp", ".m", ".mm", ".proto", ".rs", ".swift", ".dart", ".groovy", ".v", ".sv", ".lr.go", ".lr":
case ".cc", ".cpp", ".cs", ".go", ".hh", ".hpp", ".m", ".mm", ".proto", ".rs", ".swift", ".dart", ".groovy", ".v", ".sv", ".lr":

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are correct. It was skipped because .lr.go are outgenerated files. I found that later in the code.

Comment thread addlicense/main.go Outdated
return err
}
if lic == nil { // Unknown fileExtension
logger.Printf("[DEBUG] skipping because of unknown extension: %s", f.path)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like this idea, but the current logging implementation needs some rework, so this will currently print out a large number of debug noise during regular noise.

Do you mind if we remove it for this PR so we can ship the changes and log it as a GitHub Issue instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure. I created an issue: #87

Comment thread addlicense/main.go Outdated
case ".js", ".mjs", ".cjs", ".jsx", ".tsx", ".css", ".scss", ".sass", ".ts":
lic, err = executeTemplate(tmpl, data, "/**", " * ", " */")
case ".cc", ".cpp", ".cs", ".go", ".hh", ".hpp", ".m", ".mm", ".proto", ".rs", ".swift", ".dart", ".groovy", ".v", ".sv":
case ".cc", ".cpp", ".cs", ".go", ".hh", ".hpp", ".m", ".mm", ".proto", ".rs", ".swift", ".dart", ".groovy", ".v", ".sv", ".lr.go", ".lr":
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you mind adding an entry into our test suite, as well? The specific lines are https://github.com/hashicorp/copywrite/blob/main/addlicense/main_test.go#L316-L317

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Signed-off-by: Christian Zunker <christian.zunker@gmail.com>
@czunker
Copy link
Copy Markdown
Contributor Author

czunker commented Aug 29, 2023

Thanks for your feedback @CalebAlbers. I addressed your comments. Please have another look.

@CalebAlbers CalebAlbers merged commit 9103d86 into hashicorp:main Nov 13, 2023
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.

3 participants