Skip to content

Add support for Ruby, ERB and slim#266

Merged
wu-sheng merged 4 commits into
apache:mainfrom
infoPiiaf:filae
Jun 11, 2026
Merged

Add support for Ruby, ERB and slim#266
wu-sheng merged 4 commits into
apache:mainfrom
infoPiiaf:filae

Conversation

@afriqs

@afriqs afriqs commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

@afriqs afriqs marked this pull request as ready for review March 16, 2026 15:28
@wu-sheng wu-sheng requested review from Copilot and kezhenxu94 and removed request for kezhenxu94 March 16, 2026 23:52
@wu-sheng wu-sheng added the enhancement New feature or request label Mar 16, 2026
@wu-sheng wu-sheng added this to the 0.9.0 milestone Mar 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comment-style and test coverage to support applying Apache license headers to Ruby (.rb), ERB (.erb / .js.erb), and Slim (.slim) files within the skywalking-eyes header tooling.

Changes:

  • Add new comment styles for ERB (<% ... %> wrapping with # lines) and Slim (single / line comments).
  • Wire new/updated comment_style_id mappings for Ruby, ERB-containing languages, and Slim in assets/languages.yaml.
  • Extend header fixing tests and add include-test fixtures for Ruby/ERB/Slim with and without license headers.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

File Description
assets/styles.yaml Adds ERB and Slim comment-style definitions used by header generation/fixing.
assets/languages.yaml Maps Ruby / ERB languages and Slim to the new/existing comment styles.
pkg/header/fix_test.go Adds fix/insert expectations for Ruby (with/without shebang), ERB, and Slim.
test/testdata/include_test/** Adds new fixture files for header check tests across Ruby/ERB/Slim.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread assets/styles.yaml
Comment on lines +125 to +127
start: '/'
middle: '/'
end: '/'

@afriqs afriqs Mar 19, 2026

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.

Is this a a char or a regexp? Others only seem to be chars and not regexp but it fails with a regexp see https://github.com/apache/skywalking-eyes/actions/runs/23291104829/job/67726951492?pr=266#step:6:940 🤷

Comment thread assets/languages.yaml Outdated
@kezhenxu94

Copy link
Copy Markdown
Member

Please fix the CI

@kezhenxu94

Copy link
Copy Markdown
Member

@copilot fix the CI

@wu-sheng wu-sheng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I checked out this PR locally to debug the CI failure. There are two separate problems, and fixing only the first one is not enough:

1. The Slash comment style must be literal text, not a regular expression (the inline suggestion below). The style markers are joined literally by GenerateLicenseHeader, which is why the generated headers currently contain a literal ^\/. That's what breaks TestFix/test.slim and TestRewriteContent/Slim*.

2. header check cannot recognize single-/ comments at all, which is why TestCheckFile/WithLicense/.../testcase.slim fails even after reverting to a literal / (this is probably what prompted the ^\/ attempt in 23c1445). The license normalizer in pkg/license/norm.go strips //, /*, */ etc. from headers before matching, but has no rule for a single /, so Slim headers never match the configured license. Please add this rule (it must come after the /* family so it doesn't interfere):

--- a/pkg/license/norm.go
+++ b/pkg/license/norm.go
@@ -52,6 +52,7 @@
 		regexp.MustCompile(`(?m)^\s*/\*+`), // /*
 		regexp.MustCompile(`(?m)^\s*\*+/`), //  */
 		regexp.MustCompile(`(?m)^\s*\*+`),  //  *
+		regexp.MustCompile(`(?m)^\s*/`),    //  / e.g. Slim, must come after the /* and // patterns
 
 		regexp.MustCompile(`(?m)^\s*<!--+`), // <!--
 		regexp.MustCompile(`(?m)^\s*--+>`),  // -->

With both changes applied I verified locally on a clean checkout of this branch (and on its merge with current main): the full test suite passes, golangci-lint is clean, and an end-to-end round-trip works — header fix on fresh .slim/.erb/.rb files writes correct headers and header check then validates all of them.

Since "Allow edits by maintainers" is disabled on the fork, I can't push these two changes to this branch myself — please apply the suggestion below and the diff above, and the CI should turn green.

Comment thread assets/styles.yaml Outdated
Comment on lines +125 to +127
start: '^\/'
middle: '^\/'
end: '^\/'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
start: '^\/'
middle: '^\/'
end: '^\/'
start: '/'
middle: '/'
end: '/'

The comment style markers are literal texts joined by GenerateLicenseHeader, not regular expressions, so these should be the literal /.

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.

Thanks for troubleshooting it. Just pushed the updated commits.

@wu-sheng wu-sheng merged commit 8e837be into apache:main Jun 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants