Skip to content

Commit

Permalink
Honor the exemption list in language service plugin.
Browse files Browse the repository at this point in the history
Resolves the issue mentioned in microsoft/vscode#116459.

PiperOrigin-RevId: 358426009
Change-Id: Id80e6e4f46207239fdac316e7af2eab91cad17af
  • Loading branch information
uraj committed Feb 19, 2021
1 parent c0f10f7 commit 6fc93b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
23 changes: 17 additions & 6 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,25 @@ export function isInBuildMode(cmdArgs: string[]) {
return false;
}

/** Perform security checks on a single project. */
export function performCheck(program: ts.Program): ts.Diagnostic[] {
/**
* Create a new cheker with all enabled rules registered and the exemption list
* configured.
*/
export function getConfiguredChecker(program: ts.Program):
{checker: Checker, errors: ts.Diagnostic[]} {
let exemptionList: ExemptionList|undefined = undefined;

const exemptionConfigPath = resolveExemptionConfigPath(
program.getCompilerOptions()['configFilePath'] as string);

const diagnostics = [];
const errors = [];

if (exemptionConfigPath) {
const projExemptionConfigOrErr = parseExemptionConfig(exemptionConfigPath);
if (projExemptionConfigOrErr instanceof ExemptionList) {
exemptionList = projExemptionConfigOrErr;
} else {
diagnostics.push(...projExemptionConfigOrErr);
errors.push(...projExemptionConfigOrErr);
}
}

Expand All @@ -65,17 +69,24 @@ export function performCheck(program: ts.Program): ts.Diagnostic[] {
rule.register(checker);
}

return {checker, errors};
}

/** Perform security checks on a single project. */
export function performCheck(program: ts.Program): ts.Diagnostic[] {
const {checker, errors} = getConfiguredChecker(program);

// Run all enabled checks and collect errors.
for (const sf of program.getSourceFiles()) {
// We don't emit errors for delcarations, so might as well skip checking
// declaration files all together.
if (sf.isDeclarationFile) continue;
const tsecErrors = checker.execute(sf).map(
failure => failure.toDiagnosticWithStringifiedFixes());
diagnostics.push(...tsecErrors);
errors.push(...tsecErrors);
}

return diagnostics;
return errors;
}

const ALL_TSEC_RULE_NAMES =
Expand Down
12 changes: 3 additions & 9 deletions src/language_service_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* directly in the editor.
*/

import {ENABLED_RULES} from './rule_groups';
import {Checker} from './third_party/tsetse/checker';
import {ErrorCode} from './third_party/tsetse/error_code';
import {DiagnosticWithFixes} from './third_party/tsetse/failure';
import * as ts from 'typescript/lib/tsserverlibrary';

import {getConfiguredChecker} from './build';
import {createProxy} from './utils';

function diagnosticToCodeFixActions(d: DiagnosticWithFixes):
Expand Down Expand Up @@ -86,13 +86,7 @@ class TsecLanguageServicePlugin {
);
}

const checker = new Checker(program);

// Register all of the rules for now.
for (const rule of ENABLED_RULES) {
new rule().register(checker);
}

const {checker} = getConfiguredChecker(program);
const failures = checker.execute(program.getSourceFile(fileName)!);

this.codeFixActions.set(fileName, new Map());
Expand Down

0 comments on commit 6fc93b9

Please sign in to comment.