GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [javascript] Fix #1756: Support hashbang comments in CPD by toyeshhm · Pull Request #7383 · pmd/pmd

Conversation

@toyeshhm

@toyeshhm toyeshhm commented Nov 23, 2026

Copy link
Copy Markdown

Describe the PR

CPD fails on any JavaScript file that starts with a hashbang line such as #!/usr/bin/env node:

Lexical error at line 1, column 1: "#" (35), after : "" (in lexical state DEFAULT)

The JavaCC grammar that CPD uses for JavaScript (Ecmascript5.jj) has no token that starts with #, so the lexer stops at the first character. Hashbang comments have been part of the language since ECMAScript 2023 (12.5 Hashbang Comments), and they are common in Node.js CLI scripts.

This adds a HASHBANG_COMMENT special token: #! followed by everything up to the line terminator. As a special token it is treated like the other comments and produces no CPD tokens. The spec only allows a hashbang comment at the very start of the source text, so the token's lexical action throws a LexException when it starts at any other offset. A #! later in a file is still an error, as before.

Only the JavaCC lexer used by CPD is changed.

Tests in EcmascriptCpdLexerTest:

  • testHashbangComment tokenizes a new hashbang.js that starts with #!/usr/bin/env node. Before the fix it fails with the lexical error above. Now the hashbang line is skipped and the rest of the file is tokenized as usual (hashbang.txt).
  • testHashbangOnlyAtStartOfFile checks that #! on a later line is still a lexical error.

Related issues

  • Fix [javascript] Support files containing a shebang with CPD #1756

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
toyeshhm added 2 commits November 12, 2026 12:29
@toyeshhm
[javascript] Fix pmd#1756: Support hashbang comments in CPD
aaaba53
@toyeshhm
Merge upstream main into fix-1756-js-hashbang
700655c
Copilot AI balanced review requested due to automatic review settings November 23, 2026 22:37
Copilot AI reviewed Nov 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@toyeshhm
Merge upstream main into fix-1756-js-hashbang
1cd397b
# Conflicts:
#	docs/pages/release_notes.md
@pmd-actions-helper

pmd-actions-helper Bot commented Nov 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-11-27 20:44:04+00:00 for 7dbe93d)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@toyeshhm
Merge remote-tracking branch 'upstream/main' into fix-1756-js-hashbang
7dbe93d
# Conflicts:
#	docs/pages/release_notes.md

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[javascript] Support files containing a shebang with CPD

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@toyeshhm
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.