Skip to content

Conversation

@koriym
Copy link
Member

@koriym koriym commented Jan 2, 2026

Summary

Following up on PR #64, this PR removes the remaining deprecated type attributes:

  • Remove type="text/css" from <link> tags in fixAttr()
  • Remove type="text/javascript" from <script> tags in attr()

In HTML5, type="text/css" for stylesheets and type="text/javascript" for scripts are the defaults and no longer required.

Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type

Summary by CodeRabbit

  • Refactor

    • Removed unnecessary type attributes from generated script and stylesheet HTML tags, resulting in cleaner, standards-compliant output.
  • Tests

    • Updated test expectations to match simplified HTML output for scripts and stylesheets.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 2, 2026

Walkthrough

The changes remove explicit MIME type attributes (type="text/javascript" from script tags and type="text/css" from stylesheet elements) from generated HTML, relying on browser defaults. Corresponding test cases have been updated to reflect the new output.

Changes

Cohort / File(s) Summary
Script and Stylesheet Helper Updates
src/Helper/Scripts.php, src/Helper/Styles.php
Removed automatic type attribute insertion—scripts no longer emit type="text/javascript" and stylesheets no longer emit type="text/css". Attribute handling logic adjusted to conditionally format tags based on presence of other attributes.
Test Case Updates
tests/Helper/ScriptsTest.php, tests/Helper/StylesTest.php
Updated expected HTML output strings across all test cases to match the removal of MIME type attributes from generated script and link/style elements, including within conditional IE blocks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit's refrain:
Type attributes fade away,
Defaults now suffice, hooray!
Cleaner HTML, light and lean—
Modern browsers, crisp and clean. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main change: removing deprecated type attributes from link and script tags, which is the primary focus across all modified files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c967dd6 and c8009ba.

📒 Files selected for processing (4)
  • src/Helper/Scripts.php
  • src/Helper/Styles.php
  • tests/Helper/ScriptsTest.php
  • tests/Helper/StylesTest.php
💤 Files with no reviewable changes (1)
  • src/Helper/Styles.php
🧰 Additional context used
🧬 Code graph analysis (1)
src/Helper/Scripts.php (1)
src/Escaper.php (1)
  • attr (176-179)
🔇 Additional comments (10)
tests/Helper/StylesTest.php (4)

17-17: LGTM! Test expectation correctly updated.

The expected output now correctly omits the deprecated type="text/css" attribute, aligning with HTML5 standards where this attribute is optional for stylesheets.


31-34: LGTM! Consistent removal of deprecated type attributes.

All expected link tag outputs correctly omit the type="text/css" attribute, including within conditional IE comments.


50-53: LGTM! Type attribute removal preserves other attributes.

The changes correctly remove the type attribute while preserving the media attribute and indentation functionality.


75-78: LGTM! Internal style blocks correctly updated.

Expected output for inline <style> tags correctly omits the type="text/css" attribute, consistent with the changes to <link> tags.

tests/Helper/ScriptsTest.php (3)

17-17: LGTM! Script tag expectation correctly updated.

The expected output correctly omits the deprecated type="text/javascript" attribute, which is the default in HTML5.


34-38: LGTM! Custom attributes preserved correctly.

The expected outputs correctly omit the type attribute while preserving custom attributes like foo, bar, and bing. Both regular and conditional script tags are handled consistently.


60-63: LGTM! Internal script blocks correctly updated.

Expected output for inline <script> tags correctly omits the type attribute, consistent with external script tag changes.

src/Helper/Scripts.php (3)

112-112: LGTM! Consistent with addInternal implementation.

The conditional internal script generation follows the same clean pattern, correctly omitting attributes when none are provided. This maintains consistency with the addInternal() method.


184-190: LGTM! Core change removes deprecated type attribute.

The attr() method now only adds the src attribute when provided and no longer injects type="text/javascript", correctly implementing the PR objective. This aligns with HTML5 standards where the type attribute defaults to text/javascript for script elements.


91-91: Ternary logic correctly avoids extraneous whitespace.

The ternary operator generates <script>$script</script> when no attributes are present and <script $attr>$script</script> when attributes exist. This works correctly because Escaper\AttrEscaper::__invoke() returns an empty string for empty attribute arrays, which is falsy in PHP.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@koriym koriym requested a review from harikt January 2, 2026 10:45
{
$attr = $this->attr(null, $attr);
$tag = "<script $attr>$script</script>";
$tag = $attr ? "<script $attr>$script</script>" : "<script>$script</script>";
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this ? I think $attr will be empty string if $attr is empty. Any reason you bring this ?

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