From 4f7dbf67d4899f8919d2bb8e1dce656d5ab2e650 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Sun, 20 Jan 2019 16:30:00 +0900 Subject: [PATCH] Fix false positives for negative numbers in function-calc-no-invalid Fixed #3912 --- .../__tests__/index.js | 30 +- .../__tests__/parseCalcExpression.test.js | 93 ++++++ lib/utils/parseCalcExpression/parser.jison | 89 ++++-- lib/utils/parseCalcExpression/parser.js | 300 +++++++++++------- package.json | 19 +- 5 files changed, 366 insertions(+), 165 deletions(-) diff --git a/lib/rules/function-calc-no-invalid/__tests__/index.js b/lib/rules/function-calc-no-invalid/__tests__/index.js index d42a1e492b..e450e2fd25 100644 --- a/lib/rules/function-calc-no-invalid/__tests__/index.js +++ b/lib/rules/function-calc-no-invalid/__tests__/index.js @@ -49,6 +49,18 @@ testRule(rule, { }, { code: ".foo {width: calc(100px - calc(80px * 2));}" + }, + { + code: "a { margin-left: calc(-6 * 20px); }" + }, + { + code: "a { margin-left: calc(+6 * 20px); }" + }, + { + code: "a { margin-left: calc(-6 * -20px); }" + }, + { + code: "a { margin-left: calc(+6 * +20px); }" } ], @@ -72,14 +84,14 @@ testRule(rule, { description: "invalid", message: messages.expectedExpression(), line: 1, - column: 19 + column: 21 }, { code: ".foo {width: calc(100% - - 80px);}", description: "invalid", message: messages.expectedExpression(), line: 1, - column: 26 + column: 28 }, { code: ".foo {width: calc(100% -);}", @@ -283,19 +295,19 @@ testRule(rule, { code: ".foo {width: calc(100% - -#{$foo});}", message: messages.expectedExpression(), line: 1, - column: 26 + column: 27 }, { code: ".foo {width: calc(-#{$foo});}", message: messages.expectedExpression(), line: 1, - column: 19 + column: 20 }, { code: ".foo {width: calc(100% - - -#{$foo});}", message: messages.expectedExpression(), line: 1, - column: 26 + column: 29 } ] }); @@ -346,19 +358,19 @@ testRule(rule, { code: ".foo {width: calc(100% - -@foo);}", message: messages.expectedExpression(), line: 1, - column: 26 + column: 27 }, { code: ".foo {width: calc(-@foo);}", message: messages.expectedExpression(), line: 1, - column: 19 + column: 20 }, { code: ".foo {width: calc(100% - - -@foo);}", message: messages.expectedExpression(), line: 1, - column: 26 + column: 29 } ] }); @@ -389,7 +401,7 @@ testRule(rule, { code: "export default ;", message: messages.expectedExpression(), line: 1, - column: 47 + column: 49 } ] }); diff --git a/lib/utils/parseCalcExpression/__tests__/parseCalcExpression.test.js b/lib/utils/parseCalcExpression/__tests__/parseCalcExpression.test.js index b7569562f1..20b67c9829 100644 --- a/lib/utils/parseCalcExpression/__tests__/parseCalcExpression.test.js +++ b/lib/utils/parseCalcExpression/__tests__/parseCalcExpression.test.js @@ -66,6 +66,94 @@ it("parseCalcExpression parse to ast", () => { unit: "px", value: 80 }); + expect(parse("calc(-100 * -80px)")).toEqual({ + left: { + source: { end: { index: 9 }, start: { index: 5 } }, + type: "Value", + sign: "-", + value: -100 + }, + operator: "*", + right: { + source: { end: { index: 17 }, start: { index: 12 } }, + type: "LengthValue", + unit: "px", + sign: "-", + value: -80 + }, + source: { + end: { index: 18 }, + operator: { end: { index: 11 }, start: { index: 10 } }, + start: { index: 0 } + }, + type: "MathExpression" + }); + expect(parse("calc(-100px * -2)")).toEqual({ + left: { + source: { end: { index: 11 }, start: { index: 5 } }, + type: "LengthValue", + unit: "px", + sign: "-", + value: -100 + }, + operator: "*", + right: { + source: { end: { index: 16 }, start: { index: 14 } }, + type: "Value", + sign: "-", + value: -2 + }, + source: { + end: { index: 17 }, + operator: { end: { index: 13 }, start: { index: 12 } }, + start: { index: 0 } + }, + type: "MathExpression" + }); + expect(parse("calc(+100 * +80px)")).toEqual({ + left: { + source: { end: { index: 9 }, start: { index: 5 } }, + type: "Value", + sign: "+", + value: 100 + }, + operator: "*", + right: { + source: { end: { index: 17 }, start: { index: 12 } }, + type: "LengthValue", + unit: "px", + sign: "+", + value: 80 + }, + source: { + end: { index: 18 }, + operator: { end: { index: 11 }, start: { index: 10 } }, + start: { index: 0 } + }, + type: "MathExpression" + }); + expect(parse("calc(+100px * +2)")).toEqual({ + left: { + source: { end: { index: 11 }, start: { index: 5 } }, + type: "LengthValue", + unit: "px", + sign: "+", + value: 100 + }, + operator: "*", + right: { + source: { end: { index: 16 }, start: { index: 14 } }, + type: "Value", + sign: "+", + value: 2 + }, + source: { + end: { index: 17 }, + operator: { end: { index: 13 }, start: { index: 12 } }, + start: { index: 0 } + }, + type: "MathExpression" + }); }); it("parseCalcExpression case insensitive", () => { @@ -681,4 +769,9 @@ it("parseCalcExpression syntax error", () => { expect(() => parse("calc(100% - - -@foo)")).toThrow(); expect(() => parse("calc(100% - -foo())")).toThrow(); expect(() => parse("calc(100% - -foo(bar, baz))")).toThrow(); + expect(() => parse("calc(--100)")).toThrow(); + expect(() => parse("calc(++100)")).toThrow(); + expect(() => parse("calc(+-100)")).toThrow(); + expect(() => parse("calc(-+100)")).toThrow(); + expect(() => parse("calc(+var(foo))")).toThrow(); }); diff --git a/lib/utils/parseCalcExpression/parser.jison b/lib/utils/parseCalcExpression/parser.jison index 38660707b0..e22469688e 100644 --- a/lib/utils/parseCalcExpression/parser.jison +++ b/lib/utils/parseCalcExpression/parser.jison @@ -16,36 +16,36 @@ "+" return 'ADD'; "-" return 'SUB'; -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)em\b return 'LENGTH'; // em -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)ex\b return 'LENGTH'; // ex -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)ch\b return 'LENGTH'; // ch -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)rem\b return 'LENGTH'; // rem -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)vw\b return 'LENGTH'; // vw -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)vh\b return 'LENGTH'; // vh -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)vmin\b return 'LENGTH'; // vmin -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)vmax\b return 'LENGTH'; // vmax -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)vm\b return 'LENGTH'; // vm (non-standard name) -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)px\b return 'LENGTH'; // px -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)mm\b return 'LENGTH'; // mm -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)cm\b return 'LENGTH'; // cm -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)in\b return 'LENGTH'; // in -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)pt\b return 'LENGTH'; // pt -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)pc\b return 'LENGTH'; // pc -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)Q\b return 'LENGTH'; // Q -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)fr\b return 'LENGTH'; // fr -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)deg\b return 'ANGLE'; // deg -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)grad\b return 'ANGLE'; // grad -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)turn\b return 'ANGLE'; // turn -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)rad\b return 'ANGLE'; // rad -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)s\b return 'TIME'; // s -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)ms\b return 'TIME'; // ms -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)Hz\b return 'FREQ'; // Hz -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)kHz\b return 'FREQ'; // kHz -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)dpi\b return 'RES'; // dpi -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)dpcm\b return 'RES'; // dpcm -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)dppx\b return 'RES'; // dppm -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)\% return 'PERCENTAGE'; -[+-]?([0-9]+("."[0-9]+)?|"."[0-9]+)\b return 'NUMBER'; +([0-9]+("."[0-9]+)?|"."[0-9]+)em\b return 'LENGTH'; // em +([0-9]+("."[0-9]+)?|"."[0-9]+)ex\b return 'LENGTH'; // ex +([0-9]+("."[0-9]+)?|"."[0-9]+)ch\b return 'LENGTH'; // ch +([0-9]+("."[0-9]+)?|"."[0-9]+)rem\b return 'LENGTH'; // rem +([0-9]+("."[0-9]+)?|"."[0-9]+)vw\b return 'LENGTH'; // vw +([0-9]+("."[0-9]+)?|"."[0-9]+)vh\b return 'LENGTH'; // vh +([0-9]+("."[0-9]+)?|"."[0-9]+)vmin\b return 'LENGTH'; // vmin +([0-9]+("."[0-9]+)?|"."[0-9]+)vmax\b return 'LENGTH'; // vmax +([0-9]+("."[0-9]+)?|"."[0-9]+)vm\b return 'LENGTH'; // vm (non-standard name) +([0-9]+("."[0-9]+)?|"."[0-9]+)px\b return 'LENGTH'; // px +([0-9]+("."[0-9]+)?|"."[0-9]+)mm\b return 'LENGTH'; // mm +([0-9]+("."[0-9]+)?|"."[0-9]+)cm\b return 'LENGTH'; // cm +([0-9]+("."[0-9]+)?|"."[0-9]+)in\b return 'LENGTH'; // in +([0-9]+("."[0-9]+)?|"."[0-9]+)pt\b return 'LENGTH'; // pt +([0-9]+("."[0-9]+)?|"."[0-9]+)pc\b return 'LENGTH'; // pc +([0-9]+("."[0-9]+)?|"."[0-9]+)Q\b return 'LENGTH'; // Q +([0-9]+("."[0-9]+)?|"."[0-9]+)fr\b return 'LENGTH'; // fr +([0-9]+("."[0-9]+)?|"."[0-9]+)deg\b return 'ANGLE'; // deg +([0-9]+("."[0-9]+)?|"."[0-9]+)grad\b return 'ANGLE'; // grad +([0-9]+("."[0-9]+)?|"."[0-9]+)turn\b return 'ANGLE'; // turn +([0-9]+("."[0-9]+)?|"."[0-9]+)rad\b return 'ANGLE'; // rad +([0-9]+("."[0-9]+)?|"."[0-9]+)s\b return 'TIME'; // s +([0-9]+("."[0-9]+)?|"."[0-9]+)ms\b return 'TIME'; // ms +([0-9]+("."[0-9]+)?|"."[0-9]+)Hz\b return 'FREQ'; // Hz +([0-9]+("."[0-9]+)?|"."[0-9]+)kHz\b return 'FREQ'; // kHz +([0-9]+("."[0-9]+)?|"."[0-9]+)dpi\b return 'RES'; // dpi +([0-9]+("."[0-9]+)?|"."[0-9]+)dpcm\b return 'RES'; // dpcm +([0-9]+("."[0-9]+)?|"."[0-9]+)dppx\b return 'RES'; // dppm +([0-9]+("."[0-9]+)?|"."[0-9]+)\% return 'PERCENTAGE'; +([0-9]+("."[0-9]+)?|"."[0-9]+)\b return 'NUMBER'; "(" return 'LPAREN'; ")" return 'RPAREN'; @@ -111,6 +111,35 @@ expression } }; } + | SUB math_expression %prec UPREC { + if (@1.range[1] !== $2.source.start.index) { + throw new Error('Unexpected spaces was found between sign and value'); + } + if (typeof $2.value !== 'number') { + throw new Error('Unexpected sign'); + } + if ($2.sign) { + throw new Error('Unexpected continuous sign'); + } + $$ = $2; + $$.sign = '-' + $$.value = -$2.value; + $$.source.start.index = @1.range[0]; + } + | ADD math_expression %prec UPREC { + if (@1.range[1] !== $2.source.start.index) { + throw new Error('Unexpected spaces was found between sign and value'); + } + if (typeof $2.value !== 'number') { + throw new Error('Unexpected sign'); + } + if ($2.sign) { + throw new Error('Unexpected continuous sign'); + } + $$ = $2; + $$.sign = '+' + $$.source.start.index = @1.range[0]; + } | LPAREN math_expression RPAREN { $$ = $2; $$.source.start = { index: @1.range[0] }; diff --git a/lib/utils/parseCalcExpression/parser.js b/lib/utils/parseCalcExpression/parser.js index 0af90696ba..2c82601512 100644 --- a/lib/utils/parseCalcExpression/parser.js +++ b/lib/utils/parseCalcExpression/parser.js @@ -760,7 +760,7 @@ productions_: bp({ pop: u([ 19, s, - [20, 9], + [20, 11], 21, 22, s, @@ -770,7 +770,10 @@ productions_: bp({ 2, 4, s, - [3, 5], + [3, 4], + 2, + 2, + 3, s, [1, 12] ]) @@ -845,6 +848,51 @@ case 6: break; case 7: + /*! Production:: math_expression : SUB math_expression */ + + // default action (generated by JISON mode classic/merge :: 2,VT,VA,VU,-,LT,LA,-,-): + this._$ = yyparser.yyMergeLocationInfo(yysp - 1, yysp); + // END of default action (generated by JISON mode classic/merge :: 2,VT,VA,VU,-,LT,LA,-,-) + + + if (yylstack[yysp - 1].range[1] !== yyvstack[yysp].source.start.index) { + throw new Error('Unexpected spaces was found between sign and value'); + } + if (typeof yyvstack[yysp].value !== 'number') { + throw new Error('Unexpected sign'); + } + if (yyvstack[yysp].sign) { + throw new Error('Unexpected continuous sign'); + } + this.$ = yyvstack[yysp]; + this.$.sign = '-' + this.$.value = -yyvstack[yysp].value; + this.$.source.start.index = yylstack[yysp - 1].range[0]; + break; + +case 8: + /*! Production:: math_expression : ADD math_expression */ + + // default action (generated by JISON mode classic/merge :: 2,VT,VA,VU,-,LT,LA,-,-): + this._$ = yyparser.yyMergeLocationInfo(yysp - 1, yysp); + // END of default action (generated by JISON mode classic/merge :: 2,VT,VA,VU,-,LT,LA,-,-) + + + if (yylstack[yysp - 1].range[1] !== yyvstack[yysp].source.start.index) { + throw new Error('Unexpected spaces was found between sign and value'); + } + if (typeof yyvstack[yysp].value !== 'number') { + throw new Error('Unexpected sign'); + } + if (yyvstack[yysp].sign) { + throw new Error('Unexpected continuous sign'); + } + this.$ = yyvstack[yysp]; + this.$.sign = '+' + this.$.source.start.index = yylstack[yysp - 1].range[0]; + break; + +case 9: /*! Production:: math_expression : LPAREN math_expression RPAREN */ // default action (generated by JISON mode classic/merge :: 3,VT,VA,VU,-,LT,LA,-,-): @@ -857,11 +905,11 @@ case 7: this.$.source.end = { index: yylstack[yysp].range[1] }; break; -case 8: +case 10: /*! Production:: math_expression : function */ -case 9: +case 11: /*! Production:: math_expression : css_value */ -case 10: +case 12: /*! Production:: math_expression : value */ // default action (generated by JISON mode classic/merge :: 1,VT,VA,VU,-,LT,LA,-,-): @@ -872,7 +920,7 @@ case 10: this.$ = yyvstack[yysp]; break; -case 11: +case 13: /*! Production:: value : NUMBER */ // default action (generated by JISON mode classic/merge :: 1,VT,VA,VU,-,LT,LA,-,-): @@ -883,7 +931,7 @@ case 11: this.$ = { type: 'Value', value: parseFloat(yyvstack[yysp]), source: { start: { index: yylstack[yysp].range[0] }, end: { index: yylstack[yysp].range[1] } } }; break; -case 12: +case 14: /*! Production:: function : FUNCTION */ // default action (generated by JISON mode classic/merge :: 1,VT,VA,VU,-,LT,LA,-,-): @@ -894,7 +942,7 @@ case 12: this.$ = { type: 'Function', value: yyvstack[yysp], source: { start: { index: yylstack[yysp].range[0] }, end: { index: yylstack[yysp].range[1] } } }; break; -case 13: +case 15: /*! Production:: css_value : LENGTH */ // default action (generated by JISON mode classic/merge :: 1,VT,VA,VU,-,LT,LA,-,-): @@ -905,7 +953,7 @@ case 13: this.$ = { type: 'LengthValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+/i.exec(yyvstack[yysp])[0], source: { start: { index: yylstack[yysp].range[0] }, end: { index: yylstack[yysp].range[1] } } }; break; -case 14: +case 16: /*! Production:: css_value : ANGLE */ // default action (generated by JISON mode classic/merge :: 1,VT,VA,VU,-,LT,LA,-,-): @@ -916,7 +964,7 @@ case 14: this.$ = { type: 'AngleValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+/i.exec(yyvstack[yysp])[0], source: { start: { index: yylstack[yysp].range[0] }, end: { index: yylstack[yysp].range[1] } } }; break; -case 15: +case 17: /*! Production:: css_value : TIME */ // default action (generated by JISON mode classic/merge :: 1,VT,VA,VU,-,LT,LA,-,-): @@ -927,7 +975,7 @@ case 15: this.$ = { type: 'TimeValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+/i.exec(yyvstack[yysp])[0], source: { start: { index: yylstack[yysp].range[0] }, end: { index: yylstack[yysp].range[1] } } }; break; -case 16: +case 18: /*! Production:: css_value : FREQ */ // default action (generated by JISON mode classic/merge :: 1,VT,VA,VU,-,LT,LA,-,-): @@ -938,7 +986,7 @@ case 16: this.$ = { type: 'FrequencyValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+/i.exec(yyvstack[yysp])[0], source: { start: { index: yylstack[yysp].range[0] }, end: { index: yylstack[yysp].range[1] } } }; break; -case 17: +case 19: /*! Production:: css_value : RES */ // default action (generated by JISON mode classic/merge :: 1,VT,VA,VU,-,LT,LA,-,-): @@ -949,7 +997,7 @@ case 17: this.$ = { type: 'ResolutionValue', value: parseFloat(yyvstack[yysp]), unit: /[a-z]+/i.exec(yyvstack[yysp])[0], source: { start: { index: yylstack[yysp].range[0] }, end: { index: yylstack[yysp].range[1] } } }; break; -case 18: +case 20: /*! Production:: css_value : PERCENTAGE */ // default action (generated by JISON mode classic/merge :: 1,VT,VA,VU,-,LT,LA,-,-): @@ -960,7 +1008,7 @@ case 18: this.$ = { type: 'PercentageValue', value: parseFloat(yyvstack[yysp]), unit: '%', source: { start: { index: yylstack[yysp].range[0] }, end: { index: yylstack[yysp].range[1] } } }; break; -case 19: +case 21: /*! Production:: css_value : UNKNOWN */ // default action (generated by JISON mode classic/merge :: 1,VT,VA,VU,-,LT,LA,-,-): @@ -975,27 +1023,31 @@ case 19: }, table: bt({ len: u([ - 16, + 18, 1, 5, 1, - 15, + s, + [17, 3], s, [0, 13], s, - [15, 5], - 5, - 6, - 6, + [17, 5], 0, 0, 5, + 6, + 6, + c, + [5, 3], 0, 0 ]), symbol: u([ 3, 4, + 6, + 7, s, [10, 14, 1], 1, @@ -1004,11 +1056,11 @@ table: bt({ [6, 4, 1], 4, c, - [23, 11], + [25, 13], c, - [22, 4], + [24, 4], c, - [15, 75], + [17, 119], s, [5, 5, 1], 1, @@ -1019,31 +1071,25 @@ table: bt({ ]), type: u([ s, - [2, 11], + [2, 13], s, [0, 5], 1, s, - [2, 17], + [2, 19], s, [0, 4], c, - [15, 86], + [17, 132], s, - [2, 11] + [2, 9] ]), state: u([ 1, 2, + 9, 7, - 5, - 6, - 23, - c, - [4, 3], - 24, - c, - [4, 3], + 8, 25, c, [4, 3], @@ -1055,11 +1101,23 @@ table: bt({ [4, 3], 28, c, + [4, 3], + 29, + c, + [4, 3], + 30, + c, + [4, 3], + 31, + c, + [4, 3], + 32, + c, [4, 3] ]), mode: u([ s, - [1, 88], + [1, 128], s, [2, 4], c, @@ -1069,28 +1127,30 @@ table: bt({ ]), goto: u([ 3, + 6, + 5, 4, - 16, + 18, s, - [8, 8, 1], + [10, 8, 1], s, - [17, 6, 1], + [19, 6, 1], c, - [17, 11], + [19, 13], c, - [11, 55], - 29, + [13, 91], + 33, c, - [72, 4], + [110, 4], s, [3, 4], - 20, - 21, + 22, + 23, s, [4, 4], - 20, - 21, - 30, + 22, + 23, + 34, c, [17, 4] ]) @@ -1098,23 +1158,27 @@ table: bt({ defaultActions: bda({ idx: u([ s, - [5, 13, 1], + [7, 13, 1], + 25, 26, - 27, - 29, - 30 + 30, + 31, + 33, + 34 ]), goto: u([ - 8, - 9, 10, - s, - [12, 8, 1], 11, + 12, + s, + [14, 8, 1], + 13, 1, + 7, + 8, 5, 6, - 7, + 9, 2 ]) }), @@ -1155,7 +1219,7 @@ parse: function parse(input) { var TERROR = this.TERROR; var EOF = this.EOF; var ERROR_RECOVERY_TOKEN_DISCARD_COUNT = (this.options.errorRecoveryTokenDiscardCount | 0) || 3; - var NO_ACTION = [0, 31 /* === table.length :: ensures that anyone using this new state will fail dramatically! */]; + var NO_ACTION = [0, 35 /* === table.length :: ensures that anyone using this new state will fail dramatically! */]; var lexer; if (this.__lexer__) { @@ -3473,196 +3537,196 @@ EOF: 1, case 7: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)em\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)em\b */ return 12; // em break; case 8: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)ex\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)ex\b */ return 12; // ex break; case 9: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)ch\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)ch\b */ return 12; // ch break; case 10: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)rem\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)rem\b */ return 12; // rem break; case 11: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)vw\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)vw\b */ return 12; // vw break; case 12: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)vh\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)vh\b */ return 12; // vh break; case 13: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)vmin\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)vmin\b */ return 12; // vmin break; case 14: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)vmax\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)vmax\b */ return 12; // vmax break; case 15: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)vm\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)vm\b */ return 12; // vm (non-standard name) break; case 16: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)px\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)px\b */ return 12; // px break; case 17: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)mm\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)mm\b */ return 12; // mm break; case 18: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)cm\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)cm\b */ return 12; // cm break; case 19: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)in\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)in\b */ return 12; // in break; case 20: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)pt\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)pt\b */ return 12; // pt break; case 21: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)pc\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)pc\b */ return 12; // pc break; case 22: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)Q\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)Q\b */ return 12; // Q break; case 23: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)fr\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)fr\b */ return 12; // fr break; case 24: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)deg\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)deg\b */ return 13; // deg break; case 25: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)grad\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)grad\b */ return 13; // grad break; case 26: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)turn\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)turn\b */ return 13; // turn break; case 27: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)rad\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)rad\b */ return 13; // rad break; case 28: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)s\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)s\b */ return 14; // s break; case 29: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)ms\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)ms\b */ return 14; // ms break; case 30: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)Hz\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)Hz\b */ return 15; // Hz break; case 31: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)kHz\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)kHz\b */ return 15; // kHz break; case 32: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)dpi\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)dpi\b */ return 16; // dpi break; case 33: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)dpcm\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)dpcm\b */ return 16; // dpcm break; case 34: /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)dppx\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)dppx\b */ return 16; // dppm break; @@ -3698,11 +3762,11 @@ EOF: 1, 6: 7, /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)% */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)% */ 35: 17, /*! Conditions:: INITIAL */ - /*! Rule:: [+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)\b */ + /*! Rule:: ([0-9]+(\.[0-9]+)?|\.[0-9]+)\b */ 36: 10, /*! Conditions:: INITIAL */ @@ -3730,36 +3794,36 @@ EOF: 1, /* 4: */ /^(?:\/)/i, /* 5: */ /^(?:\+)/i, /* 6: */ /^(?:-)/i, - /* 7: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)em\b)/i, - /* 8: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)ex\b)/i, - /* 9: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)ch\b)/i, - /* 10: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)rem\b)/i, - /* 11: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)vw\b)/i, - /* 12: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)vh\b)/i, - /* 13: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)vmin\b)/i, - /* 14: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)vmax\b)/i, - /* 15: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)vm\b)/i, - /* 16: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)px\b)/i, - /* 17: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)mm\b)/i, - /* 18: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)cm\b)/i, - /* 19: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)in\b)/i, - /* 20: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)pt\b)/i, - /* 21: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)pc\b)/i, - /* 22: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)Q\b)/i, - /* 23: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)fr\b)/i, - /* 24: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)deg\b)/i, - /* 25: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)grad\b)/i, - /* 26: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)turn\b)/i, - /* 27: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)rad\b)/i, - /* 28: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)s\b)/i, - /* 29: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)ms\b)/i, - /* 30: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)Hz\b)/i, - /* 31: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)kHz\b)/i, - /* 32: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)dpi\b)/i, - /* 33: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)dpcm\b)/i, - /* 34: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)dppx\b)/i, - /* 35: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)%)/i, - /* 36: */ /^(?:[+-]?(\d+(\.\d+)?|\.\d+)\b)/i, + /* 7: */ /^(?:(\d+(\.\d+)?|\.\d+)em\b)/i, + /* 8: */ /^(?:(\d+(\.\d+)?|\.\d+)ex\b)/i, + /* 9: */ /^(?:(\d+(\.\d+)?|\.\d+)ch\b)/i, + /* 10: */ /^(?:(\d+(\.\d+)?|\.\d+)rem\b)/i, + /* 11: */ /^(?:(\d+(\.\d+)?|\.\d+)vw\b)/i, + /* 12: */ /^(?:(\d+(\.\d+)?|\.\d+)vh\b)/i, + /* 13: */ /^(?:(\d+(\.\d+)?|\.\d+)vmin\b)/i, + /* 14: */ /^(?:(\d+(\.\d+)?|\.\d+)vmax\b)/i, + /* 15: */ /^(?:(\d+(\.\d+)?|\.\d+)vm\b)/i, + /* 16: */ /^(?:(\d+(\.\d+)?|\.\d+)px\b)/i, + /* 17: */ /^(?:(\d+(\.\d+)?|\.\d+)mm\b)/i, + /* 18: */ /^(?:(\d+(\.\d+)?|\.\d+)cm\b)/i, + /* 19: */ /^(?:(\d+(\.\d+)?|\.\d+)in\b)/i, + /* 20: */ /^(?:(\d+(\.\d+)?|\.\d+)pt\b)/i, + /* 21: */ /^(?:(\d+(\.\d+)?|\.\d+)pc\b)/i, + /* 22: */ /^(?:(\d+(\.\d+)?|\.\d+)Q\b)/i, + /* 23: */ /^(?:(\d+(\.\d+)?|\.\d+)fr\b)/i, + /* 24: */ /^(?:(\d+(\.\d+)?|\.\d+)deg\b)/i, + /* 25: */ /^(?:(\d+(\.\d+)?|\.\d+)grad\b)/i, + /* 26: */ /^(?:(\d+(\.\d+)?|\.\d+)turn\b)/i, + /* 27: */ /^(?:(\d+(\.\d+)?|\.\d+)rad\b)/i, + /* 28: */ /^(?:(\d+(\.\d+)?|\.\d+)s\b)/i, + /* 29: */ /^(?:(\d+(\.\d+)?|\.\d+)ms\b)/i, + /* 30: */ /^(?:(\d+(\.\d+)?|\.\d+)Hz\b)/i, + /* 31: */ /^(?:(\d+(\.\d+)?|\.\d+)kHz\b)/i, + /* 32: */ /^(?:(\d+(\.\d+)?|\.\d+)dpi\b)/i, + /* 33: */ /^(?:(\d+(\.\d+)?|\.\d+)dpcm\b)/i, + /* 34: */ /^(?:(\d+(\.\d+)?|\.\d+)dppx\b)/i, + /* 35: */ /^(?:(\d+(\.\d+)?|\.\d+)%)/i, + /* 36: */ /^(?:(\d+(\.\d+)?|\.\d+)\b)/i, /* 37: */ /^(?:\()/i, /* 38: */ /^(?:\))/i, /* 39: */ /^(?:\S[^\s()*\/+-]*)/i, diff --git a/package.json b/package.json index 8f63a9f7e2..b17c2f944b 100644 --- a/package.json +++ b/package.json @@ -137,14 +137,17 @@ } }, "lint-staged": { - "*.js": [ - "prettier --write", - "eslint --max-warnings=0 --fix", - "git add" - ], - "*.md": [ - "remark --quiet --frail" - ] + "linters": { + "*.js": [ + "prettier --write", + "eslint --max-warnings=0 --fix", + "git add" + ], + "*.md": [ + "remark --quiet --frail" + ] + }, + "ignore": ["lib/utils/parseCalcExpression/parser.js"] }, "eslintConfig": { "extends": [