Merge pull request #1422 from tridactyl/add_tslint_sonarts

Add tslint sonarts
This commit is contained in:
Oliver Blanthorn 2019-03-31 15:24:31 +01:00 committed by GitHub
commit a2cf6671f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 283 additions and 122 deletions

View file

@ -10,6 +10,7 @@ script:
- npm install
- npm run test
- npm run lint
- bash -c '"$(npm bin)/tslint" --project .'
notifications:
webhooks:

View file

@ -9,19 +9,19 @@ export class ClassMetadata {
>(),
) {}
setMember(name: string, s: SymbolMetadata) {
public setMember(name: string, s: SymbolMetadata) {
this.members.set(name, s)
}
getMember(name: string) {
public getMember(name: string) {
return this.members.get(name)
}
getMembers() {
public getMembers() {
return this.members.keys()
}
toConstructor() {
public toConstructor() {
return (
`new ClassMetadata(new Map<string, SymbolMetadata>([` +
Array.from(this.members.entries())

View file

@ -1,5 +1,5 @@
import { SymbolMetadata } from "./SymbolMetadata"
import { ClassMetadata } from "./ClassMetadata"
import { SymbolMetadata } from "./SymbolMetadata"
export class FileMetadata {
constructor(
@ -13,35 +13,35 @@ export class FileMetadata {
>(),
) {}
setClass(name: string, c: ClassMetadata) {
public setClass(name: string, c: ClassMetadata) {
this.classes.set(name, c)
}
getClass(name: string) {
public getClass(name: string) {
return this.classes.get(name)
}
getClasses() {
public getClasses() {
return Array.from(this.classes.keys())
}
setFunction(name: string, f: SymbolMetadata) {
public setFunction(name: string, f: SymbolMetadata) {
this.functions.set(name, f)
}
getFunction(name: string) {
public getFunction(name: string) {
return this.functions.get(name)
}
getFunctions() {
public getFunctions() {
return Array.from(this.functions.entries())
}
getFunctionNames() {
public getFunctionNames() {
return Array.from(this.functions.keys())
}
toConstructor() {
public toConstructor() {
return (
`new FileMetadata(new Map<string, ClassMetadata>([` +
Array.from(this.classes.entries())

View file

@ -8,15 +8,15 @@ export class ProgramMetadata {
>(),
) {}
setFile(name: string, file: FileMetadata) {
public setFile(name: string, file: FileMetadata) {
this.files.set(name, file)
}
getFile(name: string) {
public getFile(name: string) {
return this.files.get(name)
}
toConstructor() {
public toConstructor() {
return (
`new ProgramMetadata(new Map<string, FileMetadata>([` +
Array.from(this.files.entries())

View file

@ -3,7 +3,7 @@ import { Type } from "../types/AllTypes"
export class SymbolMetadata {
constructor(public doc: string, public type: Type, public hidden = false) {}
toConstructor() {
public toConstructor() {
return `new SymbolMetadata(${JSON.stringify(
this.doc,
)}, ${this.type.toConstructor()}, ${this.hidden})`

View file

@ -1,20 +1,18 @@
import { Type } from "./Type"
export class AnyType implements Type {
static instance = new AnyType()
kind = "any"
public static instance = new AnyType()
public kind = "any"
constructor() {}
toConstructor() {
public toConstructor() {
return "AnyType.instance"
}
toString() {
public toString() {
return this.kind
}
convert(argument) {
public convert(argument) {
return argument
}
}

View file

@ -1,19 +1,19 @@
import { Type } from "./Type"
export class ArrayType implements Type {
kind = "array"
public kind = "array"
constructor(public elemType: Type) {}
toConstructor() {
public toConstructor() {
return `new ArrayType(${this.elemType.toConstructor()})`
}
toString() {
public toString() {
return `${this.elemType.toString()}[]`
}
convert(argument) {
public convert(argument) {
if (!Array.isArray(argument)) {
try {
argument = JSON.parse(argument)

View file

@ -1,22 +1,23 @@
import { Type } from "./Type"
export class BooleanType implements Type {
static instance = new BooleanType()
kind = "boolean"
public static instance = new BooleanType()
public kind = "boolean"
constructor() {}
toConstructor() {
public toConstructor() {
return "BooleanType.instance"
}
toString() {
public toString() {
return this.kind
}
convert(argument) {
if (argument === "true") return true
else if (argument === "false") return false
public convert(argument) {
if (argument === "true") {
return true
} else if (argument === "false") {
return false
}
throw new Error("Can't convert ${argument} to boolean")
}
}

View file

@ -1,11 +1,11 @@
import { Type } from "./Type"
export class FunctionType implements Type {
kind = "function"
public kind = "function"
constructor(public args: Type[], public ret: Type) {}
toConstructor() {
public toConstructor() {
return (
`new FunctionType([` +
// Convert every argument type to its string constructor representation
@ -14,11 +14,11 @@ export class FunctionType implements Type {
)
}
toString() {
public toString() {
return `(${this.args.map(a => a.toString()).join(", ")}) => ${this.ret.toString()}`
}
convert(argument) {
public convert(argument) {
// Possible strategies:
// - eval()
// - window[argument]

View file

@ -1,20 +1,22 @@
import { Type } from "./Type"
export class LiteralTypeType implements Type {
kind = "LiteralType"
public kind = "LiteralType"
constructor(public value: string) {}
toConstructor() {
public toConstructor() {
return `new LiteralTypeType(${JSON.stringify(this.value)})`
}
toString() {
public toString() {
return JSON.stringify(this.value)
}
convert(argument) {
if (argument === this.value) return argument
public convert(argument) {
if (argument === this.value) {
return argument
}
throw new Error(
`Argument does not match expected value (${
this.value

View file

@ -1,24 +1,26 @@
import { Type } from "./Type"
export class NumberType implements Type {
static instance = new NumberType()
kind = "number"
public static instance = new NumberType()
public kind = "number"
constructor() {}
toConstructor() {
public toConstructor() {
return "NumberType.instance"
}
toString() {
public toString() {
return this.kind
}
convert(argument) {
public convert(argument) {
let n = parseInt(argument)
if (!Number.isNaN(n)) return n
if (!Number.isNaN(n)) {
return n
}
n = parseFloat(argument)
if (!Number.isNaN(n)) return n
if (!Number.isNaN(n)) {
return n
}
throw new Error(`Can't convert to number: ${argument}`)
}
}

View file

@ -1,23 +1,23 @@
import { Type } from "./Type"
export class ObjectType implements Type {
kind = "object"
public kind = "object"
// Note: a map that has an empty key ("") uses the corresponding type as default type
constructor(public members: Map<string, Type> = new Map<string, Type>()) {}
toConstructor() {
public toConstructor() {
return `new ObjectType(new Map<string, Type>([` +
Array.from(this.members.entries()).map(([n, m]) => `[${JSON.stringify(n)}, ${m.toConstructor()}]`)
.join(", ") +
`]))`
}
toString() {
public toString() {
return this.kind
}
convertMember(memberName: string[], memberValue: string) {
public convertMember(memberName: string[], memberValue: string) {
let type = this.members.get(memberName[0])
if (!type) {
// No type, try to get the default type
@ -27,13 +27,13 @@ export class ObjectType implements Type {
return memberValue
}
}
if (type.kind == "object") {
if (type.kind === "object") {
return (type as ObjectType).convertMember(memberName.slice(1), memberValue)
}
return type.convert(memberValue)
}
convert(argument) {
public convert(argument) {
try {
return JSON.parse(argument)
} catch (e) {

View file

@ -1,21 +1,23 @@
import { Type } from "./Type"
export class StringType implements Type {
static instance = new StringType()
kind = "string"
public static instance = new StringType()
public kind = "string"
constructor() {}
toConstructor() {
public toConstructor() {
return "StringType.instance"
}
toString() {
public toString() {
return this.kind
}
convert(argument) {
if (typeof argument === "string") return argument
public convert(argument) {
if (typeof argument === "string") {
return argument
}
throw new Error(`Can't convert to string: ${argument}`)
}
}

View file

@ -1,11 +1,11 @@
import { Type } from "./Type"
export class TupleType implements Type {
kind = "tuple"
public kind = "tuple"
constructor(public elemTypes: Type[]) {}
toConstructor() {
public toConstructor() {
return (
`new TupleType([` +
// Convert every element type to its constructor representation
@ -14,11 +14,11 @@ export class TupleType implements Type {
)
}
toString() {
public toString() {
return `[${this.elemTypes.map(e => e.toString()).join(", ")}]`
}
convert(argument) {
public convert(argument) {
if (!Array.isArray(argument)) {
try {
argument = JSON.parse(argument)
@ -29,7 +29,7 @@ export class TupleType implements Type {
throw new Error(`Can't convert to tuple: ${argument}`)
}
}
if (argument.length != this.elemTypes.length) {
if (argument.length !== this.elemTypes.length) {
throw new Error(
`Error converting tuple: number of elements and type mismatch ${argument}`,
)

View file

@ -5,5 +5,5 @@ export interface Type {
name?: string
toConstructor(): string
toString(): string
convert: (argument: string) => any
convert(argument: string): any
}

View file

@ -1,9 +1,9 @@
import { Type } from "./Type"
export class TypeReferenceType implements Type {
constructor(public kind: string, public args: Type[]) {}
public constructor(public kind: string, public args: Type[]) {}
toConstructor() {
public toConstructor() {
return (
`new TypeReferenceType(${JSON.stringify(this.kind)}, [` +
// Turn every type argument into its constructor representation
@ -12,11 +12,11 @@ export class TypeReferenceType implements Type {
)
}
toString() {
public toString() {
return `${this.kind}<${this.args.map(a => a.toString()).join(", ")}>`
}
convert(argument) {
public convert(argument) {
throw new Error("Conversion of simple type references not implemented.")
}
}

View file

@ -1,11 +1,11 @@
import { Type } from "./Type"
export class UnionType implements Type {
kind = "union"
public kind = "union"
constructor(public types: Type[]) {}
toConstructor() {
public toConstructor() {
return (
`new UnionType([` +
// Convert every type to its string constructor representation
@ -14,12 +14,12 @@ export class UnionType implements Type {
)
}
toString() {
public toString() {
return this.types.map(t => t.toString()).join(" | ")
}
convert(argument) {
for (let t of this.types) {
public convert(argument) {
for (const t of this.types) {
try {
return t.convert(argument)
} catch (e) {}

View file

@ -1,20 +1,20 @@
import { Type } from "./Type"
export class VoidType implements Type {
static instance = new VoidType()
kind = "void"
public static instance = new VoidType()
public kind = "void"
constructor() {}
toConstructor() {
public toConstructor() {
return "VoidType.instance"
}
toString() {
public toString() {
return this.kind
}
convert(argument) {
public convert(argument) {
return null
}
}

131
package-lock.json generated
View file

@ -2148,6 +2148,12 @@
"integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=",
"dev": true
},
"builtin-modules": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz",
"integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=",
"dev": true
},
"builtin-status-codes": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz",
@ -2855,7 +2861,7 @@
"dev": true
},
"csp-serdes": {
"version": "github:cmcaine/csp-serdes#6c6fe34dbd138855e5c26f331b094e9a75358a64",
"version": "github:cmcaine/csp-serdes#91876274b0bfa5cd10ceebabe9f8cb29b0ccd7aa",
"from": "github:cmcaine/csp-serdes"
},
"css": {
@ -4520,8 +4526,7 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"aproba": {
"version": "1.2.0",
@ -4542,14 +4547,12 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -4564,20 +4567,17 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
@ -4694,8 +4694,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
@ -4707,7 +4706,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -4722,7 +4720,6 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -4730,14 +4727,12 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -4756,7 +4751,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -4837,8 +4831,7 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"object-assign": {
"version": "4.1.1",
@ -4850,7 +4843,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -4936,8 +4928,7 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"safer-buffer": {
"version": "2.1.2",
@ -4973,7 +4964,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -4993,7 +4983,6 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -5037,14 +5026,12 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
}
}
},
@ -5626,6 +5613,12 @@
"integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==",
"dev": true
},
"immutable": {
"version": "3.8.2",
"resolved": "https://registry.npmjs.org/immutable/-/immutable-3.8.2.tgz",
"integrity": "sha1-wkOZUUVbs5kT2vKBN28VMOEErfM=",
"dev": true
},
"import-fresh": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.0.0.tgz",
@ -10583,6 +10576,82 @@
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==",
"dev": true
},
"tslint": {
"version": "5.14.0",
"resolved": "https://registry.npmjs.org/tslint/-/tslint-5.14.0.tgz",
"integrity": "sha512-IUla/ieHVnB8Le7LdQFRGlVJid2T/gaJe5VkjzRVSRR6pA2ODYrnfR1hmxi+5+au9l50jBwpbBL34txgv4NnTQ==",
"dev": true,
"requires": {
"babel-code-frame": "^6.22.0",
"builtin-modules": "^1.1.1",
"chalk": "^2.3.0",
"commander": "^2.12.1",
"diff": "^3.2.0",
"glob": "^7.1.1",
"js-yaml": "^3.7.0",
"minimatch": "^3.0.4",
"mkdirp": "^0.5.1",
"resolve": "^1.3.2",
"semver": "^5.3.0",
"tslib": "^1.8.0",
"tsutils": "^2.29.0"
},
"dependencies": {
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "^1.9.0"
}
},
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
"dev": true
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"requires": {
"has-flag": "^3.0.0"
}
}
}
},
"tslint-sonarts": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/tslint-sonarts/-/tslint-sonarts-1.9.0.tgz",
"integrity": "sha512-CJWt+IiYI8qggb2O/JPkS6CkC5DY1IcqRsm9EHJ+AxoWK70lvtP7jguochyNDMP2vIz/giGdWCfEM39x/I/Vnw==",
"dev": true,
"requires": {
"immutable": "^3.8.2"
}
},
"tsutils": {
"version": "2.29.0",
"resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz",
"integrity": "sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==",
"dev": true,
"requires": {
"tslib": "^1.8.1"
}
},
"tty-browserify": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz",

View file

@ -27,6 +27,8 @@
"source-map-loader": "^0.2.4",
"ts-jest": "^24.0.0",
"ts-node": "^8.0.2",
"tslint": "^5.14.0",
"tslint-sonarts": "^1.9.0",
"typedoc": "^0.14.2",
"typedoc-default-themes": "git://github.com/tridactyl/typedoc-default-themes.git#fix_weird_member_names_bin",
"typescript": "^3.3.3333",

View file

@ -13,12 +13,12 @@ export function jack_in() {
"",
)
const colour = "#0F0" //green text
rain(chinese,colour)
rain(chinese, colour)
}
export let snow = () => rain(["❄"],"#FFF",0.15)
export let snow = () => rain(["❄"], "#FFF", 0.15)
export function rain(characters: string[], colour, darkening=0.05){
export function rain(characters: string[], colour, darkening = 0.05) {
let d = document.createElement("div")
d.style.position = "fixed"
d.style.display = "block"
@ -53,7 +53,7 @@ export function rain(characters: string[], colour, darkening=0.05){
function draw() {
//Black BG for the canvas
//translucent BG to show trail
ctx.fillStyle = "rgba(0, 0, 0, "+darkening+")"
ctx.fillStyle = "rgba(0, 0, 0, " + darkening + ")"
ctx.fillRect(0, 0, c.width, c.height)
ctx.fillStyle = colour

84
tslint.json Normal file
View file

@ -0,0 +1,84 @@
{
"extends": ["tslint:recommended", "tslint-sonarts"],
"rules": {
"align": false,
"array-type": false,
"arrow-parens": false,
"ban-types": false,
"bool-param-default": false,
"callable-types": false,
"class-name": false,
"cognitive-complexity": false,
"comment-format": false,
"curly": false,
"forin": false,
"if-filter": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-classes-per-file": false,
"max-line-length": false,
"max-union-size": false,
"member-access": false,
"member-ordering": false,
"missing-whitespace": false,
"no-angle-bracket-type-assertion": false,
"no-array-delete": false,
"no-big-function": false,
"no-bitwise": false,
"no-collapsible-if": false,
"no-commented-code": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-console": false,
"no-construct": false,
"no-dead-store": false,
"no-duplicate-string": false,
"no-empty": false,
"no-eval": false,
"no-extra-semicolon": false,
"no-identical-functions": false,
"no-ignored-return": false,
"no-map-without-using": false,
"no-misleading-array-reverse": false,
"no-nested-template-literals": false,
"no-nexted-template-literals": false,
"no-redundant-boolean": false,
"no-redundant-jump": false,
"no-self-assignment": false,
"no-shadowed-variable": false,
"no-small-switch": false,
"no-string-literal": false,
"no-string-throw": false,
"no-trailing-whitespace": false,
"no-try-promise": false,
"no-unenclosed-multiline-block": false,
"no-unnecessary-initializer": false,
"no-unnecessary-type-assertion": false,
"no-unsafe-finally": false,
"no-unused-expression": false,
"no-useless-cast": false,
"no-useless-catch": false,
"no-useless-catch": false,
"no-var-keyword": false,
"no-variable-usage-before-declaration": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"object-literal-sort-keys": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"ordered-imports": false,
"prefer-const": false,
"prefer-immediate-return": false,
"prefer-promise-shorthand": false,
"quotemark": false,
"radix": false,
"semicolon": false,
"trailing-comma": false,
"triple-equals": false,
"use-primitive-type": false,
"variable-name": false,
"whitespace": false
}
}