Skip to content
This repository has been archived by the owner on May 20, 2020. It is now read-only.

Commit

Permalink
Upgrading/fixing and documenting dependencies 2018-02 (#11)
Browse files Browse the repository at this point in the history
- upgrading everything beside tslint
- documented the reasons for the way this package depends on others
- added example configurations, cleaner imports in rule
- build and test the build output before creating a version
- 0.1.0
  • Loading branch information
karfau authored Feb 23, 2018
1 parent 19abe97 commit bd4bb37
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 158 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v8.1.4
v8.9.0
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# bm-tslint-rules

This is a utility package to ease adding tslint checking to a project.

## Dependencies

It is different from other [rule configurations](https://github.com/palantir/tslint#custom-rules--plugins) in that it depends on a fixed version of the following npm packages:
* [`tslint`](https://github.com/palantir/tslint) for running it against a codebase (so it doesn't need to be part of your `package.json`)
the configurations that are extended in the following order:
* [`tslint-eslint-rules`](https://github.com/buzinas/tslint-eslint-rules/blob/master/CHANGELOG.md)
* [`tslint-microsoft-contrib`](https://github.com/Microsoft/tslint-microsoft-contrib/wiki/Release-Notes)
* [`tslint-react`](https://github.com/Microsoft/tslint-microsoft-contrib/wiki/Release-Notes)

to make sure upgrading dependencies in a project does not break any code/CI pipeline because of fixed/improve/more strict tslint rules.

Instead we are doing regular upgrade days in this project and each project can decide when to switch to a newer version of this package on it's own.

For executing the custom rule(s) coming with this package there is the additional (peer-)dependency [`ts-node`](https://github.com/TypeStrong/ts-node/). Since `ts-node` also [needs `typescript`](https://github.com/TypeStrong/ts-node/blob/v4.1.0/src/index.ts#L11) at runtime, that is the second peer dependency (`^2.4.1` since this is the version `ts-node` [devDepends on](https://github.com/TypeStrong/ts-node/blob/v4.1.0/package.json#L75).

## Usage

1. install an [available version](https://github.com/bettermarks/bm-tslint-rules/releases) (e.g. `v0.1.0`)) as a devDependency:

`npm install -D github:bettermarks/bm-tslint-rules#<VERSION>`
(You should not use leave out `<VERSION>` since this refers to master and differs depending on which time you install it and npm's cache prevents updates once it fetched it.)

2. copy [`tslint.json`](https://github.com/bettermarks/bm-tslint-rules/blob/master/examples/minimal/tslint.json) to your project root.

(optionally adopt the configuration to your need, see [examples](https://github.com/bettermarks/bm-tslint-rules/blob/master/examples))

3. add the following to the `scripts` in your `package.json`:
```json
"tslint": "tslint [OPTIONS]",
```
- you will need to find the [options](https://palantir.github.io/tslint/usage/cli/) that work best for your project, we recommend:

```json
"tslint": "tslint -c tslint.json --project tsconfig.json -t stylish",
```

4. on the command line run `npm run tslint`.

## Configured rules

The repo exports its [`tslint.json`]() as it's main file.

Since documenting each and every rule here would possible get outdated soon here are the sources for the rules we have configured:

* [`tslint-eslint-rules`](https://github.com/buzinas/tslint-eslint-rules#rules-copied-from-the-eslint-website)
* `tslint-microsoft-contrib`:
- [extending recommended ruleset](https://github.com/Microsoft/tslint-microsoft-contrib/blob/master/recommended_ruleset.js),
- [available rules and options](https://github.com/Microsoft/tslint-microsoft-contrib#supported-rules)
* `tslint-react`:
- [extending ruleset](https://github.com/palantir/tslint-react/blob/master/tslint-react.json)
- [available rules and options](https://github.com/palantir/tslint-react#rules)


## Custom Rules

### no-absolute-import-to-own-parent

TODO: document
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
machine:
node:
version: v8.2.0
version: v8.9.0
services:
- docker
dependencies:
Expand Down
6 changes: 3 additions & 3 deletions dist/noAbsoluteImportToOwnParentRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var __extends = (this && this.__extends) || (function () {
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var Lint = require("tslint");
var tslint_1 = require("tslint");
var path = require("path");
var configuration_1 = require("tslint/lib/configuration");
var Rule = /** @class */ (function (_super) {
Expand All @@ -35,7 +35,7 @@ var Rule = /** @class */ (function (_super) {
};
Rule.FAILURE_STRING = 'importing parent path ';
return Rule;
}(Lint.Rules.AbstractRule));
}(tslint_1.Rules.AbstractRule));
exports.Rule = Rule;
// The walker takes care of all the work.
var NoImportsWalker = /** @class */ (function (_super) {
Expand Down Expand Up @@ -63,4 +63,4 @@ var NoImportsWalker = /** @class */ (function (_super) {
_super.prototype.visitImportDeclaration.call(this, node);
};
return NoImportsWalker;
}(Lint.RuleWalker));
}(tslint_1.RuleWalker));
9 changes: 9 additions & 0 deletions examples/add-configuration/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": [
"bm-tslint-rules",
"tslint-clean-code"
],
"rules": {
"newspaper-order": true
}
}
8 changes: 8 additions & 0 deletions examples/disable-rules/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": [
"bm-tslint-rules"
],
"rules": {
"no-absolute-import-to-own-parent": false
}
}
5 changes: 5 additions & 0 deletions examples/minimal/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"bm-tslint-rules"
]
}
13 changes: 13 additions & 0 deletions examples/rules-directory/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": [
"bm-tslint-rules"
],
"rulesDirectory": "node_modules/tslint-no-unused-expression-chai/rules",
"rules": {
"no-unused-expression": false,
"no-unused-expression-chai": [
true,
"allow-fast-null-checks"
]
}
}
Loading

0 comments on commit bd4bb37

Please sign in to comment.