Skip to content

Commit

Permalink
Use native parser for js (#33)
Browse files Browse the repository at this point in the history
* chore(ci): run eslint checks on CI

* docs(eslint): tell more about universal eslint preset

* fix(eslint): use native parser and ignore ts-rules for js-files

* fix(eslint): support more estensions for imports

* docs: note about beta
  • Loading branch information
Dmitry Naumov authored and MarsiBarsi committed Dec 5, 2019
1 parent ad08682 commit 6b93c99
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 17 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.js
Expand Up @@ -3,7 +3,4 @@ module.exports = {
'./eslint/base/prettier',
'./eslint/angular',
],
parserOptions: {
createDefaultProgram: true, // Allows to work with non-ts files
},
}
14 changes: 12 additions & 2 deletions README.md
Expand Up @@ -8,10 +8,16 @@ 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
```

> **You don't need** to install `eslint`, `tslint`, `prettier` or `stylelint`, they are added as dependencies of `@tinkoff/linters` and will be installed automatically.
<details>
Expand All @@ -24,6 +30,10 @@ npm uninstall $(node -e 'const p=require("./package");console.log(Object.keys(p.
</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`.

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`**
Expand All @@ -49,7 +59,7 @@ Add npm-script:
```

Add `.eslintignore` file.
> Don't add `.prettierignore` because it isn't used by prettier in this setup.
> Don't add `.ts`/`.js` files to `.prettierignore` because it isn't used by prettier in this setup.
<details>
<summary>
Expand Down Expand Up @@ -94,7 +104,7 @@ If you're got this error:
```
Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
```
- Make sure that `.ts` file mentioned in this error is included in your projects `./tsconfig.json`
- Make sure that `.ts`/`.tsx` file mentioned in this error is included in your projects `./tsconfig.json`
- OR Update config:
##### **`.eslintrc.js`**
```diff
Expand Down
25 changes: 19 additions & 6 deletions eslint/common/conventions.js
@@ -1,18 +1,16 @@
const breaking = require('../utils/breaking');

const allExtensions = ['.ts', '.tsx', '.d.ts', '.js', '.jsx'];
const tsExtensions = ['.ts', '.tsx', '.d.ts'];
const extensions = require('../consts/extensions');

module.exports = {
plugins: ['import'],
settings: {
'import/extensions': allExtensions,
'import/extensions': extensions.all,
'import/parsers': {
'@typescript-eslint/parser': tsExtensions,
'@typescript-eslint/parser': extensions.ts,
},
'import/resolver': {
node: {
extensions: allExtensions,
extensions: extensions.all,
},
},
},
Expand Down Expand Up @@ -52,5 +50,20 @@ module.exports = {
},
},
],
'no-unused-vars': [
breaking({since: 2}),
{
vars: 'local',
args: 'none',
ignoreRestSiblings: true,
argsIgnorePattern: '^_',
caughtErrors: 'none',
},
],
'no-use-before-define': breaking({
since: 2,
before: 'off',
after: 'warn',
}),
},
};
4 changes: 4 additions & 0 deletions eslint/common/index.js
Expand Up @@ -6,6 +6,10 @@ module.exports = {
jasmine: true,
es6: true,
},
parserOptions: {
ecmaVersion: 2019,
sourceType: 'module',
},
extends: [
'eslint:recommended',
'./formatting',
Expand Down
6 changes: 4 additions & 2 deletions eslint/common/typescript/conventions.js
@@ -1,6 +1,7 @@
const breaking = require('../../utils/breaking');
const {tsOnly} = require('../../utils/ts');

module.exports = {
module.exports = tsOnly({
rules: {
'no-unused-vars': 'off', // types and interfaces are not recognized by eslint
'@typescript-eslint/no-unused-vars': [
Expand All @@ -27,6 +28,7 @@ module.exports = {
],
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/triple-slash-reference': 'error',
'no-use-before-define': 'off', // types and interfaces are not recognized by eslint
'@typescript-eslint/no-use-before-define': breaking({
since: 2,
before: 'off',
Expand All @@ -40,4 +42,4 @@ module.exports = {
}),
'@tinkoff/require-return-type': 'error',
},
};
});
12 changes: 10 additions & 2 deletions eslint/common/typescript/enviroment.js
@@ -1,4 +1,7 @@
module.exports = {
const extensions = require('../../consts/extensions');
const {tsOnly} = require('../../utils/ts');

module.exports = tsOnly({
env: {
es6: true,
},
Expand All @@ -7,10 +10,15 @@ module.exports = {
project: './tsconfig.json',
sourceType: 'module',
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': extensions.ts,
},
},
plugins: [
'@typescript-eslint',
'@typescript-eslint/tslint',
'functional',
'@tinkoff',
],
};
});
2 changes: 2 additions & 0 deletions eslint/consts/extensions.js
@@ -0,0 +1,2 @@
exports.all = ['.es', '.esm', '.es6', '.cjs', '.ts', '.tsx', '.js', '.jsx'];
exports.ts = ['.ts', '.tsx'];
1 change: 0 additions & 1 deletion eslint/rules/tests/require-return-type.test.js
Expand Up @@ -18,7 +18,6 @@ const codeframe = cli.getFormatter('codeframe');

test('require-return-type snapshot', () => {
const report = cli.executeOnFiles([
path.join(__dirname, './require-return-type.test.js'),
path.join(__dirname, './require-return-type.fixture.ts'),
]);

Expand Down
7 changes: 7 additions & 0 deletions eslint/utils/ts.js
@@ -0,0 +1,7 @@
const extensions = require('../consts/extensions');

const tsOnlyFiles = `*{${extensions.ts.join(',')}}`;

exports.tsOnly = config => ({
overrides: [Object.assign({}, config, {files: tsOnlyFiles})],
});
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -11,7 +11,7 @@
"lint:ts": "tslint -c tslint.json -p tsconfig.json \"src/**/*.ts\"",
"lint:es": "eslint \"eslint/**/*.{ts,js}\"",
"prelint:ci": "run-s build:prod",
"lint:ci": "run-p prettier lint:ts:ci",
"lint:ci": "run-p prettier lint:ts:ci lint:es",
"lint:ts:ci": "tslint -c tslint.json -p tsconfig.json -t ./node_modules/tslint-teamcity-reporter/index.js \"src/**/*.ts\"",
"********** Build": "",
"build:prod": "tsc",
Expand Down

0 comments on commit 6b93c99

Please sign in to comment.