How to use the tslint.Formatters function in tslint

To help you get started, we’ve selected a few tslint 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 vuejs / vue-cli / packages / @vue / cli-plugin-typescript / lib / tslint.js View on Github external
return globby(patterns, { cwd }).then(files => {
    files.forEach(lintFile)
    if (silent) return
    const result = linter.getResult()
    if (result.output.trim()) {
      process.stdout.write(result.output)
    } else if (result.fixes.length) {
      // some formatters do not report fixes.
      const f = new tslint.Formatters.ProseFormatter()
      process.stdout.write(f.format(result.failures, result.fixes))
    } else if (!result.failures.length) {
      console.log(`No lint errors found.\n`)
    }

    if (result.failures.length && !args.force) {
      process.exitCode = 1
    }
  })
}
github Akryum / nodepack / packages / @nodepack / plugin-typescript / src / lib / tslint.js View on Github external
return globby(files, { cwd }).then(files => {
    files.forEach(lint)
    if (silent) return
    const result = linter.getResult()
    if (!result) {
      console.log(`No result.\n`)
    } else if (result.output.trim()) {
      process.stdout.write(result.output)
    } else if (result.fixes && result.fixes.length) {
      // some formatters do not report fixes.
      const f = new tslint.Formatters.ProseFormatter()
      process.stdout.write(f.format(result.failures, result.fixes))
    } else if (!result.failures.length) {
      console.log(`No lint errors found.\n`)
    }

    if (result.failures.length && !args.force) {
      process.exitCode = 1
    }
  })
}
github Akryum / nodepack / packages / @nodepack / plugin-typescript / src / lib / tslint.js View on Github external
return globby(files, { cwd }).then(files => {
    files.forEach(lint)
    if (silent) return
    const result = linter.getResult()
    if (!result) {
      console.log(`No result.\n`)
    } else if (result.output.trim()) {
      process.stdout.write(result.output)
    } else if (result.fixes && result.fixes.length) {
      // some formatters do not report fixes.
      const f = new tslint.Formatters.ProseFormatter()
      process.stdout.write(f.format(result.failures, result.fixes))
    } else if (!result.failures.length) {
      console.log(`No lint errors found.\n`)
    }

    if (result.failures.length && !args.force) {
      process.exitCode = 1
    }
  })
}
github guidsdo / multipleTypescriptCompilers / lib / tslint / TscFormatter.js View on Github external
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslint_1 = require("tslint");
const index_1 = require("../index");
// Export as Formatter for Tslint's autofind feature
class Formatter extends tslint_1.Formatters.AbstractFormatter {
    format(failures) {
        return failures.map(this.formatFailure).join("\n");
    }
    formatFailure(failure) {
        const fileName = index_1.getRelativePath(failure.getFileName());
        const severity = Formatter.alwaysShowRuleFailuresAsWarnings
            ? "warning"
            : failure.getRuleSeverity().toLocaleLowerCase();
        const start = failure.getStartPosition();
        const lineStart = start.getLineAndCharacter().line + 1;
        const charStart = start.getLineAndCharacter().character + 1;
        const issue = failure.getFailure();
        // Format it as TSC..
        // https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher
        // and use TS2515 because the plugin uses it..
        // See: https://github.com/angelozerr/tslint-language-service/blob/master/src/index.ts#L17
github microsoft / reactxp / samples / TodoList / gulpfile.js View on Github external
function usesWebpack() {
    return (platform === PLATFORMS.WEB || platform === PLATFORMS.TESTS);
}

function getPlatformSpecificResources() {
    var configKey = {
        'ios': 'iOS',
        'android': 'android',
        'windows': 'windows',
        'macos':'macos'
    }[platform];

    return config[configKey] || {};
}

var defaultFormatter = new tslintEng.Formatters.StylishFormatter();
var createCacheInvalidator = function(cacheName) {
    function formatter() {}
    formatter.prototype.format = function(ruleFailures) {
        // Remove affected files from the cache.
        if (ruleFailures && ruleFailures.length && cached.caches[cacheName]) {
            ruleFailures.forEach(function(ruleFailure) {
                var path = ruleFailure.path || ruleFailure.fileName;
                // Note: The path does not always use the same folder separator as the cache's key.
                var pathForwards = path.replace(/\\/g, '/');
                var pathBackwards = path.replace(/\//g, '\\');
                delete cached.caches[cacheName][path];
                delete cached.caches[cacheName][pathForwards];
                delete cached.caches[cacheName][pathBackwards];
            });
        }
github liangchunn / typescript-node-scripts / src / lib / formatters / lintTableFormatter.ts View on Github external
import chalk from 'chalk'
import stripAnsi from 'strip-ansi'
import textTable from 'text-table'
import * as Lint from 'tslint'

export class Formatter extends Lint.Formatters.AbstractFormatter {
  public format(failures: Lint.RuleFailure[]): string {
    return textTable(failures.map(this.formatFailure), {
      align: ['', 'r', 'l'] as any,
      stringLength: str => stripAnsi(str).length,
    })
      .split('\n')
      .map(ln =>
        ln.replace(/(\d+)\s+(\d+)/, (_, line, char) => `${line}:${char}`)
      )
      .join('\n')
  }
  private formatFailure(failure: Lint.RuleFailure): string[] {
    const { line, character } = failure.getStartPosition().getLineAndCharacter()
    const message = failure.getFailure()
    const ruleName = failure.getRuleName()
    return [
github mgechev / codelyzer / docs / src / worker / web-linter.ts View on Github external
public getResult(): LintResult {
    const formatter = new Linter.Formatters.JsonFormatter();
    const output = formatter.format(this.failures);

    return {
      warningCount: 0,
      errorCount: this.failures.length,
      failures: this.failures,
      format: 'json',
      output
    };
  }
github wbuchwalter / tslint-loader / formatters / customFormatter.js View on Github external
var Formatter = (function (_super) {
  __extends(Formatter, _super);
  function Formatter() {
    _super.apply(this, arguments);
  }
  Formatter.prototype.format = function (failures) {
    var outputLines = failures.map(function (failure) {
      var failureString = failure.getFailure();
      var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
      var positionTuple = "[" + (lineAndCharacter.line + 1) + ", " + (lineAndCharacter.character + 1) + "]";
      return positionTuple + ": " + failureString;
    });
    return outputLines.join("\n") + "\n";
  };
  return Formatter;
})(Lint.Formatters.AbstractFormatter);
exports.Formatter = Formatter;
github luoxue-victor / webpack-box / packages / tslint / lint.js View on Github external
return globby(files, { cwd }).then(files => {
    files.forEach(lint)
    if (silent) return
    const result = linter.getResult()
    if (result.output.trim()) {
      process.stdout.write(result.output)
    } else if (result.fixes.length) {
      const f = new tslint.Formatters.ProseFormatter()
      process.stdout.write(f.format(result.failures, result.fixes))
    } else if (!result.failures.length) {
      done('tslint 没有发现错误.\n')
    }

    if (result.failures.length && !args.force) {
      process.exitCode = 1
    }
  })
}
github microsoft / tslint-microsoft-contrib / utils / BaseFormatter.js View on Github external
BaseFormatter.prototype.readFile = function (fileName) {
        return fs.readFileSync(fileName, { encoding: 'UTF-8' });
    };
    BaseFormatter.prototype.writeFile = function (fileName, fileContents) {
        fs.writeFileSync(fileName, fileContents, { encoding: 'UTF-8' });
    };
    BaseFormatter.prototype.formatFailure = function (failure) {
        var fileName = failure.getFileName();
        var failureString = failure.getFailure();
        var ruleName = failure.getRuleName();
        var lineAndCharacter = failure.getStartPosition().getLineAndCharacter();
        var positionTuple = '[' + (lineAndCharacter.line + 1) + ', ' + (lineAndCharacter.character + 1) + ']';
        return '(' + ruleName + ') ' + fileName + positionTuple + ': ' + failureString;
    };
    return BaseFormatter;
}(tslint_1.Formatters.AbstractFormatter));
exports.BaseFormatter = BaseFormatter;
//# sourceMappingURL=BaseFormatter.js.map