@fimbul/ymir
Advanced tools
Comparing version 0.18.0 to 0.21.0-dev.20190318
{ | ||
"name": "@fimbul/ymir", | ||
"version": "0.18.0", | ||
"version": "0.21.0-dev.20190318", | ||
"description": "Core library for the Fimbullinter project", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -66,11 +66,7 @@ import 'reflect-metadata'; | ||
} | ||
export declare abstract class RuleContext { | ||
} | ||
export interface TypedRuleContext extends RuleContext { | ||
readonly program: ts.Program; | ||
} | ||
export declare abstract class TypedRuleContext { | ||
} | ||
export declare type Settings = ReadonlyMap<string, {} | null | undefined>; | ||
export declare function isTypescriptFile(sourceFile: ts.SourceFile): boolean; | ||
export declare function predicate(check: RuleSupportsPredicate): (target: typeof AbstractRule) => void; | ||
export declare function typescriptOnly(target: typeof AbstractRule): void; | ||
@@ -80,3 +76,3 @@ export declare function excludeDeclarationFiles(target: typeof AbstractRule): void; | ||
export declare function requiresCompilerOption(option: BooleanCompilerOptions): (target: typeof TypedRule) => void; | ||
export declare type RuleSupportsPredicate = (sourceFile: ts.SourceFile, context: RuleSupportsContext) => boolean; | ||
export declare type RuleSupportsPredicate = (sourceFile: ts.SourceFile, context: RuleSupportsContext) => boolean | string; | ||
export declare abstract class AbstractRule { | ||
@@ -83,0 +79,0 @@ readonly context: RuleContext; |
@@ -39,23 +39,22 @@ "use strict"; | ||
} | ||
class RuleContext { | ||
function predicate(check) { | ||
return (target) => { | ||
target.supports = combinePredicates(target.supports, check); | ||
}; | ||
} | ||
exports.RuleContext = RuleContext; | ||
class TypedRuleContext { | ||
} | ||
exports.TypedRuleContext = TypedRuleContext; | ||
function combinePredicates(existing, predicate) { | ||
exports.predicate = predicate; | ||
function combinePredicates(existing, additonal) { | ||
if (existing === undefined) | ||
return predicate; | ||
return (sourceFile, context) => predicate(sourceFile, context) && existing(sourceFile, context); | ||
return additonal; | ||
return (sourceFile, context) => { | ||
const result = additonal(sourceFile, context); | ||
return result !== true ? result : existing(sourceFile, context); | ||
}; | ||
} | ||
function isTypescriptFile(sourceFile) { | ||
return /\.tsx?$/.test(sourceFile.fileName); | ||
} | ||
exports.isTypescriptFile = isTypescriptFile; | ||
function typescriptOnly(target) { | ||
target.supports = combinePredicates(target.supports, isTypescriptFile); | ||
target.supports = combinePredicates(target.supports, (sourceFile) => /\.tsx?$/.test(sourceFile.fileName) || 'TypeScript only'); | ||
} | ||
exports.typescriptOnly = typescriptOnly; | ||
function excludeDeclarationFiles(target) { | ||
target.supports = combinePredicates(target.supports, (sourceFile) => !sourceFile.isDeclarationFile); | ||
target.supports = combinePredicates(target.supports, (sourceFile) => !sourceFile.isDeclarationFile || 'excludes declaration files'); | ||
} | ||
@@ -65,3 +64,3 @@ exports.excludeDeclarationFiles = excludeDeclarationFiles; | ||
return (target) => { | ||
target.supports = combinePredicates(target.supports, (_, context) => programContainsLibraryFile(context.program, fileName)); | ||
target.supports = combinePredicates(target.supports, (_, context) => programContainsLibraryFile(context.program, fileName) || `requires library file '${fileName}'`); | ||
}; | ||
@@ -76,3 +75,3 @@ } | ||
return (target) => { | ||
target.supports = combinePredicates(target.supports, (_, context) => tsutils_1.isCompilerOptionEnabled(context.program.getCompilerOptions(), option)); | ||
target.supports = combinePredicates(target.supports, (_, context) => tsutils_1.isCompilerOptionEnabled(context.program.getCompilerOptions(), option) || `requires compilerOption '${option}'`); | ||
}; | ||
@@ -79,0 +78,0 @@ } |
Sorry, the diff of this file is not supported yet
36686
522