From b4122b757f4b05479533f5ff083c6cb84d86a2a1 Mon Sep 17 00:00:00 2001 From: Peter Burns Date: Thu, 12 Apr 2018 17:43:47 -0700 Subject: [PATCH 1/2] Get the configured analyzer from the project config object itself. --- packages/cli/src/analyze/analyze.ts | 3 +-- packages/cli/src/lint/lint.ts | 4 ++-- packages/cli/src/util.ts | 28 ---------------------------- 3 files changed, 3 insertions(+), 32 deletions(-) diff --git a/packages/cli/src/analyze/analyze.ts b/packages/cli/src/analyze/analyze.ts index e7d6835ad..49eea6646 100644 --- a/packages/cli/src/analyze/analyze.ts +++ b/packages/cli/src/analyze/analyze.ts @@ -16,11 +16,10 @@ import * as globby from 'globby'; import {AnalysisFormat, generateAnalysis} from 'polymer-analyzer'; import {Feature} from 'polymer-analyzer/lib/model/model'; import {ProjectConfig} from 'polymer-project-config'; -import {getConfiguredAnalyzer} from '../util'; export async function analyze(config: ProjectConfig, inputs: string[]): Promise { - const {analyzer} = getConfiguredAnalyzer(config); + const {analyzer} = await config.initializeAnalyzer(); const isInTests = /(\b|\/|\\)(test)(\/|\\)/; const isNotTest = (f: Feature) => diff --git a/packages/cli/src/lint/lint.ts b/packages/cli/src/lint/lint.ts index e46133fde..d590a6ae3 100644 --- a/packages/cli/src/lint/lint.ts +++ b/packages/cli/src/lint/lint.ts @@ -26,7 +26,7 @@ import {ProjectConfig} from 'polymer-project-config'; import {CommandResult} from '../commands/command'; import {Options} from '../commands/lint'; -import {getConfiguredAnalyzer, indent, prompt} from '../util'; +import {indent, prompt} from '../util'; const logger = logging.getLogger('cli.lint'); @@ -54,7 +54,7 @@ export async function lint(options: Options, config: ProjectConfig) { filesToIgnore: lintOptions.filesToIgnore, }); - const {analyzer, urlLoader, urlResolver} = getConfiguredAnalyzer(config); + const {analyzer, urlLoader, urlResolver} = await config.initializeAnalyzer(); const linter = new lintLib.Linter(rules, analyzer); if (options.watch) { diff --git a/packages/cli/src/util.ts b/packages/cli/src/util.ts index e7678deb7..4394c0406 100644 --- a/packages/cli/src/util.ts +++ b/packages/cli/src/util.ts @@ -14,8 +14,6 @@ import * as inquirer from 'inquirer'; import {execSync} from 'mz/child_process'; -import {Analyzer, FsUrlLoader, PackageUrlResolver} from 'polymer-analyzer'; -import {ProjectConfig} from 'polymer-project-config'; /** * Check if the current shell environment is MinGW. MinGW can't handle some @@ -70,29 +68,3 @@ export function indent(str: string, additionalIndentation = ' ') { export function dashToCamelCase(text: string): string { return text.replace(/-([a-z])/g, (v) => v[1].toUpperCase()); } - -export function getConfiguredAnalyzer(config: ProjectConfig) { - const urlLoader = new FsUrlLoader(config.root); - const urlResolver = new PackageUrlResolver( - {packageDir: config.root, componentDir: config.componentDir}); - - const analyzer = new Analyzer({ - urlLoader, - urlResolver, - moduleResolution: convertModuleResolution(config.moduleResolution) - }); - return {urlLoader, urlResolver, analyzer}; -} - -function convertModuleResolution(moduleResolution: 'node'|'none'): 'node'| - undefined { - switch (moduleResolution) { - case 'node': - return 'node'; - case 'none': - return undefined; - default: - const never: never = moduleResolution; - throw new Error(`Unknown module resolution parameter: ${never}`); - } -} From 6c2b407991c68c5d5540c35f817ed5e50be4ee07 Mon Sep 17 00:00:00 2001 From: Peter Burns Date: Tue, 27 Mar 2018 21:03:05 -0700 Subject: [PATCH 2/2] Let the config construct the warning filter too. --- packages/cli/src/lint/lint.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/lint/lint.ts b/packages/cli/src/lint/lint.ts index d590a6ae3..71496d4af 100644 --- a/packages/cli/src/lint/lint.ts +++ b/packages/cli/src/lint/lint.ts @@ -48,21 +48,28 @@ export async function lint(options: Options, config: ProjectConfig) { } const rules = lintLib.registry.getRules(ruleCodes); - const filter = new WarningFilter({ - warningCodesToIgnore: new Set(lintOptions.ignoreWarnings || []), - minimumSeverity: Severity.WARNING, - filesToIgnore: lintOptions.filesToIgnore, - }); - - const {analyzer, urlLoader, urlResolver} = await config.initializeAnalyzer(); + const {analyzer, urlLoader, urlResolver, warningFilter} = + await config.initializeAnalyzer(); const linter = new lintLib.Linter(rules, analyzer); if (options.watch) { return watchLoop( - analyzer, urlLoader, urlResolver, linter, options, config, filter); + analyzer, + urlLoader, + urlResolver, + linter, + options, + config, + warningFilter); } else { return run( - analyzer, urlLoader, urlResolver, linter, options, config, filter); + analyzer, + urlLoader, + urlResolver, + linter, + options, + config, + warningFilter); } }