@fimbul/wotan
Advanced tools
Comparing version 0.17.0-dev.20181218 to 0.17.0-dev.20181219
@@ -19,4 +19,5 @@ import * as ts from 'typescript'; | ||
private getFailures; | ||
private loadPluginModule; | ||
getSupportedCodeFixes(fixes: string[]): string[]; | ||
dispose(): void; | ||
} |
@@ -13,2 +13,7 @@ "use strict"; | ||
const resolve = require("resolve"); | ||
const path = require("path"); | ||
const yaml = require("js-yaml"); | ||
const argparse_1 = require("../src/argparse"); | ||
const normalize_glob_1 = require("normalize-glob"); | ||
const minimatch_1 = require("minimatch"); | ||
exports.version = '1'; | ||
@@ -54,3 +59,25 @@ class LanguageServiceInterceptor { | ||
getFailures(file, program) { | ||
let globalConfigDir = this.project.getCurrentDirectory(); | ||
let globalOptions; | ||
while (true) { | ||
const scriptSnapshot = this.project.getScriptSnapshot(globalConfigDir + '/.fimbullinter.yaml'); | ||
if (scriptSnapshot !== undefined) { | ||
this.log(`Using '${globalConfigDir}/.fimbullinter.yaml' for global options.`); | ||
globalOptions = yaml.safeLoad(scriptSnapshot.getText(0, scriptSnapshot.getLength())) || {}; | ||
break; | ||
} | ||
const parentDir = path.dirname(globalConfigDir); | ||
if (parentDir === globalConfigDir) { | ||
this.log("Cannot find '.fimbullinter.yaml'."); | ||
globalOptions = {}; | ||
break; | ||
} | ||
globalConfigDir = parentDir; | ||
} | ||
const globalConfig = argparse_1.parseGlobalOptions(globalOptions); | ||
if (!isIncluded(file.fileName, globalConfigDir, globalConfig)) | ||
return []; | ||
const container = new inversify_1.Container({ defaultScope: inversify_1.BindingScopeEnum.Singleton }); | ||
for (const module of globalConfig.modules) | ||
container.load(this.loadPluginModule(module, globalConfigDir, globalOptions)); | ||
container.bind(ymir_1.FileSystem).toConstantValue(new ProjectFileSystem(this.project)); | ||
@@ -89,3 +116,3 @@ container.bind(ymir_1.DirectoryService).toConstantValue({ | ||
}); | ||
container.load(core_module_1.createCoreModule({}), default_module_1.createDefaultModule()); | ||
container.load(core_module_1.createCoreModule(globalOptions), default_module_1.createDefaultModule()); | ||
const fileFilter = container.get(ymir_1.FileFilterFactory).create({ program, host: this.project }); | ||
@@ -95,3 +122,5 @@ if (!fileFilter.filter(file)) | ||
const configManager = container.get(configuration_manager_1.ConfigurationManager); | ||
const config = configManager.find(file.fileName); | ||
const config = globalConfig.config === undefined | ||
? configManager.find(file.fileName) | ||
: configManager.loadLocalOrResolved(globalConfig.config, globalConfigDir); | ||
const effectiveConfig = config && configManager.reduce(config, file.fileName); | ||
@@ -103,2 +132,14 @@ if (effectiveConfig === undefined) | ||
} | ||
loadPluginModule(moduleName, basedir, options) { | ||
moduleName = resolve.sync(moduleName, { | ||
basedir, | ||
extensions: ['.js'], | ||
isFile: (f) => this.project.fileExists(f), | ||
readFileSync: (f) => this.project.readFile(f), | ||
}); | ||
const m = this.require(moduleName); | ||
if (!m || typeof m.createModule !== 'function') | ||
throw new Error(`Module '${moduleName}' does not export a function 'createModule'.`); | ||
return m.createModule(options); | ||
} | ||
getSupportedCodeFixes(fixes) { | ||
@@ -112,2 +153,16 @@ return fixes; | ||
exports.LanguageServiceInterceptor = LanguageServiceInterceptor; | ||
function isIncluded(fileName, basedir, options) { | ||
outer: if (options.files.length !== 0) { | ||
for (const include of options.files) | ||
for (const normalized of normalize_glob_1.normalizeGlob(include, basedir)) | ||
if (new minimatch_1.Minimatch(normalized).match(fileName)) | ||
break outer; | ||
return false; | ||
} | ||
for (const exclude of options.exclude) | ||
for (const normalized of normalize_glob_1.normalizeGlob(exclude, basedir)) | ||
if (new minimatch_1.Minimatch(normalized, { dot: true }).match(fileName)) | ||
return false; | ||
return true; | ||
} | ||
class ProjectFileSystem { | ||
@@ -114,0 +169,0 @@ constructor(host) { |
{ | ||
"name": "@fimbul/wotan", | ||
"version": "0.17.0-dev.20181218", | ||
"version": "0.17.0-dev.20181219", | ||
"description": "Pluggable TypeScript and JavaScript linter", | ||
@@ -5,0 +5,0 @@ "bin": "bin/main.js", |
@@ -11,3 +11,3 @@ import { Configuration, CacheFactory, ReducedConfiguration, Settings, DirectoryService, ConfigurationProvider } from '@fimbul/ymir'; | ||
find(file: string): Configuration | undefined; | ||
loadLocalOrResolved(pathOrName: string): Configuration; | ||
loadLocalOrResolved(pathOrName: string, basedir?: string): Configuration; | ||
resolve(name: string, basedir: string): string; | ||
@@ -14,0 +14,0 @@ reduce(config: Configuration, file: string): ReducedConfiguration | undefined; |
@@ -31,5 +31,5 @@ "use strict"; | ||
} | ||
loadLocalOrResolved(pathOrName) { | ||
const absolute = path.resolve(this.directories.getCurrentDirectory(), pathOrName); | ||
return this.load(this.fs.isFile(absolute) ? absolute : this.resolve(pathOrName, this.directories.getCurrentDirectory())); | ||
loadLocalOrResolved(pathOrName, basedir = this.directories.getCurrentDirectory()) { | ||
const absolute = path.resolve(basedir, pathOrName); | ||
return this.load(this.fs.isFile(absolute) ? absolute : this.resolve(pathOrName, basedir)); | ||
} | ||
@@ -36,0 +36,0 @@ resolve(name, basedir) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
295975
3702