Skip to content

Commit

Permalink
Merge pull request #7 from Sergiioo/upgrade-tooling
Browse files Browse the repository at this point in the history
replace gulp with npm scripts, and add prettier
  • Loading branch information
Sergiioo committed Sep 2, 2018
2 parents 894964b + 1d99412 commit b500894
Show file tree
Hide file tree
Showing 20 changed files with 1,043 additions and 229 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ root = true
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
indent_size = 2
trim_trailing_whitespace = false
charset = utf-8

Expand All @@ -19,4 +19,4 @@ end_of_line = crlf

[{package.json,.travis.yml}]
indent_style = space
indent_size = 4
indent_size = 2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dist/

# NPM
node_modules/
npm-debug.log*

# JSPM
jspm_packages/
Expand Down
3 changes: 0 additions & 3 deletions .jshintignore

This file was deleted.

36 changes: 0 additions & 36 deletions .jshintrc

This file was deleted.

11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ language: node_js
notifications:
email: true
node_js:
- '5'
- '6'
before_script:
- npm install -g gulp
script: gulp
- "8"
- "10"
- "lts/*"
script:
- yarn build
- yarn test
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
# tslint-defocus

## About
This is a tslint rule that warns about focussed Jasmine tests - fdescribe and fit

This is a tslint rule that warns about focussed Jasmine tests - `fdescribe` and `fit`

## Usage
* Install with: `npm install tslint-defocus --save-dev`
* Extend this package in your `.tslint.json` file, e.g.:

- Install with: `npm install tslint-defocus --save-dev` or `yarn add tslint-defocus --dev`
- Extend this package in your `.tslint.json` file, e.g.:

```
"extends": [
"tslint-defocus"
Expand All @@ -18,9 +21,12 @@ This is a tslint rule that warns about focussed Jasmine tests - fdescribe and fi
"defocus": true,
...
```

(as per the [instructions for custom rules](http://palantir.github.io/tslint/usage/custom-rules/))
* Run tslint as you usually would (gulp plugin, directly from node, etc)
* If you forget to remove a call to `fdescribe` or `fit` then you will see something like from tslint:

- Run `tslint` as you usually would (gulp plugin, directly from node, etc)
- If you forget to remove a call to `fdescribe` or `fit` then you will see something like from tslint:

```
(defocus) app.ts[4, 1]: Calls to 'fdescribe' are not allowed.
(defocus) app.ts[8, 5]: Calls to 'fit' are not allowed.
Expand All @@ -31,10 +37,13 @@ This is a tslint rule that warns about focussed Jasmine tests - fdescribe and fi
Version 2.0.x of this rule requires version 5.x of tslint.

## Developer instructions
* installed the required global npm packages: `npm install gulp --global --no-optional`.
* Clone [from github](https://github.com/Sergiioo/tslint-defocus)
* Run `npm run setup` to install and get started
* Build, lint and unit test by running the default gulp task with: `gulp`

- installed the required global npm packages: `npm install gulp --global --no-optional`.
- Clone [from github](https://github.com/Sergiioo/tslint-defocus)
- Run `npm install` or `yarn install` to install and get started
- This repo uses npm scripts for its build. Try `yarn build` and `yarn test`.
- There are also watch mode variants - `yarn build:watch` and `yarn test:watch`.

## License

MIT
44 changes: 0 additions & 44 deletions gulpfile.js

This file was deleted.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
rulesDirectory: "dist",
rulesDirectory: "dist"
};
41 changes: 24 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,35 @@
},
"devDependencies": {
"@types/chai": "^4.0.1",
"@types/mocha": "^2.2.41",
"@types/node": "^8.0.7",
"@types/mocha": "^5.2.5",
"@types/node": "^10.9.2",
"chai": "^4.0.2",
"del": "^3.0.0",
"gulp": "^3.9.1",
"gulp-spawn-mocha": "^3.1.0",
"gulp-tslint": "^8.1.1",
"gulp-typescript": "^3.0.0",
"istanbul": "^0.4.5",
"mocha": "^3.1.0",
"run-sequence": "^2.0.0",
"concurrently": "^4.0.1",
"husky": "^1.0.0-rc.13",
"mocha": "^5.2.0",
"prettier": "^1.14.2",
"pretty-quick": "^1.6.0",
"rimraf": "^2.6.2",
"tslint": "^5.4.3",
"typescript": "^2.4.1"
"tslint-config-prettier": "^1.15.0",
"typescript": "^3.0.1"
},
"peerDependencies": {
"tslint": "^5.4.3",
"typescript": "^2.4.1"
"tslint": "^5.x",
"typescript": "^2.x | ^3.x"
},
"scripts": {
"clean": "gulp clean",
"build": "gulp",
"help": "gulp help",
"test": "gulp test"
"clean": "rimraf dist",
"build": "tsc",
"watch:build": "tsc --watch",
"watch:test": "npm run test -- --watch",
"watch": "concurrently npm:watch:*",
"test": "mocha \"dist/**/*spec.js\"",
"lint": "tslint --project tsconfig.json"
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
}
}
}
52 changes: 26 additions & 26 deletions src/defocusRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@ import * as Lint from "tslint";
import * as ts from "typescript";

export class Rule extends Lint.Rules.AbstractRule {
public static metadata: Lint.IRuleMetadata = {
/* tslint:disable:object-literal-sort-keys */
ruleName: "defocus",
description: "Bans the use of `fdescribe` and 'fit' Jasmine functions.",
rationale:
"It is all too easy to mistakenly commit a focussed Jasmine test suite or spec.",
options: null,
optionsDescription: "Not configurable.",
type: "functionality",
typescriptOnly: false
};

public static metadata: Lint.IRuleMetadata = {
/* tslint:disable:object-literal-sort-keys */
ruleName: "defocus",
description: "Bans the use of `fdescribe` and 'fit' Jasmine functions.",
rationale: "It is all too easy to mistakenly commit a focussed Jasmine test suite or spec.",
options: null,
optionsDescription: "Not configurable.",
type: "functionality",
typescriptOnly: false,
};

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithFunction(sourceFile, walk);
}
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithFunction(sourceFile, walk);
}
}

function walk(ctx: Lint.WalkContext<void>) {
return ts.forEachChild(ctx.sourceFile, function cb(node: ts.Node): void {
if (node.kind === ts.SyntaxKind.CallExpression) {
const expression = (node as ts.CallExpression).expression;
const functionName = expression.getText();
bannedFunctions.forEach((banned) => {
if (banned === functionName) {
ctx.addFailureAtNode(expression, failureMessage(functionName));
}
});
return ts.forEachChild(ctx.sourceFile, function cb(node: ts.Node): void {
if (node.kind === ts.SyntaxKind.CallExpression) {
const expression = (node as ts.CallExpression).expression;
const functionName = expression.getText();
bannedFunctions.forEach(banned => {
if (banned === functionName) {
ctx.addFailureAtNode(expression, failureMessage(functionName));
}
return ts.forEachChild(node, cb);
});
});
}
return ts.forEachChild(node, cb);
});
}

const bannedFunctions: ReadonlyArray<string> = ["fdescribe", "fit"];

const failureMessage = (functionName: string) => {
return `Calls to '${functionName}' are not allowed.`;
return `Calls to '${functionName}' are not allowed.`;
};
Loading

0 comments on commit b500894

Please sign in to comment.