updated baselines on classAbstract tests

This commit is contained in:
Arthur Ozga
2015-06-30 14:44:13 -07:00
parent 18d6e73aa0
commit 5864a66fbc
10 changed files with 115 additions and 121 deletions

View File

@@ -1,67 +1,67 @@
//// [APISample_linter.ts]
/*
* Note: This test is a public API sample. The sample sources can be found
at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#traversing-the-ast-with-a-little-linter
* Please log a "breaking change" issue for any API breaking change affecting this issue
*/
declare var process: any;
declare var console: any;
declare var readFileSync: any;
import * as ts from "typescript";
export function delint(sourceFile: ts.SourceFile) {
delintNode(sourceFile);
function delintNode(node: ts.Node) {
switch (node.kind) {
case ts.SyntaxKind.ForStatement:
case ts.SyntaxKind.ForInStatement:
case ts.SyntaxKind.WhileStatement:
case ts.SyntaxKind.DoStatement:
if ((<ts.IterationStatement>node).statement.kind !== ts.SyntaxKind.Block) {
report(node, "A looping statement's contents should be wrapped in a block body.");
}
break;
case ts.SyntaxKind.IfStatement:
let ifStatement = (<ts.IfStatement>node);
if (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) {
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
}
if (ifStatement.elseStatement &&
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&
ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
}
break;
case ts.SyntaxKind.BinaryExpression:
let op = (<ts.BinaryExpression>node).operatorToken.kind;
if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) {
report(node, "Use '===' and '!=='.")
}
break;
}
ts.forEachChild(node, delintNode);
}
function report(node: ts.Node, message: string) {
let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
}
}
const fileNames = process.argv.slice(2);
fileNames.forEach(fileName => {
// Parse a file
let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
// delint it
delint(sourceFile);
/*
* Note: This test is a public API sample. The sample sources can be found
at: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#traversing-the-ast-with-a-little-linter
* Please log a "breaking change" issue for any API breaking change affecting this issue
*/
declare var process: any;
declare var console: any;
declare var readFileSync: any;
import * as ts from "typescript";
export function delint(sourceFile: ts.SourceFile) {
delintNode(sourceFile);
function delintNode(node: ts.Node) {
switch (node.kind) {
case ts.SyntaxKind.ForStatement:
case ts.SyntaxKind.ForInStatement:
case ts.SyntaxKind.WhileStatement:
case ts.SyntaxKind.DoStatement:
if ((<ts.IterationStatement>node).statement.kind !== ts.SyntaxKind.Block) {
report(node, "A looping statement's contents should be wrapped in a block body.");
}
break;
case ts.SyntaxKind.IfStatement:
let ifStatement = (<ts.IfStatement>node);
if (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) {
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
}
if (ifStatement.elseStatement &&
ifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&
ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
}
break;
case ts.SyntaxKind.BinaryExpression:
let op = (<ts.BinaryExpression>node).operatorToken.kind;
if (op === ts.SyntaxKind.EqualsEqualsToken || op == ts.SyntaxKind.ExclamationEqualsToken) {
report(node, "Use '===' and '!=='.")
}
break;
}
ts.forEachChild(node, delintNode);
}
function report(node: ts.Node, message: string) {
let { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
}
}
const fileNames = process.argv.slice(2);
fileNames.forEach(fileName => {
// Parse a file
let sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES6, /*setParentNodes */ true);
// delint it
delint(sourceFile);
});
//// [APISample_linter.js]
@@ -75,26 +75,26 @@ function delint(sourceFile) {
delintNode(sourceFile);
function delintNode(node) {
switch (node.kind) {
case 191 /* ForStatement */:
case 192 /* ForInStatement */:
case 190 /* WhileStatement */:
case 189 /* DoStatement */:
if (node.statement.kind !== 184 /* Block */) {
case 192 /* ForStatement */:
case 193 /* ForInStatement */:
case 191 /* WhileStatement */:
case 190 /* DoStatement */:
if (node.statement.kind !== 185 /* Block */) {
report(node, "A looping statement's contents should be wrapped in a block body.");
}
break;
case 188 /* IfStatement */:
case 189 /* IfStatement */:
var ifStatement = node;
if (ifStatement.thenStatement.kind !== 184 /* Block */) {
if (ifStatement.thenStatement.kind !== 185 /* Block */) {
report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body.");
}
if (ifStatement.elseStatement &&
ifStatement.elseStatement.kind !== 184 /* Block */ &&
ifStatement.elseStatement.kind !== 188 /* IfStatement */) {
ifStatement.elseStatement.kind !== 185 /* Block */ &&
ifStatement.elseStatement.kind !== 189 /* IfStatement */) {
report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body.");
}
break;
case 173 /* BinaryExpression */:
case 174 /* BinaryExpression */:
var op = node.operatorToken.kind;
if (op === 29 /* EqualsEqualsToken */ || op == 30 /* ExclamationEqualsToken */) {
report(node, "Use '===' and '!=='.");

View File

@@ -1,9 +1,9 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractConstructor.ts(2,5): error TS1236: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractConstructor.ts(2,5): error TS1242: 'abstract' modifier can only appear on a class or method declaration.
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractConstructor.ts (1 errors) ====
abstract class A {
abstract constructor() {}
~~~~~~~~
!!! error TS1236: 'abstract' modifier can only appear on a class or method declaration.
!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration.
}

View File

@@ -1,4 +1,4 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractDeclarations.d.ts(2,5): error TS1236: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractDeclarations.d.ts(2,5): error TS1242: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractDeclarations.d.ts(2,28): error TS1184: An implementation cannot be declared in ambient contexts.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractDeclarations.d.ts(11,15): error TS2515: Non-abstract class 'CC' does not implement inherited abstract member 'foo' from class 'AA'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractDeclarations.d.ts(13,15): error TS2515: Non-abstract class 'DD' does not implement inherited abstract member 'foo' from class 'BB'.
@@ -9,7 +9,7 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst
declare abstract class A {
abstract constructor() {}
~~~~~~~~
!!! error TS1236: 'abstract' modifier can only appear on a class or method declaration.
!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration.
~
!!! error TS1184: An implementation cannot be declared in ambient contexts.
}

View File

@@ -3,12 +3,11 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(21,1): error TS2511: Cannot create an instance of the abstract class 'B'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(26,7): error TS2515: Non-abstract class 'C' does not implement inherited abstract member 'bar' from class 'B'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(46,5): error TS2391: Function implementation is missing or not immediately following the declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(46,5): error TS2512: Overload signatures must all be `abstract` or not `abstract.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(49,7): error TS2514: Classes containing abstract methods must be marked abstract.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(50,5): error TS1238: Abstract methods can only appear within an abstract class.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(46,5): error TS2512: Overload signatures must all be abstract or not abstract.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts(50,5): error TS1244: Abstract methods can only appear within an abstract class.
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts (8 errors) ====
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractInstantiations2.ts (7 errors) ====
class A {
// ...
}
@@ -66,13 +65,11 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst
~~~
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
~~~
!!! error TS2512: Overload signatures must all be `abstract` or not `abstract.
!!! error TS2512: Overload signatures must all be abstract or not abstract.
}
class H { // error -- not declared abstract
~
!!! error TS2514: Classes containing abstract methods must be marked abstract.
abstract baz() : number;
~~~~~~~~
!!! error TS1238: Abstract methods can only appear within an abstract class.
!!! error TS1244: Abstract methods can only appear within an abstract class.
}

View File

@@ -1,9 +1,9 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMethodWithImplementation.ts(2,5): error TS1240: Method 'foo' cannot have an implementation because it is marked abstract.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMethodWithImplementation.ts(2,5): error TS1245: Method 'foo' cannot have an implementation because it is marked abstract.
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMethodWithImplementation.ts (1 errors) ====
abstract class A {
abstract foo() {}
~~~~~~~~~~~~~~~~~
!!! error TS1240: Method 'foo' cannot have an implementation because it is marked abstract.
!!! error TS1245: Method 'foo' cannot have an implementation because it is marked abstract.
}

View File

@@ -1,9 +1,9 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMixedWithModifiers.ts(6,13): error TS1237: 'private' modifier cannot be used with 'abstract' modifier.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMixedWithModifiers.ts(6,13): error TS1243: 'private' modifier cannot be used with 'abstract' modifier.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMixedWithModifiers.ts(8,14): error TS1029: 'public' modifier must precede 'abstract' modifier.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMixedWithModifiers.ts(9,14): error TS1029: 'protected' modifier must precede 'abstract' modifier.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMixedWithModifiers.ts(10,14): error TS1237: 'private' modifier cannot be used with 'abstract' modifier.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMixedWithModifiers.ts(12,14): error TS1237: 'static' modifier cannot be used with 'abstract' modifier.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMixedWithModifiers.ts(14,12): error TS1237: 'static' modifier cannot be used with 'abstract' modifier.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMixedWithModifiers.ts(10,14): error TS1243: 'private' modifier cannot be used with 'abstract' modifier.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMixedWithModifiers.ts(12,14): error TS1243: 'static' modifier cannot be used with 'abstract' modifier.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMixedWithModifiers.ts(14,12): error TS1243: 'static' modifier cannot be used with 'abstract' modifier.
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMixedWithModifiers.ts (6 errors) ====
@@ -14,7 +14,7 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst
protected abstract foo_c();
private abstract foo_d();
~~~~~~~~
!!! error TS1237: 'private' modifier cannot be used with 'abstract' modifier.
!!! error TS1243: 'private' modifier cannot be used with 'abstract' modifier.
abstract public foo_bb();
~~~~~~
@@ -24,13 +24,13 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst
!!! error TS1029: 'protected' modifier must precede 'abstract' modifier.
abstract private foo_dd();
~~~~~~~
!!! error TS1237: 'private' modifier cannot be used with 'abstract' modifier.
!!! error TS1243: 'private' modifier cannot be used with 'abstract' modifier.
abstract static foo_d();
~~~~~~
!!! error TS1237: 'static' modifier cannot be used with 'abstract' modifier.
!!! error TS1243: 'static' modifier cannot be used with 'abstract' modifier.
static abstract foo_e();
~~~~~~~~
!!! error TS1237: 'static' modifier cannot be used with 'abstract' modifier.
!!! error TS1243: 'static' modifier cannot be used with 'abstract' modifier.
}

View File

@@ -1,6 +1,6 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(7,5): error TS2512: Overload signatures must all be `abstract` or not `abstract.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(10,14): error TS2512: Overload signatures must all be `abstract` or not `abstract.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(12,14): error TS2512: Overload signatures must all be `abstract` or not `abstract.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(7,5): error TS2512: Overload signatures must all be abstract or not abstract.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(10,14): error TS2512: Overload signatures must all be abstract or not abstract.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(12,14): error TS2512: Overload signatures must all be abstract or not abstract.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(15,5): error TS2391: Function implementation is missing or not immediately following the declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractOverloads.ts(20,14): error TS2516: All declarations of an abstract method must be consecutive.
@@ -14,16 +14,16 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst
abstract bar();
bar();
~~~
!!! error TS2512: Overload signatures must all be `abstract` or not `abstract.
!!! error TS2512: Overload signatures must all be abstract or not abstract.
abstract bar();
abstract baz();
~~~
!!! error TS2512: Overload signatures must all be `abstract` or not `abstract.
!!! error TS2512: Overload signatures must all be abstract or not abstract.
baz();
abstract baz();
~~~
!!! error TS2512: Overload signatures must all be `abstract` or not `abstract.
!!! error TS2512: Overload signatures must all be abstract or not abstract.
baz() {}
qux();

View File

@@ -1,34 +1,34 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(2,5): error TS1236: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(3,12): error TS1236: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(4,15): error TS1236: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(5,13): error TS1236: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(7,5): error TS1236: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(12,13): error TS1237: 'private' modifier cannot be used with 'abstract' modifier.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(2,5): error TS1242: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(3,12): error TS1242: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(4,15): error TS1242: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(5,13): error TS1242: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(7,5): error TS1242: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts(12,13): error TS1243: 'private' modifier cannot be used with 'abstract' modifier.
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractProperties.ts (6 errors) ====
abstract class A {
abstract x : number;
~~~~~~~~
!!! error TS1236: 'abstract' modifier can only appear on a class or method declaration.
!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration.
public abstract y : number;
~~~~~~~~
!!! error TS1236: 'abstract' modifier can only appear on a class or method declaration.
!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration.
protected abstract z : number;
~~~~~~~~
!!! error TS1236: 'abstract' modifier can only appear on a class or method declaration.
!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration.
private abstract w : number;
~~~~~~~~
!!! error TS1236: 'abstract' modifier can only appear on a class or method declaration.
!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration.
abstract m: () => void;
~~~~~~~~
!!! error TS1236: 'abstract' modifier can only appear on a class or method declaration.
!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration.
abstract foo_x() : number;
public abstract foo_y() : number;
protected abstract foo_z() : number;
private abstract foo_w() : number;
~~~~~~~~
!!! error TS1237: 'private' modifier cannot be used with 'abstract' modifier.
!!! error TS1243: 'private' modifier cannot be used with 'abstract' modifier.
}

View File

@@ -1,16 +1,13 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethods2.ts(1,7): error TS2514: Classes containing abstract methods must be marked abstract.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethods2.ts(2,5): error TS1238: Abstract methods can only appear within an abstract class.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethods2.ts(2,5): error TS1244: Abstract methods can only appear within an abstract class.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethods2.ts(5,7): error TS2515: Non-abstract class 'B' does not implement inherited abstract member 'foo' from class 'A'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethods2.ts(21,7): error TS2515: Non-abstract class 'BB' does not implement inherited abstract member 'foo' from class 'AA'.
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethods2.ts (4 errors) ====
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractUsingAbstractMethods2.ts (3 errors) ====
class A {
~
!!! error TS2514: Classes containing abstract methods must be marked abstract.
abstract foo();
~~~~~~~~
!!! error TS1238: Abstract methods can only appear within an abstract class.
!!! error TS1244: Abstract methods can only appear within an abstract class.
}
class B extends A {}

View File

@@ -1,7 +1,7 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractWithInterface.ts(1,1): error TS1236: 'abstract' modifier can only appear on a class or method declaration.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractWithInterface.ts(1,1): error TS1242: 'abstract' modifier can only appear on a class or method declaration.
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractWithInterface.ts (1 errors) ====
abstract interface I {}
~~~~~~~~
!!! error TS1236: 'abstract' modifier can only appear on a class or method declaration.
!!! error TS1242: 'abstract' modifier can only appear on a class or method declaration.