• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript rule.RuleFailure类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了RuleFailure类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例3: formatFailure

 private formatFailure(failure: RuleFailure): string {
     const fileName: string = failure.getFileName();
     const failureString: string = failure.getFailure();
     const ruleName: string = failure.getRuleName();
     const lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
     const positionTuple = '[' + (lineAndCharacter.line + 1) + ', ' + (lineAndCharacter.character + 1) + ']';
     return '(' + ruleName + ') ' + fileName + positionTuple + ': ' + failureString;
 }
开发者ID:AloeDream,项目名称:tslint-microsoft-contrib,代码行数:8,代码来源:BaseFormatter.ts


示例4: super

        super('no-var-keyword', (failure: RuleFailure): void => {
            const fileName: string = failure.getFileName();
            const start: RuleFailurePosition = failure.getStartPosition();
            const fileContents: string = this.readFile(fileName);

            const leftSide: string = fileContents.substring(0, start.getPosition());
            const rightSide: string = fileContents.substring(start.getPosition() + 3);

            const newContent: string = leftSide + 'let' + rightSide;
            this.writeFile(fileName, newContent);
            /* tslint:disable:no-console */
            console.log('Automatically converting var to let. Please re-compile and re-lint: ' + fileName);
            /* tslint:enable:no-console */
        });
开发者ID:AloeDream,项目名称:tslint-microsoft-contrib,代码行数:14,代码来源:fixNoVarKeywordFormatter.ts


示例5: super

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

            let leftSide: string = fileContents.substring(0, start);
            leftSide = leftSide.replace(/let\s?$/, 'const ');
            const rightSide: string = fileContents.substring(start);
            const newContent: string = leftSide + rightSide;

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript tsmonad.Maybe类代码示例发布时间:2022-05-25
下一篇:
TypeScript tslint.RuleFailure类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap