Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract tslint config into a standalone package #2159

Merged
merged 3 commits into from Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 2 additions & 19 deletions packages/build/config/tslint.build.json
@@ -1,23 +1,6 @@
{
"$schema": "http://json.schemastore.org/tslint",
"extends": [
"./tslint.common.json"
],
// This configuration files enabled rules which require type checking
// and therefore cannot be run by Visual Studio Code TSLint extension
// See https://github.com/Microsoft/vscode-tslint/issues/70
"rules": {
// These rules find errors related to TypeScript features.

// These rules catch common errors in JS programming or otherwise
// confusing constructs that are prone to producing bugs.

// User-land promises like Bluebird implement "PromiseLike" (not "Promise")
// interface only. The string "PromiseLike" bellow is needed to
// tell tslint that it's ok to `await` such promises.
"await-promise": [true, "PromiseLike", "RequestPromise"],
"no-floating-promises": [true, "PromiseLike", "RequestPromise"],
"no-unused-variable": true,
"no-void-expression": [true, "ignore-arrow-function-shorthand"]
}
"@loopback/tslint-config/tslint.build.json"
]
}
28 changes: 4 additions & 24 deletions packages/build/config/tslint.common.json
@@ -1,26 +1,6 @@
{
// See https://palantir.github.io/tslint/rules/
"rules": {
// These rules find errors related to TypeScript features.
"adjacent-overload-signatures": true,
"prefer-for-of": true,
"unified-signatures": true,
"no-any": true,

// These rules catch common errors in JS programming or otherwise
// confusing constructs that are prone to producing bugs.

"label-position": true,
"no-arg": true,
"no-construct": true,
"no-duplicate-variable": true,

"no-invalid-this": true,
"no-misused-new": true,
"no-shadowed-variable": true,
"no-string-throw": true,
"no-unused-expression": true,
"no-var-keyword": true,
"triple-equals": [true, "allow-null-check", "allow-undefined-check"]
}
"$schema": "http://json.schemastore.org/tslint",
"extends": [
"@loopback/tslint-config/tslint.common.json"
]
}
1 change: 1 addition & 0 deletions packages/build/package.json
Expand Up @@ -13,6 +13,7 @@
"copyright.owner": "IBM Corp.",
"license": "MIT",
"dependencies": {
"@loopback/tslint-config": "^1.0.0-1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm why is this dependency^1.0.0-1 as opposed to ^1.0.0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tslint-config was not released yet. I specified the version number as a pre-release version, hoping that lerna will automatically increment it to 1.0.0 when we run the release process. Should I use a different version number?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's fine to leave it as is, just wanted to know the reasoning behind it.

"@types/mocha": "^5.0.0",
"@types/node": "^10.11.2",
"cross-spawn": "^6.0.5",
Expand Down
1 change: 1 addition & 0 deletions packages/tslint-config/.npmrc
@@ -0,0 +1 @@
package-lock=false
25 changes: 25 additions & 0 deletions packages/tslint-config/LICENSE
@@ -0,0 +1,25 @@
Copyright (c) IBM Corp. 2017,2018. All Rights Reserved.
Node module: @loopback/tslint-config
This project is licensed under the MIT License, full text below.

--------

MIT license

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
43 changes: 43 additions & 0 deletions packages/tslint-config/README.md
@@ -0,0 +1,43 @@
# @loopback/tslint-config

Shared TSLint config to enforce a consistent code style for LoopBack development

## Installation

```shell
$ npm install --save @loopback/tslint-config
```

## Basic Use

An example `tslint.json` file:

```json5
{
$schema: 'http://json.schemastore.org/tslint',
extends: ['@loopback/tslint-config/tslint.common.json'],
}
```

An example `tslint.buid.json` file:

```json5
{
$schema: 'http://json.schemastore.org/tslint',
extends: ['@loopback/tslint-config/tslint.build.json'],
}
```

## Contributions

- [Guidelines](https://github.com/strongloop/loopback-next/blob/master/docs/CONTRIBUTING.md)
- [Join the team](https://github.com/strongloop/loopback-next/issues/110)

## Contributors

See
[all contributors](https://github.com/strongloop/loopback-next/graphs/contributors).

## License

MIT
23 changes: 23 additions & 0 deletions packages/tslint-config/package.json
@@ -0,0 +1,23 @@
{
"name": "@loopback/tslint-config",
"version": "1.0.0-1",
"description": "",
"engines": {
"node": ">=8.9"
},
"author": "IBM",
"copyright.owner": "IBM Corp.",
"license": "MIT",
"peerDependencies": {
"tslint": ">=5.11.0"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. The idea behind this peer dependency is to specify the minimum version of tslint that can understand our rules. Unfortunately, a typical LB4 project does not install tslint directly but gets it from @loopback/build instead.

As a result, npm install can print the following warning:

npm WARN @loopback/tslint-config@1.0.0-1 requires a peer of tslint@>=5.11.0 but none is installed. You must install peer dependencies yourself.

I am not sure what to do about it. We can remove this peer dependency, but that way we loose control over tslint version used with our config. Or we can modify our project templates and example projects to install tslint directly, kind of duplicating @loopback/build's dependency on tslint.

I think in the long term, it may be best to get rid of lb-tslint and use https://github.com/Microsoft/tslint-microsoft-contrib to invoke tslint as part of tsc build.

@strongloop/loopback-maintainers thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's worse, some 3rd-party tslint rules like tslint-consistent-codestyle (see #2156) are loading tslint directly and fail if it's not installed as a peer dependency (e.g. because it's sourced from @loopback/build). I'll have to deal with this problem in #2156.

},
"files": [
"README.md",
"tslint.common.json",
"tslint.build.json"
],
"repository": {
"type": "git",
"url": "https://github.com/strongloop/loopback-next.git"
}
}
23 changes: 23 additions & 0 deletions packages/tslint-config/tslint.build.json
@@ -0,0 +1,23 @@
{
"$schema": "http://json.schemastore.org/tslint",
"extends": [
"./tslint.common.json"
],
// This configuration files enabled rules which require type checking
// and therefore cannot be run by Visual Studio Code TSLint extension
// See https://github.com/Microsoft/vscode-tslint/issues/70
"rules": {
// These rules find errors related to TypeScript features.

// These rules catch common errors in JS programming or otherwise
// confusing constructs that are prone to producing bugs.

// User-land promises like Bluebird implement "PromiseLike" (not "Promise")
// interface only. The string "PromiseLike" bellow is needed to
// tell tslint that it's ok to `await` such promises.
"await-promise": [true, "PromiseLike", "RequestPromise"],
"no-floating-promises": [true, "PromiseLike", "RequestPromise"],
"no-unused-variable": true,
"no-void-expression": [true, "ignore-arrow-function-shorthand"]
}
}
26 changes: 26 additions & 0 deletions packages/tslint-config/tslint.common.json
@@ -0,0 +1,26 @@
{
// See https://palantir.github.io/tslint/rules/
"rules": {
// These rules find errors related to TypeScript features.
"adjacent-overload-signatures": true,
"prefer-for-of": true,
"unified-signatures": true,
"no-any": true,

// These rules catch common errors in JS programming or otherwise
// confusing constructs that are prone to producing bugs.

"label-position": true,
"no-arg": true,
"no-construct": true,
"no-duplicate-variable": true,

"no-invalid-this": true,
"no-misused-new": true,
"no-shadowed-variable": true,
"no-string-throw": true,
"no-unused-expression": true,
"no-var-keyword": true,
"triple-equals": [true, "allow-null-check", "allow-undefined-check"]
}
}