How to use the tslint.Configuration 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 nativescript-vue / vue-cli-plugin-nativescript-vue / lib / tslint.js View on Github external
linter.lint(
      // append .ts so that tslint apply TS rules
      filePath,
      '',
      // use Vue config to ignore blank lines
      isVue ? vueConfig : config
    );
    restoreWriteFile();
  };

  const files = args._ && args._.length ? args._ : ['src/**/*.ts', 'src/**/*.vue', 'src/**/*.tsx', 'tests/**/*.ts', 'tests/**/*.tsx'];

  // respect linterOptions.exclude from tslint.json
  if (config.linterOptions && config.linterOptions.exclude) {
    // use the raw tslint.json data because config contains absolute paths
    const rawTslintConfig = tslint.Configuration.readConfigurationFile(tslintConfigPath);
    const excludedGlobs = rawTslintConfig.linterOptions.exclude;
    excludedGlobs.forEach((g) => files.push('!' + g));
  }

  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) {
      // 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`);
github pnp / pnpjs / tools / gulptasks / lint.js View on Github external
gulp.task("lint:tests", (done) => {

    var program = tslint.Linter.createProgram("./test/tsconfig.json");

    // we need to load and override the configuration
    let config = tslint.Configuration.loadConfigurationFromPath("./tslint.json");
    config.rules.set("no-unused-expression", { ruleSeverity: "off" });

    pump([
        gulp.src([
            "./packages/**/*.test.ts",
            "!**/node_modules/**",
            "!**/*.d.ts"
        ]),
        gulpTslint({
            configuration: config,
            formatter: "prose",
            program: program,
        }),
        gulpTslint.report({ emitError: false }),
    ], (err) => {
github fimbullinter / wotan / packages / valtyr / src / configuration-provider.ts View on Github external
public find(fileName: string) {
        fileName = path.dirname(fileName);
        let result = this.cache.get(fileName);
        if (result === undefined && !this.cache.has(fileName)) {
            result = TSLint.Configuration.findConfigurationPath(null, fileName); // tslint:disable-line:no-null-keyword
            const {root} = path.parse(fileName);
            // prevent infinite loop when result is on different drive
            const configDirname = result === undefined || root !== path.parse(result).root ? root : path.dirname(result);
            this.cache.set(fileName, result);
            while (fileName !== configDirname) {
                this.cache.set(fileName, result);
                fileName = path.dirname(fileName);
            }
        }
        return result;
    }
github kratiahuja / broccoli-tslinter / index.js View on Github external
var Filter = require('broccoli-persistent-filter');
var chalk = require('chalk');
var existsSync = require('exists-sync');
var path = require('path');
var Linter = require('tslint').Linter;
var Configuration = require('tslint').Configuration;
var fs = require('fs');
var testGenerators = require('aot-test-generators');

function TSLint(inputNode, options) {
  if (!(this instanceof TSLint)) {
    return new TSLint(inputNode, options);
  }
  options = options || {};

  this.options = {
    outputFile: options.outputFile,
    failBuild: options.failBuild || false,
    disableTestGenerator: options.disableTestGenerator || false,
    testGenerator: options.testGenerator || null,
    logError: options.logError
  };
github typescript-eslint / typescript-eslint / packages / benchmark / tslint-runner.js View on Github external
exports.runTSLint = function(directory, files, useServices) {
  const program = useServices
    ? tslint.Linter.createProgram(`${directory}tsconfig.json`)
    : undefined;
  const linter = new tslint.Linter(
    {
      fix: false,
      formatter: 'json'
    },
    program
  );
  const tslintConfig = tslint.Configuration.loadConfigurationFromPath(
    `./${directory}tslint.json`
  );
  for (const file of files) {
    linter.lint(
      file,
      fs.readFileSync(path.join(__dirname, file), 'utf8'),
      tslintConfig
    );
  }
  const result = linter.getResult();
  if (result.errorCount === 0) {
    throw new Error('something went wrong');
  }
  return result.failures[0].failure;
};
github swimos / swim / swim-js / swim-core-js / @swim / build / main / Target.ts View on Github external
constructor(project: Project, config: TargetConfig) {
    this.project = project;

    this.id = config.id;
    this.uid = this.project.id + ":" + this.id;
    this.path = config.path !== void 0 ? config.path : this.id;
    this.baseDir = path.resolve(this.project.baseDir, this.path);

    this.deps = [];

    this.preamble = config.preamble;

    this.compilerOptions = config.compilerOptions || this.project.compilerOptions;
    this.lintConfig = tslint.Configuration.findConfiguration(null, this.baseDir).results!;

    this.selected = false;
    this.watching = false;
    this.failed = false;
    this.retest = false;
    this.redoc = false;

    this.compileStart = 0;
    this.bundleTimer = 0;
    this.bundle = this.bundle.bind(this);
    this.onBundleWarning = this.onBundleWarning.bind(this);
    this.onBundleError = this.onBundleError.bind(this);
  }
github luoxue-victor / webpack-box / packages / tslint / lint.js View on Github external
const isVue = isVueFile(file)
    patchWriteFile()
    linter.lint(
      filePath,
      '',
      isVue ? vueConfig : config
    )
    restoreWriteFile()
  }

  const files = args._ && args._.length
    ? args._
    : [cwd + '/src/**/*.ts', cwd + '/src/**/*.vue', cwd + '/src/**/*.tsx']

  if (config.linterOptions && config.linterOptions.exclude) {
    const rawTslintConfig = tslint.Configuration.readConfigurationFile(tslintConfigPath)
    const excludedGlobs = rawTslintConfig.linterOptions.exclude
    excludedGlobs.forEach((g) => files.push('!' + g))
  }

  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')
    }
github Siteimprove / alfa / scripts / helpers / project.js View on Github external
function getLinterOptions(configFile) {
  const { results } = TSLint.Configuration.findConfiguration(
    "tslint.json",
    configFile
  );

  return results;
}
github DonJayamanne / pythonVSCode / gulpfile.js View on Github external
function getLinter(options) {
    configuration = configuration ? configuration : tslint.Configuration.findConfiguration(null, '.');
    const program = tslint.Linter.createProgram('./tsconfig.json');
    const linter = new tslint.Linter({ formatter: 'json' }, program);
    return { linter, configuration };
}
let compilationInProgress = false;
github microsoft / rushstack / gulp-core-build-typescript / src / TSLintTask.ts View on Github external
rulesDirectory: ((): string[] => {
      const msCustomRulesMain: string = require.resolve('tslint-microsoft-contrib');
      const msCustomRulesDirectory: string = path.dirname(msCustomRulesMain);
      return TSLint.Configuration.getRulesDirectories([msCustomRulesDirectory], __dirname);
    })(),
    sourceMatch: [