Commit 68fe7006 authored by Anton Lobov's avatar Anton Lobov
Browse files

WEB-31909 Allow to suppress warning for NaN in json

parent 959a0b17
Showing with 249 additions and 200 deletions
+249 -200
This diff is collapsed.
......@@ -151,13 +151,14 @@ public class _Json5Lexer implements FlexLexer {
private static final String ZZ_ACTION_PACKED_0 =
"\1\1\1\2\1\3\2\4\1\3\1\5\1\6\6\1"+
"\5\4\1\7\1\10\1\11\1\12\1\13\1\14\1\15"+
"\1\16\1\5\2\0\1\6\5\1\1\4\2\1\5\4"+
"\1\15\1\16\1\4\2\5\2\6\1\1\4\4\1\1"+
"\1\0\1\16\1\4\1\17\1\4\1\20\1\16\1\4"+
"\1\21\2\4";
"\1\16\1\5\2\0\1\6\4\1\2\0\1\1\1\4"+
"\2\1\5\4\1\15\1\16\1\4\2\5\2\6\2\0"+
"\1\1\4\4\1\1\1\0\1\16\1\0\1\1\1\4"+
"\1\17\1\4\1\20\1\16\1\0\1\4\1\21\1\0"+
"\1\4\1\0\1\4\1\0";
private static int [] zzUnpackAction() {
int [] result = new int[68];
int [] result = new int[78];
int offset = 0;
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
return result;
......@@ -188,12 +189,13 @@ public class _Json5Lexer implements FlexLexer {
"\0\51\0\u030b\0\u0334\0\51\0\u035d\0\u0386\0\51\0\u03af"+
"\0\u03d8\0\u0401\0\u042a\0\u0453\0\u047c\0\u04a5\0\u04ce\0\u04f7"+
"\0\u0520\0\u0549\0\u0572\0\u059b\0\u05c4\0\u05ed\0\u0616\0\u063f"+
"\0\u0668\0\u0691\0\u06ba\0\u047c\0\u06e3\0\u070c\0\u0735\0\u075e"+
"\0\173\0\u0787\0\173\0\u07b0\0\173\0\u07d9\0\173\0\51"+
"\0\u0802\0\173\0\u082b\0\u0854";
"\0\u0668\0\u0691\0\u06ba\0\u06e3\0\u070c\0\u0735\0\u075e\0\u04ce"+
"\0\u0787\0\u07b0\0\u07d9\0\u0802\0\173\0\u082b\0\173\0\u0854"+
"\0\51\0\u087d\0\173\0\u08a6\0\173\0\51\0\u08cf\0\u08f8"+
"\0\173\0\u0921\0\u094a\0\u0973\0\u099c\0\u09c5";
private static int [] zzUnpackRowMap() {
int [] result = new int[68];
int [] result = new int[78];
int offset = 0;
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
return result;
......@@ -226,61 +228,64 @@ public class _Json5Lexer implements FlexLexer {
"\17\4\6\0\5\4\1\0\4\3\2\4\1\3\1\6"+
"\1\4\1\3\4\0\17\4\6\0\5\4\2\7\2\0"+
"\7\7\1\34\1\35\34\7\2\10\2\0\10\10\1\36"+
"\1\37\33\10\20\0\1\40\1\41\1\42\1\43\22\0"+
"\1\43\7\0\2\4\1\0\2\4\5\0\1\4\1\44"+
"\1\14\1\15\1\16\1\4\1\17\5\4\1\23\2\4"+
"\1\37\33\10\20\0\1\40\1\41\1\42\1\43\1\0"+
"\1\44\5\0\1\45\12\0\1\43\7\0\2\4\1\0"+
"\2\4\5\0\1\4\1\46\1\14\1\15\1\16\1\4"+
"\1\17\5\4\1\23\2\4\6\0\2\4\1\16\2\4"+
"\5\0\2\4\1\0\2\4\5\0\1\4\3\15\1\16"+
"\1\47\11\4\6\0\2\4\1\16\2\4\5\0\2\4"+
"\1\0\2\4\5\0\1\4\2\14\1\15\1\16\12\4"+
"\6\0\2\4\1\16\2\4\5\0\2\4\1\0\2\4"+
"\5\0\1\4\3\15\1\16\1\45\11\4\6\0\2\4"+
"\1\16\2\4\5\0\2\4\1\0\2\4\5\0\1\4"+
"\2\14\1\15\1\16\12\4\6\0\2\4\1\16\2\4"+
"\5\0\2\4\1\0\2\4\5\0\1\4\2\15\1\4"+
"\1\16\12\4\6\0\2\4\1\16\2\4\5\0\2\4"+
"\1\0\2\4\4\0\1\46\3\47\14\4\6\0\5\4"+
"\5\0\2\4\1\0\2\4\5\0\7\4\1\50\7\4"+
"\5\0\1\4\2\15\1\4\1\16\12\4\6\0\2\4"+
"\1\16\2\4\5\0\2\4\1\0\2\4\4\0\1\50"+
"\3\51\14\4\6\0\5\4\5\0\2\4\1\0\2\4"+
"\5\0\7\4\1\52\7\4\6\0\5\4\5\0\2\4"+
"\1\0\2\4\5\0\17\4\6\0\1\4\1\53\3\4"+
"\5\0\2\4\1\0\2\4\5\0\15\4\1\54\1\4"+
"\6\0\5\4\5\0\2\4\1\0\2\4\5\0\17\4"+
"\6\0\1\4\1\51\3\4\5\0\2\4\1\0\2\4"+
"\5\0\15\4\1\52\1\4\6\0\5\4\5\0\2\4"+
"\1\0\2\4\5\0\17\4\6\0\1\53\4\4\5\0"+
"\2\4\1\0\2\4\5\0\15\4\1\54\1\4\6\0"+
"\5\4\1\55\3\0\1\55\2\32\1\0\1\4\1\32"+
"\5\55\17\32\6\55\5\32\5\56\2\33\1\56\1\33"+
"\1\57\5\56\17\33\6\56\5\33\3\7\1\60\3\7"+
"\1\61\2\7\1\61\36\7\3\10\1\62\3\10\1\63"+
"\2\10\1\63\36\10\20\0\3\42\1\43\22\0\1\43"+
"\22\0\2\41\1\42\1\43\22\0\1\43\22\0\2\42"+
"\1\0\1\43\22\0\1\43\20\0\4\46\34\0\2\4"+
"\6\0\1\55\4\4\5\0\2\4\1\0\2\4\5\0"+
"\15\4\1\56\1\4\6\0\5\4\1\57\3\0\1\57"+
"\2\32\1\0\1\4\1\32\5\57\17\32\6\57\5\32"+
"\5\60\2\33\1\60\1\33\1\61\5\60\17\33\6\60"+
"\5\33\3\7\1\62\3\7\1\63\2\7\1\63\36\7"+
"\3\10\1\64\3\10\1\65\2\10\1\65\36\10\20\0"+
"\3\42\1\43\22\0\1\43\22\0\2\41\1\42\1\43"+
"\22\0\1\43\22\0\2\42\1\0\1\43\22\0\1\43"+
"\20\0\4\50\55\0\1\66\56\0\1\67\21\0\2\4"+
"\1\0\2\4\5\0\1\4\3\15\1\16\12\4\6\0"+
"\2\4\1\16\2\4\5\0\1\64\1\4\1\0\2\4"+
"\5\0\1\4\2\64\1\4\1\64\3\4\1\64\4\4"+
"\1\64\1\4\6\0\2\4\1\64\2\4\20\0\2\46"+
"\34\0\2\4\1\0\2\4\5\0\1\4\2\47\14\4"+
"\2\4\1\16\2\4\5\0\1\70\1\4\1\0\2\4"+
"\5\0\1\4\2\70\1\4\1\70\3\4\1\70\4\4"+
"\1\70\1\4\6\0\2\4\1\70\2\4\20\0\2\50"+
"\34\0\2\4\1\0\2\4\5\0\1\4\2\51\14\4"+
"\6\0\5\4\5\0\2\4\1\0\2\4\5\0\10\4"+
"\1\65\6\4\6\0\5\4\5\0\2\4\1\0\2\4"+
"\5\0\17\4\6\0\3\4\1\66\1\4\5\0\2\4"+
"\1\0\2\4\5\0\17\4\6\0\3\4\1\67\1\4"+
"\1\71\6\4\6\0\5\4\5\0\2\4\1\0\2\4"+
"\5\0\17\4\6\0\3\4\1\72\1\4\5\0\2\4"+
"\1\0\2\4\5\0\17\4\6\0\3\4\1\73\1\4"+
"\5\0\2\4\1\0\2\4\5\0\17\4\6\0\1\4"+
"\1\70\3\4\5\0\2\4\1\0\2\4\5\0\14\4"+
"\1\71\2\4\6\0\5\4\1\55\3\0\3\55\2\0"+
"\40\55\11\56\1\72\44\56\1\33\1\73\1\56\1\33"+
"\1\57\5\56\17\33\6\56\5\33\3\7\1\0\7\7"+
"\1\34\1\35\37\7\1\60\3\7\1\61\2\7\1\61"+
"\1\74\3\4\5\0\2\4\1\0\2\4\5\0\14\4"+
"\1\75\2\4\6\0\5\4\1\57\3\0\3\57\2\0"+
"\40\57\11\60\1\76\44\60\1\33\1\77\1\60\1\33"+
"\1\61\5\60\17\33\6\60\5\33\3\7\1\0\7\7"+
"\1\34\1\35\37\7\1\62\3\7\1\63\2\7\1\63"+
"\1\34\1\35\34\7\3\10\1\0\10\10\1\36\1\37"+
"\36\10\1\62\3\10\1\63\2\10\1\63\1\10\1\36"+
"\1\37\33\10\5\0\2\4\1\0\2\4\5\0\11\4"+
"\1\74\5\4\6\0\5\4\5\0\2\4\1\0\2\4"+
"\5\0\17\4\6\0\3\4\1\75\1\4\5\0\2\4"+
"\1\0\2\4\5\0\17\4\6\0\4\4\1\76\5\0"+
"\2\4\1\0\2\4\5\0\17\4\6\0\2\4\1\77"+
"\2\4\6\56\1\100\2\56\1\72\37\56\5\0\2\4"+
"\1\0\2\4\5\0\7\4\1\101\7\4\6\0\5\4"+
"\5\0\2\4\1\0\2\4\5\0\17\4\6\0\2\4"+
"\1\102\2\4\5\0\2\4\1\0\2\4\5\0\11\4"+
"\1\103\5\4\6\0\5\4\5\0\2\4\1\0\2\4"+
"\5\0\12\4\1\104\4\4\6\0\5\4\5\0\2\4"+
"\1\0\2\4\5\0\13\4\1\71\3\4\6\0\5\4";
"\36\10\1\64\3\10\1\65\2\10\1\65\1\10\1\36"+
"\1\37\33\10\27\0\1\100\54\0\1\101\22\0\2\4"+
"\1\0\2\4\5\0\11\4\1\102\5\4\6\0\5\4"+
"\5\0\2\4\1\0\2\4\5\0\17\4\6\0\3\4"+
"\1\103\1\4\5\0\2\4\1\0\2\4\5\0\17\4"+
"\6\0\4\4\1\104\5\0\2\4\1\0\2\4\5\0"+
"\17\4\6\0\2\4\1\105\2\4\6\60\1\106\2\60"+
"\1\76\37\60\30\0\1\107\25\0\2\4\1\0\2\4"+
"\5\0\7\4\1\110\7\4\6\0\5\4\5\0\2\4"+
"\1\0\2\4\5\0\17\4\6\0\2\4\1\111\2\4"+
"\26\0\1\112\27\0\2\4\1\0\2\4\5\0\11\4"+
"\1\113\5\4\6\0\5\4\30\0\1\114\25\0\2\4"+
"\1\0\2\4\5\0\12\4\1\115\4\4\6\0\5\4"+
"\31\0\1\116\24\0\2\4\1\0\2\4\5\0\13\4"+
"\1\75\3\4\6\0\5\4\32\0\1\101\16\0";
private static int [] zzUnpackTrans() {
int [] result = new int[2173];
int [] result = new int[2542];
int offset = 0;
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
return result;
......@@ -319,10 +324,12 @@ public class _Json5Lexer implements FlexLexer {
private static final String ZZ_ATTRIBUTE_PACKED_0 =
"\1\1\1\11\21\1\6\11\2\1\1\11\2\0\1\11"+
"\32\1\1\0\5\1\1\11\4\1";
"\4\1\2\0\20\1\2\0\6\1\1\0\1\1\1\0"+
"\1\11\4\1\1\11\1\0\2\1\1\0\1\1\1\0"+
"\1\1\1\0";
private static int [] zzUnpackAttribute() {
int [] result = new int[68];
int [] result = new int[78];
int offset = 0;
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
return result;
......
......@@ -22,6 +22,7 @@ inspection.compliance.msg.multiple.top.level.values=JSON standard allows only on
inspection.compliance.option.comments=Warn about comments
inspection.compliance.option.multiple.top.level.values=Warn about multiple top-level values
inspection.compliance.option.nan.infinity=Warn about NaN and Infinity/-Infinity numeric values
inspection.duplicate.keys.name=Duplicate keys in object literals
inspection.duplicate.keys.msg.duplicate.keys=Object contains duplicate keys "{0}"
......
......@@ -29,7 +29,7 @@ LINE_COMMENT="//".*
BLOCK_COMMENT="/"\*([^*]|\*+[^*/])*(\*+"/")?
DOUBLE_QUOTED_STRING=\"([^\\\"\r\n]|\\[^\r\n])*\"?
SINGLE_QUOTED_STRING='([^\\'\r\n]|\\[^\r\n])*'?
NUMBER=-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]*)?
NUMBER=(-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]*)?)|Infinity|-Infinity|NaN
IDENTIFIER=[[:jletterdigit:]~!()*\-."/"@\^<>=]+
%%
......
......@@ -51,6 +51,7 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool {
private static final Logger LOG = Logger.getInstance(JsonStandardComplianceInspection.class);
public boolean myWarnAboutComments = true;
public boolean myWarnAboutNanInfinity = true;
public boolean myWarnAboutMultipleTopLevelValues = true;
@NotNull
......@@ -90,6 +91,7 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool {
final MultipleCheckboxOptionsPanel optionsPanel = new MultipleCheckboxOptionsPanel(this);
optionsPanel.addCheckbox(JsonBundle.message("inspection.compliance.option.comments"), "myWarnAboutComments");
optionsPanel.addCheckbox(JsonBundle.message("inspection.compliance.option.multiple.top.level.values"), "myWarnAboutMultipleTopLevelValues");
optionsPanel.addCheckbox(JsonBundle.message("inspection.compliance.option.nan.infinity"), "myWarnAboutNanInfinity");
return optionsPanel;
}
......@@ -179,9 +181,23 @@ public class JsonStandardComplianceInspection extends LocalInspectionTool {
if (JsonPsiUtil.isPropertyKey(literal) && !isValidPropertyName(literal)) {
myHolder.registerProblem(literal, JsonBundle.message("inspection.compliance.msg.illegal.property.key"), new AddDoubleQuotesFix());
}
// for standard JSON, the inspection for NaN, Infinity and -Infinity is now configurable
if (!allowNanInfinity() && literal instanceof JsonNumberLiteral && myWarnAboutNanInfinity) {
final String text = JsonPsiUtil.getElementTextWithoutHostEscaping(literal);
if (StandardJsonLiteralChecker.INF.equals(text) ||
StandardJsonLiteralChecker.MINUS_INF.equals(text) ||
StandardJsonLiteralChecker.NAN.equals(text)) {
myHolder.registerProblem(literal, JsonBundle.message("syntax.error.illegal.floating.point.literal"));
}
}
super.visitLiteral(literal);
}
protected boolean allowNanInfinity() {
return false;
}
@Override
public void visitReferenceExpression(@NotNull JsonReferenceExpression reference) {
if (!allowIdentifierPropertyNames() || !JsonPsiUtil.isPropertyKey(reference) || !isValidPropertyName(reference)) {
......
......@@ -11,11 +11,17 @@ import java.util.regex.Pattern;
public class StandardJsonLiteralChecker implements JsonLiteralChecker {
private static final Pattern VALID_ESCAPE = Pattern.compile("\\\\([\"\\\\/bfnrt]|u[0-9a-fA-F]{4})");
private static final Pattern VALID_NUMBER_LITERAL = Pattern.compile("-?(0|[1-9][0-9]*)(\\.[0-9]+)?([eE][+-]?[0-9]+)?");
public static final String INF = "Infinity";
public static final String MINUS_INF = "-Infinity";
public static final String NAN = "NaN";
@Nullable
@Override
public String getErrorForNumericLiteral(String literalText) {
if (!VALID_NUMBER_LITERAL.matcher(literalText).matches()) {
if (!INF.equals(literalText) &&
!MINUS_INF.equals(literalText) &&
!NAN.equals(literalText) &&
!VALID_NUMBER_LITERAL.matcher(literalText).matches()) {
return JsonBundle.message("syntax.error.illegal.floating.point.literal");
}
return null;
......
......@@ -52,6 +52,11 @@ public class Json5StandardComplianceInspection extends JsonStandardComplianceIns
return true;
}
@Override
protected boolean allowNanInfinity() {
return true;
}
protected boolean isValidPropertyName(@NotNull PsiElement literal) {
if (literal instanceof JsonLiteral) {
String textWithoutHostEscaping = JsonPsiUtil.getElementTextWithoutHostEscaping(literal);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment