@fimbul/wotan
Advanced tools
Comparing version 0.24.0-dev.20210216 to 0.24.0-dev.20210218
@@ -13,2 +13,3 @@ import * as ts from 'typescript'; | ||
protected log: (message: string) => void; | ||
private lastProjectVersion; | ||
private findingsForFile; | ||
@@ -20,3 +21,5 @@ private oldState; | ||
getSemanticDiagnostics(diagnostics: ts.Diagnostic[], fileName: string): ts.Diagnostic[]; | ||
private getFindings; | ||
getSuggestionDiagnostics(diagnostics: ts.DiagnosticWithLocation[], fileName: string): ts.DiagnosticWithLocation[]; | ||
private getFindingsForFile; | ||
private getFindingsForFileWorker; | ||
private loadPluginModule; | ||
@@ -23,0 +26,0 @@ getSupportedCodeFixes(fixes: string[]): string[]; |
@@ -34,2 +34,3 @@ "use strict"; | ||
this.log = log; | ||
this.lastProjectVersion = ''; | ||
this.findingsForFile = new WeakMap(); | ||
@@ -42,32 +43,63 @@ this.oldState = undefined; | ||
getSemanticDiagnostics(diagnostics, fileName) { | ||
this.log(`getSemanticDiagnostics for ${fileName}`); | ||
const result = this.getFindingsForFile(fileName); | ||
if (result === null || result === void 0 ? void 0 : result.findings.length) | ||
diagnostics = diagnostics.concat(utils_1.mapDefined(result.findings, (finding) => finding.severity === 'suggestion' | ||
? undefined | ||
: { | ||
file: result.file, | ||
category: this.config.displayErrorsAsWarnings || finding.severity === 'warning' | ||
? ts.DiagnosticCategory.Warning | ||
: ts.DiagnosticCategory.Error, | ||
code: finding.ruleName, | ||
source: 'wotan', | ||
messageText: finding.message, | ||
start: finding.start.position, | ||
length: finding.end.position - finding.start.position, | ||
})); | ||
return diagnostics; | ||
} | ||
getSuggestionDiagnostics(diagnostics, fileName) { | ||
this.log(`getSuggestionDiagnostics for ${fileName}`); | ||
const result = this.getFindingsForFile(fileName); | ||
if (result === null || result === void 0 ? void 0 : result.findings.length) | ||
diagnostics = diagnostics.concat(utils_1.mapDefined(result.findings, (finding) => finding.severity !== 'suggestion' | ||
? undefined | ||
: { | ||
file: result.file, | ||
category: ts.DiagnosticCategory.Suggestion, | ||
code: finding.ruleName, | ||
source: 'wotan', | ||
messageText: finding.message, | ||
start: finding.start.position, | ||
length: finding.end.position - finding.start.position, | ||
})); | ||
return diagnostics; | ||
} | ||
getFindingsForFile(fileName) { | ||
const program = this.languageService.getProgram(); | ||
if (program === undefined) | ||
return diagnostics; | ||
return; | ||
const file = program.getSourceFile(fileName); | ||
if (file === undefined) { | ||
this.log(`file ${fileName} is not included in the Program`); | ||
return diagnostics; | ||
this.log(`File ${fileName} is not included in the Program`); | ||
return; | ||
} | ||
this.log(`started linting ${fileName}`); | ||
const findings = this.getFindings(file, program); | ||
const projectVersion = this.project.getProjectVersion(); | ||
if (this.lastProjectVersion === projectVersion) { | ||
const cached = this.findingsForFile.get(file); | ||
if (cached !== undefined) { | ||
this.log(`Reusing last result with ${cached.length} findings`); | ||
return { file, findings: cached }; | ||
} | ||
} | ||
else { | ||
this.findingsForFile = new WeakMap(); | ||
this.lastProjectVersion = projectVersion; | ||
} | ||
const findings = this.getFindingsForFileWorker(file, program); | ||
this.findingsForFile.set(file, findings); | ||
diagnostics = diagnostics.concat(findings.map((finding) => ({ | ||
file, | ||
category: finding.severity === 'error' | ||
? this.config.displayErrorsAsWarnings | ||
? ts.DiagnosticCategory.Warning | ||
: ts.DiagnosticCategory.Error | ||
: finding.severity === 'warning' | ||
? ts.DiagnosticCategory.Warning | ||
: ts.DiagnosticCategory.Suggestion, | ||
code: finding.ruleName, | ||
source: 'wotan', | ||
messageText: finding.message, | ||
start: finding.start.position, | ||
length: finding.end.position - finding.start.position, | ||
}))); | ||
this.log(`finished linting ${fileName} with ${findings.length} findings`); | ||
return diagnostics; | ||
return { file, findings }; | ||
} | ||
getFindings(file, program) { | ||
getFindingsForFileWorker(file, program) { | ||
let globalConfigDir = this.project.getCurrentDirectory(); | ||
@@ -78,3 +110,3 @@ let globalOptions; | ||
if (scriptSnapshot !== undefined) { | ||
this.log(`Using '${globalConfigDir}/.fimbullinter.yaml' for global options.`); | ||
this.log(`Using '${globalConfigDir}/.fimbullinter.yaml' for global options`); | ||
globalOptions = yaml.load(scriptSnapshot.getText(0, scriptSnapshot.getLength())) || {}; | ||
@@ -85,3 +117,3 @@ break; | ||
if (parentDir === globalConfigDir) { | ||
this.log("Cannot find '.fimbullinter.yaml'."); | ||
this.log("Cannot find '.fimbullinter.yaml'"); | ||
globalOptions = {}; | ||
@@ -93,4 +125,6 @@ break; | ||
const globalConfig = argparse_1.parseGlobalOptions(globalOptions); | ||
if (!isIncluded(file.fileName, globalConfigDir, globalConfig)) | ||
if (!isIncluded(file.fileName, globalConfigDir, globalConfig)) { | ||
this.log('File is excluded by global options'); | ||
return []; | ||
} | ||
const container = new inversify_1.Container({ defaultScope: inversify_1.BindingScopeEnum.Singleton }); | ||
@@ -141,4 +175,6 @@ for (const module of globalConfig.modules) | ||
const fileFilter = container.get(ymir_1.FileFilterFactory).create({ program, host: this.project }); | ||
if (!fileFilter.filter(file)) | ||
if (!fileFilter.filter(file)) { | ||
this.log('File is excluded by FileFilter'); | ||
return []; | ||
} | ||
const configManager = container.get(configuration_manager_1.ConfigurationManager); | ||
@@ -149,4 +185,6 @@ const config = globalConfig.config === undefined | ||
const effectiveConfig = config && configManager.reduce(config, file.fileName); | ||
if (effectiveConfig === undefined) | ||
if (effectiveConfig === undefined) { | ||
this.log('File is excluded by configuration'); | ||
return []; | ||
} | ||
const linterOptions = { | ||
@@ -163,5 +201,6 @@ reportUselessDirectives: globalConfig.reportUselessDirectives | ||
if (cached !== undefined) { | ||
this.log('Using cached results'); | ||
this.log(`Using ${cached.length} cached findings`); | ||
return cached; | ||
} | ||
this.log('Start linting'); | ||
const linter = container.get(linter_1.Linter); | ||
@@ -171,2 +210,3 @@ const result = linter.lintFile(file, effectiveConfig, program, linterOptions); | ||
programState.save(); | ||
this.log(`Found ${result.length} findings`); | ||
return result; | ||
@@ -183,3 +223,3 @@ } | ||
if (!m || typeof m.createModule !== 'function') | ||
throw new Error(`Module '${moduleName}' does not export a function 'createModule'.`); | ||
throw new Error(`Module '${moduleName}' does not export a function 'createModule'`); | ||
return m.createModule(options); | ||
@@ -219,9 +259,9 @@ } | ||
createDirectory() { | ||
throw new Error('should not be called.'); | ||
throw new Error('should not be called'); | ||
} | ||
deleteFile() { | ||
throw new Error('should not be called.'); | ||
throw new Error('should not be called'); | ||
} | ||
writeFile() { | ||
throw new Error('should not be called.'); | ||
throw new Error('should not be called'); | ||
} | ||
@@ -228,0 +268,0 @@ normalizePath(f) { |
{ | ||
"name": "@fimbul/wotan", | ||
"version": "0.24.0-dev.20210216", | ||
"version": "0.24.0-dev.20210218", | ||
"description": "Pluggable TypeScript and JavaScript linter", | ||
@@ -5,0 +5,0 @@ "bin": "bin/main.js", |
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
421797
5293