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

refactor(@angular-devkit/build-angular): remove redundant tslint vers… #18894

Merged
merged 2 commits into from Sep 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 11 additions & 26 deletions packages/angular_devkit/build_angular/src/tslint/index.ts
Expand Up @@ -22,27 +22,6 @@ interface LintResult extends tslint.LintResult {
fileNames: string[];
}

async function _loadTslint() {
let tslint;
try {
tslint = await import('tslint');
} catch {
throw new Error('Unable to find TSLint. Ensure TSLint is installed.');
}

const version = tslint.Linter.VERSION && tslint.Linter.VERSION.split('.');
if (
!version || version.length < 2
|| (Number(version[0]) === 5 && Number(version[1]) < 5) // 5.5+
|| Number(version[0]) < 5 // 6.0+
) {
throw new Error('TSLint must be version 5.5 or higher.');
}

return tslint;
}


async function _run(
options: TslintBuilderOptions,
context: BuilderContext,
Expand All @@ -64,11 +43,17 @@ async function _run(
throw new Error('A "project" must be specified to enable type checking.');
}

const projectTslint = await _loadTslint();
let tslint;
try {
tslint = await import('tslint');
} catch {
throw new Error('Unable to find TSLint. Ensure TSLint is installed.');
}

const tslintConfigPath = options.tslintConfig
? path.resolve(systemRoot, options.tslintConfig)
: null;
const Linter = projectTslint.Linter;
const Linter = tslint.Linter;

let result: undefined | LintResult = undefined;
if (options.tsConfig) {
Expand All @@ -81,7 +66,7 @@ async function _run(
let i = 0;
for (const program of allPrograms) {
const partial = await _lint(
projectTslint,
tslint,
systemRoot,
tslintConfigPath,
options,
Expand Down Expand Up @@ -111,15 +96,15 @@ async function _run(
context.reportProgress(++i, allPrograms.length);
}
} else {
result = await _lint(projectTslint, systemRoot, tslintConfigPath, options);
result = await _lint(tslint, systemRoot, tslintConfigPath, options);
}

if (result == undefined) {
throw new Error('Invalid lint configuration. Nothing to lint.');
}

if (!options.silent) {
const Formatter = projectTslint.findFormatter(options.format || '');
const Formatter = tslint.findFormatter(options.format || '');
if (!Formatter) {
throw new Error(`Invalid lint format "${options.format}".`);
}
Expand Down