Skip to content

Commit

Permalink
fix(eslint-plugin): fix dependency + add lerna (#35)
Browse files Browse the repository at this point in the history
* docs: fix prettier config filename typo

* chore: move old tslint rules files

* chore: fix lerna chngelogs with Conventional Commits

* chore: use lint-staged to commit lerna changes in .md and .json files

* chore: fix build and packages linking
  • Loading branch information
Dmitry Naumov authored and MarsiBarsi committed Dec 18, 2019
1 parent f617d0a commit cf67afb
Show file tree
Hide file tree
Showing 103 changed files with 18,335 additions and 14,020 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
@@ -1 +1,3 @@
*.fixture.*
packages/linters/tslint/rules
packages/linters/tslint/src
4 changes: 2 additions & 2 deletions .eslintrc.js
@@ -1,6 +1,6 @@
module.exports = {
extends: [
'./eslint/base/prettier',
'./eslint/angular',
'./packages/linters/eslint/base/prettier',
'./packages/linters/eslint/angular',
],
}
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -4,4 +4,3 @@

# Other
node_modules
tslint/rules
2 changes: 1 addition & 1 deletion .huskyrc
@@ -1,6 +1,6 @@
{
"hooks": {
"pre-commit": "npm run lint",
"pre-commit": "lint-staged",
"pre-push": "npm run test:ci"
}
}
4 changes: 4 additions & 0 deletions .lintstagedrc.json
@@ -0,0 +1,4 @@
{
"packages/**/*.{ts,js}": ["eslint", "git add"],
"**/*.{md,json,template.html}": ["prettier --write --loglevel=warn", "git add"]
}
1 change: 1 addition & 0 deletions .prettierignore
@@ -1,2 +1,3 @@
*.lint
*.fix
package-lock.json
7 changes: 6 additions & 1 deletion .travis.yml
@@ -1,11 +1,16 @@
language: node_js
cache:
npm: false
node_js:
- "10"
- "9"
- "8"
- "node"

install:
- npm i -g lerna@^3.18.3
- npm run bootstrap

script:
- npm run lint:ci
- npm run test:ci
- npm run build:prod
13 changes: 8 additions & 5 deletions CHANGELOG.md
@@ -1,30 +1,33 @@
# Change Log

<a name="0.5.0"></a>

# [0.5.0](https://github.com/TinkoffCreditSystems/linters/compare/v0.4.0...v0.5.0) (2019-10-11)

### Features

* add RxJs 6+ rules ([120e45c](https://github.com/TinkoffCreditSystems/linters/pull/14/commits/120e45c))
- add RxJs 6+ rules ([120e45c](https://github.com/TinkoffCreditSystems/linters/pull/14/commits/120e45c))

<a name="0.4.0"></a>

# [0.4.0](https://github.com/TinkoffCreditSystems/linters/compare/v0.3.0...v0.4.0) (2019-09-02)

### Features

* bump dependencies ([940af6a](https://github.com/TinkoffCreditSystems/linters/pull/11/commits/940af6a))
- bump dependencies ([940af6a](https://github.com/TinkoffCreditSystems/linters/pull/11/commits/940af6a))

<a name="0.3.0"></a>

# [0.3.0](https://github.com/TinkoffCreditSystems/linters/compare/v0.2.0...v0.3.0) (2019-02-04)

### Features

* enable `trailingComma` in prettier.config.js ([#6](https://github.com/TinkoffCreditSystems/linters/issues/6)) ([93a6485](https://github.com/TinkoffCreditSystems/linters/commit/93a6485))
- enable `trailingComma` in prettier.config.js ([#6](https://github.com/TinkoffCreditSystems/linters/issues/6)) ([93a6485](https://github.com/TinkoffCreditSystems/linters/commit/93a6485))

<a name="0.2.0"></a>
# [0.2.0](https://github.com/TinkoffCreditSystems/linters/compare/v0.1.0...v0.2.0) (2019-01-18)

# [0.2.0](https://github.com/TinkoffCreditSystems/linters/compare/v0.1.0...v0.2.0) (2019-01-18)

### Features

* update dependencies `stylelint`, `stylelint-config-standard`, `stylelint-order` ([2152ae3](https://github.com/TinkoffCreditSystems/linters/commit/2152ae3))
- update dependencies `stylelint`, `stylelint-config-standard`, `stylelint-order` ([2152ae3](https://github.com/TinkoffCreditSystems/linters/commit/2152ae3))
128 changes: 77 additions & 51 deletions README.md
@@ -1,6 +1,7 @@
# Tinkoff Linter Configuration [![Build](https://img.shields.io/travis/TinkoffCreditSystems/linters/master)](https://travis-ci.org/TinkoffCreditSystems/linters) [![code style: @tinkoff/linters](https://img.shields.io/badge/code%20style-%40tinkoff%2Flinters-blue)](https://github.com/TinkoffCreditSystems/linters) [![npm version](https://img.shields.io/npm/v/@tinkoff/linters)](https://www.npmjs.com/package/@tinkoff/linters)

This repository contains configuration files for the linters we use in Tinkoff. It includes:

- configs and rules for [TSLint](https://palantir.github.io/tslint/)
- configs for [Stylelint](https://stylelint.io/)
- configs for [Prettier](https://prettier.io)
Expand All @@ -9,11 +10,13 @@ This repository contains configuration files for the linters we use in Tinkoff.
## Install

Stable version (no `eslint` support, just `tslint`)

```
$ npm install @tinkoff/linters --save-dev
```

Try our beta with ESLint!

```
$ npm install @tinkoff/linters@beta --save-dev
```
Expand All @@ -24,41 +27,49 @@ $ npm install @tinkoff/linters@beta --save-dev
<summary>If you have any of those deps or experiencing problems</summary>

Run following in your project:

```sh
npm uninstall $(node -e 'const p=require("./package");console.log(Object.keys(p.dependencies||[]).concat(Object.keys(p.devDependencies||[])).filter(name=>/eslint|stylelint|prettier|tslint/.test(name)).join(" "))')
```

</details>

## ESLint + Prettier
This preset is compatible with any and ES Modules based project, written in `TS` and/or `ES6+`. No matter is it `node`/`react` or `angular`.

This preset is compatible with any and ES Modules based project, written in `TS` and/or `ES6+`. No matter is it `node`/`react` or `angular`.

For now there is additional `angular` rules available, and we planning to add `RxJS` rules in near future.

Add following files in your project:

##### **`.eslintrc.js`**

```js
module.exports = {
extends: [
'./node_modules/@tinkoff/linters/eslint/base/prettier',
'./node_modules/@tinkoff/linters/eslint/angular',
]
}
],
};
```

##### **`.prettierrc.js`**

```js
module.exports = {
...require('@tinkoff/linters/prettier/prettier.config')
...require('@tinkoff/linters/prettier/prettier.config'),
};
```

Add npm-script:

```sh
"lint:es": "eslint --fix \"src/**/*.{ts,js}\"",
"lint:es:ci": "eslint --format ./node_modules/eslint-teamcity/index.js \"src/**/*.{ts,js}\"",
```

Add `.eslintignore` file.

> Don't add `.ts`/`.js` files to `.prettierignore` because it isn't used by prettier in this setup.
<details>
Expand All @@ -69,24 +80,28 @@ Add `.eslintignore` file.
> In this case you should have both `.eslintignore` and `.prettierignore` files
You need to use different base config:

##### **`.eslintrc.js`**

```js
module.exports = {
extends: [
'./node_modules/@tinkoff/linters/eslint/base',
'./node_modules/@tinkoff/linters/eslint/angular',
]
}
],
};
```

##### **`.prettier.config.js`**

```js
module.exports = {
...require('@tinkoff/linters/prettier/prettier.config')
...require('@tinkoff/linters/prettier/prettier.config'),
};

```

Add npm-script:

```sh
"prelint:es": "prettier --write \"src/**/*.{ts,js}\"",
"lint:es": "eslint --fix \"src/**/*.{ts,js}\"",
Expand All @@ -96,42 +111,34 @@ Add npm-script:

</details>


<details>
<summary>Troubleshooting</summary>

If you're got this error:

```
Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
```
- Make sure that `.ts`/`.tsx` file mentioned in this error is included in your projects `./tsconfig.json`
- OR Update config:
##### **`.eslintrc.js`**
```diff
module.exports = {
extends: [
'./node_modules/@tinkoff/linters/eslint/base',
'./node_modules/@tinkoff/linters/eslint/angular',
],
+ parserOptions: {
+ createDefaultProgram: true, // Allows to work with non-ts files
+ },
}
```
> `createDefaultProgram` may cause [performance issues](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/README.md#configuration)
</details>

- Make sure that `.ts`/`.tsx` file mentioned in this error is included in your projects `./tsconfig.json`
- OR Update config: ##### **`.eslintrc.js`**
`diff module.exports = { extends: [ './node_modules/@tinkoff/linters/eslint/base', './node_modules/@tinkoff/linters/eslint/angular', ], + parserOptions: { + createDefaultProgram: true, // Allows to work with non-ts files + }, }` > `createDefaultProgram` may cause [performance issues](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/README.md#configuration)
</details>

## Stylelint

You should extend your Stylelint configs with only one `bases` config:

##### **`.stylelintrc`**

```json
{
"extends": ["@tinkoff/linters/stylelint/bases/prettier.stylelint.json"]
"extends": ["@tinkoff/linters/stylelint/bases/prettier.stylelint.json"]
}
```

Add npm-script:

```sh
"lint:less": "stylelint --config .stylelintrc --fix \"src/**/*.less\"",
"lint:less:ci": "stylelint --config .stylelintrc --custom-formatter=node_modules/stylelint-teamcity-reporter \"src/**/*.less\"",
Expand All @@ -144,6 +151,7 @@ $ npm i husky lint-staged --save-dev
```

##### **`.huskyrc.json`**

```js
{
"hooks": {
Expand All @@ -153,6 +161,7 @@ $ npm i husky lint-staged --save-dev
```

##### **`.lintstagedrc.json`**

```js
{
"src/**/*.{ts,js}": ["lint:es", "git add"],
Expand All @@ -162,7 +171,9 @@ $ npm i husky lint-staged --save-dev
```

## TSLint (deprecated)

TSLint no longer supported. See [roadmap](/ROADMAP.md).

<details>
<summary>Installation</summary>

Expand All @@ -172,21 +183,23 @@ Example of `tslint.json` file in your project:

```json
{
"extends": [
"@tinkoff/linters/tslint/bases/prettier.tslint.json",
"@tinkoff/linters/tslint/mixins/rxjs5.5.tslint.json", // For RxJs 5.5
"@tinkoff/linters/tslint/mixins/rxjs6.tslint.json" // For RxJS 6+
]
"extends": [
"@tinkoff/linters/tslint/bases/prettier.tslint.json",
"@tinkoff/linters/tslint/mixins/rxjs5.5.tslint.json", // For RxJs 5.5
"@tinkoff/linters/tslint/mixins/rxjs6.tslint.json" // For RxJS 6+
]
}
```

</details>

## VS Code

To make eslint work with `.ts` files:
- Install [eslint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
- [Find VSCode's settings file](https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations)
- Add following to settings:

- Install [eslint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
- [Find VSCode's settings file](https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations)
- Add following to settings:
```json
"eslint.validate": [
"javascript",
Expand All @@ -196,8 +209,6 @@ To make eslint work with `.ts` files:
]
```



<br />
<br />

Expand Down Expand Up @@ -230,12 +241,16 @@ When a ternary operator contains complex expressions, it becomes difficult to re

```ts
// bad
const defaultQuestionnaire = this.isCompany || this.accountIsBlocked ? defaultQuestionnaireCompany && 'super text' : defaultQuestionnaireIp;
const defaultQuestionnaire =
this.isCompany || this.accountIsBlocked
? defaultQuestionnaireCompany && 'super text'
: defaultQuestionnaireIp;

// good
const defaultQuestionnaire = this.isCompany || this.accountIsBlocked
? defaultQuestionnaireCompany && 'super text'
: defaultQuestionnaireIp;
const defaultQuestionnaire =
this.isCompany || this.accountIsBlocked
? defaultQuestionnaireCompany && 'super text'
: defaultQuestionnaireIp;

// good
const result = isShown ? [] : null;
Expand All @@ -248,20 +263,16 @@ The only exception is the arrow functions. For them it is not necessary.

```ts
class User {
constructor(name: string, age: number) {
}
constructor(name: string, age: number) {}

// good
getStatus(): string {
}
getStatus(): string {}

// bad
getFullname() {
}
getFullname() {}

// ok
setStatus(status: string) {
}
setStatus(status: string) {}
}

// bad
Expand Down Expand Up @@ -314,8 +325,7 @@ function doSomething(count: number): number {
if (age > 30) {
}

for (let i = 0; i < 10; i++) {
}
for (let i = 0; i < 10; i++) {}

return {name, age};
}
Expand All @@ -331,4 +341,20 @@ Show that you use `@tinkoff/linters` in your project [![code style: @tinkoff/lin

## Development

Run tests with `npm run test`.
- Intall deps with `npm run bootstrap`.
- Run tests with `npm run test:ci`.
- Follow [Conventional Commits specification](https://conventionalcommits.org/) for every commitmessage.

## Release

- Prepare your release in `master` or `release/*` branch.
- Run `npm run version` and look what happens.
- Or `npm run version -- --no-push` and `git push --follow-tags` if you not sure.
- Run `npm run publish`.

#### Pre-release:

Do the same as above, except this cases:

- prev version isn't prerelease, but next must be prerelease: `npm run version -- --conventional-prerelease`
- prev version is prerelease, but next must be release: `npm run version -- --conventional-graduate`

0 comments on commit cf67afb

Please sign in to comment.