This package has been deprecated

Author message:

TSLint has been deprecated in favor of ESLint. Please see https://github.com/palantir/tslint/issues/4534 for more information.

@favware/milky-tslint
TypeScript icon, indicating that this package has built-in type declarations

1.1.5 • Public • Published

DEPRECATED

TSLint has been deprecated in favor of ESLint. Please see this TSLint issue for more information.


logo

@favware/milky-tslint

TypeScript linter Gulp plugin, based on gulp-tslint but updated for modernization


Project Status

GitHub Codecov

Bundle Sizes

npm bundle size npm bundle size npm

Social Media and Donations

Join Discord server Twitter Follow Patreon Donate PayPal Donate


TypeScript linter plugin for Gulp. Based on gulp-tslint by panuhorsmalahti

Gulp down that milk 🥛!

Install

Install with yarn or npm:

yarn add @favware/milky-tslint tslint

# npm install @favware/milky-tslint tslint

Usage

const tslint = require('tslint');
const ts = require('typescript');
const { milkyLint, milkyReport } = require('milky-tslint');

gulp.task('lint', () => {
  const lintProgram = tslint.Linter.createProgram('./tsconfig.json', '.');
  ts.getPreEmitDiagnostics(lintProgram);

  return gulp
    .src(tsSource)
    .pipe(
      milkyLint({
        formatter: 'stylish',
        program: lintProgram,
        tslint: tslint,
        fix: !!argv.fix
      })
    )
    .pipe(milkyReport());
});

TSLint Type Checking will work if you first use the createProgram function as shown above. You should do this inside the gulp task, otherwise it will get cached and not function in consecutive runs of the task.

tslint.json is attempted to be read from near the input file. It must be available or supplied directly through the options.

The format in which failures are outputted may be controlled by specifying a TSLint formatter.

The default formatter is stylish and the supported formatters are at least:

  • checkstyle - Formats errors as though they were Checkstyle output.
  • codeFrame - Framed formatter which creates a frame of error code.
  • filesList - Lists files containing lint errors.
  • json - Formats errors as simple JSON.
  • junit - Formats errors as though they were JUnit output.
  • msbuild - Formats errors for consumption by msbuild.
  • pmd - Formats errors as though they were PMD output.
  • prose - The default formatter which outputs simple human-readable messages.
  • stylish - Human-readable formatter which creates stylish messages.
  • tap - Formats output as TAP stream.
  • verbose - The human-readable formatter which includes the rule name in messages.
  • vso - Formats output as VSO/TFS logging commands.

For a full list of supported formatters please go to the TSLint core formatters documentation

Custom TSLint formatters may also be used by specifying the formatter and formattersDirectory properties on the options passed to milky-tslint.

If there is at least one failure a PluginError is emitted after execution of the reporters:

[gulp] Error in plugin 'milky-tslint': Failed to lint: input.ts

You can prevent editing the error by setting emitError in report options to false.

gulp.task('lint-noerroremit', () => {
  const lintProgram = tslint.Linter.createProgram('./tsconfig.json', '.');
  ts.getPreEmitDiagnostics(lintProgram);

  return gulp
    .src(tsSource)
    .pipe(
      milkyLint({
        formatter: 'stylish',
        program: lintProgram,
        tslint: tslint,
        fix: !!argv.fix
      })
    )
    .pipe(
      milkyReport({
        emitError: false
      })
    );
});

tslint.json can be supplied as a parameter by setting the configuration property.

gulp.task('tslint-json', () =>
  gulp
    .src('input.ts')
    .pipe(
      milkyLint({
        configuration: {
          rules: {
            'class-name': true
            // ...
          }
        }
      })
    )
    .pipe(milkyReport.report())
);

You can also supply a file path to the configuration option, and the file name doesn't need to be tslint.json.

.pipe(milkyLint({
    // contains rules in the tslint.json format
    configuration: "source/settings.json"
}))

Report limits

You can optionally specify a report limit in the .report options that will turn off reporting for files after the limit has been reached. If the limit is 0 or less, the limit is ignored, which is the default setting.

gulp.task('tslint', () =>
  gulp
    .src(['input.ts'])
    .pipe(
      milkyLint({
        formatter: 'prose'
      })
    )
    .pipe(
      milkyReport.report({
        reportLimit: 2
      })
    )
);

Allowing Warnings

TSLint 5.0 introduced support for a "warning" severity for linting errors. By default, warnings cause milky-tslint to emit an error to maintain backwards-compatibility with previous versions. To let the build succeed in the presence of warnings, use the allowWarnings report option.

gulp.task('tslint', () =>
  gulp
    .src('input.ts')
    .pipe(
      milkyLint({
        formatter: 'prose'
      })
    )
    .pipe(
      milkyReport.report({
        allowWarnings: true
      })
    )
);

All default tslint options

const tslintOptions = {
  configuration: {},
  fix: false,
  formatter: 'stylish',
  formattersDirectory: null,
  rulesDirectory: null,
  tslint: null,
  program: null
};

All default report options

const reportOptions = {
  emitError: false,
  reportLimit: 0,
  summarizeFailureOutput: true,
  allowWarnings: false
};

API Documentation

Package Sidebar

Install

npm i @favware/milky-tslint

Weekly Downloads

0

Version

1.1.5

License

MIT

Unpacked Size

12.2 kB

Total Files

4

Last publish

Collaborators

  • favna
  • favware-bot