Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let the ProjectConfig handle creating a configured analyzer and warning filter in the CLI #129

Merged
merged 2 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed that we pass around config but we only use config.root, would it make sense to refactor all these signatures to get the root instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next time I touch this file I'm gonna refactor this into a class rather than pass these same 7-8 options around everywhere

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}`);
}
}