Skip to content

Commit

Permalink
Enable tslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheyne committed Feb 26, 2017
1 parent f5bfa46 commit d54c5e8
Show file tree
Hide file tree
Showing 27 changed files with 259 additions and 203 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ before_script:
- npm prune
script:
- npm run typings
- npm run format
- npm test
- npm run lint
- git diff --exit-code HEAD
- npm test
after_success:
- npm run semantic-release
branches:
Expand Down
18 changes: 9 additions & 9 deletions interpreters/dfa/dfa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export class DFAGraph {
// startState: DFANode;
}

export type Nodes = DFANode
export type Edges = DFAEdge
export type Graph = DFAGraph
export type Nodes = DFANode;
export type Edges = DFAEdge;
export type Graph = DFAGraph;

export class State {
constructor(public active: DFANode,
Expand All @@ -30,8 +30,8 @@ export class State {
}

function isEmpty(label?: string) {
if (label != undefined) {
if (label != "") {
if (label !== undefined) {
if (label !== "") {
return false;
}
}
Expand Down Expand Up @@ -76,7 +76,7 @@ export function start(input: DFAGraph, data: string): State | boolean {
if (!start) {
throw new Error("Must have one start state");
}
if (accepts.size == 0) {
if (accepts.size === 0) {
throw new Error("Must have at least one accept state");
}

Expand All @@ -85,16 +85,16 @@ export function start(input: DFAGraph, data: string): State | boolean {

export function step(current: State): State | boolean {
if (current.inputLeft.length === 0) {
return current.active.isAcceptState == true;
return current.active.isAcceptState === true;
}
const destinations = current.active.children
.filter(edge => edge.label === current.inputLeft[0])
.map(edge => edge.destination);

if (destinations.length == 1) {
if (destinations.length === 1) {
return new State(destinations[0], current.inputLeft.substr(1),
`transitioning from ${current.active.label} to ${destinations[0].label}`);
} else if (destinations.length == 0) {
} else if (destinations.length === 0) {
return false;
} else {
throw "This is a DFA!";
Expand Down
16 changes: 8 additions & 8 deletions interpreters/nfa/nfa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export class NFAGraph {
// startState: NFANode;
}

export type Nodes = NFANode
export type Edges = NFAEdge
export type Graph = NFAGraph
export type Nodes = NFANode;
export type Edges = NFAEdge;
export type Graph = NFAGraph;

export class State {
constructor(public active: NFANode[],
Expand All @@ -29,8 +29,8 @@ export class State {
}

function isEmpty(label?: string) {
if (label != undefined) {
if (label != "") {
if (label !== undefined) {
if (label !== "") {
return false;
}
}
Expand Down Expand Up @@ -69,7 +69,7 @@ export function start(input: NFAGraph, data: string): State | boolean {
if (!start) {
throw new Error("Must have one start state");
}
if (accepts.size == 0) {
if (accepts.size === 0) {
throw new Error("Must have at least one accept state");
}

Expand All @@ -78,13 +78,13 @@ export function start(input: NFAGraph, data: string): State | boolean {

export function step(current: State): State | boolean {
if (current.inputLeft.length === 0) {
return current.active.reduce((a, b) => b.isAcceptState == true || a, false);
return current.active.reduce((a, b) => b.isAcceptState === true || a, false);
}
const destinations = current.active.reduce((dests, a) => dests.concat(a.children), [] as NFAEdge[])
.filter(edge => edge.label === current.inputLeft[0])
.map(edge => edge.destination);

if (destinations.length == 0) {
if (destinations.length === 0) {
return false;
} else {
return new State(destinations, current.inputLeft.substr(1));
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
}
},
"scripts": {
"format": "tsfmt -r --baseDir ./src/ && tsfmt -r --baseDir ./tests/",
"formater": "tsfmt -r ./src/*.ts && tsfmt -r ./test/*.ts && tsfmt -r ./sinap-includes/*.ts",
"formater:verify": "tsfmt --verify ./src/*.ts && tsfmt --verify ./test/*.ts && tsfmt --verify ./sinap-includes/*.ts",
"format": "npm run formater && tslint --project . --fix",
"lint": "npm run formater:verify && tslint --project .",
"clean": "rm -r ./lib/ ./test/build/ ./node_modules/ ./typings/",
"build": "webpack",
"typings": "typings install",
Expand All @@ -43,7 +46,8 @@
"raw-loader": "0.5.1",
"semantic-release": "^6.3.2",
"ts-loader": "2.0.0",
"typescript-formatter": "latest",
"tslint": "^4.4.2",
"typescript-formatter": "^4.1.2",
"typings": "^2.1.0",
"webpack": "2.2.1",
"webpack-merge": "2.6.1",
Expand Down
4 changes: 2 additions & 2 deletions sinap-includes/plugin-stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function deserialize(pojo: SerialJSO): Graph {
traverse(el);
}
}
}
};

traverse(elements);

Expand Down Expand Up @@ -119,7 +119,7 @@ export class Program implements PluginProgram {
} catch (e) {
return {
error: e
}
};
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export class CoreModel {

/**
* Create a new CoreModel. If `pojo` is provided, build the model from the
* serial represnetation.
*
* serial represnetation.
*
* Note that this modifies the pojo object given and once it is passed to this
* constructor, it should not be reused.
* constructor, it should not be reused.
*/
constructor(private plugin: Plugin, pojo?: SerialJSO) {
if (pojo === undefined) {
Expand All @@ -47,12 +47,12 @@ export class CoreModel {
assert.deepEqual(plugin.pluginKind, pojo.kind);

if (pojo.format !== "sinap-file-format" || pojo.version !== "0.0.7") {
throw Error("not a CoreModel");;
throw Error("not a CoreModel");
}

this.elements = pojo.elements.map((e) => this.plugin.makeElement(CoreElementKind[e.kind as any] as any, e.type));

// TODO: typecheck all values against plugin-declared.
// TODO: typecheck all values against plugin-declared.
const traverse = (a: any) => {
if (typeof (a) !== "object") {
return;
Expand All @@ -65,7 +65,7 @@ export class CoreModel {
traverse(el);
}
}
}
};

traverse(pojo.elements);

Expand All @@ -87,13 +87,13 @@ export class CoreModel {
removeElement(element: CoreElement) {
const idx = this.elements.indexOf(element);
if (idx === -1) {
throw Error("element doesn't exist");;
throw Error("element doesn't exist");
}
this.elements.splice(idx, 1);
}

/**
* Generate an acyclic JS object which can be used to reconstruct this
* Generate an acyclic JS object which can be used to reconstruct this
* model.
*/
serialize(): SerialJSO {
Expand Down
4 changes: 2 additions & 2 deletions src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ export interface FileService {
}

export interface AppLocations {
currentDirectory: Directory,
pluginDirectory: Directory
currentDirectory: Directory;
pluginDirectory: Directory;
}
20 changes: 10 additions & 10 deletions src/plugin-loader.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as ts from "typescript";
import { File, FileService, readAsJson, Directory, Plugin, CompilationResult } from ".";

const pluginFileKey = 'plugin-file';
const pluginKindKey = 'kind'
const pluginFileKey = "plugin-file";
const pluginKindKey = "kind";

const options: ts.CompilerOptions = {
noEmitOnError: false,
Expand Down Expand Up @@ -32,9 +32,9 @@ function getInterpreterInfo(directory: Directory): Promise<InterpreterInfo> {
const fileArr: [string, File][] = pluginFiles.map((file): [string, File] => [file.name, file]);
const fileMap = new Map(fileArr);
// TODO run npm install.
return nullPromise(fileMap.get('package.json'), `package.json for plugin ${directory.fullName}`)
return nullPromise(fileMap.get("package.json"), `package.json for plugin ${directory.fullName}`)
.then((npmFile: File): Promise<InterpreterInfo> => {
return readAsJson(npmFile).then((pluginJson): Promise<InterpreterInfo> => nullPromise(pluginJson.sinap, 'sinap'))
return readAsJson(npmFile).then((pluginJson): Promise<InterpreterInfo> => nullPromise(pluginJson.sinap, "sinap"))
.then((sinapJson) => {
const filePromise = nullPromise(sinapJson[pluginFileKey], `sinap.${pluginFileKey}`);
const pluginKind = nullPromise(sinapJson[pluginKindKey], `sinap.${pluginKindKey}`);
Expand All @@ -49,7 +49,7 @@ function getInterpreterInfo(directory: Directory): Promise<InterpreterInfo> {
}

/**
* An abstract representation of a plugin
* An abstract representation of a plugin
*/
function loadPlugin(pluginInfo: InterpreterInfo, fileService: FileService): Promise<Plugin> {
const pluginLocation = pluginInfo.interp;
Expand All @@ -76,7 +76,7 @@ function loadPlugin(pluginInfo: InterpreterInfo, fileService: FileService): Prom
};
program.emit();
if (script === undefined) {
throw Error("failed to emit");;
throw Error("failed to emit");
}
const compInfo = new CompilationResult(script, results);
return new Plugin(program, compInfo, pluginInfo.pluginKind);
Expand All @@ -85,7 +85,7 @@ function loadPlugin(pluginInfo: InterpreterInfo, fileService: FileService): Prom

export function printDiagnostics(diagnostics: ts.Diagnostic[]) {
for (const result of diagnostics) {
console.log()
console.log();
if (result.file) {
const { line, character } = result.file.getLineAndCharacterOfPosition(result.start);
const starts = result.file.getLineStarts();
Expand All @@ -110,9 +110,9 @@ function createCompilerHost(files: Map<string, string>, options: ts.CompilerOpti
getSourceFile: (fileName): ts.SourceFile => {
let source = files.get(fileName);
if (!source) {
// if we didn't bundle the source file, maybe it's a lib?
// if we didn't bundle the source file, maybe it's a lib?
if (fileName.indexOf("/") !== -1) {
throw Error("no relative/absolute paths here");;
throw Error("no relative/absolute paths here");
}
source = fileService.getModuleFile(fileService.joinPath("typescript", "lib", fileName));
}
Expand All @@ -133,7 +133,7 @@ function createCompilerHost(files: Map<string, string>, options: ts.CompilerOpti
getCurrentDirectory: () => "",
getNewLine: () => "\n",
fileExists: (fileName): boolean => {
return files.has(fileName)
return files.has(fileName);
},
readFile: () => "",
directoryExists: () => true,
Expand Down
8 changes: 4 additions & 4 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function unionToList(type: Type): [string, ObjectType][] {
} else if (type instanceof ObjectType) {
return [[type.name, type]];
}
throw `type must be a union type or an object type.`
throw `type must be a union type or an object type.`;

}

Expand Down Expand Up @@ -74,19 +74,19 @@ export class PluginTypeEnvironment extends TypeEnvironment {
elementTypes(kind: CoreElementKind) {
const type = this.pluginTypes.get(kindToKey(kind));
if (type === undefined) {
throw Error("kind not found");;
throw Error("kind not found");
}
return type.keys();
}

getElementType(kind: CoreElementKind, type: string): ObjectType {
const t = this.pluginTypes.get(kindToKey(kind));
if (t === undefined) {
throw Error("kind not found");;
throw Error("kind not found");
}
const ty = t.get(type);
if (ty === undefined) {
throw Error("type not found");;
throw Error("type not found");
}
return ty;
}
Expand Down
2 changes: 1 addition & 1 deletion src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PluginProgram, isError } from "../sinap-includes/plugin-program";
import { CoreValue, Plugin, IType, Type, UnionType, FakeUnionType } from ".";

function signatureAssignable(t1: IType[], t2: IType[]) {
return t1.reduce((a, v, i) => a && v.isAssignableTo(t2[i]), true)
return t1.reduce((a, v, i) => a && v.isAssignableTo(t2[i]), true);
}

function pickReturnType(argTypes: IType[], signatures: [Type[], Type][], stateType: Type): IType {
Expand Down
10 changes: 5 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function hasAssignableFrom(t: Type | AssignableFrom): t is AssignableFrom {

/**
* Store a mapping of typescript types to our wrappers.
*
*
* In order to avoid infinite loops, we need to cache the ones
* that we find.
* that we find.
*/
export class TypeEnvironment {
private types = new Map<ts.Type, Type>();
Expand Down Expand Up @@ -64,7 +64,7 @@ export class Type implements interfaces.Type {
}
// TODO: protect the arguments
/**
* Never call this manually, use getType on the appropriate
* Never call this manually, use getType on the appropriate
* TypeEnvironment
*/
constructor(public env: TypeEnvironment, public type: ts.Type) {
Expand Down Expand Up @@ -102,7 +102,7 @@ export class FakeUnionType implements interfaces.Type {
* Return if this type is assignable to that type
*/
public isAssignableTo(that: Type, cond = (that: UnionType) => (acc: boolean, t: Type, i: number) => acc && t.isAssignableTo(that.types[i])) {
if ((that.type as any).intrinsicName === 'any') {
if ((that.type as any).intrinsicName === "any") {
return true;
}
if (that instanceof UnionType) {
Expand Down Expand Up @@ -136,7 +136,7 @@ export class ObjectType extends Type implements interfaces.ObjectType {
constructor(env: TypeEnvironment, type: ts.ObjectType) {
super(env, type);
if (this.type.symbol === undefined || this.type.symbol.members === undefined) {
//throw Error("not an object type");;
// throw Error("not an object type");
// TODO: address this
return;
}
Expand Down
Loading

0 comments on commit d54c5e8

Please sign in to comment.