UNPKG

3.33 kBMarkdownView Raw
1[![Build Status](https://github.com/mightyiam/eslint-config-standard-with-typescript/actions/workflows/ci.yaml/badge.svg)](https://github.com/mightyiam/eslint-config-standard-with-typescript/actions/workflows/ci.yaml)
2[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
3[![npm](https://img.shields.io/npm/v/eslint-config-standard-with-typescript)](https://www.npmjs.com/package/eslint-config-standard-with-typescript)
4
5An [ESLint shareable config](https://eslint.org/docs/developer-guide/shareable-configs) for TypeScript that is based on [eslint-config-standard](https://github.com/standard/eslint-config-standard) and has TypeScript specific rules from [@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin).
6
7# Peer dependencies
8
9This package specifies the following `peerDependencies`:
10
11- TypeScript, which you may already have installed
12- [ESLint](https://github.com/eslint/eslint)
13- 3 Peer dependencies of [eslint-config-standard](https://github.com/standard/eslint-config-standard)
14- [@typescript-eslint/eslint-plugin](https://www.npmjs.com/package/@typescript-eslint/eslint-plugin); ESLint rules for TypeScript.
15
16Yes, this is a large number of `peerDependencies`.
17This is due to [a known limitation in ESLint](https://github.com/eslint/eslint/issues/3458).
18
19# @typescript-eslint dependencies
20
21This package has `@typescript-eslint/parser` in `dependencies`.
22And it has `@typescript-eslint/eslint-plugin` in `peerDependencies`.
23Both are specified as ranges.
24It's probably safest for the installed versions of these packages to be the same.
25This can be achieved by:
26
271. Pin (exact version) the `@typescript-eslint/eslint-plugin` in `package.json`.
281. Have a `package-lock.json` which locks the version of the `@typescript-eslint/parser` sub-dependency.
29
30And both pin/lock to the same version.
31
32# Yarn
33
34Yarn does not automatically install `peerDependencies`,
35so if that's what you're using, install them manually.
36Here is an example, but use it only for reference,
37because your decisions regarding version ranges and range specifiers may vary.
38
39```
40yarn add --dev \
41 typescript@\* \
42 eslint@^8.0.1 \
43 eslint-plugin-promise@^6.0.0 \
44 eslint-plugin-import@^2.25.2 \
45 eslint-plugin-n@^15.0.0 \
46 @typescript-eslint/eslint-plugin@^6.4.0 \
47 eslint-config-standard-with-typescript@latest
48```
49
50# Example config
51
52Here is an example `.eslintrc.js`.
53Pay close attention to the `files` property, because it [determines which files are linted][specifying-target-files-to-lint].
54
55```js
56module.exports = {
57 overrides: [
58 {
59 files: ['*.js', '*.jsx', '*.ts', '*.tsx'],
60 extends: 'standard-with-typescript'
61 }
62 ],
63}
64```
65
66Note: the config exported by this package sets `parserOptions.project = true`.
67Read about the `project` option [here](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/README.md#configuration).
68
69There are [some more `parserOptions`](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/README.md#configuration) you may care about.
70
71[specifying-target-files-to-lint]: https://eslint.org/docs/latest/use/configure/configuration-files#specifying-target-files-to-lint
72
73# Example command line usage:
74
75```
76$ npx eslint .
77```