How to use the @fimbul/ymir.requireLibraryFile function in @fimbul/ymir

To help you get started, we’ve selected a few @fimbul/ymir examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fimbullinter / wotan / packages / mimir / src / rules / prefer-number-methods.ts View on Github external
import { TypedRule, Replacement, excludeDeclarationFiles, requireLibraryFile } from '@fimbul/ymir';
import * as ts from 'typescript';
import { WrappedAst, getWrappedNodeAtPosition, isIdentifier, isCallExpression, unionTypeParts } from 'tsutils';

@excludeDeclarationFiles
@requireLibraryFile('lib.es2015.core.d.ts')
export class Rule extends TypedRule {
    public apply() {
        const re = /\b(?:isNaN|isFinite)\s*[/(]/g;
        let wrappedAst: WrappedAst | undefined;
        for (let match = re.exec(this.sourceFile.text); match !== null; match = re.exec(this.sourceFile.text)) {
            const {node} = getWrappedNodeAtPosition(wrappedAst || (wrappedAst = this.context.getWrappedAst()), match.index)!;
            if (!isIdentifier(node) || node.text !== 'isNaN' && node.text !== 'isFinite' || node.end - node.text.length !== match.index)
                continue;
            const parent = node.parent!;
            if (isCallExpression(parent) && parent.expression === node && parent.arguments.length === 1 &&
                this.isCorrectArgumentType(parent.arguments[0]))
                this.addFinding(
                    match.index,
                    node.end,
                    `Prefer 'Number.${node.text}' over '${node.text}'.`,
                    Replacement.append(match.index, 'Number.'),