Skip to content

Commit 337a609

Browse files
feat: implement @strvcom/eslint-config-typescript 🚀
1 parent 4f21e58 commit 337a609

3 files changed

Lines changed: 246 additions & 0 deletions

File tree

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/**
2+
* strvcom/eslint-config-typescript
3+
*
4+
* @author Robert Rossmann <rr.rossmann@me.com>
5+
* @copyright 2019 STRV
6+
* @license http://choosealicense.com/licenses/bsd-3-clause BSD-3-Clause License
7+
*/
8+
9+
'use strict'
10+
11+
module.exports = {
12+
13+
settings: {
14+
// Correctly recognise .ts and .d.ts files when checking import paths against the filesystem
15+
'import/resolver': {
16+
node: {
17+
extensions: [
18+
'.ts',
19+
'.d.ts',
20+
'.mjs',
21+
'.js',
22+
'.json',
23+
],
24+
},
25+
},
26+
},
27+
28+
parser: '@typescript-eslint/parser',
29+
30+
parserOptions: {
31+
ecmaVersion: 2018,
32+
sourceType: 'module',
33+
},
34+
35+
plugins: [
36+
'@typescript-eslint',
37+
],
38+
39+
env: {
40+
es6: true,
41+
},
42+
43+
rules: {
44+
// TS code is mostly self-documented and having JSDoc directives for everything is redundant
45+
// when you can easily infer return values and argument types from the code itself.
46+
'valid-jsdoc': 'off',
47+
48+
// Disabled because it generates false positives with interface declarations and TypeScript
49+
// blows up anyway during compilation when it encouters an undefined variable.
50+
'no-undef': 'off',
51+
52+
// Require that member overloads be consecutive
53+
// Grouping overloaded members together can improve readability of the code.
54+
'@typescript-eslint/adjacent-overload-signatures': 'warn',
55+
56+
// Require PascalCased class and interface names
57+
// This rule aims to make it easy to differentiate classes from regular variables at a glance.
58+
'@typescript-eslint/class-name-casing': 'warn',
59+
60+
// Require explicit return types on functions and class methods
61+
// Explicit types for function return values makes it clear to any calling code what type is
62+
// returned. This ensures that the return value is assigned to a variable of the correct type;
63+
// or in the case where there is no return value, that the calling code doesn't try to use the
64+
// undefined value when it shouldn't.
65+
'@typescript-eslint/explicit-function-return-type': ['warn', {
66+
allowExpressions: true,
67+
}],
68+
69+
// Require explicit accessibility modifiers on class properties and methods
70+
// This rule aims to make code more readable and explicit about who can use which properties.
71+
'@typescript-eslint/explicit-member-accessibility': 'warn',
72+
73+
// Require that interface names be prefixed with I
74+
// It can be hard to differentiate between classes and interfaces. Prefixing interfaces with "I"
75+
// can help telling them apart at a glance.
76+
'@typescript-eslint/interface-name-prefix': ['warn', 'always'],
77+
78+
// Require a specific member delimiter style for interfaces and type literals
79+
// This rule aims to standardise the way interface and type literal members are delimited.
80+
'@typescript-eslint/member-delimiter-style': ['warn', {
81+
multiline: {
82+
delimiter: 'none',
83+
},
84+
singleline: {
85+
delimiter: 'comma',
86+
},
87+
}],
88+
89+
// Require a consistent member declaration order
90+
// A consistent ordering of fields, methods and constructors can make interfaces, type literals,
91+
// classes and class expressions easier to read, navigate and edit.
92+
'@typescript-eslint/member-ordering': 'warn',
93+
94+
// Enforces the use of `as Type` assertions instead of `<Type>` assertions
95+
// This rule aims to standardise the use of type assertion style across the codebase.
96+
'@typescript-eslint/no-angle-bracket-type-assertion': 'warn',
97+
98+
// Disallow generic Array constructors
99+
// Use of the Array constructor to construct a new array is generally discouraged in favor of
100+
// array literal notation because of the single-argument pitfall and because the Array global
101+
// may be redefined.
102+
'@typescript-eslint/no-array-constructor': 'error',
103+
104+
// Disallow the declaration of empty interfaces
105+
// An empty interface is equivalent to its supertype. If the interface does not implement a
106+
// supertype, then the interface is equivalent to an empty object ({}). In both cases it can be
107+
// omitted.
108+
'@typescript-eslint/no-empty-interface': 'warn',
109+
110+
// Disallows explicit type declarations for variables or parameters initialized to a number,
111+
// string, or boolean
112+
// This rule disallows explicit type declarations on parameters, variables and properties where
113+
// the type can be easily inferred from its value.
114+
'@typescript-eslint/no-explicit-any': 'warn',
115+
116+
117+
// Disallow the use of custom TypeScript modules and namespaces
118+
// Custom TypeScript modules (module foo {}) and namespaces (namespace foo {}) are considered
119+
// outdated ways to organize TypeScript code. ES2015 module syntax is now preferred
120+
// (import/export).
121+
'@typescript-eslint/no-namespace': 'error',
122+
123+
// Disallow non-null assertions using the ! postfix operator
124+
// Using non-null assertions cancels the benefits of the strict null-checking mode.
125+
'@typescript-eslint/no-non-null-assertion': 'warn',
126+
127+
// Disallow the use of parameter properties in class constructors
128+
// This rule disallows the use of parameter properties in constructors, forcing the user to
129+
// explicitly declare all properties in the class.
130+
'@typescript-eslint/no-parameter-properties': 'warn',
131+
132+
// Disallow /// <reference path="" /> comments
133+
// Triple-slash reference directive comments should not be used anymore. Use import instead.
134+
'@typescript-eslint/no-triple-slash-reference': 'error',
135+
136+
// Prevent TypeScript-specific constructs from being erroneously flagged as unused
137+
// This rule only has an effect when the no-unused-vars core rule is enabled. It ensures that
138+
// TypeScript-specific constructs, such as implemented interfaces, are not erroneously flagged
139+
// as unused.
140+
'@typescript-eslint/no-unused-vars': 'error',
141+
142+
// Disallow the use of variables before they are defined
143+
// This rule will warn when it encounters a reference to an identifier that has not yet been
144+
// declared.
145+
'@typescript-eslint/no-use-before-define': ['error', {
146+
functions: false,
147+
classes: false,
148+
typedefs: false,
149+
}],
150+
151+
// Disallows the use of require statements except in import statements
152+
// In other words, the use of forms such as var foo = require("foo") are banned. Instead use ES6
153+
// style imports or import foo = require("foo") imports.
154+
'@typescript-eslint/no-var-requires': 'error',
155+
156+
// Require the use of the namespace keyword instead of the module keyword to declare custom
157+
// TypeScript modules
158+
// In an effort to prevent further confusion between custom TypeScript modules and the new
159+
// ES2015 modules, starting with TypeScript v1.5 the keyword namespace is now the preferred way
160+
// to declare custom TypeScript modules.
161+
'@typescript-eslint/prefer-namespace-keyword': 'warn',
162+
163+
// Require consistent spacing around type annotations
164+
// This rule aims to enforce specific spacing patterns around type annotations and function
165+
// types in type literals.
166+
'@typescript-eslint/type-annotation-spacing': 'warn',
167+
},
168+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "@strv/eslint-config-typescript",
3+
"description": "STRV's ESLint config for TypeScript projects",
4+
"version": "0.1.0",
5+
"author": "Robert Rossmann <rr.rossmann@me.com>",
6+
"bugs": {
7+
"url": "https://github.com/strvcom/code-quality-tools/issues"
8+
},
9+
"contributors": [
10+
"Pavel Prichodko <prichodko.p@gmail.com>",
11+
"Danny Kijkov <daniel.kijkov@strv.com>"
12+
],
13+
"dependencies": {
14+
"@strv/eslint-config-base": "^0.1.0",
15+
"eslint-plugin-jsx-a11y": "^6.1.2",
16+
"eslint-plugin-react": "^7.11.1"
17+
},
18+
"engines": {
19+
"node": ">=6"
20+
},
21+
"keywords": [
22+
"config",
23+
"eslint",
24+
"react",
25+
"strv"
26+
],
27+
"license": "BSD-3-Clause",
28+
"main": "index.js",
29+
"peerDependencies": {
30+
"eslint": "^5.3.0"
31+
},
32+
"publishConfig": {
33+
"access": "public"
34+
},
35+
"repository": {
36+
"type": "git",
37+
"url": "git://github.com/strvcom/code-quality-tools.git"
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# @strvcom/eslint-config-typescript
2+
3+
> 🔥 Experimental. Please report bugs, conflicts and other compatibility problems 🙏.
4+
5+
These configuration files are suitable to lint TypeScript code.
6+
7+
## Configurations
8+
9+
### `@strv/eslint-config-typescript`
10+
11+
Suitable for linting TypeScript source files.
12+
13+
In addition to using this ruleset, you should also choose one base ruleset depending on your target platform:
14+
15+
- `@strv/eslint-config-node/v10`
16+
- `@strv/eslint-config-react/v16`
17+
18+
A full configuration for a TypeScript on Node.js project:
19+
20+
```js
21+
// .eslintrc.js
22+
'use strict'
23+
24+
module.exports = {
25+
26+
extends: [
27+
'@strv/eslint-config-node/v10',
28+
'@strv/eslint-config-node/optional',
29+
'@strv/eslint-config-typescript',
30+
'@strv/eslint-config-styleguide',
31+
],
32+
}
33+
```
34+
35+
To actually lint .ts files, you must pass the `--ext` flag to ESLint:
36+
37+
```sh
38+
eslint --ext ts --no-unused-disable-directives .
39+
```

0 commit comments

Comments
 (0)