You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
PMD CPD throws an error when parsing ECMAScript files that start with a shebang. This is required for executable Node.js scripts (declared in the
bin
property of
package.json
, and detailed in
this ESLint rule
).
As noted on the
MDN page on JavaScript lexical grammar
, the hashbang style comment is valid ECMAScript syntax, and should be treated as any other comment. This behavior is consistent in testing on Chrome, Edge, and Firefox on Windows.
Exception Stacktrace:
The following error is thrown:
# pmd cpd --dir . --minimum-tokens 15 --language ecmascript --debug
[main] INFO net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand - Log level is at TRACE
[main] DEBUG net.sourceforge.pmd.cpd.CPD - Searching directory . for files
[main] DEBUG net.sourceforge.pmd.cpd.CPD - Tokenizing /app/./bin/cli.js
net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error in file '/app/./bin/cli.js' at line 1, column 1: "#" (35), after : "" (in lexical state DEFAULT)
at net.sourceforge.pmd.lang.ecmascript5.ast.Ecmascript5ParserImplTokenManager.getNextToken(Ecmascript5ParserImplTokenManager.java:5585)
at net.sourceforge.pmd.lang.ecmascript5.ast.Ecmascript5ParserImplTokenManager.getNextToken(Ecmascript5ParserImplTokenManager.java:7)
at net.sourceforge.pmd.cpd.token.internal.BaseTokenFilter.getNextToken(BaseTokenFilter.java:45)
at net.sourceforge.pmd.cpd.impl.JavaCCTokenizer.tokenize(JavaCCTokenizer.java:53)
at net.sourceforge.pmd.cpd.CPD.addAndThrowLexicalError(CPD.java:230)
at net.sourceforge.pmd.cpd.CPD.add(CPD.java:224)
at net.sourceforge.pmd.cpd.CPD.add(CPD.java:193)
at net.sourceforge.pmd.cpd.CPD.add(CPD.java:155)
at net.sourceforge.pmd.cpd.CPD.addDirectory(CPD.java:166)
at net.sourceforge.pmd.cpd.CPD.addRecursively(CPD.java:150)
at net.sourceforge.pmd.cpd.CPD.addSourcesFilesToCPD(CPD.java:87)
at net.sourceforge.pmd.cpd.CPD.extractAllSources(CPD.java:65)
at net.sourceforge.pmd.cpd.CPD.<init>(CPD.java:59)
at net.sourceforge.pmd.cli.commands.internal.CpdCommand.execute(CpdCommand.java:135)
at net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand.call(AbstractPmdSubcommand.java:35)
at net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand.call(AbstractPmdSubcommand.java:20)
at picocli.CommandLine.executeUserObject(CommandLine.java:2041)
at picocli.CommandLine.access$1500(CommandLine.java:148)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
at picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
at picocli.CommandLine.execute(CommandLine.java:2170)
at net.sourceforge.pmd.cli.PmdCli.main(PmdCli.java:18)
Code Sample demonstrating the issue:
#!/usr/bin/env node
console.log('this is a test');
Steps to reproduce:
Please provide detailed steps for how we can reproduce the bug.
Run pmd cpd --dir . --minimum-tokens 15 --language ecmascript --debug with the above code sample in a file in the current working directory.