-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
danger-plugin-tslint runs TSLint on your codebase with your defined `tsconfig.json` and `tslint.json` files. If there are any failures, this plugin will call `fail()` with the formatted output in a message. Otherwise, it will call `message()` saying that TSLint passed. 🆒 Usage example: ```js // dangerfile.js import tslint from 'danger-plugin-tslint' tslint() ``` If you want to supply custom options, you can do that too: ```js // dangerfile.js import path from 'path' import tslint from 'danger-plugin-tslint' tslint({ tslintPath: path.resolve(__dirname, 'path/to/tslint.json'), tsconfigPath: path.resolve(__dirname, 'path/to/tsconfig.json'), formatter: 'stylish', }) ```
- Loading branch information
Showing
19 changed files
with
996 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,43 @@ | ||
# danger-plugin-tslint | ||
|
||
TODO | ||
[![Build Status](https://travis-ci.org/macklinu/danger-plugin-tslint.svg?branch=master)](https://travis-ci.org/macklinu/danger-plugin-tslint) | ||
[![npm version](https://badge.fury.io/js/danger-plugin-tslint.svg)](https://badge.fury.io/js/danger-plugin-tslint) | ||
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) | ||
|
||
> [Danger](https://github.com/danger/danger-js) plugin for TSLint | ||
|
||
## Usage | ||
|
||
Install: | ||
|
||
```sh | ||
yarn add danger-plugin-tslint --dev | ||
``` | ||
|
||
At a glance: | ||
|
||
```js | ||
// dangerfile.js | ||
import tslint from 'danger-plugin-tslint' | ||
|
||
tslint() | ||
``` | ||
|
||
See the [documentation](http://macklin.underdown.me/danger-plugin-tslint/modules/tslint.html#tslint-1) for detailed information (and also check out [`src/index.ts`](https://github.com/macklinu/danger-plugin-tslint/blob/master/src/index.ts)). | ||
|
||
## Changelog | ||
|
||
See the GitHub [release history](https://github.com/macklinu/danger-plugin-tslint/releases). | ||
|
||
## Development | ||
|
||
Install [Yarn](https://yarnpkg.com/en/), and install the dependencies - `yarn install`. | ||
|
||
Run the [Jest](https://facebook.github.io/jest/) test suite with `yarn test`. | ||
|
||
This project uses [semantic-release](https://github.com/semantic-release/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](https://github.com/commitizen/cz-cli). | ||
|
||
:heart: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function add(a, b) { | ||
return a + b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as path from 'path' | ||
import tslint from '../../src' | ||
|
||
// tslint:disable:no-string-literal | ||
|
||
beforeEach(() => { | ||
global['fail'] = jest.fn() | ||
}) | ||
|
||
test('Should fail because of missing semicolon', () => { | ||
tslint({ | ||
tsconfigPath: path.resolve(__dirname, 'tsconfig.json'), | ||
tslintPath: path.resolve(__dirname, 'tslint.json'), | ||
}) | ||
expect(global['fail']).toHaveBeenCalledWith( | ||
expect.stringMatching(/add.ts\[2, 15\]: Missing semicolon/), | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["es5", "es2015"], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"target": "es5" | ||
}, | ||
"files": [ | ||
"add.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"semicolon": [true] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function add(a, b) { | ||
return a + b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as path from 'path' | ||
import tslint from '../../src' | ||
|
||
// tslint:disable:no-string-literal | ||
|
||
beforeEach(() => { | ||
global['message'] = jest.fn() | ||
}) | ||
|
||
test('Should pass because there are no lint errors', () => { | ||
tslint({ | ||
tsconfigPath: path.resolve(__dirname, 'tsconfig.json'), | ||
tslintPath: path.resolve(__dirname, 'tslint.json'), | ||
}) | ||
expect(global['message']).toHaveBeenCalledWith(':white_check_mark: TSLint passed') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["es5", "es2015"], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"target": "es5" | ||
}, | ||
"files": [ | ||
"add.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"semicolon": [true] | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict' | ||
|
||
const ghpages = require('gh-pages') | ||
|
||
const docsDir = 'docs' | ||
const options = { | ||
user: { | ||
name: 'Macklin Underdown', | ||
email: 'macklinu@users.noreply.github.com' | ||
}, | ||
} | ||
const callback = (err) => { | ||
if (err) { | ||
console.error(err) | ||
} else { | ||
console.log('🚀 Docs deployed to GitHub Pages') | ||
} | ||
} | ||
|
||
ghpages.publish(docsDir, options, callback) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Danger global functions | ||
declare function fail(message: string): void | ||
declare function message(message: string): void |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* @module tslint | ||
*/ | ||
/** | ||
* This second comment is required until | ||
* https://github.com/christopherthielen/typedoc-plugin-external-module-name/issues/6 is resolved. | ||
*/ | ||
|
||
import * as fs from 'fs' | ||
import { Configuration, findFormatter, Linter, RuleFailure } from 'tslint' | ||
|
||
/** | ||
* Possible TSLint [formatters](https://palantir.github.io/tslint/formatters/). | ||
*/ | ||
type Formatter = | ||
| 'checkstyle' | ||
| 'codeFrame' | ||
| 'fileslist' | ||
| 'json' | ||
| 'msbuild' | ||
| 'pmd' | ||
| 'prose' | ||
| 'stylish' | ||
| 'tap' | ||
| 'verbose' | ||
| 'vso' | ||
|
||
interface IPluginConfig { | ||
/** | ||
* The path to your project's `tslint.json` file. | ||
* @default `'tslint.json'` | ||
*/ | ||
tslintPath?: string | ||
/** | ||
* The path to your project's `tsconfig.json` file. | ||
* @default `'tsconfig.json'` | ||
*/ | ||
tsconfigPath?: string | ||
/** | ||
* A TSLint [formatter](https://palantir.github.io/tslint/formatters/). | ||
* @default `'prose'` | ||
*/ | ||
formatter?: Formatter | ||
} | ||
|
||
/** | ||
* Runs TSLint on a project's source code and reports results to Danger. | ||
* If there are any lint violations, Danger will fail the build and post results in a comment. | ||
* If there are no lint violations, Danger will comment saying that TSLint passed. | ||
* | ||
* @export | ||
* @param config The optional config object. | ||
*/ | ||
export default function tslint(config: IPluginConfig = {}): void { | ||
const { | ||
tslintPath = 'tslint.json', | ||
tsconfigPath = 'tsconfig.json', | ||
formatter = 'prose', | ||
} = config | ||
|
||
// Set up TSLint | ||
const options = { fix: false } | ||
const program = Linter.createProgram(tsconfigPath) | ||
const linter = new Linter(options, program) | ||
const filenames = Linter.getFileNames(program) | ||
|
||
// Lint all files from tsconfig.json | ||
filenames.forEach((fileName) => { | ||
const configuration = Configuration.findConfiguration(tslintPath, fileName).results | ||
const fileContents = fs.readFileSync(fileName, 'utf8') | ||
linter.lint(fileName, fileContents, configuration) | ||
}) | ||
|
||
// Handle lint output | ||
const { failures } = linter.getResult() | ||
if (failures.length > 0) { | ||
const formattedFailures = _getFormattedFailures(formatter, failures) | ||
fail(formattedFailures) | ||
} else { | ||
message(':white_check_mark: TSLint passed') | ||
} | ||
} | ||
|
||
function _getFormattedFailures(formatter: Formatter, failures: RuleFailure[]): string { | ||
const Formatter = findFormatter(formatter) | ||
if (Formatter !== undefined) { | ||
return new Formatter().format(failures) | ||
} | ||
throw new Error(`formatter '${formatter}' not found`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["es5", "es2015"], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"outDir": "dist", | ||
"pretty": true, | ||
"removeComments": true, | ||
"sourceMap": false, | ||
"strictNullChecks": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"target": "es5", | ||
"noImplicitAny": false, | ||
"strict": true, | ||
"sourceMap": false | ||
} | ||
"types": ["node"] | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"extends": [ | ||
"tslint:recommended" | ||
] | ||
], | ||
"rules": { | ||
"semicolon": [true, "never"], | ||
"quotemark": [true, "single"] | ||
} | ||
} |
Oops, something went wrong.