@fimbul/wotan
Advanced tools
Comparing version 0.16.0-dev.20181107 to 0.16.0-dev.20181114
{ | ||
"name": "@fimbul/wotan", | ||
"version": "0.16.0-dev.20181107", | ||
"version": "0.16.0-dev.20181114", | ||
"description": "Pluggable TypeScript and JavaScript linter", | ||
@@ -34,3 +34,3 @@ "bin": "bin/main.js", | ||
"@types/escape-string-regexp": "^1.0.0", | ||
"@types/glob": "^5.0.33", | ||
"@types/glob": "^7.1.1", | ||
"@types/is-negated-glob": "^1.0.0", | ||
@@ -44,3 +44,2 @@ "@types/js-yaml": "^3.10.1", | ||
"@types/semver": "^5.4.0", | ||
"@types/to-absolute-glob": "^2.0.0", | ||
"escape-string-regexp": "^1.0.5", | ||
@@ -63,2 +62,3 @@ "rimraf": "^2.6.2" | ||
"minimatch": "^3.0.4", | ||
"normalize-glob": "^0.0.1", | ||
"reflect-metadata": "^0.1.12", | ||
@@ -68,3 +68,2 @@ "resolve": "^1.5.0", | ||
"stable": "^0.1.8", | ||
"to-absolute-glob": "^2.0.2", | ||
"tslib": "^1.8.1", | ||
@@ -71,0 +70,0 @@ "tsutils": "^3.1.0" |
@@ -1,6 +0,4 @@ | ||
import { Command } from './commands'; | ||
import { GlobalOptions } from '@fimbul/ymir'; | ||
import { LintOptions } from './runner'; | ||
import { OptionParser } from './optparse'; | ||
export declare function parseArguments(args: string[], globalOptions?: GlobalOptions): Command; | ||
export interface ParsedGlobalOptions extends LintOptions { | ||
@@ -7,0 +5,0 @@ modules: string[]; |
@@ -1,3 +0,1 @@ | ||
import { GlobalOptions } from '@fimbul/ymir'; | ||
export declare function run(argv: string[]): Promise<void>; | ||
export declare function loadConfig(dir: string): Promise<GlobalOptions>; | ||
export {}; |
@@ -17,5 +17,4 @@ import * as ts from 'typescript'; | ||
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): ReadonlyArray<Failure>; | ||
private prepareRules; | ||
private applyRules; | ||
} |
@@ -1,49 +0,1 @@ | ||
import * as ts from 'typescript'; | ||
import { ProcessorLoader } from './services/processor-loader'; | ||
import { CachedFileSystem } from './services/cached-file-system'; | ||
import { Configuration, AbstractProcessor } from '@fimbul/ymir'; | ||
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; | ||
readDirectory(rootDir: string, extensions: ReadonlyArray<string>, excludes: ReadonlyArray<string> | undefined, includes: ReadonlyArray<string>, depth?: number): string[]; | ||
private tryFindConfig; | ||
private processDirectory; | ||
fileExists(file: string): boolean; | ||
directoryExists(dir: string): boolean; | ||
getFileSystemFile(file: string): string | undefined; | ||
readFile(file: string): string; | ||
private readProcessedFile; | ||
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 | undefined; | ||
createProgram(rootNames: ReadonlyArray<string>, options: ts.CompilerOptions, oldProgram: ts.Program | undefined, projectReferences: ReadonlyArray<ts.ProjectReference> | undefined): ts.Program; | ||
updateSourceFile(sourceFile: ts.SourceFile, program: ts.Program, newContent: string, _changeRange: ts.TextChangeRange): { | ||
sourceFile: ts.SourceFile; | ||
program: ts.Program; | ||
}; | ||
onReleaseOldSourceFile(sourceFile: ts.SourceFile): void; | ||
uncacheFile(fileName: string): void; | ||
} | ||
export {}; |
@@ -17,3 +17,3 @@ "use strict"; | ||
const debug = require("debug"); | ||
const resolveGlob = require("to-absolute-glob"); | ||
const normalize_glob_1 = require("normalize-glob"); | ||
const log = debug('wotan:runner'); | ||
@@ -31,11 +31,8 @@ let Runner = class Runner { | ||
const config = options.config !== undefined ? this.configManager.loadLocalOrResolved(options.config) : undefined; | ||
const resolveOptions = { cwd: this.directories.getCurrentDirectory() }; | ||
const files = options.files.map(resolve); | ||
const exclude = options.exclude.map(resolve); | ||
const cwd = this.directories.getCurrentDirectory(); | ||
const files = options.files.map((pattern) => ({ hasMagic: glob.hasMagic(pattern), normalized: Array.from(normalize_glob_1.normalizeGlob(pattern, cwd)) })); | ||
const exclude = utils_1.flatMap(options.exclude, (pattern) => normalize_glob_1.normalizeGlob(pattern, cwd)); | ||
if (options.project.length === 0 && options.files.length !== 0) | ||
return this.lintFiles(Object.assign({}, options, { files, exclude }), config); | ||
return this.lintProject(Object.assign({}, options, { files, exclude }), config); | ||
function resolve(pattern) { | ||
return resolveGlob(pattern, resolveOptions); | ||
} | ||
} | ||
@@ -153,3 +150,9 @@ *lintProject(options, config) { | ||
const allMatchedFiles = []; | ||
const include = patterns.map((p) => new minimatch_1.Minimatch(p)); | ||
const include = []; | ||
const nonMagicGlobs = []; | ||
for (const pattern of patterns) { | ||
if (!pattern.hasMagic) | ||
nonMagicGlobs.push(pattern.normalized[0]); | ||
include.push(...pattern.normalized.map((p) => new minimatch_1.Minimatch(p))); | ||
} | ||
const ex = exclude.map((p) => new minimatch_1.Minimatch(p, { dot: true })); | ||
@@ -190,3 +193,3 @@ const projectsSeen = []; | ||
} | ||
ensurePatternsMatch(include, ex, allMatchedFiles, projectsSeen); | ||
ensurePatternsMatch(nonMagicGlobs, ex, allMatchedFiles, projectsSeen); | ||
function isFileIncluded(fileName) { | ||
@@ -329,3 +332,3 @@ return (include.length === 0 || include.some((p) => p.match(fileName))) && !ex.some((p) => p.match(fileName)); | ||
cwd, | ||
absolute: true, | ||
nobrace: true, | ||
cache: {}, | ||
@@ -339,11 +342,12 @@ ignore: exclude, | ||
for (const pattern of patterns) { | ||
const match = glob.sync(pattern, globOptions); | ||
if (match.length !== 0) { | ||
result.push(...match); | ||
let matched = pattern.hasMagic; | ||
for (const normalized of pattern.normalized) { | ||
const match = glob.sync(normalized, globOptions); | ||
if (match.length !== 0) { | ||
matched = true; | ||
result.push(...match); | ||
} | ||
} | ||
else if (!glob.hasMagic(pattern)) { | ||
const normalized = new minimatch_1.Minimatch(pattern).set[0].join('/'); | ||
if (!isExcluded(normalized, exclude.map((p) => new minimatch_1.Minimatch(p, { dot: true })))) | ||
throw new ymir_1.ConfigurationError(`'${normalized}' does not exist.`); | ||
} | ||
if (!matched && !isExcluded(pattern.normalized[0], exclude.map((p) => new minimatch_1.Minimatch(p, { dot: true })))) | ||
throw new ymir_1.ConfigurationError(`'${pattern.normalized[0]}' does not exist.`); | ||
} | ||
@@ -353,9 +357,5 @@ return new Set(result.map(utils_1.unixifyPath)); | ||
function ensurePatternsMatch(include, exclude, files, projects) { | ||
for (const pattern of include) { | ||
if (!glob.hasMagic(pattern.pattern)) { | ||
const normalized = pattern.set[0].join('/'); | ||
if (!files.includes(normalized) && !isExcluded(normalized, exclude)) | ||
throw new ymir_1.ConfigurationError(`'${normalized}' is not included in any of the projects: '${projects.join("', '")}'.`); | ||
} | ||
} | ||
for (const pattern of include) | ||
if (!files.includes(pattern) && !isExcluded(pattern, exclude)) | ||
throw new ymir_1.ConfigurationError(`'${pattern}' is not included in any of the projects: '${projects.join("', '")}'.`); | ||
} | ||
@@ -362,0 +362,0 @@ function isExcluded(file, exclude) { |
import { Format, Cache } from '@fimbul/ymir'; | ||
import * as ts from 'typescript'; | ||
export declare const OFFSET_TO_NODE_MODULES = 3; | ||
export declare function arrayify<T>(maybeArr: T | ReadonlyArray<T> | undefined): ReadonlyArray<T>; | ||
@@ -12,4 +11,5 @@ export declare function resolveCachedResult<K, V>(cache: Cache<K, V>, key: K, cb: (key: K) => V): V; | ||
export declare function mapDefined<T, U>(input: Iterable<T>, cb: (item: T) => U | undefined): U[]; | ||
export declare function flatMap<T, U>(input: Iterable<T>, cb: (item: T) => Iterable<U>): U[]; | ||
export declare function addUnique<T>(arr: T[], item: T & { | ||
[K in keyof T]: T[K]; | ||
}): boolean; |
@@ -115,2 +115,9 @@ "use strict"; | ||
exports.mapDefined = mapDefined; | ||
function flatMap(input, cb) { | ||
const result = []; | ||
for (const item of input) | ||
result.push(...cb(item)); | ||
return result; | ||
} | ||
exports.flatMap = flatMap; | ||
function addUnique(arr, item) { | ||
@@ -117,0 +124,0 @@ if (arr.includes(item)) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
14
273601
3398
+ Addednormalize-glob@^0.0.1
+ Addednormalize-glob@0.0.1(transitive)
- Removedto-absolute-glob@^2.0.2
- Removedis-absolute@1.0.0(transitive)
- Removedis-relative@1.0.0(transitive)
- Removedis-unc-path@1.0.0(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedto-absolute-glob@2.0.2(transitive)
- Removedunc-path-regex@0.1.2(transitive)