Skip to content

Commit

Permalink
Merge pull request #129 from Polymer/fixup-cli
Browse files Browse the repository at this point in the history
Let the ProjectConfig handle creating a configured analyzer and warning filter in the CLI
  • Loading branch information
rictic authored Apr 13, 2018
2 parents 555aed2 + 6c2b407 commit f54f6d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 40 deletions.
3 changes: 1 addition & 2 deletions packages/cli/src/analyze/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnalysisFormat|undefined> {
const {analyzer} = getConfiguredAnalyzer(config);
const {analyzer} = await config.initializeAnalyzer();

const isInTests = /(\b|\/|\\)(test)(\/|\\)/;
const isNotTest = (f: Feature) =>
Expand Down
27 changes: 17 additions & 10 deletions packages/cli/src/lint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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} = getConfiguredAnalyzer(config);
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);
}
}

Expand Down
28 changes: 0 additions & 28 deletions packages/cli/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}`);
}
}

0 comments on commit f54f6d4

Please sign in to comment.