Comparing version 0.1.2 to 0.1.3
export * from './server-host'; | ||
export * from './logger'; | ||
export * from './utils'; | ||
//# sourceMappingURL=index.d.ts.map |
import { server } from 'typescript/lib/tsserverlibrary'; | ||
export declare const logger: server.Logger; | ||
//# sourceMappingURL=logger.d.ts.map |
"use strict"; | ||
/* istanbul ignore file */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -3,0 +4,0 @@ exports.logger = { |
import { server } from 'typescript/lib/tsserverlibrary'; | ||
export declare const serverHost: server.ServerHost; | ||
//# sourceMappingURL=server-host.d.ts.map |
"use strict"; | ||
/* istanbul ignore file */ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -3,0 +4,0 @@ const tsserverlibrary_1 = require("typescript/lib/tsserverlibrary"); |
import { DiagnosticMessageChain } from 'typescript/lib/tsserverlibrary'; | ||
export declare function getDeepestMessageText(message: DiagnosticMessageChain | string): string; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -24,2 +24,1 @@ import { ValidatorOptions, GeneralValidatorTypeOptions } from './validator'; | ||
} | ||
//# sourceMappingURL=@worker-messages.d.ts.map |
export {}; | ||
//# sourceMappingURL=@worker.d.ts.map |
export * from './tiva'; | ||
export * from './validator'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -16,2 +16,1 @@ /// <reference types="node" /> | ||
} | ||
//# sourceMappingURL=tiva.d.ts.map |
@@ -30,3 +30,5 @@ "use strict"; | ||
this.worker.postMessage(initializeRequest); | ||
this.nextRequest().catch(error => this.emit('error', error)); | ||
this.nextRequest().catch( | ||
/* istanbul ignore next */ | ||
error => this.emit('error', error)); | ||
} | ||
@@ -58,2 +60,3 @@ async validate(type, object) { | ||
let handlers = this.requestPromiseHandlers.shift(); | ||
/* istanbul ignore else */ | ||
if (handlers) { | ||
@@ -60,0 +63,0 @@ let [resolve, reject] = handlers; |
@@ -6,2 +6,1 @@ import { ValidatorExtensions } from './validator'; | ||
export declare const builtInExtensions: ValidatorExtensions<BuiltInValidatorExtensionContext>; | ||
//# sourceMappingURL=@built-in-extensions.d.ts.map |
export * from './validator'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -33,3 +33,3 @@ import { Dict } from 'tslang'; | ||
private context; | ||
constructor(options: ValidatorOptions); | ||
constructor(options?: ValidatorOptions); | ||
diagnose(type: GeneralValidatorTypeOptions, value: unknown): string[] | undefined; | ||
@@ -39,2 +39,1 @@ private validateWithExtensions; | ||
} | ||
//# sourceMappingURL=validator.d.ts.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
class Validator { | ||
constructor(options) { | ||
constructor(options = {}) { | ||
this.options = options; | ||
@@ -34,2 +34,3 @@ this.projectPath = this.options.project | ||
let scriptInfo = this.projectService.getScriptInfo(this.validatorFilePath); | ||
/* istanbul ignore if */ | ||
if (!scriptInfo) { | ||
@@ -86,13 +87,26 @@ throw new Error('Expecting script info present'); | ||
let extensionMap = this.extensionMap; | ||
let tags = tsserverlibrary_1.getJSDocTags(node); | ||
let tags = tsutils_1.getJsDoc(node).flatMap((doc) => { | ||
let text = doc.getText(); | ||
let tags = []; | ||
let regex = /^(?:\/\*\*[ \t]*|[ \t]*(?:\*[ \t]*)?)@([\w-]+)(?:[ \t]+((?:(?!\*\/$).)+?))?\s*?(?:\*\/)?$/gm; | ||
let group; | ||
// eslint-disable-next-line no-cond-assign | ||
while ((group = regex.exec(text))) { | ||
tags.push({ | ||
name: group[1], | ||
comment: group[2], | ||
}); | ||
} | ||
return tags; | ||
}); | ||
let tagExtensionPairs = tags | ||
.map(tag => [tag, extensionMap.get(tag.tagName.getText())]) | ||
.map(tag => [tag, extensionMap.get(tag.name)]) | ||
.filter((pair) => !!pair[1]); | ||
if (tagExtensionPairs.length) { | ||
let extensionReasons = this.extensionReasons; | ||
let sourceFileName = node.getSourceFile().fileName; | ||
let values = this.findValuesByDefinition(node); | ||
for (let value of values) { | ||
for (let [tag, extension] of tagExtensionPairs) { | ||
let comment = tag.comment; | ||
let tagUniqueId = `${tag.getSourceFile().fileName}:${tag.getStart()}`; | ||
for (let [{ name, comment }, extension] of tagExtensionPairs) { | ||
let tagUniqueId = `${sourceFileName}:${node.getStart()}:${name}`; | ||
let reason = extension(value, comment, this.context, tagUniqueId); | ||
@@ -112,2 +126,3 @@ if (typeof reason === 'string') { | ||
// TODO: when is member.name undefined? | ||
/* istanbul ignore else */ | ||
if (member.name) { | ||
@@ -120,2 +135,3 @@ this.validateWithExtensions(member); | ||
let definitions = this.languageService.getDefinitionAtPosition(node.getSourceFile().fileName, node.typeName.getEnd()); | ||
/* istanbul ignore else */ | ||
if (definitions) { | ||
@@ -160,3 +176,3 @@ let program = this.program; | ||
findValuesByDefinition(node) { | ||
let references = this.languageService.getImplementationAtPosition(node.getSourceFile().fileName, node.name.getStart()) || []; | ||
let references = this.languageService.getImplementationAtPosition(node.getSourceFile().fileName, node.name.getStart()) || /* istanbul ignore next */ []; | ||
let validatorFilePath = this.validatorFilePath; | ||
@@ -169,3 +185,5 @@ return references | ||
let parent = tsutils_1.getTokenAtPosition(this.sourceFile, reference.textSpan.start).parent; | ||
return parent && tsserverlibrary_1.isPropertyAssignment(parent) ? parent : undefined; | ||
return parent && tsserverlibrary_1.isPropertyAssignment(parent) | ||
? parent | ||
: /* istanbul ignore next */ undefined; | ||
}) | ||
@@ -172,0 +190,0 @@ .filter((assignment) => !!assignment) |
{ | ||
"name": "tiva", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Expensive plain object type validator leverages TypeScript language service.", | ||
@@ -11,7 +11,8 @@ "license": "MIT", | ||
"scripts": { | ||
"build": "tsc --project src/library", | ||
"lint-prettier": "prettier --check \"**/*.{ts,tsx,js,jsx,json,yml,md}\"", | ||
"lint-ts": "eslint 'src/**/*.ts'", | ||
"build": "tsc --build", | ||
"lint-prettier": "prettier --with-node-modules --check \"**/*.{ts,tsx,js,jsx,json,yml,md}\"", | ||
"lint-ts": "eslint \"src/**/*.ts\"", | ||
"lint": "yarn lint-prettier && yarn lint-ts", | ||
"test": "rimraf bld && yarn build && yarn lint" | ||
"test": "rimraf bld && yarn build && yarn lint && yarn jest", | ||
"report-coverage": "cat coverage/lcov.info | coveralls" | ||
}, | ||
@@ -22,11 +23,16 @@ "main": "bld/library/index.js", | ||
"src/library/**/*.ts", | ||
"bld/library" | ||
"bld/library", | ||
"!*.tsbuildinfo" | ||
], | ||
"devDependencies": { | ||
"@magicspace/configs": "^0.2.2", | ||
"@magicspace/eslint-plugin": "^0.1.2", | ||
"@magicspace/eslint-plugin": "^0.1.4", | ||
"@types/jest": "^24.0.23", | ||
"@types/node": "^12.12.3", | ||
"@types/validator": "^10.11.3", | ||
"coveralls": "^3.0.7", | ||
"eslint": "^6.6.0", | ||
"prettier": "^1.19.0" | ||
"jest": "^24.9.0", | ||
"prettier": "^1.19.0", | ||
"ts-jest": "^24.1.0" | ||
}, | ||
@@ -33,0 +39,0 @@ "dependencies": { |
[![NPM Package](https://badge.fury.io/js/tiva.svg)](https://www.npmjs.com/package/tiva) | ||
[![Build Status](https://travis-ci.org/makeflow/tiva.svg?branch=master)](https://travis-ci.org/makeflow/tiva) | ||
[![Coverage Status](https://coveralls.io/repos/github/makeflow/tiva/badge.svg?branch=master)](https://coveralls.io/github/makeflow/tiva?branch=master) | ||
@@ -4,0 +5,0 @@ # Tiva |
@@ -0,1 +1,3 @@ | ||
/* istanbul ignore file */ | ||
import {server} from 'typescript/lib/tsserverlibrary'; | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
/* istanbul ignore file */ | ||
import {sys, server, FileWatcher} from 'typescript/lib/tsserverlibrary'; | ||
@@ -2,0 +4,0 @@ |
@@ -42,3 +42,6 @@ import {EventEmitter} from 'events'; | ||
this.nextRequest().catch(error => this.emit('error', error)); | ||
this.nextRequest().catch( | ||
/* istanbul ignore next */ | ||
error => this.emit('error', error), | ||
); | ||
} | ||
@@ -91,2 +94,3 @@ | ||
/* istanbul ignore else */ | ||
if (handlers) { | ||
@@ -93,0 +97,0 @@ let [resolve, reject] = handlers; |
import * as Path from 'path'; | ||
import {getTokenAtPosition} from 'tsutils'; | ||
import {getTokenAtPosition, getJsDoc} from 'tsutils'; | ||
import {Dict} from 'tslang'; | ||
import { | ||
getJSDocTags, | ||
isArrayTypeNode, | ||
@@ -21,3 +20,2 @@ isClassDeclaration, | ||
isUnionTypeNode, | ||
JSDocTag, | ||
LanguageService, | ||
@@ -99,3 +97,3 @@ Node, | ||
constructor(private options: ValidatorOptions) { | ||
constructor(private options: ValidatorOptions = {}) { | ||
this.projectService = new server.ProjectService({ | ||
@@ -125,2 +123,3 @@ host: serverHost, | ||
/* istanbul ignore if */ | ||
if (!scriptInfo) { | ||
@@ -215,7 +214,30 @@ throw new Error('Expecting script info present'); | ||
let tags = getJSDocTags(node); | ||
interface DocTag { | ||
name: string; | ||
comment: string | undefined; | ||
} | ||
let tags = getJsDoc(node).flatMap((doc): DocTag[] => { | ||
let text = doc.getText(); | ||
let tags: DocTag[] = []; | ||
let regex = /^(?:\/\*\*[ \t]*|[ \t]*(?:\*[ \t]*)?)@([\w-]+)(?:[ \t]+((?:(?!\*\/$).)+?))?\s*?(?:\*\/)?$/gm; | ||
let group: RegExpExecArray | null; | ||
// eslint-disable-next-line no-cond-assign | ||
while ((group = regex.exec(text))) { | ||
tags.push({ | ||
name: group[1], | ||
comment: group[2], | ||
}); | ||
} | ||
return tags; | ||
}); | ||
let tagExtensionPairs = tags | ||
.map(tag => [tag, extensionMap.get(tag.tagName.getText())]) | ||
.filter((pair): pair is [JSDocTag, ValidatorExtension] => !!pair[1]); | ||
.map(tag => [tag, extensionMap.get(tag.name)]) | ||
.filter((pair): pair is [DocTag, ValidatorExtension] => !!pair[1]); | ||
@@ -225,10 +247,8 @@ if (tagExtensionPairs.length) { | ||
let sourceFileName = node.getSourceFile().fileName; | ||
let values = this.findValuesByDefinition(node); | ||
for (let value of values) { | ||
for (let [tag, extension] of tagExtensionPairs) { | ||
let comment = tag.comment; | ||
let tagUniqueId = `${ | ||
tag.getSourceFile().fileName | ||
}:${tag.getStart()}`; | ||
for (let [{name, comment}, extension] of tagExtensionPairs) { | ||
let tagUniqueId = `${sourceFileName}:${node.getStart()}:${name}`; | ||
@@ -252,2 +272,3 @@ let reason = extension(value, comment, this.context, tagUniqueId); | ||
// TODO: when is member.name undefined? | ||
/* istanbul ignore else */ | ||
if (member.name) { | ||
@@ -263,2 +284,3 @@ this.validateWithExtensions(member); | ||
/* istanbul ignore else */ | ||
if (definitions) { | ||
@@ -310,3 +332,3 @@ let program = this.program; | ||
node.name.getStart(), | ||
) || []; | ||
) || /* istanbul ignore next */ []; | ||
@@ -326,3 +348,5 @@ let validatorFilePath = this.validatorFilePath; | ||
return parent && isPropertyAssignment(parent) ? parent : undefined; | ||
return parent && isPropertyAssignment(parent) | ||
? parent | ||
: /* istanbul ignore next */ undefined; | ||
}) | ||
@@ -329,0 +353,0 @@ .filter((assignment): assignment is PropertyAssignment => !!assignment) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1051
54
53099
10
47