GithubHelp home page GithubHelp logo

macklinu / danger-plugin-tslint Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 3.0 1022 KB

Danger plugin for TSLint

License: MIT License

TypeScript 93.05% JavaScript 6.95%
danger danger-plugin code-review tslint

danger-plugin-tslint's Introduction

danger-plugin-tslint

Build Status npm version semantic-release Greenkeeper badge

Danger plugin for TSLint

Usage

Setup TSLint

This Danger plugin requires that you output the TSLint results as a JSON file before running danger on CI.

One way to do this is to use TSLint's JSON formatter and tee.

Given a package.json with a "lint" script:

{
  "scripts": {
    "lint": "tslint 'src/**/*.{ts,tsx}'"
  }
}

Running yarn run lint --silent -- --format json will only output the JSON results, which are piped into tee and written to disk in the reports/lint-results.json file.

# ci-script.sh

mkdir -p reports/
yarn run lint --silent -- --format json | tee reports/lint-results.json

yarn run danger

In this example, may also want to add the reports/ directory to your .gitignore file, as this file does not need to be checked into source control.

Setup Danger

Install:

yarn add danger-plugin-tslint --dev

At a glance:

// dangerfile.js
import path from 'path'
import tslint from 'danger-plugin-tslint'

// Handle TSLint results in `reports/lint-results.json` and leave a Danger comment on the PR
tslint({
  lintResultsJsonPath: path.resolve(__dirname, 'reports', 'lint-results.json'),
})

By default tslint() will use the defaultResultHandler in src/resultHandlers.ts. If you want to supply a custom result handler, which also requires you to call Danger functions like fail() and message() , you can do that too:

// dangerfile.js
import path from 'path'
import tslint from 'danger-plugin-tslint'

tslint({
  lintResultsJsonPath: path.resolve(__dirname, 'reports', 'lint-results.json'),
  handleResults: (results) => {
    if (results.length > 0) {
      const formattedResults = formatResults(results)
      fail(`TSLint failed\n\n${formattedResults}`)
    } else {
      message('👍 TSLint passed')
    }
  }
})

Here are examples of what the Danger comment will look like for success or failure:

success failure

See the documentation for detailed information (and also check out src/index.ts).

Changelog

See the GitHub release history.

Development

Install Yarn, and install the dependencies - yarn install.

Run the Jest test suite with yarn test.

This project uses semantic-release for automated NPM package publishing.

The main caveat: instead of running git commit, run yarn commit and follow the prompts to input a conventional changelog message via commitizen.

❤️

danger-plugin-tslint's People

Contributors

greenkeeper[bot] avatar macklinu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

danger-plugin-tslint's Issues

Ship types.d.ts

There are no consumable types when installing from npm. I'd like to generate them from source code, but I could also define a types file for 1.0.x and come back to generating types later.

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Feature Request: tslint() can accept JSON

Hi there macklinu,

First off, thank you for writing this plugin. It's pretty great. In using it, I discovered something that I think might be helpful for other users, and I'd love to help implement it.

I'm finding that I would like to be able to send the plugin the results JSON model after I've done some minor transforms on it. In this case, I'd want to only have it process the model after I have excluded non-modified files. An alternative to this is parsing this info in handleResults, but I find that I like the default behavior provided and do not want to reimplement it.

Right now, the implementation only accepts passing it a file path, but I believe we could support both scenarios, and perhaps even a scenario where an intermediary transform is allowed.

I think this would be pretty easy to support, and was curious if you'd be willing to review and accept a PR after I've had a chance to implement it. Thank you for taking the time to read this.

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.