This package has been deprecated

Author message:

Moved to @favware/milky-tslint. Please migrate for future updates

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

1.0.2 • Public • Published

logo

milky-tslint

DepfuLicense

NPM bundle size (minified)NPM bundle size (minified + gzip)NPM VersionNPM Weekly DownloadsNPM Total Downloads

Follow me on TwitterDonate with PayPalBecome a Patron

Join Discord Server
NPM Stats

TypeScript linter plugin for Gulp. Based on gulp-tslint by panuhorsmalahti but updated for 2018/2019 coding methods and packages

Gulp down that milk

Add milky-tslint with npm or yarn

yarn add -D milky-tslint
npm i --save-dev milky-tslint
Peer dependencies

The tslint module is a peer dependency of milky-tslint, which allows you to update tslint independently from milky-tslint. milky-tslint requires TypeScript version >=2 and tslint version >=4.

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
};

Development

  1. Fork this repository
  2. Install dependencies with yarn
  3. Make changes
  4. Compile to JS with gulp build
  5. Confirm linting is correct with gulp lint
  6. Send pull requests

Buy me a donut

This project is open source and always will be, even if I don't get donations. That said, I know there are people out there that may still want to donate just to show their appreciation so this is for you guys. Thanks in advance!

I accept donations through PayPal, BitCoin, Ethereum and LiteCoin. You can use the buttons below to donate through your method of choice

Donate With QR Address
Donate with PayPal
1E643TNif2MTh75rugepmXuq35Tck4TnE5
0xF653F666903cd8739030D2721bF01095896F5D6E
LZHvBkaJqKJRa8N7Dyu41Jd1PDBAofCik6

Package Sidebar

Install

npm i milky-tslint

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

18 kB

Total Files

8

Last publish

Collaborators

  • favna