<commit_before>
export class Rule extends Lint.Rules.AbstractRule {
    public static FAILURE_STRING = "unused import: ";

    public apply(sourceFile): Lint.RuleFailure[] {
        var documentRegistry = ts.createDocumentRegistry();
        var languageServiceHost = Lint.createLanguageServiceHost("file.ts", sourceFile.getFullText());
        var languageService = ts.createLanguageService(languageServiceHost, documentRegistry);
        return this.applyWithWalker(new NoUnusedImportsWalker(sourceFile, this.getOptions(), languageService));
    }
}

class NoUnusedImportsWalker extends Lint.RuleWalker {

    private fileName: string;
    private languageServices: any;

    public constructor(sourceFile : ts.SourceFile, options, languageServices) {
        super(sourceFile, options);
        this.fileName = sourceFile.fileName;
        console.log('analyzing: ' + sourceFile.fileName);
        this.languageServices = languageServices;
    }

    protected visitImportEqualsDeclaration(node: ts.ImportEqualsDeclaration): void {
        if (!Lint.hasModifier(node.modifiers, ts.SyntaxKind.ExportKeyword)) {
            this.validateReferencesForVariable(node.name.text, node.name.getStart());
        }
        super.visitImportEqualsDeclaration(node);
    }

    private validateReferencesForVariable(name, position) {
        var highlights = this.languageServices.getDocumentHighlights("file.ts", position, ["file.ts"]);
        if (highlights[0].highlightSpans.length <= 1) {
            this.addFailure(this.createFailure(position, name.length, Rule.FAILURE_STRING + "'" + name + "'"));
        }
    }
}
<commit_msg>Added types to No Unused Import Rule<commit_after>
export class Rule extends Lint.Rules.AbstractRule {
    public static FAILURE_STRING = "unused import: ";

    public apply(sourceFile : ts.SourceFile): Lint.RuleFailure[] {
        var documentRegistry = ts.createDocumentRegistry();
        var languageServiceHost = Lint.createLanguageServiceHost("file.ts", sourceFile.getFullText());
        var languageService = ts.createLanguageService(languageServiceHost, documentRegistry);
        return this.applyWithWalker(new NoUnusedImportsWalker(sourceFile, this.getOptions(), languageService));
    }
}

class NoUnusedImportsWalker extends Lint.RuleWalker {

    private languageServices: ts.LanguageService;

    public constructor(sourceFile : ts.SourceFile, options : Lint.IOptions, languageServices : ts.LanguageService) {
        super(sourceFile, options);
        this.languageServices = languageServices;
    }

    protected visitImportEqualsDeclaration(node: ts.ImportEqualsDeclaration): void {
        if (!Lint.hasModifier(node.modifiers, ts.SyntaxKind.ExportKeyword)) {
            this.validateReferencesForVariable(node.name.text, node.name.getStart());
        }
        super.visitImportEqualsDeclaration(node);
    }

    private validateReferencesForVariable(name : string, position : number) {
        var highlights = this.languageServices.getDocumentHighlights("file.ts", position, ["file.ts"]);
        if (highlights[0].highlightSpans.length <= 1) {
            this.addFailure(this.createFailure(position, name.length, Rule.FAILURE_STRING + "'" + name + "'"));
        }
    }
}

{'fraction_non_alphanumeric': 0.10581683168316831, 'fraction_numerical': 0.0012376237623762376, 'mean_word_length': 3.9208523592085234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6929636', 'n_tokens_mistral': 861, 'n_tokens_neox': 844, 'n_words': 160}