How to use the @fimbul/ymir.requiresCompilerOption 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 / delete-only-optional-property.ts View on Github external
import { excludeDeclarationFiles, TypedRule, requiresCompilerOption } from '@fimbul/ymir';
import {
    WrappedAst,
    getWrappedNodeAtPosition,
    isDeleteExpression,
    isElementAccessExpression,
} from 'tsutils';
import * as ts from 'typescript';
import { elementAccessSymbols } from '../utils';

@excludeDeclarationFiles
@requiresCompilerOption('strictNullChecks')
export class Rule extends TypedRule {
    public apply() {
        const re = /\bdelete\b/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 (!isDeleteExpression(node) || node.expression.pos !== re.lastIndex)
                continue;
            const {expression} = node;
            if (isElementAccessExpression(expression)) {
                for (const {symbol, name} of elementAccessSymbols(expression, this.checker))
                    this.checkSymbol(symbol, node, name);
            } else {
                this.checkSymbol(this.checker.getSymbolAtLocation(expression), node);
            }
        }