How to use the tslint.Linter 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 / vscode / build / gulpfile.hygiene.js View on Github external
let formatted = result.dest.replace(/\r\n/gm, '\n');

			if (original !== formatted) {
				console.error("File not formatted. Run the 'Format Document' command to fix it:", file.relative);
				errorCount++;
			}
			cb(null, file);

		}, err => {
			cb(err);
		});
	});

	const tslintConfiguration = tslint.Configuration.findConfiguration('tslint.json', '.');
	const tslintOptions = { fix: false, formatter: 'json' };
	const tsLinter = new tslint.Linter(tslintOptions);

	const tsl = es.through(function (file) {
		const contents = file.contents.toString('utf8');
		tsLinter.lint(file.relative, contents, tslintConfiguration.results);
		this.emit('data', file);
	});

	let input;

	if (Array.isArray(some) || typeof some === 'string' || !some) {
		const options = { base: '.', follow: true, allowEmpty: true };
		if (some) {
			input = vfs.src(some, options).pipe(filter(all)); // split this up to not unnecessarily filter all a second time
		} else {
			input = vfs.src(all, options);
		}
github angular / angular-cli / scripts / lint.ts View on Github external
export default async function(options: ParsedArgs, logger: logging.Logger) {
  _buildRules(logger);

  const lintOptions: ILinterOptions = {
    fix: options.fix,
  };

  const program = Linter.createProgram(path.join(__dirname, '../tsconfig.json'));
  const linter = new Linter(lintOptions, program);
  const tsLintPath = path.join(__dirname, '../tslint.json');
  const tsLintConfig = Configuration.loadConfigurationFromPath(tsLintPath);

  // Remove comments from the configuration, ie. keys that starts with "//".
  [...tsLintConfig.rules.keys()]
    .filter(x => x.startsWith('//'))
    .forEach(key => tsLintConfig.rules.delete(key));

  // Console is used directly by tslint, and when finding a rule that doesn't exist it's considered
  // a warning by TSLint but _only_ shown on the console and impossible to see through the API.
  // In order to see any warnings that happen from TSLint itself, we hook into console.warn() and
  // record any calls.
  const oldWarn = console.warn;
  let warnings = false;
  console.warn = (...args) => {
    warnings = true;
github Akryum / nodepack / packages / @nodepack / plugin-typescript / src / lib / tslint.js View on Github external
module.exports = function lint (args = {}, api, silent) {
  const cwd = api.resolve('.')
  const fs = require('fs')
  const globby = require('globby')
  const tslint = require('tslint')

  const options = {
    fix: args['fix'] !== false,
    formatter: args.format || 'codeFrame',
    formattersDirectory: args['formatters-dir'],
    rulesDirectory: args['rules-dir'],
  }

  const program = tslint.Linter.createProgram(api.resolve('tsconfig.json'))

  const linter = new tslint.Linter(options, program)

  const tslintConfigPath = api.resolve('tslint.json')

  const config = tslint.Configuration.findConfiguration(tslintConfigPath).results

  const lint = file => {
    const filePath = api.resolve(file)
    linter.lint(
      // append .ts so that tslint apply TS rules
      filePath,
      '',
      config,
    )
  }

  const files = args._ && args._.length
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 {
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 tkqubo / codeclimate-tslint / src / tsLinter.ts View on Github external
protected createLinter(): Linter {
    return new Linter(this.linterOption);
  }
github wix / haste / packages / haste-task-tslint / src / index.js View on Github external
function runLinter(options, configurationFilePath, files) {
  const linter = new Linter(options);

  files.forEach(({ filename, content }) => {
    const config = Configuration.findConfiguration(configurationFilePath, filename).results;
    linter.lint(filename, content, config);
  });

  return linter.getResult();
}
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
    );
  }