Fix existing linting errors, update error phase, and add a new flags linter (#2086)

This commit is contained in:
André Bargull 2019-03-06 09:24:44 -08:00 committed by Leo Balter
parent b78e085571
commit c822f4c929
32 changed files with 146 additions and 23 deletions

View File

@ -10,7 +10,7 @@ description: >
info: |
HashbangComment::
#! SingleLineCommentChars[opt]
flags: [raw, noStrict]
flags: [raw]
features: [hashbang]
---*/

View File

@ -13,5 +13,5 @@ flags: [raw]
---*/
"use strict"
throw new Error("This code should not execute");
throw "Test262: This statement should not be evaluated.";
var public = 1;

View File

@ -13,5 +13,5 @@ flags: [raw]
---*/
"use strict";
throw new Error("This code should not execute");
throw "Test262: This statement should not be evaluated.";
var public = 1;

View File

@ -14,5 +14,5 @@ flags: [raw]
"use strict";
"use strict";
throw new Error("This code should not execute");
throw "Test262: This statement should not be evaluated.";
var public = 1;

View File

@ -13,5 +13,5 @@ flags: [raw]
---*/
"use strict";
throw new Error("This code should not execute");
throw "Test262: This statement should not be evaluated.";
eval = 42;

View File

@ -15,5 +15,5 @@ flags: [raw]
"a";
"use strict";
"c";
throw new Error("This code should not execute");
throw "Test262: This statement should not be evaluated.";
eval = 42;

View File

@ -9,11 +9,13 @@ description: >
is strict function code if FunctionDeclaration is contained in use
strict
negative:
phase: early
phase: parse
type: SyntaxError
flags: [noStrict]
---*/
$DONOTEVALUATE();
function testcase() {
"use strict";
function fun() {

View File

@ -8,11 +8,13 @@ description: >
Strict Mode - Use Strict Directive Prologue is ''use strict''
which lost the last character ';'
negative:
phase: early
phase: parse
type: SyntaxError
flags: [noStrict]
---*/
$DONOTEVALUATE();
function fun() {
"use strict"
var static;

View File

@ -8,11 +8,13 @@ description: >
Strict Mode - Function code of a FunctionDeclaration contains Use
Strict Directive which appears at the start of the block
negative:
phase: early
phase: parse
type: SyntaxError
flags: [noStrict]
---*/
$DONOTEVALUATE();
function fun() {
"use strict";
var static;

View File

@ -9,11 +9,13 @@ description: >
is strict function code if FunctionExpression is contained in use
strict
negative:
phase: early
phase: parse
type: SyntaxError
flags: [noStrict]
---*/
$DONOTEVALUATE();
function testcase() {
"use strict";
var static;

View File

@ -8,11 +8,13 @@ description: >
Strict Mode - Use Strict Directive Prologue is ''use strict''
which lost the last character ';'
negative:
phase: early
phase: parse
type: SyntaxError
flags: [noStrict]
---*/
$DONOTEVALUATE();
(function() {
"use strict"

View File

@ -8,11 +8,13 @@ description: >
Strict Mode - Function code of a FunctionExpression contains Use
Strict Directive which appears at the start of the block
negative:
phase: early
phase: parse
type: SyntaxError
flags: [noStrict]
---*/
$DONOTEVALUATE();
(function() {
"use strict";

View File

@ -8,7 +8,7 @@ description: >
info: |
It is an early Syntax Error if Module is not the syntactic goal symbol.
negative:
phase: early
phase: parse
type: SyntaxError
features: [import.meta]
---*/

View File

@ -21,7 +21,7 @@ info: |
and AssignmentTargetType(LeftHandSideExpression) is not simple.
flags: [module]
negative:
phase: early
phase: parse
type: SyntaxError
features: [import.meta, destructuring-assignment]
---*/

View File

@ -21,7 +21,7 @@ info: |
and AssignmentTargetType(LeftHandSideExpression) is not simple.
flags: [module]
negative:
phase: early
phase: parse
type: SyntaxError
features: [import.meta, destructuring-assignment]
---*/

View File

@ -21,7 +21,7 @@ info: |
ArrayLiteral and AssignmentTargetType of LeftHandSideExpression is invalid.
flags: [module]
negative:
phase: early
phase: parse
type: ReferenceError
features: [import.meta]
---*/

View File

@ -20,7 +20,7 @@ info: |
It is a Syntax Error if AssignmentTargetType of LeftHandSideExpression is not simple.
flags: [module]
negative:
phase: early
phase: parse
type: SyntaxError
features: [import.meta, async-iteration]
---*/

View File

@ -20,7 +20,7 @@ info: |
It is a Syntax Error if AssignmentTargetType of LeftHandSideExpression is not simple.
flags: [module]
negative:
phase: early
phase: parse
type: SyntaxError
features: [import.meta]
---*/

View File

@ -20,7 +20,7 @@ info: |
It is a Syntax Error if AssignmentTargetType of LeftHandSideExpression is not simple.
flags: [module]
negative:
phase: early
phase: parse
type: SyntaxError
features: [import.meta]
---*/

View File

@ -21,7 +21,7 @@ info: |
and AssignmentTargetType(LeftHandSideExpression) is not simple.
flags: [module]
negative:
phase: early
phase: parse
type: SyntaxError
features: [import.meta, destructuring-assignment]
---*/

View File

@ -21,7 +21,7 @@ info: |
and AssignmentTargetType(LeftHandSideExpression) is not simple.
flags: [module]
negative:
phase: early
phase: parse
type: SyntaxError
features: [import.meta, destructuring-assignment, object-rest]
---*/

View File

@ -22,7 +22,7 @@ info: |
It is an early Reference Error if AssignmentTargetType of LeftHandSideExpression is invalid.
flags: [module]
negative:
phase: early
phase: parse
type: ReferenceError
features: [import.meta]
---*/

View File

@ -0,0 +1,36 @@
from ..check import Check
class CheckFlags(Check):
'''Ensure tests don't contain any contradicting or redundant flag combinations.'''
ID = 'FLAGS'
def run(self, name, meta, source):
if meta is None or meta.get('flags') is None:
return
flags = meta['flags']
onlyStrict = 'onlyStrict' in flags
noStrict = 'noStrict' in flags
module = 'module' in flags
raw = 'raw' in flags
canBlockIsFalse = 'CanBlockIsFalse' in flags
canBlockIsTrue = 'CanBlockIsTrue' in flags
if onlyStrict and noStrict:
return '"onlyStrict" and "noStrict" flags are mutually exclusive'
if canBlockIsFalse and canBlockIsTrue:
return '"CanBlockIsFalse" and "CanBlockIsTrue" flags are mutually exclusive'
if raw and onlyStrict:
return 'Raw tests cannot prepend a "use strict" directive'
if raw and noStrict:
return '"raw" flag implies no "use strict" directive should be prepended'
if module and onlyStrict:
return 'Module tests cannot be run in non-strict mode'
if module and noStrict:
return '"module" flag implies the test is run in strict mode'

3
tools/lint/lib/checks/negative.py Executable file → Normal file
View File

@ -27,6 +27,9 @@ class CheckNegative(Check):
if not 'phase' in negative:
return '"negative" must specify a "phase" field'
if negative["phase"] not in ["parse", "resolution", "runtime"]:
return '"phase" must be one of ["parse", "resolution", "runtime"]'
if negative["phase"] in ["parse", "resolution"]:
if meta.get('flags') and 'raw' in meta['flags']:
if not _THROW_STMT_LEGACY.search(source):

View File

@ -38,6 +38,7 @@ from lib.checks.license import CheckLicense
from lib.checks.negative import CheckNegative
from lib.checks.filename import CheckFileName
from lib.checks.nopadding import CheckNoPadding
from lib.checks.flags import CheckFlags
from lib.eprint import eprint
import lib.frontmatter
import lib.exceptions
@ -59,7 +60,8 @@ checks = [
CheckHarness(),
CheckLicense(),
CheckNegative(),
CheckNoPadding()
CheckNoPadding(),
CheckFlags(),
]
def lint(file_names):

View File

@ -0,0 +1,9 @@
FLAGS
^ expected errors | v input
// Copyright (C) 2019 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
flags: [CanBlockIsFalse, CanBlockIsTrue]
---*/

View File

@ -0,0 +1,9 @@
FLAGS
^ expected errors | v input
// Copyright (C) 2019 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
flags: [module, noStrict]
---*/

View File

@ -0,0 +1,9 @@
FLAGS
^ expected errors | v input
// Copyright (C) 2019 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
flags: [module, onlyStrict]
---*/

View File

@ -0,0 +1,9 @@
FLAGS
^ expected errors | v input
// Copyright (C) 2019 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
flags: [onlyStrict, noStrict]
---*/

View File

@ -0,0 +1,9 @@
FLAGS
^ expected errors | v input
// Copyright (C) 2019 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
flags: [raw, noStrict]
---*/

View File

@ -0,0 +1,9 @@
FLAGS
^ expected errors | v input
// Copyright (C) 2019 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
flags: [raw, onlyStrict]
---*/

View File

@ -0,0 +1,16 @@
NEGATIVE
^ expected errors | v input
// Copyright (C) 2019 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-assignment-operators-static-semantics-early-errors
description: Minimal test
negative:
type: SyntaxError
phase: early
flags: [raw]
---*/
$DONOTEVALUATE();
!!!