@fimbul/wotan
Advanced tools
Comparing version 0.1.0 to 0.2.0-dev.20180218
@@ -15,3 +15,3 @@ import 'reflect-metadata'; | ||
export * from './src/services/default/configuration-provider'; | ||
export * from './src/services/default/line-switch-parser'; | ||
export * from './src/services/default/line-switches'; | ||
export * from './src/services/cached-file-system'; | ||
@@ -22,3 +22,2 @@ export * from './src/services/configuration-manager'; | ||
export * from './src/services/rule-loader'; | ||
export * from './src/services/line-switches'; | ||
export * from './src/linter'; | ||
@@ -25,0 +24,0 @@ export * from './src/runner'; |
@@ -18,3 +18,3 @@ "use strict"; | ||
tslib_1.__exportStar(require("./src/services/default/configuration-provider"), exports); | ||
tslib_1.__exportStar(require("./src/services/default/line-switch-parser"), exports); | ||
tslib_1.__exportStar(require("./src/services/default/line-switches"), exports); | ||
tslib_1.__exportStar(require("./src/services/cached-file-system"), exports); | ||
@@ -25,3 +25,2 @@ tslib_1.__exportStar(require("./src/services/configuration-manager"), exports); | ||
tslib_1.__exportStar(require("./src/services/rule-loader"), exports); | ||
tslib_1.__exportStar(require("./src/services/line-switches"), exports); | ||
tslib_1.__exportStar(require("./src/linter"), exports); | ||
@@ -28,0 +27,0 @@ tslib_1.__exportStar(require("./src/runner"), exports); |
{ | ||
"name": "@fimbul/wotan", | ||
"version": "0.1.0", | ||
"version": "0.2.0-dev.20180218", | ||
"description": "Pluggable TypeScript and JavaScript linter", | ||
"bin": "bin/main.js", | ||
"scripts": { | ||
"clean": "rimraf '{index,{src,test/conformance}/**/*}.{js?(.map),d.ts}'", | ||
"check-dependencies": "depcruise index.js src/**/*.js bin test/conformance/*.js -v .dependency-cruiser.json" | ||
}, | ||
"publishConfig": { | ||
@@ -49,3 +45,2 @@ "access": "public" | ||
"@types/to-absolute-glob": "^2.0.0", | ||
"dependency-cruiser": "^2.10.1", | ||
"escape-string-regexp": "^1.0.5", | ||
@@ -52,0 +47,0 @@ "rimraf": "^2.6.2" |
@@ -12,3 +12,2 @@ "use strict"; | ||
const test_1 = require("../test"); | ||
const line_switches_1 = require("../services/line-switches"); | ||
exports.CORE_DI_MODULE = new inversify_1.ContainerModule((bind) => { | ||
@@ -23,5 +22,4 @@ bind(cached_file_system_1.CachedFileSystem).toSelf(); | ||
bind(test_1.RuleTester).toSelf(); | ||
bind(line_switches_1.LineSwitchService).toSelf(); | ||
bind(inversify_1.Container).toDynamicValue((context) => context.container); | ||
}); | ||
//# sourceMappingURL=core.module.js.map |
@@ -14,3 +14,3 @@ "use strict"; | ||
const configuration_provider_1 = require("../services/default/configuration-provider"); | ||
const line_switch_parser_1 = require("../services/default/line-switch-parser"); | ||
const line_switches_1 = require("../services/default/line-switches"); | ||
exports.DEFAULT_DI_MODULE = new inversify_1.ContainerModule((bind, _unbind, isBound) => { | ||
@@ -35,5 +35,7 @@ if (!isBound(types_1.FormatterLoaderHost)) | ||
bind(types_1.ConfigurationProvider).to(configuration_provider_1.DefaultConfigurationProvider); | ||
if (!isBound(types_1.LineSwitchParser)) | ||
bind(types_1.LineSwitchParser).to(line_switch_parser_1.DefaultLineSwitchParser); | ||
if (!isBound(types_1.FailureFilterFactory)) | ||
bind(types_1.FailureFilterFactory).to(line_switches_1.LineSwitchFilterFactory); | ||
if (!isBound(line_switches_1.LineSwitchParser)) | ||
bind(line_switches_1.LineSwitchParser).to(line_switches_1.DefaultLineSwitchParser); | ||
}); | ||
//# sourceMappingURL=default.module.js.map |
import * as ts from 'typescript'; | ||
import { Failure, EffectiveConfiguration, LintAndFixFileResult, MessageHandler, AbstractProcessor, DeprecationHandler } from './types'; | ||
import { LineSwitchService } from './services/line-switches'; | ||
import { Failure, EffectiveConfiguration, LintAndFixFileResult, MessageHandler, AbstractProcessor, DeprecationHandler, FailureFilterFactory } from './types'; | ||
import { RuleLoader } from './services/rule-loader'; | ||
@@ -15,8 +14,9 @@ export interface UpdateFileResult { | ||
private deprecationHandler; | ||
private lineSwitches; | ||
constructor(ruleLoader: RuleLoader, logger: MessageHandler, deprecationHandler: DeprecationHandler, lineSwitches: LineSwitchService); | ||
private filterFactory; | ||
constructor(ruleLoader: RuleLoader, logger: MessageHandler, deprecationHandler: DeprecationHandler, filterFactory: FailureFilterFactory); | ||
lintFile(file: ts.SourceFile, config: EffectiveConfiguration, program?: ts.Program): Failure[]; | ||
lintAndFix(file: ts.SourceFile, content: string, config: EffectiveConfiguration, updateFile: UpdateFileCallback, iterations?: number, program?: ts.Program, processor?: AbstractProcessor): LintAndFixFileResult; | ||
getFailures(sourceFile: ts.SourceFile, config: EffectiveConfiguration, program: ts.Program | undefined, processor: AbstractProcessor | undefined): Failure[]; | ||
private prepareRules(config, sourceFile, program); | ||
private applyRules(sourceFile, program, rules, settings); | ||
} |
@@ -7,3 +7,2 @@ "use strict"; | ||
const fix_1 = require("./fix"); | ||
const line_switches_1 = require("./services/line-switches"); | ||
const debug = require("debug"); | ||
@@ -16,7 +15,7 @@ const inversify_1 = require("inversify"); | ||
let Linter = class Linter { | ||
constructor(ruleLoader, logger, deprecationHandler, lineSwitches) { | ||
constructor(ruleLoader, logger, deprecationHandler, filterFactory) { | ||
this.ruleLoader = ruleLoader; | ||
this.logger = logger; | ||
this.deprecationHandler = deprecationHandler; | ||
this.lineSwitches = lineSwitches; | ||
this.filterFactory = filterFactory; | ||
} | ||
@@ -96,3 +95,3 @@ lintFile(file, config, program) { | ||
const result = []; | ||
let disables; | ||
let failureFilter; | ||
let ruleName; | ||
@@ -102,10 +101,24 @@ let severity; | ||
let convertedAst; | ||
const isDisabled = (range) => { | ||
if (disables === undefined) | ||
disables = this.lineSwitches.getDisabledRanges(sourceFile, rules.map((r) => r.ruleName), getWrappedAst); | ||
return this.lineSwitches.isDisabled(disables, ruleName, range); | ||
const addFailure = (pos, end, message, fix) => { | ||
const failure = { | ||
ruleName, | ||
severity, | ||
message, | ||
start: Object.assign({ position: pos }, ts.getLineAndCharacterOfPosition(sourceFile, pos)), | ||
end: Object.assign({ position: end }, ts.getLineAndCharacterOfPosition(sourceFile, end)), | ||
fix: fix === undefined | ||
? undefined | ||
: !Array.isArray(fix) | ||
? { replacements: [fix] } | ||
: fix.length === 0 | ||
? undefined | ||
: { replacements: fix }, | ||
}; | ||
if (failureFilter === undefined) | ||
failureFilter = this.filterFactory.create({ sourceFile, getWrappedAst, ruleNames: rules.map((r) => r.ruleName) }); | ||
if (failureFilter.filter(failure)) | ||
result.push(failure); | ||
}; | ||
const context = { | ||
addFailure, | ||
isDisabled, | ||
getFlatAst, | ||
@@ -124,20 +137,2 @@ getWrappedAst, | ||
return result; | ||
function addFailure(pos, end, message, fix) { | ||
if (isDisabled({ pos, end })) | ||
return; | ||
result.push({ | ||
ruleName, | ||
severity, | ||
message, | ||
start: Object.assign({ position: pos }, ts.getLineAndCharacterOfPosition(sourceFile, pos)), | ||
end: Object.assign({ position: end }, ts.getLineAndCharacterOfPosition(sourceFile, end)), | ||
fix: fix === undefined | ||
? undefined | ||
: !Array.isArray(fix) | ||
? { replacements: [fix] } | ||
: fix.length === 0 | ||
? undefined | ||
: { replacements: fix }, | ||
}); | ||
} | ||
function getFlatAst() { | ||
@@ -156,5 +151,5 @@ return (convertedAst || (convertedAst = tsutils_1.convertAst(sourceFile))).flat; | ||
types_1.DeprecationHandler, | ||
line_switches_1.LineSwitchService]) | ||
types_1.FailureFilterFactory]) | ||
], Linter); | ||
exports.Linter = Linter; | ||
//# sourceMappingURL=linter.js.map |
@@ -1,1 +0,46 @@ | ||
export {}; | ||
import * as ts from 'typescript'; | ||
import { ProcessorLoader } from './services/processor-loader'; | ||
import { CachedFileSystem } from './services/cached-file-system'; | ||
import { Configuration, AbstractProcessor } from './types'; | ||
import { ConfigurationManager } from './services/configuration-manager'; | ||
export interface ProcessedFileInfo { | ||
originalName: string; | ||
originalContent: string; | ||
processor: AbstractProcessor; | ||
} | ||
export declare class ProjectHost implements ts.CompilerHost { | ||
cwd: string; | ||
config: Configuration | undefined; | ||
private fs; | ||
private configManager; | ||
private processorLoader; | ||
private reverseMap; | ||
private files; | ||
private directoryEntries; | ||
private processedFiles; | ||
private sourceFileCache; | ||
private fileContent; | ||
constructor(cwd: string, config: Configuration | undefined, fs: CachedFileSystem, configManager: ConfigurationManager, processorLoader: ProcessorLoader); | ||
getProcessedFileInfo(fileName: string): ProcessedFileInfo | undefined; | ||
getDirectoryEntries(dir: string): ts.FileSystemEntries; | ||
private tryFindConfig(file); | ||
private processDirectory(dir); | ||
fileExists(file: string): boolean; | ||
directoryExists(dir: string): boolean; | ||
getFileSystemFile(file: string): string | undefined; | ||
readFile(file: string): string; | ||
private readProcessedFile(file); | ||
writeFile(): void; | ||
useCaseSensitiveFileNames(): boolean; | ||
getDefaultLibFileName: typeof ts.getDefaultLibFilePath; | ||
getCanonicalFileName: (f: string) => string; | ||
getNewLine(): string; | ||
realpath: ((fileName: string) => string) | undefined; | ||
getCurrentDirectory(): string; | ||
getDirectories(dir: string): string[]; | ||
getSourceFile(fileName: string, languageVersion: ts.ScriptTarget): ts.SourceFile; | ||
updateSourceFile(sourceFile: ts.SourceFile, program: ts.Program, newContent: string, changeRange: ts.TextChangeRange): { | ||
sourceFile: ts.SourceFile; | ||
program: ts.Program; | ||
}; | ||
} |
@@ -31,2 +31,10 @@ "use strict"; | ||
} | ||
tryFindConfig(file) { | ||
try { | ||
return this.configManager.find(file); | ||
} | ||
catch (_a) { | ||
return; | ||
} | ||
} | ||
processDirectory(dir) { | ||
@@ -43,3 +51,2 @@ const files = []; | ||
} | ||
let c = this.config || 'initial'; | ||
for (const entry of entries) { | ||
@@ -50,4 +57,3 @@ const fileName = `${dir}/${entry}`; | ||
if (!utils_1.hasSupportedExtension(fileName)) { | ||
if (c === 'initial') | ||
c = this.configManager.find(fileName); | ||
const c = this.config || this.tryFindConfig(fileName); | ||
const processor = c && this.configManager.getProcessor(c, fileName); | ||
@@ -57,3 +63,7 @@ if (processor) { | ||
const newName = fileName + | ||
ctor.getSuffixForFile(fileName, this.configManager.getSettings(c, fileName), () => this.fs.readFile(fileName)); | ||
ctor.getSuffixForFile({ | ||
fileName, | ||
getSettings: () => this.configManager.getSettings(c, fileName), | ||
readFile: () => this.fs.readFile(fileName), | ||
}); | ||
if (utils_1.hasSupportedExtension(newName)) { | ||
@@ -110,3 +120,3 @@ files.push(newName); | ||
let content = this.fs.readFile(realFile); | ||
const config = this.config || this.configManager.find(realFile); | ||
const config = this.config || this.tryFindConfig(realFile); | ||
if (config === undefined) | ||
@@ -118,3 +128,8 @@ return content; | ||
const ctor = this.processorLoader.loadProcessor(processorPath); | ||
const processor = new ctor(content, realFile, file, this.configManager.getSettings(config, realFile)); | ||
const processor = new ctor({ | ||
source: content, | ||
sourceFileName: realFile, | ||
targetFileName: file, | ||
settings: this.configManager.getSettings(config, realFile), | ||
}); | ||
this.processedFiles.set(file, { | ||
@@ -121,0 +136,0 @@ processor, |
@@ -79,3 +79,7 @@ "use strict"; | ||
else { | ||
name = file + ctor.getSuffixForFile(file, effectiveConfig.settings, () => originalContent = this.fs.readFile(file)); | ||
name = file + ctor.getSuffixForFile({ | ||
fileName: file, | ||
getSettings: () => effectiveConfig.settings, | ||
readFile: () => originalContent = this.fs.readFile(file), | ||
}); | ||
if (!utils_1.hasSupportedExtension(name, options.extensions)) | ||
@@ -86,3 +90,8 @@ continue; | ||
originalContent = this.fs.readFile(file); | ||
processor = new ctor(originalContent, file, name, effectiveConfig.settings); | ||
processor = new ctor({ | ||
source: originalContent, | ||
sourceFileName: file, | ||
targetFileName: name, | ||
settings: effectiveConfig.settings, | ||
}); | ||
content = processor.preprocess(); | ||
@@ -89,0 +98,0 @@ } |
@@ -11,7 +11,8 @@ import * as ts from 'typescript'; | ||
export interface Replacement { | ||
start: number; | ||
end: number; | ||
text: string; | ||
readonly start: number; | ||
readonly end: number; | ||
readonly text: string; | ||
} | ||
export declare abstract class Replacement { | ||
private constructor(); | ||
static replace(start: number, end: number, text: string): Replacement; | ||
@@ -22,11 +23,11 @@ static append(pos: number, text: string): Replacement; | ||
export interface Fix { | ||
replacements: Replacement[]; | ||
readonly replacements: ReadonlyArray<Replacement>; | ||
} | ||
export interface Failure { | ||
start: FailurePosition; | ||
end: FailurePosition; | ||
message: string; | ||
ruleName: string; | ||
severity: Severity; | ||
fix: Fix | undefined; | ||
readonly start: FailurePosition; | ||
readonly end: FailurePosition; | ||
readonly message: string; | ||
readonly ruleName: string; | ||
readonly severity: Severity; | ||
readonly fix: Fix | undefined; | ||
} | ||
@@ -37,7 +38,13 @@ export declare namespace Failure { | ||
export interface FailurePosition { | ||
line: number; | ||
character: number; | ||
position: number; | ||
readonly line: number; | ||
readonly character: number; | ||
readonly position: number; | ||
} | ||
export declare type Severity = 'error' | 'warning'; | ||
export interface RuleConstructor { | ||
readonly requiresTypeInformation: boolean; | ||
readonly deprecated?: boolean | string; | ||
supports?(sourceFile: ts.SourceFile, options: any, settings: GlobalSettings): boolean; | ||
new (context: RuleContext): AbstractRule; | ||
} | ||
export interface RuleContext { | ||
@@ -49,3 +56,2 @@ readonly program?: ts.Program; | ||
addFailure(start: number, end: number, message: string, fix?: Replacement | Replacement[]): void; | ||
isDisabled(range: ts.TextRange): boolean; | ||
getFlatAst(): ReadonlyArray<ts.Node>; | ||
@@ -98,2 +104,5 @@ getWrappedAst(): WrappedAst; | ||
} | ||
export interface FormatterConstructor { | ||
new (): AbstractFormatter; | ||
} | ||
export interface Configuration { | ||
@@ -154,3 +163,3 @@ readonly aliases?: ReadonlyMap<string, Configuration.Alias>; | ||
export interface LoadConfigurationContext { | ||
stack: ReadonlyArray<string>; | ||
readonly stack: ReadonlyArray<string>; | ||
load(name: string): Configuration; | ||
@@ -163,2 +172,17 @@ } | ||
} | ||
export interface ProcessorConstructor { | ||
getSuffixForFile(context: ProcessorSuffixContext): string; | ||
new (context: ProcessorContext): AbstractProcessor; | ||
} | ||
export interface ProcessorSuffixContext { | ||
fileName: string; | ||
getSettings(): GlobalSettings; | ||
readFile(): string; | ||
} | ||
export interface ProcessorContext { | ||
source: string; | ||
sourceFileName: string; | ||
targetFileName: string; | ||
settings: GlobalSettings; | ||
} | ||
export interface ProcessorUpdateResult { | ||
@@ -169,2 +193,3 @@ transformed: string; | ||
export declare abstract class AbstractProcessor { | ||
static getSuffixForFile(_context: ProcessorSuffixContext): string; | ||
protected source: string; | ||
@@ -174,4 +199,3 @@ protected sourceFileName: string; | ||
protected settings: GlobalSettings; | ||
static getSuffixForFile(_fileName: string, _settings: GlobalSettings, _readFile: () => string): string; | ||
constructor(source: string, sourceFileName: string, targetFileName: string, settings: GlobalSettings); | ||
constructor(context: ProcessorContext); | ||
abstract preprocess(): string; | ||
@@ -263,13 +287,14 @@ abstract postprocess(failures: Failure[]): Failure[]; | ||
} | ||
export interface LineSwitchParser { | ||
parse(sourceFile: ts.SourceFile, ruleNames: ReadonlyArray<string>, context: LineSwitchParserContext): ReadonlyMap<string, ReadonlyArray<LineSwitch>>; | ||
export interface FailureFilterFactory { | ||
create(context: FailureFilterContext): FailureFilter; | ||
} | ||
export declare abstract class LineSwitchParser { | ||
export declare abstract class FailureFilterFactory { | ||
} | ||
export interface LineSwitchParserContext { | ||
getCommentAtPosition(pos: number): ts.CommentRange | undefined; | ||
export interface FailureFilterContext { | ||
sourceFile: ts.SourceFile; | ||
ruleNames: ReadonlyArray<string>; | ||
getWrappedAst(): WrappedAst; | ||
} | ||
export interface LineSwitch { | ||
readonly enable: boolean; | ||
readonly position: number; | ||
export interface FailureFilter { | ||
filter(failure: Failure): boolean; | ||
} |
@@ -6,2 +6,3 @@ "use strict"; | ||
class Replacement { | ||
constructor() { } | ||
static replace(start, end, text) { | ||
@@ -92,11 +93,11 @@ return { start, end, text }; | ||
class AbstractProcessor { | ||
constructor(source, sourceFileName, targetFileName, settings) { | ||
this.source = source; | ||
this.sourceFileName = sourceFileName; | ||
this.targetFileName = targetFileName; | ||
this.settings = settings; | ||
} | ||
static getSuffixForFile(_fileName, _settings, _readFile) { | ||
static getSuffixForFile(_context) { | ||
return ''; | ||
} | ||
constructor(context) { | ||
this.source = context.source; | ||
this.sourceFileName = context.sourceFileName; | ||
this.targetFileName = context.targetFileName; | ||
this.settings = context.settings; | ||
} | ||
} | ||
@@ -142,5 +143,5 @@ exports.AbstractProcessor = AbstractProcessor; | ||
exports.DirectoryService = DirectoryService; | ||
class LineSwitchParser { | ||
class FailureFilterFactory { | ||
} | ||
exports.LineSwitchParser = LineSwitchParser; | ||
exports.FailureFilterFactory = FailureFilterFactory; | ||
//# sourceMappingURL=types.js.map |
import { Format, Cache } from './types'; | ||
import * as ts from 'typescript'; | ||
export declare const OFFSET_TO_NODE_MODULES = 3; | ||
export declare function isStrictNullChecksEnabled(options: ts.CompilerOptions): boolean; | ||
@@ -4,0 +5,0 @@ export declare function isStrictPropertyInitializationEnabled(options: ts.CompilerOptions): boolean; |
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
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
360039
16
4649
142