make ts compiler options more strict

This commit is contained in:
Kim Biesbjerg 2019-09-18 13:36:08 +02:00
parent 7bf0c138b8
commit 8c8fe8d131
5 changed files with 16 additions and 13 deletions

View File

@ -9,12 +9,12 @@ const MARKER_IMPORT_NAME = 'marker';
export class MarkerParser implements ParserInterface {
public extract(contents: string, filePath: string): TranslationCollection | null {
const sourceFile = tsquery.ast(contents, filePath);
public extract(source: string, filePath: string): TranslationCollection | null {
const sourceFile = tsquery.ast(source, filePath);
const markerImportName = getNamedImportAlias(sourceFile, MARKER_MODULE_NAME, MARKER_IMPORT_NAME);
if (!markerImportName) {
return;
return null;
}
let collection: TranslationCollection = new TranslationCollection();

View File

@ -14,7 +14,7 @@ export class ServiceParser implements ParserInterface {
const classDeclarations = findClassDeclarations(sourceFile);
if (!classDeclarations) {
return;
return null;
}
let collection: TranslationCollection = new TranslationCollection();

View File

@ -22,7 +22,7 @@ export function getNamedImports(node: Node, moduleName: string): NamedImports[]
export function getNamedImportAlias(node: Node, moduleName: string, importName: string): string | null {
const [namedImportNode] = getNamedImports(node, moduleName);
if (!namedImportNode) {
return;
return null;
}
const query = `ImportSpecifier:has(Identifier[name="${importName}"]) > Identifier`;
@ -88,7 +88,7 @@ export function getStringsFromExpression(expression: Expression): string[] {
if (isArrayLiteralExpression(expression)) {
return expression.elements.reduce((result: string[], element: Expression) => {
const strings = this.getStringsFromExpression(element);
const strings = getStringsFromExpression(element);
return [
...result,
...strings
@ -97,8 +97,8 @@ export function getStringsFromExpression(expression: Expression): string[] {
}
if (isBinaryExpression(expression)) {
const [left] = this.getStringsFromExpression(expression.left);
const [right] = this.getStringsFromExpression(expression.right);
const [left] = getStringsFromExpression(expression.left);
const [right] = getStringsFromExpression(expression.right);
if (expression.operatorToken.kind === SyntaxKind.PlusToken) {
if (typeof left === 'string' && typeof right === 'string') {
@ -119,8 +119,8 @@ export function getStringsFromExpression(expression: Expression): string[] {
}
if (isConditionalExpression(expression)) {
const [whenTrue] = this.getStringsFromExpression(expression.whenTrue);
const [whenFalse] = this.getStringsFromExpression(expression.whenFalse);
const [whenTrue] = getStringsFromExpression(expression.whenTrue);
const [whenFalse] = getStringsFromExpression(expression.whenFalse);
const result = [];
if (typeof whenTrue === 'string') {

View File

@ -33,7 +33,7 @@ export class TranslationCollection {
public filter(callback: (key?: string, val?: string) => boolean): TranslationCollection {
let values: TranslationType = {};
this.forEach((key: string, val: string) => {
this.forEach((key, val) => {
if (callback.call(this, key, val)) {
values[key] = val;
}
@ -43,7 +43,7 @@ export class TranslationCollection {
public map(callback: (key?: string, val?: string) => string): TranslationCollection {
let values: TranslationType = {};
this.forEach((key: string, val: string) => {
this.forEach((key, val) => {
values[key] = callback.call(this, key, val);
});
return new TranslationCollection(values);
@ -56,7 +56,7 @@ export class TranslationCollection {
public intersect(collection: TranslationCollection): TranslationCollection {
let values: TranslationType = {};
this.filter(key => collection.has(key))
.forEach((key: string, val: string) => {
this.forEach((key, val) => {
values[key] = val;
});

View File

@ -3,6 +3,9 @@
"allowSyntheticDefaultImports": true,
"noUnusedLocals": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitUseStrict": true,
"removeComments": true,
"declaration": true,
"target": "es2015",