添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
朝气蓬勃的火柴  ·  Supporting PMD CPD in ...·  1 周前    · 
温柔的楼梯  ·  [core] PMD/CPD ...·  1 周前    · 
傲视众生的鼠标垫  ·  PMD CPD - Visual ...·  1 周前    · 
私奔的佛珠  ·  “严惩毒品犯罪 ...·  3 月前    · 
老实的电影票  ·  [3D] ...·  4 月前    · 
不羁的风衣  ·  AUR (en) - perl-wx·  5 月前    · 

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

Affects PMD Version: 7.0.0-rc2

Description:

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.

Running PMD through: CLI

Digging a little further:

  • Hashbang comments were officially added to ECMAScript in the 2023 specification (the original proposal)
  • This is a duplicate of [javascript] Support files containing a shebang with CPD #1756
  • @aarongoldenthal , many thanks for the research!

    I'll keep then the original issue and close this one as duplicate.

    Duplicate of #1756