[typescript] Exclude TypeScriptLexerBase from checkstyle, fix PMD issues

This commit is contained in:
Andreas Dangel 2023-04-04 19:09:15 +02:00
parent e4b9c30323
commit c134386898
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
3 changed files with 49 additions and 29 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
<suppressions>
<suppress files="[\\/]generated-sources[\\/]" checks="[a-zA-Z0-9]*"/>
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]net[\\/]sourceforge[\\/]pmd[\\/]lang[\\/]typescript[\\/]ast[\\/]TypeScriptLexerBase.java" checks="[a-zA-Z0-9]*"/>
</suppressions>

View File

@ -78,6 +78,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<suppressionsLocation>pmd-javascript-checkstyle-suppressions.xml</suppressionsLocation>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>

View File

@ -7,17 +7,16 @@
package net.sourceforge.pmd.lang.typescript.ast;
import java.util.Stack;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.Token;
import java.util.Stack;
/**
* All lexer methods that used in grammar (IsStrictMode)
* should start with Upper Case Char similar to Lexer rules.
*/
abstract class TypeScriptLexerBase extends Lexer {
abstract class TypeScriptLexerBase extends Lexer
{
/**
* Stores values of nested modes. By default mode is strict or
* defined externally (useStrictDefault)
@ -102,21 +101,26 @@ abstract class TypeScriptLexerBase extends Lexer {
return next;
}
protected void ProcessOpenBrace() {
protected void ProcessOpenBrace()
{
bracesDepth++;
useStrictCurrent = scopeStrictModes.size() > 0 && scopeStrictModes.peek() || useStrictDefault;
scopeStrictModes.push(useStrictCurrent);
}
protected void ProcessCloseBrace() {
protected void ProcessCloseBrace()
{
bracesDepth--;
useStrictCurrent = scopeStrictModes.size() > 0 ? scopeStrictModes.pop() : useStrictDefault;
}
protected void ProcessStringLiteral() {
if (lastToken == null || lastToken.getType() == TypeScriptLexer.OpenBrace) {
protected void ProcessStringLiteral()
{
if (lastToken == null || lastToken.getType() == TypeScriptLexer.OpenBrace)
{
String text = getText();
if ("\"use strict\"".equals(text) || "'use strict'".equals(text)) {
if ("\"use strict\"".equals(text) || "'use strict'".equals(text))
{
if (scopeStrictModes.size() > 0) {
scopeStrictModes.pop();
}
@ -146,23 +150,23 @@ abstract class TypeScriptLexerBase extends Lexer {
}
switch (this.lastToken.getType()) {
case TypeScriptLexer.Identifier:
case TypeScriptLexer.NullLiteral:
case TypeScriptLexer.BooleanLiteral:
case TypeScriptLexer.This:
case TypeScriptLexer.CloseBracket:
case TypeScriptLexer.CloseParen:
case TypeScriptLexer.OctalIntegerLiteral:
case TypeScriptLexer.DecimalLiteral:
case TypeScriptLexer.HexIntegerLiteral:
case TypeScriptLexer.StringLiteral:
case TypeScriptLexer.PlusPlus:
case TypeScriptLexer.MinusMinus:
// After any of the tokens above, no regex literal can follow.
return false;
default:
// In all other cases, a regex literal _is_ possible.
return true;
case TypeScriptLexer.Identifier:
case TypeScriptLexer.NullLiteral:
case TypeScriptLexer.BooleanLiteral:
case TypeScriptLexer.This:
case TypeScriptLexer.CloseBracket:
case TypeScriptLexer.CloseParen:
case TypeScriptLexer.OctalIntegerLiteral:
case TypeScriptLexer.DecimalLiteral:
case TypeScriptLexer.HexIntegerLiteral:
case TypeScriptLexer.StringLiteral:
case TypeScriptLexer.PlusPlus:
case TypeScriptLexer.MinusMinus:
// After any of the tokens above, no regex literal can follow.
return false;
default:
// In all other cases, a regex literal _is_ possible.
return true;
}
}
}