Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Nov 13, 2023

Conversation

czunker
Copy link
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

hashicorp-cla commented Aug 23, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@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!

@@ -364,7 +365,7 @@ func licenseHeader(path string, tmpl *template.Template, data LicenseData) ([]by
lic, err = executeTemplate(tmpl, data, "/*", " * ", " */")
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
Member

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
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.

@@ -242,6 +242,7 @@ func processFile(f *file, t *template.Template, license LicenseData, checkonly b
return err
}
if lic == nil { // Unknown fileExtension
logger.Printf("[DEBUG] skipping because of unknown extension: %s", f.path)
Copy link
Member

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
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

@@ -364,7 +365,7 @@ func licenseHeader(path string, tmpl *template.Template, data LicenseData) ([]by
lic, err = executeTemplate(tmpl, data, "/*", " * ", " */")
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
Member

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
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
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
1 check 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.

None yet

3 participants