Giter Club home page Giter Club logo

custom-tslint-formatters's Introduction

Custom TSLint Formatters

A collection of custom TSLint formatters. With colors.

Included Formatters

grouped

Prints a block for each file with the file name as headline, followed by a summary.

custom tslint formatter grouped

Errors are printed as error: row:column <error>, warnings are printed as warning: row:column <warning>.

Errors are in red, warnings in yellow.

vscode

This is a technical formatter that can be used as input for a task in Visual Studio Code to lint all files in a project.

vscode lint task

Usage

First add a new npm task to your package.json:

{
  "lint:vscode": "tslint -s node_modules/custom-tslint-formatters/formatters -t vscode 'src/**/*.+(ts|tsx)'"
}

Then add a new task to .vscode/tasks.json:

{
  "version": "0.1.0",
  "command": "npm",
  "isShellCommand": true,
  "showOutput": "always",
  "suppressTaskName": true,
  "tasks": [
    {
      "taskName": "lint",
      "args": ["run", "lint:vscode"],
      "problemMatcher": {
        "owner": "tslint",
        "fileLocation": ["relative", "${workspaceRoot}"],
        "severity": "warning",
        "pattern": {
          "regexp": "^\\[tslint\\] (.*):(\\d+):(\\d+):\\s+(.*)$",
          "file": 1,
          "line": 2,
          "column": 3,
          "message": 4
        }
      },
      "showOutput": "never"
    }
  ]
}

Installation

npm install custom-tslint-formatters --save-dev

Usage

On the commandline specify the formatters directory with -s and the formatter with -t (see list of formatters above):

tslint -s node_modules/custom-tslint-formatters/formatters -t grouped src/**/*.ts

For tslint-loader add a tslint configuration block to your webpack config specifying the formattersDirectory as well as the formatter (see list of formatters above):

module.exports = {
  module: {
    preLoaders: [
      {
        test: /\.ts$/,
        loader: "tslint"
      }
    ]
  },
  tslint: {
    formattersDirectory: 'node_modules/custom-tslint-formatters/formatters',
    formatter: 'grouped'
  }
}

custom-tslint-formatters's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

custom-tslint-formatters's Issues

Dependency on @types/* can cause conflict in type definition resolution (Duplicate identifier for @types/node)

https://github.com/KingHenne/custom-tslint-formatters/blob/f2376dfe122b0b03d96b55a7c70e6bffa26ea4ce/package.json#L36-L37

  "dependencies": {
    "@types/chalk": "^0.4.31",
    "@types/node": "^7.0.12",

When custom-tslint-formatters is used as a dependency of a module with npm-shrinkwrap.json that is required by a TypeScript module for Node which itself depends on @types/node, the @types/node get installed twice into node_modules (using npm@3).

When building the TypeScript module, having more than one @types/node of the same version causes a ton of errors about duplicate identifiers because TypeScript gets two definitions for the global Node symbols.
Here's a sample of these errors with both conflicting paths visible:

node_modules/@some-company/ts-build-tools/node_modules/@types/node/index.d.ts(4283,18): error TS2300: Duplicate identifier 'Protocol'.


118 type BufferEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "base64" | "latin1" | "binary" | "hex";
         ~~~~~~~~~~~~~~

node_modules/@types/node/index.d.ts(118,6): error TS2300: Duplicate identifier 'BufferEncoding'.


289     export class EventEmitter {
                     ~~~~~~~~~~~~

In this example, @some-company/ts-build-tools depends on custom-tslint-formatters and has npm-shrinkwrap.json, so npm ls looks like this:

├─┬ @some-company/[email protected]
...
│ ├─┬ [email protected]
│ │ ├── @types/[email protected]
│ │ └── @types/[email protected]
...
├── @types/[email protected]
...

Related issue (with no solution as of now): microsoft/TypeScript#6496

The only workaround for now is to ensure only one declaration is installed, but this is impossible for packages that are dependencies.

As this package does not export any typings, these @types/ dependencies could be moved to devDependencies to avoid such behavior until the root issue is resolved within TypeScript compiler.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.