forked from phoedos/pmd
[typescript] Exclude TypeScriptLexerBase from checkstyle, fix PMD issues
This commit is contained in:
parent
e4b9c30323
commit
c134386898
@ -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>
|
@ -78,6 +78,14 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<suppressionsLocation>pmd-javascript-checkstyle-suppressions.xml</suppressionsLocation>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -7,17 +7,16 @@
|
|||||||
|
|
||||||
package net.sourceforge.pmd.lang.typescript.ast;
|
package net.sourceforge.pmd.lang.typescript.ast;
|
||||||
|
|
||||||
import java.util.Stack;
|
import org.antlr.v4.runtime.*;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.CharStream;
|
import java.util.Stack;
|
||||||
import org.antlr.v4.runtime.Lexer;
|
|
||||||
import org.antlr.v4.runtime.Token;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All lexer methods that used in grammar (IsStrictMode)
|
* All lexer methods that used in grammar (IsStrictMode)
|
||||||
* should start with Upper Case Char similar to Lexer rules.
|
* 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
|
* Stores values of nested modes. By default mode is strict or
|
||||||
* defined externally (useStrictDefault)
|
* defined externally (useStrictDefault)
|
||||||
@ -102,21 +101,26 @@ abstract class TypeScriptLexerBase extends Lexer {
|
|||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ProcessOpenBrace() {
|
protected void ProcessOpenBrace()
|
||||||
|
{
|
||||||
bracesDepth++;
|
bracesDepth++;
|
||||||
useStrictCurrent = scopeStrictModes.size() > 0 && scopeStrictModes.peek() || useStrictDefault;
|
useStrictCurrent = scopeStrictModes.size() > 0 && scopeStrictModes.peek() || useStrictDefault;
|
||||||
scopeStrictModes.push(useStrictCurrent);
|
scopeStrictModes.push(useStrictCurrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ProcessCloseBrace() {
|
protected void ProcessCloseBrace()
|
||||||
|
{
|
||||||
bracesDepth--;
|
bracesDepth--;
|
||||||
useStrictCurrent = scopeStrictModes.size() > 0 ? scopeStrictModes.pop() : useStrictDefault;
|
useStrictCurrent = scopeStrictModes.size() > 0 ? scopeStrictModes.pop() : useStrictDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ProcessStringLiteral() {
|
protected void ProcessStringLiteral()
|
||||||
if (lastToken == null || lastToken.getType() == TypeScriptLexer.OpenBrace) {
|
{
|
||||||
|
if (lastToken == null || lastToken.getType() == TypeScriptLexer.OpenBrace)
|
||||||
|
{
|
||||||
String text = getText();
|
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) {
|
if (scopeStrictModes.size() > 0) {
|
||||||
scopeStrictModes.pop();
|
scopeStrictModes.pop();
|
||||||
}
|
}
|
||||||
@ -138,31 +142,31 @@ abstract class TypeScriptLexerBase extends Lexer {
|
|||||||
* Returns {@code true} if the lexer can match a regex literal.
|
* Returns {@code true} if the lexer can match a regex literal.
|
||||||
*/
|
*/
|
||||||
protected boolean IsRegexPossible() {
|
protected boolean IsRegexPossible() {
|
||||||
|
|
||||||
if (this.lastToken == null) {
|
if (this.lastToken == null) {
|
||||||
// No token has been produced yet: at the start of the input,
|
// No token has been produced yet: at the start of the input,
|
||||||
// no division is possible, so a regex literal _is_ possible.
|
// no division is possible, so a regex literal _is_ possible.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (this.lastToken.getType()) {
|
switch (this.lastToken.getType()) {
|
||||||
case TypeScriptLexer.Identifier:
|
case TypeScriptLexer.Identifier:
|
||||||
case TypeScriptLexer.NullLiteral:
|
case TypeScriptLexer.NullLiteral:
|
||||||
case TypeScriptLexer.BooleanLiteral:
|
case TypeScriptLexer.BooleanLiteral:
|
||||||
case TypeScriptLexer.This:
|
case TypeScriptLexer.This:
|
||||||
case TypeScriptLexer.CloseBracket:
|
case TypeScriptLexer.CloseBracket:
|
||||||
case TypeScriptLexer.CloseParen:
|
case TypeScriptLexer.CloseParen:
|
||||||
case TypeScriptLexer.OctalIntegerLiteral:
|
case TypeScriptLexer.OctalIntegerLiteral:
|
||||||
case TypeScriptLexer.DecimalLiteral:
|
case TypeScriptLexer.DecimalLiteral:
|
||||||
case TypeScriptLexer.HexIntegerLiteral:
|
case TypeScriptLexer.HexIntegerLiteral:
|
||||||
case TypeScriptLexer.StringLiteral:
|
case TypeScriptLexer.StringLiteral:
|
||||||
case TypeScriptLexer.PlusPlus:
|
case TypeScriptLexer.PlusPlus:
|
||||||
case TypeScriptLexer.MinusMinus:
|
case TypeScriptLexer.MinusMinus:
|
||||||
// After any of the tokens above, no regex literal can follow.
|
// After any of the tokens above, no regex literal can follow.
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
// In all other cases, a regex literal _is_ possible.
|
// In all other cases, a regex literal _is_ possible.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user