0.5.1 • Published 10 months ago

@nevware21/grunt-eslint-ts v0.5.1

Weekly downloads
-
License
-
Repository
github
Last release
10 months ago

GitHub Workflow Status (main) npm version downloads

Grunt-eslint-ts provides a Grunt-compatible wrapper for running eslint using the @typescript-eslint parser for processing TypeScript files, and provides some additional options that improves the TypeScript development workflow.

Grunt-eslint-ts-plugin Features

TBD...

Unsupported Grunt features

  • Path Mapping feature as it is not supported by tsc from the command-line
  • Grunt dest target property, use the src options instead.
  • Grunt files property for identifying files to be compiled (*.ts), planned future feature (#18 - Feature Add support for Grunt files object)

Quickstart

Install the npm packare: npm install @nevware21/grunt-eslint-ts --save-dev

PackageDescriptpion
ESLintnpm install eslint --save-dev - if you don't have ESLint installed in your project, run
@typescript-eslint/eslint-pluginnpm install @typescript-eslint/eslint-plugin --save-dev - if you don't have the @typescript plugin installed
@typescript-eslint/parsernpm install @typescript-eslint/parser --save-dev - if you dont have the parser installed
eslint-plugin-security (Optional)npm install eslint-plugin-security --save-dev - If you want to auto inject the extra security plugin
TypeScriptnpm install typescript --save-dev - if you don't have TypeScript installed in your project, run
GruntJSnpm install grunt --save-dev - if you don't have GruntJS installed in your project
Grunt-Clinpm install grunt-cli --save-dev - Suggested, if you have never used Grunt on your system

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

Mininimal

module.exports = function(grunt) {
  grunt.initConfig({
    lint: {
      default : {
        tsconfig: './tsconfig.json'
      }
    }
  });
  grunt.loadNpmTasks("@nevware21/grunt-eslint-ts");
  grunt.registerTask("default", ["lint"]);
};

Options

The options can be specified at the global options, task options or directly on the task level, with the task level values overridding any value defined in the global options

Task only level options

NameTypeDescription
ignoreFailuresbooleanIgnore failures and continue, useful for initial linting runs for mono-repo's

Common options: Global and Task

NameTypeDescription
parserIESLintParserOverride the parser and plugin to use, defaults to { plugin: "@typescript-eslint"; name: "@typescript-eslint/parser" }, set to null to block the defaults from getting injected
additionalConfigLinter.ConfigAdditional Config that will be used to override the base Configuration, any additionalConfig will override any defaults
rulesLinter.RulesRecordAdditional specific rules to pass as overrides
logOutputbooleanLog the output (stdout, stderr) of the execute command eslint response
suppressWarningsbooleanOnly include errors in the output
fixbooleanFix all fixable errors and warnings
disableOutputFixesbooleanWhen automatic fixes are request and found, ignore the fix and don't output the fixed version, useful for debugging specific fixes that don't seem correct and you have automatic fixing enabled by default
debugbooleanLog additional debug messages some are only display with grunt verbose messages enabled
quietbooleanDon't output the report to the console / grunt output
outputFilestringOutput the results to the provided file
formatstringSpecify the format of the eslint report, defaults to codeframe
tsconfigstringThe path to the tsConfig file to use, when specified
maxWarningsnumberIf more than this number of warnings are reported failed the task
srcstringstring[]A single string or an array of source files to be "added" to the tsconfig as either files or include. When a string it assumes a single entry, there is not encoded list etc.

IEsLintParser

NameTypeDescription
namestringThe name of the parser to use for the eslint configuration, defaults to @typescript-eslint/parser if the @typescript-eslint/parser package exists in the node_modules
pluginsstring | string[]The plugin(s) to include for the eslint configuration, defaults to @typescript-eslint if the @typescript-eslint parser / plugin package exists in the node_modules, when the plugin is detected this also injects the plugin:@typescript-eslint/recommended rules extension (This may change in a future release to be a configuration).
parserOptionsLinter.ParserOptionsAdditional parser options to apply for the eslint configuration

eslint-plugin-security

When the eslint-plugin-security package is detected in the node_modules this will be automatically injected into the eslint configuration during linting with the plugin:security/recommended rules. (This may change in a future release to be a configuration)

Example showing some option combinations

module.exports = function(grunt) {
  grunt.initConfig({
    "lint": {
        options: {
            format: "codeframe",
            suppressWarnings: false,
            debug: true,
            logOutput: true,
            failNoFiles: false          // Defaults to `true` linting will fail if no files are configured
        },
        "shared": {
            tsconfig: "./shared/tsconfig.json",
            ignoreFailures: true,
            src: [
                // Adds extra source files above those listed in the tsconfig.json
                './shared/src/**/*.ts'
            ]
        },
        "ts_plugin": {
            tsconfig: "./ts-plugin/tsconfig.json",
            ignoreFailures: true
        },
        "eslint_ts": {
            tsconfig: "./eslint-ts-plugin/tsconfig.json",
            ignoreFailures: true
        },
        "shared-fix": {
            // You can specify the options, either in an options object like there or directly in the task
            // definition like those above
            options: {
                tsconfig: "./shared/tsconfig.json",
                fix: true,
                src: [
                    './shared/src/**/*.ts'
                ]                
            }
        },
        "ts_plugin-fix": {
            options: {
                tsconfig: "./ts-plugin/tsconfig.json",
                fix: true
            }
        },
        "eslint_ts-fix": {
            options: {
                tsconfig: "./eslint-ts-plugin/tsconfig.json",
                fix: true,
            }
        }
    }
  });

  grunt.loadNpmTasks("@nevware21/grunt-eslint-ts");
  grunt.registerTask("dolint", [ "lint:shared", "lint:ts_plugin", "lint:eslint_ts" ]);
  grunt.registerTask("lint-fix", [ "lint:shared-fix", "lint:ts_plugin-fix", "lint:eslint_ts-fix" ]);
};

Version 0.1.0 used a taskname of eslint-ts, while 0.2.0 changes the primary taskname to lint but includes an alias task eslint-ts for backward compatibility. Will likely be removed prior to v1.0.0.

Contributing

Read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes.

Release History

See The ChangeLog

0.5.1

10 months ago

0.5.0

11 months ago

0.2.5

12 months ago

0.2.3

3 years ago

0.2.4

3 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.1

4 years ago