How to use the tslint.Configuration.findConfiguration 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 microsoft / dtslint / src / lint.ts View on Github external
async function getLintConfig(
    expectedConfigPath: string,
    tsconfigPath: string,
    minVersion: TsVersion,
    maxVersion: TsVersion,
    tsLocal: string | undefined,
): Promise {
    const configExists = await pathExists(expectedConfigPath);
    const configPath = configExists ? expectedConfigPath : joinPaths(__dirname, "..", "dtslint.json");
    // Second param to `findConfiguration` doesn't matter, since config path is provided.
    const config = Configuration.findConfiguration(configPath, "").results;
    if (!config) {
        throw new Error(`Could not load config at ${configPath}`);
    }

    const expectRule = config.rules.get("expect");
    if (!expectRule || expectRule.ruleSeverity !== "error") {
        throw new Error("'expect' rule should be enabled, else compile errors are ignored");
    }
    if (expectRule) {
        const versionsToTest =
            range(minVersion, maxVersion).map(versionName => ({ versionName, path: typeScriptPath(versionName, tsLocal) }));
        const expectOptions: ExpectOptions = { tsconfigPath, versionsToTest };
        expectRule.ruleArguments = [expectOptions];
    }
    return config;
}
github kratiahuja / broccoli-tslinter / index.js View on Github external
TSLint.prototype.processString = function(content, relativePath) {
  var linter = new Linter(this.options);
  var configLoad = Configuration.findConfiguration(this.tslintConfigPath, relativePath);
  linter.lint(relativePath, content, configLoad.results);
  var result = linter.getResult();

  this.totalFiles++;

  var passed = result.errorCount === 0;
  var errors = [];
  if (!passed) {
    // error is seen
    this.errorCount += result.errorCount;

    errors = result.failures.map((failure) => {
      var position = failure.startPosition.lineAndCharacter;
      var line = position.line + 1;
      var character = position.character + 1;
      return `${failure.ruleSeverity.toUpperCase()}: ${failure.fileName}[${line}, ${character}]: ${failure.failure} (${failure.ruleName})`;
github sevenval / frontend-configs / packages / tslint-config-sevenval / src / __tests__ / helpers.ts View on Github external
export function run(filename: string, config: string) {
  const fileContents = fs.readFileSync(filename, 'utf8');
  const linter = new Linter({
    fix: false,
    formatter: 'json',
  });

  const configuration = Configuration.findConfiguration(config, filename)
    .results;
  linter.lint(filename, fileContents, configuration);
  return linter.getResult();
}
github palantir / blueprint / packages / node-build-scripts / ts-lint.js View on Github external
const fs = require("fs");
const { run } = require("tslint/lib/runner");
const { Configuration } = require("tslint");
const { junitReportPath } = require("./utils");

let format = "codeFrame";
let out;
let outputStream = process.stdout;
if (process.env.JUNIT_REPORT_PATH != null) {
    format = "junit";
    out = junitReportPath("tslint");
    console.info(`TSLint report will appear in ${out}`);
    outputStream = fs.createWriteStream(out, { flags: "w+" });
}

const configFile = Configuration.findConfiguration(null, __dirname).path;

run({
    config: configFile,
    exclude: [],
    files: ["{src,test}/**/*.tsx"],
    fix: process.argv.includes("--fix"),
    format,
    out,
}, {
    error(m) {
        process.stderr.write(m);
    },
    log(m) {
        outputStream.write(m);
    },
})
github grafana / grafana / packages / grafana-toolkit / src / cli / tasks / plugin.build.ts View on Github external
export const lintPlugin = useSpinner('Linting', async ({ fix }) => {
  let tsLintConfigPath = path.resolve(process.cwd(), 'tslint.json');
  if (!fs.existsSync(tsLintConfigPath)) {
    tsLintConfigPath = path.resolve(__dirname, '../../config/tslint.plugin.json');
  }
  const options = {
    fix: fix === true,
    formatter: 'json',
  };

  const configuration = Configuration.findConfiguration(tsLintConfigPath).results;
  const sourcesToLint = getTypescriptSources();

  const lintResults = sourcesToLint
    .map(fileName => {
      const linter = new Linter(options);
      const fileContents = fs.readFileSync(fileName, 'utf8');
      linter.lint(fileName, fileContents, configuration);
      return linter.getResult();
    })
    .filter(result => {
      return result.errorCount > 0 || result.warningCount > 0;
    });

  if (lintResults.length > 0) {
    console.log('\n');
    const failures = lintResults.reduce((failures, result) => {
github TracerBench / tracerbench / packages / tracerbench / scripts / lint.js View on Github external
files.forEach(file => {
    const fileContents = program.getSourceFile(file).getFullText();
    const configuration = Configuration.findConfiguration("tslint.json", file)
      .results;
    linter.lint(file, fileContents, configuration);
  });
github wix / haste / packages / haste-task-tslint / src / index.js View on Github external
files.forEach(({ filename, content }) => {
    const config = Configuration.findConfiguration(configurationFilePath, filename).results;
    linter.lint(filename, content, config);
  });
github cartant / tslint-etc / source / fixtures-spec.ts View on Github external
function lint(dir: string, configFileName?: string, fixtureFileName?: string): LintResult {

        const fixturesDir = path.resolve("./fixtures");
        const fixtureDir = `${fixturesDir}/${dir}`;
        const fileName = `${fixtureDir}/${fixtureFileName || "fixture.ts"}`;
        const content = fs.readFileSync(fileName, "utf8");
        const program = Linter.createProgram(`${fixtureDir}/tsconfig.json`);
        const linter = new Linter({ fix: false }, program);

        const configuration = Configuration.findConfiguration(
            configFileName ?
                `${fixtureDir}/${configFileName}` :
                `${fixturesDir}/tslint.json`,
            fileName
        ).results;

        linter.lint(fileName, content, configuration);
        return linter.getResult();
    }
});
github guidsdo / multipleTypescriptCompilers / src / tslint / TslintRunner.ts View on Github external
private lintFilesAsync() {
        const program = Linter.createProgram(this.tsconfig);
        const linter = new Linter({ fix: this.autofix, formatter: Formatter }, program);
        const files = Linter.getFileNames(program);
        const configuration = Configuration.findConfiguration(this.tslintCfg).results;

        const lintInEventLoop = (remainingFiles: string[]) => {
            const file = remainingFiles.shift()!;
            const fileContents = program.getSourceFile(file)!.getFullText();
            linter.lint(file, fileContents, configuration);

            if (remainingFiles.length && !this.terminated) {
                setImmediate(lintInEventLoop, remainingFiles);
            } else {
                this.running = false;

                if (this.terminated) {
                    debugLog("Tslint: Aborted", this.tsconfig);
                } else {
                    this.lastResult = linter.getResult().output;
                    debugLog("Tslint: Done", this.tsconfig);