Give some love to the linter

This commit is contained in:
dcodeIO 2018-03-13 14:03:57 +01:00
parent 23a7db4dc3
commit 081ac768ae
34 changed files with 526 additions and 401 deletions

View File

@ -534,7 +534,7 @@ exports.main = function main(argv, options, callback) {
function readFileNode(filename) {
try {
var text;
let text;
stats.readCount++;
stats.readTime += measure(() => {
text = fs.readFileSync(filename, { encoding: "utf8" });

2
dist/asc.js vendored

File diff suppressed because one or more lines are too long

2
dist/asc.js.map vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

41
lib/lint/README.md Normal file
View File

@ -0,0 +1,41 @@
![AS](https://avatars1.githubusercontent.com/u/28916798?s=48) lint
======================
Recommended [TSLint](https://github.com/palantir/tslint) rules for use with AssemblyScript. Meant to spot the most common issues as you type.
Not a sophisticated checker in its current state.
Usage
-----
Add the following `tslint.json` to your project:
```json
{
"extends": "@assemblyscript/lint"
}
```
Add additional rules if necessary.
Add a script to your `package.json`:
```json
"scripts": {
"lint": "tslint -c tslint.json --project ./path/to[/tsconfig.json] --format as"
}
```
Now, to check your sources, run:
```
$> npm run lint
```
If you are using [Visual Studio Code](https://code.visualstudio.com/), there's also a [TSLint extension](https://marketplace.visualstudio.com/items?itemName=eg2.tslint) that highlights issues as you type.
Custom rules
------------
* **as-types** checks that all types are annotated or have an initializer.
* **as-variables** checks the use of `var` and `let` to match their semantic meaning. For reference, `var` becomes a distinct local or mutable global, while `let` becomes a shared local.

118
lib/lint/base.json Normal file
View File

@ -0,0 +1,118 @@
{
"rules": {
"adjacent-overload-signatures": {},
"ban-types": {
"severity": "error",
"options": [
["object", "Not supported."],
["any", "Not supported."],
["undefined", "Not supported."],
["never", "Not supported."],
["number", "Use one of the WebAssembly types instead."],
["boolean", "Use `bool` instead."]
]
},
"object-literal-shorthand": {
"severity": "error",
"options": ["never"]
},
"restrict-plus-operands": {
"severity": "error"
},
"curly": {
"options": ["ignore-same-line"]
},
"deprecation": {},
"encoding": {
"severity": "error"
},
"eofline": {},
"label-position": {
"severity": "error"
},
"new-parens": {
"severity": "error"
},
"no-any": {
"severity": "error"
},
"no-arg": {
"severity": "error"
},
"no-consecutive-blank-lines": {},
"no-debugger": {
"severity": "error"
},
"no-default-export": {
"severity": "error"
},
"no-duplicate-imports": {
"severity": "error"
},
"no-duplicate-super": {
"severity": "error"
},
"no-duplicate-switch-case": {
"severity": "error"
},
"no-duplicate-variable": {
"severity": "error"
},
"no-eval": {
"severity": "error"
},
"no-inferred-empty-object-type": {
"severity": "error"
},
"no-internal-module": {
"severity": "error"
},
"no-invalid-template-strings": {
"severity": "error"
},
"no-invalid-this": {
"severity": "error"
},
"no-irregular-whitespace": {},
"no-misused-new": {
"severity": "error"
},
"no-object-literal-type-assertion": {
"severity": "error"
},
"no-parameter-properties": {
"severity": "error"
},
"no-require-imports": {
"severity": "error"
},
"no-shadowed-variable": {},
"no-sparse-arrays": {},
"no-string-literal": {
"severity": "error"
},
"no-string-throw": {
"severity": "error"
},
"no-trailing-whitespace": {},
"no-unbound-method": {
"severity": "error"
},
"no-unsafe-any": {
"severity": "error"
},
"no-unused-variable": {
"options": [{
"ignore-pattern": "^_"
}]
},
"no-void-expression": {
"severity": "error"
},
"prefer-method-signature": {},
"radix": {},
"semicolon": {
"options": ["always"]
}
}
}

View File

@ -0,0 +1,50 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const abstractFormatter_1 = require("tslint/lib/language/formatter/abstractFormatter");
const colorBlue = "\u001b[93m";
const colorYellow = "\u001b[93m";
const colorRed = "\u001b[91m";
const colorReset = "\u001b[0m";
class Formatter extends abstractFormatter_1.AbstractFormatter {
format(failures) {
return `${this.mapToMessages(failures).join("\n")}\n`;
}
mapToMessages(failures) {
return failures.map((failure) => {
var fileName = failure.getFileName();
var failureString = failure.getFailure();
var ruleName = failure.getRuleName();
var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
var positionTuple = `:${lineAndCharacter.line + 1}:${lineAndCharacter.character + 1}`;
if (this.lastSeverity == failure.getRuleSeverity() && this.lastFailure == failureString) {
return " in " + fileName + positionTuple;
}
else {
let message = this.lastSeverity ? "\n" : "";
switch (this.lastSeverity = failure.getRuleSeverity()) {
case "warning": {
message += colorYellow + "WARNING:" + colorReset;
break;
}
case "error": {
message += colorRed + "ERROR:" + colorReset;
break;
}
default: {
message += failure.getRuleSeverity();
break;
}
}
this.lastFailure = failureString;
return message + " " + failureString + " [" + ruleName + "]\n in " + fileName + positionTuple;
}
});
}
}
Formatter.metadata = {
formatterName: "as",
description: "AssemblyScript's TSLint formatter.",
sample: "Similar to ASC's output.",
consumer: "human",
};
exports.Formatter = Formatter;

11
lib/lint/index.json Normal file
View File

@ -0,0 +1,11 @@
{
"extends": "./base.json",
"rulesDirectory": ["./rules", "./rules/internal"],
"formattersDirectory": ["./formatters"],
"rules": {
"as-types": {
"severity": "error"
},
"as-variables": {}
}
}

21
lib/lint/package.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "@assemblyscript/lint",
"version": "1.0.0",
"main": "index.json",
"scripts": {
"build": "tsc --project ./src --outDir . --diagnostics"
},
"peerDependencies": {
"tslint": "^5.9.1"
},
"devDependencies": {
"typescript": "^2.7.2"
},
"files": [
"index.json",
"package.json",
"README.md",
"rules/",
"formatters/"
]
}

View File

@ -0,0 +1,58 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ts = require("typescript");
const Lint = require("tslint");
class Rule extends Lint.Rules.AbstractRule {
apply(sourceFile) {
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
}
}
Rule.MISSING_TYPE_OR_INITIALIZER = "Missing type or initializer.";
Rule.MISSING_RETURN_TYPE = "Missing return type.";
exports.Rule = Rule;
class DiagnosticsWalker extends Lint.RuleWalker {
visitVariableDeclaration(node) {
var list = node.parent;
if (list) {
let stmt = list.parent;
if (stmt && stmt.kind != ts.SyntaxKind.ForOfStatement) {
this.checkTypeOrInitializer(node);
}
}
super.visitVariableDeclaration(node);
}
visitPropertyDeclaration(node) {
this.checkTypeOrInitializer(node);
super.visitPropertyDeclaration(node);
}
visitParameterDeclaration(node) {
this.checkTypeOrInitializer(node);
super.visitParameterDeclaration(node);
}
checkTypeOrInitializer(node) {
if (!node.type && !node.initializer) {
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
}
}
visitFunctionDeclaration(node) {
this.checkFunctionReturnType(node);
super.visitFunctionDeclaration(node);
}
visitArrowFunction(node) {
this.checkFunctionReturnType(node);
super.visitArrowFunction(node);
}
visitMethodDeclaration(node) {
this.checkFunctionReturnType(node);
super.visitMethodDeclaration(node);
}
visitGetAccessor(node) {
this.checkFunctionReturnType(node);
super.visitGetAccessor(node);
}
checkFunctionReturnType(node) {
if (!node.type) {
this.addFailureAtNode(node, Rule.MISSING_RETURN_TYPE);
}
}
}

View File

@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Lint = require("tslint");
const tsutils_1 = require("tsutils");
class Rule extends Lint.Rules.AbstractRule {
apply(sourceFile) {
return this.applyWithWalker(new VariablesWalker(sourceFile, this.getOptions()));
}
}
Rule.TOP_LEVEL_VAR = "Top-level variable should be 'var' (distinct local or global).";
Rule.BLOCK_LEVEL_LET = "Block-level variable should be 'let' (shared local).";
exports.Rule = Rule;
class VariablesWalker extends Lint.RuleWalker {
visitVariableDeclarationList(node) {
if (tsutils_1.isVariableStatement(node.parent)) {
if (tsutils_1.isBlock(node.parent.parent)) {
if (tsutils_1.isFunctionScopeBoundary(node.parent.parent.parent) ||
tsutils_1.isNamespaceDeclaration(node.parent.parent.parent)) {
if (tsutils_1.getVariableDeclarationKind(node) == 1 /* Let */) {
this.addFailureAtNode(node, Rule.TOP_LEVEL_VAR);
}
}
else if (tsutils_1.getVariableDeclarationKind(node) == 0 /* Var */) {
this.addFailureAtNode(node, Rule.BLOCK_LEVEL_LET);
}
}
else if (tsutils_1.isSourceFile(node.parent.parent) ||
tsutils_1.isModuleBlock(node.parent.parent)) {
if (tsutils_1.getVariableDeclarationKind(node) == 1 /* Let */) {
this.addFailureAtNode(node, Rule.TOP_LEVEL_VAR);
}
}
else if (tsutils_1.getVariableDeclarationKind(node) == 0 /* Var */) {
this.addFailureAtNode(node, Rule.BLOCK_LEVEL_LET);
}
}
else if (tsutils_1.getVariableDeclarationKind(node) == 0 /* Var */) {
this.addFailureAtNode(node, Rule.BLOCK_LEVEL_LET);
}
super.visitVariableDeclarationList(node);
}
}

View File

@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ts = require("typescript");
const Lint = require("tslint");
const tsutils_1 = require("tsutils");
class Rule extends Lint.Rules.AbstractRule {
apply(sourceFile) {
return this.applyWithWalker(new CaseWalker(sourceFile, this.getOptions()));
}
}
Rule.NOT_BRACED = "Multi-line case clauses should be braced.";
exports.Rule = Rule;
class CaseWalker extends Lint.RuleWalker {
visitDefaultClause(node) {
this.checkDefaultOrCaseClause(node);
super.visitDefaultClause(node);
}
visitCaseClause(node) {
this.checkDefaultOrCaseClause(node);
super.visitCaseClause(node);
}
checkDefaultOrCaseClause(node) {
var count = node.statements.length;
if (count > 1) {
this.addFailureAtNode(node, Rule.NOT_BRACED);
}
else if (count == 1) {
let stmt = node.statements[0];
if (stmt.kind != ts.SyntaxKind.Block) {
if (!tsutils_1.isSameLine(node.getSourceFile(), node.getStart(), stmt.getStart())) {
this.addFailureAtNode(node, Rule.NOT_BRACED);
}
}
}
}
}

View File

@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ts = require("typescript");
const Lint = require("tslint");
const tsutils_1 = require("tsutils");
class Rule extends Lint.Rules.AbstractRule {
apply(sourceFile) {
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
}
}
Rule.NOT_ON_SEPARATE_LINE = "Diagnostic message not on a separate line.";
exports.Rule = Rule;
class DiagnosticsWalker extends Lint.RuleWalker {
visitPropertyAccessExpression(node) {
if (node.expression.kind === ts.SyntaxKind.Identifier) {
if (node.expression.text == "DiagnosticCode" &&
tsutils_1.isSameLine(node.getSourceFile(), node.parent.getStart(), node.getStart())) {
this.addFailureAtNode(node, Rule.NOT_ON_SEPARATE_LINE);
}
}
super.visitPropertyAccessExpression(node);
}
}

View File

@ -0,0 +1,68 @@
import * as ts from "typescript";
import * as Lint from "tslint";
export class Rule extends Lint.Rules.AbstractRule {
static MISSING_TYPE_OR_INITIALIZER = "Missing type or initializer.";
static MISSING_RETURN_TYPE = "Missing return type.";
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
}
}
class DiagnosticsWalker extends Lint.RuleWalker {
visitVariableDeclaration(node: ts.VariableDeclaration) {
var list = node.parent;
if (list) {
let stmt = list.parent;
if (stmt && stmt.kind != ts.SyntaxKind.ForOfStatement) {
this.checkTypeOrInitializer(node);
}
}
super.visitVariableDeclaration(node);
}
visitPropertyDeclaration(node: ts.PropertyDeclaration) {
this.checkTypeOrInitializer(node);
super.visitPropertyDeclaration(node);
}
visitParameterDeclaration(node: ts.ParameterDeclaration) {
this.checkTypeOrInitializer(node);
super.visitParameterDeclaration(node);
}
private checkTypeOrInitializer(node: ts.NamedDeclaration & { type?: ts.TypeNode, initializer?: ts.Expression }) {
if (!node.type && !node.initializer) {
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
}
}
visitFunctionDeclaration(node: ts.FunctionDeclaration) {
this.checkFunctionReturnType(node);
super.visitFunctionDeclaration(node);
}
visitArrowFunction(node: ts.ArrowFunction) {
this.checkFunctionReturnType(node);
super.visitArrowFunction(node);
}
visitMethodDeclaration(node: ts.MethodDeclaration) {
this.checkFunctionReturnType(node);
super.visitMethodDeclaration(node);
}
visitGetAccessor(node: ts.GetAccessorDeclaration) {
this.checkFunctionReturnType(node);
super.visitGetAccessor(node);
}
private checkFunctionReturnType(node: ts.FunctionLikeDeclaration) {
if (!node.type) {
this.addFailureAtNode(node, Rule.MISSING_RETURN_TYPE);
}
}
}

View File

@ -18,11 +18,11 @@ export class Rule extends Lint.Rules.AbstractRule {
static BLOCK_LEVEL_LET = "Block-level variable should be 'let' (shared local).";
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
return this.applyWithWalker(new VariablesWalker(sourceFile, this.getOptions()));
}
}
class DiagnosticsWalker extends Lint.RuleWalker {
class VariablesWalker extends Lint.RuleWalker {
visitVariableDeclarationList(node: ts.VariableDeclarationList): void {
if (isVariableStatement(node.parent)) {

View File

@ -7,11 +7,11 @@ export class Rule extends Lint.Rules.AbstractRule {
static NOT_BRACED = "Multi-line case clauses should be braced.";
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
return this.applyWithWalker(new CaseWalker(sourceFile, this.getOptions()));
}
}
class DiagnosticsWalker extends Lint.RuleWalker {
class CaseWalker extends Lint.RuleWalker {
visitDefaultClause(node: ts.DefaultClause) {
this.checkDefaultOrCaseClause(node);

View File

@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"module": "commonjs",
"lib": ["es6", "es2015.collection"]
},

View File

@ -1,63 +0,0 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var abstractFormatter_1 = require("tslint/lib/language/formatter/abstractFormatter");
var colorBlue = "\u001b[93m";
var colorYellow = "\u001b[93m";
var colorRed = "\u001b[91m";
var colorReset = "\u001b[0m";
var Formatter = /** @class */ (function (_super) {
__extends(Formatter, _super);
function Formatter() {
return _super !== null && _super.apply(this, arguments) || this;
}
Formatter.prototype.format = function (failures) {
return this.mapToMessages(failures).join("\n") + "\n";
};
Formatter.prototype.mapToMessages = function (failures) {
var _this = this;
return failures.map(function (failure) {
var fileName = failure.getFileName();
var failureString = failure.getFailure();
var ruleName = failure.getRuleName();
var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
var positionTuple = ":" + (lineAndCharacter.line + 1) + ":" + (lineAndCharacter.character + 1);
if (_this.lastSeverity == failure.getRuleSeverity() && _this.lastFailure == failureString) {
return " in " + fileName + positionTuple;
}
else {
var message = _this.lastSeverity ? "\n" : "";
switch (_this.lastSeverity = failure.getRuleSeverity()) {
case "warning":
message += colorYellow + "WARNING:" + colorReset;
break;
case "error":
message += colorRed + "ERROR:" + colorReset;
break;
default:
message += failure.getRuleSeverity();
break;
}
_this.lastFailure = failureString;
return message + " " + failureString + " [" + ruleName + "]\n in " + fileName + positionTuple;
}
});
};
Formatter.metadata = {
formatterName: "as",
description: "AssemblyScript's TSLint formatter.",
sample: "Similar to ASC's output.",
consumer: "human"
};
return Formatter;
}(abstractFormatter_1.AbstractFormatter));
exports.Formatter = Formatter;

View File

@ -1,55 +0,0 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var ts = require("typescript");
var Lint = require("tslint");
var Rule = /** @class */ (function (_super) {
__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
};
Rule.MISSING_TYPE_OR_INITIALIZER = "Missing type or initializer.";
Rule.MISSING_RETURN_TYPE = "Missing return type.";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
var DiagnosticsWalker = /** @class */ (function (_super) {
__extends(DiagnosticsWalker, _super);
function DiagnosticsWalker() {
return _super !== null && _super.apply(this, arguments) || this;
}
DiagnosticsWalker.prototype.visitVariableDeclaration = function (node) {
if (!node.type && !node.initializer &&
node.parent.parent.kind != ts.SyntaxKind.ForOfStatement) {
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
}
};
DiagnosticsWalker.prototype.visitPropertyDeclaration = function (node) {
if (!node.type && !node.initializer) {
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
}
};
DiagnosticsWalker.prototype.visitParameterDeclaration = function (node) {
if (!node.type && !node.initializer) {
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
}
};
DiagnosticsWalker.prototype.visitFunctionDeclaration = function (node) {
if (!node.type) {
this.addFailureAtNode(node, Rule.MISSING_RETURN_TYPE);
}
};
return DiagnosticsWalker;
}(Lint.RuleWalker));

View File

@ -1,42 +0,0 @@
import * as ts from "typescript";
import * as Lint from "tslint";
export class Rule extends Lint.Rules.AbstractRule {
static MISSING_TYPE_OR_INITIALIZER = "Missing type or initializer.";
static MISSING_RETURN_TYPE = "Missing return type.";
apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
}
}
class DiagnosticsWalker extends Lint.RuleWalker {
visitVariableDeclaration(node: ts.VariableDeclaration) {
if (
!node.type && !node.initializer &&
node.parent.parent.kind != ts.SyntaxKind.ForOfStatement
) {
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
}
}
visitPropertyDeclaration(node: ts.PropertyDeclaration) {
if (!node.type && !node.initializer) {
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
}
}
visitParameterDeclaration(node: ts.ParameterDeclaration) {
if (!node.type && !node.initializer) {
this.addFailureAtNode(node, Rule.MISSING_TYPE_OR_INITIALIZER);
}
}
visitFunctionDeclaration(node: ts.FunctionDeclaration) {
if (!node.type) {
this.addFailureAtNode(node, Rule.MISSING_RETURN_TYPE);
}
}
}

View File

@ -1,62 +0,0 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var Lint = require("tslint");
var tsutils_1 = require("tsutils");
var Rule = /** @class */ (function (_super) {
__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
};
Rule.TOP_LEVEL_VAR = "Top-level variable should be 'var' (distinct local or global).";
Rule.BLOCK_LEVEL_LET = "Block-level variable should be 'let' (shared local).";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
var DiagnosticsWalker = /** @class */ (function (_super) {
__extends(DiagnosticsWalker, _super);
function DiagnosticsWalker() {
return _super !== null && _super.apply(this, arguments) || this;
}
DiagnosticsWalker.prototype.visitVariableDeclarationList = function (node) {
if (tsutils_1.isVariableStatement(node.parent)) {
if (tsutils_1.isBlock(node.parent.parent)) {
if (tsutils_1.isFunctionScopeBoundary(node.parent.parent.parent) ||
tsutils_1.isNamespaceDeclaration(node.parent.parent.parent)) {
if (tsutils_1.getVariableDeclarationKind(node) == 1 /* Let */) {
this.addFailureAtNode(node, Rule.TOP_LEVEL_VAR);
}
}
else if (tsutils_1.getVariableDeclarationKind(node) == 0 /* Var */) {
this.addFailureAtNode(node, Rule.BLOCK_LEVEL_LET);
}
}
else if (tsutils_1.isSourceFile(node.parent.parent) ||
tsutils_1.isModuleBlock(node.parent.parent)) {
if (tsutils_1.getVariableDeclarationKind(node) == 1 /* Let */) {
this.addFailureAtNode(node, Rule.TOP_LEVEL_VAR);
}
}
else if (tsutils_1.getVariableDeclarationKind(node) == 0 /* Var */) {
this.addFailureAtNode(node, Rule.BLOCK_LEVEL_LET);
}
}
else if (tsutils_1.getVariableDeclarationKind(node) == 0 /* Var */) {
this.addFailureAtNode(node, Rule.BLOCK_LEVEL_LET);
}
_super.prototype.visitVariableDeclarationList.call(this, node);
};
return DiagnosticsWalker;
}(Lint.RuleWalker));

View File

@ -1,56 +0,0 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var ts = require("typescript");
var Lint = require("tslint");
var tsutils_1 = require("tsutils");
var Rule = /** @class */ (function (_super) {
__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
};
Rule.NOT_BRACED = "Multi-line case clauses should be braced.";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
var DiagnosticsWalker = /** @class */ (function (_super) {
__extends(DiagnosticsWalker, _super);
function DiagnosticsWalker() {
return _super !== null && _super.apply(this, arguments) || this;
}
DiagnosticsWalker.prototype.visitDefaultClause = function (node) {
this.checkDefaultOrCaseClause(node);
_super.prototype.visitDefaultClause.call(this, node);
};
DiagnosticsWalker.prototype.visitCaseClause = function (node) {
this.checkDefaultOrCaseClause(node);
_super.prototype.visitCaseClause.call(this, node);
};
DiagnosticsWalker.prototype.checkDefaultOrCaseClause = function (node) {
var count = node.statements.length;
if (count > 1) {
this.addFailureAtNode(node, Rule.NOT_BRACED);
}
else if (count == 1) {
var stmt = node.statements[0];
if (stmt.kind != ts.SyntaxKind.Block) {
if (!tsutils_1.isSameLine(node.getSourceFile(), node.getStart(), stmt.getStart())) {
this.addFailureAtNode(node, Rule.NOT_BRACED);
}
}
}
};
return DiagnosticsWalker;
}(Lint.RuleWalker));

View File

@ -1,43 +0,0 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var ts = require("typescript");
var Lint = require("tslint");
var tsutils_1 = require("tsutils");
var Rule = /** @class */ (function (_super) {
__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions()));
};
Rule.NOT_ON_SEPARATE_LINE = "Diagnostic message not on a separate line.";
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
var DiagnosticsWalker = /** @class */ (function (_super) {
__extends(DiagnosticsWalker, _super);
function DiagnosticsWalker() {
return _super !== null && _super.apply(this, arguments) || this;
}
DiagnosticsWalker.prototype.visitPropertyAccessExpression = function (node) {
if (node.expression.kind === ts.SyntaxKind.Identifier) {
if (node.expression.text == "DiagnosticCode" &&
tsutils_1.isSameLine(node.getSourceFile(), node.parent.getStart(), node.getStart())) {
this.addFailureAtNode(node, Rule.NOT_ON_SEPARATE_LINE);
}
}
_super.prototype.visitPropertyAccessExpression.call(this, node);
};
return DiagnosticsWalker;
}(Lint.RuleWalker));

View File

@ -41,8 +41,8 @@
"build": "webpack --mode production",
"clean": "node scripts/clean",
"lint": "npm run lint:compiler && npm run lint:library",
"lint:compiler": "tslint -c tslint.json --project src --formatters-dir lib/tslint --format as",
"lint:library": "tslint -c tslint.json --project std/assembly --formatters-dir lib/tslint --format as",
"lint:compiler": "tslint -c tslint.json --project src --formatters-dir lib/lint/formatters --format as",
"lint:library": "tslint -c tslint.json --project std/assembly --formatters-dir lib/lint/formatters --format as",
"test:config": "tsc --noEmit -p src --diagnostics --listFiles",
"test:parser": "node tests/parser",
"test:compiler": "node tests/compiler",

View File

@ -119,7 +119,7 @@ export abstract class Node {
static createOmittedType(
range: Range
) {
): TypeNode {
return Node.createType(
Node.createIdentifierExpression("", range),
null,

View File

@ -1892,7 +1892,11 @@ export class Compiler extends DiagnosticEmitter {
return expr;
}
compileExpressionRetainType(expression: Expression, contextualType: Type, wrapSmallIntegers: bool = true) {
compileExpressionRetainType(
expression: Expression,
contextualType: Type,
wrapSmallIntegers: bool = true
): ExpressionRef {
return this.compileExpression(
expression,
contextualType == Type.void

View File

@ -27,7 +27,7 @@ export class Decompiler {
constructor() { }
/** Decompiles a module to an AST that can then be serialized. */
decompile(module: Module) {
decompile(module: Module): void {
throw new Error("not implemented");
}

View File

@ -215,7 +215,7 @@ export abstract class DiagnosticEmitter {
arg0: string | null = null,
arg1: string | null = null,
arg2: string | null = null
) {
): void {
var message = DiagnosticMessage.create(code, category, arg0, arg1, arg2).withRange(range);
this.diagnostics.push(message);
// console.log(formatDiagnosticMessage(message, true, true) + "\n"); // temporary

View File

@ -223,7 +223,7 @@ export class MemorySegment {
buffer: Uint8Array;
offset: I64;
static create(buffer: Uint8Array, offset: I64) {
static create(buffer: Uint8Array, offset: I64): MemorySegment {
var segment = new MemorySegment();
segment.buffer = buffer;
segment.offset = offset;

View File

@ -612,7 +612,7 @@ export class Program extends DiagnosticEmitter {
decorators: DecoratorNode[] | null,
prototype: FunctionPrototype,
classPrototype: ClassPrototype
) {
): void {
// handle operator annotations. operators are either instance methods taking
// a second argument of the instance's type or static methods taking two
// arguments of the instance's type. return values vary depending on the

View File

@ -1,9 +1,9 @@
{
"extends": "../assembly.json",
"compilerOptions": {
"diagnostics": true
},
"include": [
"./**/*.ts"
],
"exclude": [
"./collector/*.ts"
]
}

View File

@ -1,67 +1,41 @@
{
"rulesDirectory": [
"./lib/tslint",
"./lib/tslint/internal"
],
"extends": "./lib/lint",
"defaultSeverity": "warning",
"rules": {
"as-types": { "severity": "error" },
"as-variables": true,
"as-internal-case": true,
"as-internal-diagnostics": true,
"adjacent-overload-signatures": true,
"ban-types": [ true, ["Object"], ["any"], ["undefined"], ["never"] ],
"curly": [true, "ignore-same-line"],
"deprecation": true,
"encoding": true,
"eofline": true,
"indent": [true, "spaces", 2],
"label-position": true,
"max-line-length": [ true, { "limit": 120, "ignore-pattern": " *DiagnosticCode\\.[^ ]+,$" } ],
"member-access": [ true, "no-public" ],
"new-parens": true,
"no-any": true,
"no-arg": true,
"no-consecutive-blank-lines": true,
"no-debugger": true,
"no-default-export": true,
"no-duplicate-imports": true,
"no-duplicate-super": true,
"no-duplicate-switch-case": true,
"no-duplicate-variable": true,
"no-eval": true,
"no-inferred-empty-object-type": true,
"no-internal-module": true,
"no-invalid-template-strings": true,
"no-invalid-this": true,
"no-irregular-whitespace": true,
"no-mergeable-namespace": true,
"no-misused-new": true,
"no-object-literal-type-assertion": true,
"no-parameter-properties": true,
"no-require-imports": true,
"no-shadowed-variable": true,
"no-sparse-arrays": true,
"no-string-literal": true,
"no-string-throw": true,
"no-trailing-whitespace": true,
"no-unbound-method": true,
"no-unsafe-any": true,
"no-unused-variable": [true, {"ignore-pattern": "^_"}],
"no-void-expression": true,
"object-literal-shorthand": [ true, "never" ],
"prefer-method-signature": true,
"quotemark": [true, "double"],
"radix": true,
"restrict-plus-operands": true,
"semicolon": [true, "always"]
"as-internal-case": {},
"as-internal-diagnostics": {},
"indent": {
"options": ["spaces", 2]
},
"max-line-length": {
"options": [{
"limit": 120,
"ignore-pattern": " *DiagnosticCode\\.[^ ]+,$"
}]
},
"member-access": {
"options": ["no-public"]
},
"quotemark": {
"options": ["double"]
},
"semicolon": {
"options": ["always"]
}
},
"jsRules": {
"quotemark": [true, "double"],
"radix": true,
"max-line-length": [ true, { "limit": 120, "ignore-pattern": " *DiagnosticCode\\.[^ ]+,$" } ],
"semicolon": [true, "always"]
"max-line-length": {
"options": [{
"limit": 120,
"ignore-pattern": " *DiagnosticCode\\.[^ ]+,$"
}]
},
"quotemark": {
"options": ["double"]
},
"radix": {},
"semicolon": {
"options": ["always"]
}
}
}