当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript RuleFailure.getEndPosition方法代码示例

本文整理汇总了TypeScript中tslint/lib/language/rule/rule.RuleFailure.getEndPosition方法的典型用法代码示例。如果您正苦于以下问题:TypeScript RuleFailure.getEndPosition方法的具体用法?TypeScript RuleFailure.getEndPosition怎么用?TypeScript RuleFailure.getEndPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tslint/lib/language/rule/rule.RuleFailure的用法示例。


在下文中一共展示了RuleFailure.getEndPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: super

        super('no-unused-imports', (failure: RuleFailure): void => {
            const fileName: string = failure.getFileName();
            const start: RuleFailurePosition = failure.getStartPosition();
            const end: RuleFailurePosition = failure.getEndPosition();

            let fileContents: string = this.readFile(fileName);

            let startOfViolation: number = fileContents.lastIndexOf('\n', start.getPosition());
            if (startOfViolation === -1) {
                startOfViolation = 0; // make sure to handle the first line in the file
            }
            const endOfViolation: number = fileContents.indexOf('\n', end.getPosition());

            let line: string = fileContents.substring(startOfViolation, endOfViolation);
            line = line.trim(); // trim off any new lines, handle those in regular expression
            line = line.replace(/\(/, '\\(').replace(/\)/, '\\)');
            const regex: RegExp = new RegExp('\\n*' + line + '\\n*', 'mg');

            if (startOfViolation === 0) {
                fileContents = fileContents.replace(regex, '');
            } else {
                fileContents = fileContents.replace(regex, '\n');
            }
            this.writeFile(fileName, fileContents);
            /* tslint:disable:no-console */
            console.log('Automatically removing unused import. Please re-compile and re-lint: ' + fileName);
            /* tslint:enable:no-console */
        });
开发者ID:AloeDream,项目名称:tslint-microsoft-contrib,代码行数:28,代码来源:fixNoUnusedImportsFormatter.ts

示例2: super

        super('no-require-imports', (failure: RuleFailure): void => {
            const fileName: string = failure.getFileName();
            const fileContents: string = this.readFile(fileName);
            const start: number = failure.getStartPosition().getPosition();
            const end: number = failure.getEndPosition().getPosition();

            let importStartIndex = fileContents.lastIndexOf('\n', start) + 1;
            if (importStartIndex === -1) {
                importStartIndex = 0;
            }
            const importEndIndex = fileContents.indexOf('\n', end);

            const leftSide: string = fileContents.substring(0, importStartIndex);
            const middle: string = fileContents.substring(importStartIndex, importEndIndex).trim();
            const rightSide: string = fileContents.substring(importEndIndex);

            let newImport: string = middle.replace(
                /import\s+(.*)\s+=\s*require\(((.|\s)*)\);/m,
                'import {$1} from $2;');
            newImport = newImport.replace(/from \n/, 'from\n'); // clean up some spacing
            const newContent: string = leftSide + newImport + rightSide;

            this.writeFile(fileName, newContent);
            /* tslint:disable:no-console */
            console.log('Automatically converting require-style import to an ES6 import. Please re-compile and re-lint: ' + fileName);
            /* tslint:enable:no-console */
        });
开发者ID:AloeDream,项目名称:tslint-microsoft-contrib,代码行数:27,代码来源:fixNoRequireImportsFormatter.ts


注:本文中的tslint/lib/language/rule/rule.RuleFailure.getEndPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。