Skip to content
This repository was archived by the owner on Mar 7, 2019. It is now read-only.

Commit 048096e

Browse files
committed
feat: use @typescript-eslint for TypeScript rules
1 parent cc58bbd commit 048096e

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

environments/typescript/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ These configuration files are suitable to lint TypeScript code.
1111
You must install an ESLint-compatible TypeScript parser and add it to your _.eslintrc.js_ file:
1212

1313
```sh
14-
npm i -D typescript-eslint-parser@latest
14+
npm i -D @typescript-eslint/parser@latest
15+
npm i -D @typescript-eslint/eslint-plugin@latest
1516
```
1617

1718
In addition to using this ruleset, you should also choose one base ruleset depending on your target platform:
@@ -26,7 +27,8 @@ A full configuration for a TypeScript on Node.js project:
2627
'use strict'
2728

2829
module.exports = {
29-
parser: 'typescript-eslint-parser',
30+
parser: '@typescript-eslint/parser',
31+
plugins: ['@typescript-eslint'],
3032

3133
extends: [
3234
'@strv/javascript/environments/nodejs/v10',

environments/typescript/recommended.js

+29-22
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = {
2626
},
2727

2828
plugins: [
29-
'typescript',
29+
'@typescript-eslint',
3030
],
3131

3232
parserOptions: {
@@ -49,93 +49,100 @@ module.exports = {
4949

5050
// Require that member overloads be consecutive
5151
// Grouping overloaded members together can improve readability of the code.
52-
'typescript/adjacent-overload-signatures': 'warn',
52+
'@typescript-eslint/adjacent-overload-signatures': 'warn',
5353

5454
// Require PascalCased class and interface names
5555
// This rule aims to make it easy to differentiate classes from regular variables at a glance.
56-
'typescript/class-name-casing': 'warn',
56+
'@typescript-eslint/class-name-casing': 'warn',
5757

5858
// Require explicit return types on functions and class methods
5959
// Explicit types for function return values makes it clear to any calling code what type is
6060
// returned. This ensures that the return value is assigned to a variable of the correct type;
6161
// or in the case where there is no return value, that the calling code doesn't try to use the
6262
// undefined value when it shouldn't.
63-
'typescript/explicit-function-return-type': ['warn', {
63+
'@typescript-eslint/explicit-function-return-type': ['warn', {
6464
allowExpressions: true,
6565
}],
6666

6767
// Require explicit accessibility modifiers on class properties and methods
6868
// This rule aims to make code more readable and explicit about who can use which properties.
69-
'typescript/explicit-member-accessibility': 'warn',
69+
'@typescript-eslint/explicit-member-accessibility': 'warn',
7070

7171
// Require that interface names be prefixed with I
7272
// It can be hard to differentiate between classes and interfaces. Prefixing interfaces with "I"
7373
// can help telling them apart at a glance.
74-
'typescript/interface-name-prefix': ['warn', 'always'],
74+
'@typescript-eslint/interface-name-prefix': ['warn', 'always'],
7575

7676
// Require a specific member delimiter style for interfaces and type literals
7777
// This rule aims to standardise the way interface and type literal members are delimited.
78-
'typescript/member-delimiter-style': ['warn', {
79-
delimiter: 'none',
78+
'@typescript-eslint/member-delimiter-style': ['warn', {
79+
multiline: {
80+
delimiter: 'none',
81+
requireLast: false
82+
},
83+
singleline: {
84+
delimiter: 'comma',
85+
requireLast: false
86+
},
8087
}],
8188

8289
// Require a consistent member declaration order
8390
// A consistent ordering of fields, methods and constructors can make interfaces, type literals,
8491
// classes and class expressions easier to read, navigate and edit.
85-
'typescript/member-ordering': 'warn',
92+
'@typescript-eslint/member-ordering': 'warn',
8693

8794
// Enforces the use of `as Type` assertions instead of `<Type>` assertions
8895
// This rule aims to standardise the use of type assertion style across the codebase.
89-
'typescript/no-angle-bracket-type-assertion': 'warn',
96+
'@typescript-eslint/no-angle-bracket-type-assertion': 'warn',
9097

9198
// Disallow generic Array constructors
9299
// Use of the Array constructor to construct a new array is generally discouraged in favor of
93100
// array literal notation because of the single-argument pitfall and because the Array global
94101
// may be redefined.
95-
'typescript/no-array-constructor': 'error',
102+
'@typescript-eslint/no-array-constructor': 'error',
96103

97104
// Disallow the declaration of empty interfaces
98105
// An empty interface is equivalent to its supertype. If the interface does not implement a
99106
// supertype, then the interface is equivalent to an empty object ({}). In both cases it can be
100107
// omitted.
101-
'typescript/no-empty-interface': 'warn',
108+
'@typescript-eslint/no-empty-interface': 'warn',
102109

103110
// Disallows explicit type declarations for variables or parameters initialized to a number,
104111
// string, or boolean
105112
// This rule disallows explicit type declarations on parameters, variables and properties where
106113
// the type can be easily inferred from its value.
107-
'typescript/no-explicit-any': 'warn',
114+
'@typescript-eslint/no-explicit-any': 'warn',
108115

109116

110117
// Disallow the use of custom TypeScript modules and namespaces
111118
// Custom TypeScript modules (module foo {}) and namespaces (namespace foo {}) are considered
112119
// outdated ways to organize TypeScript code. ES2015 module syntax is now preferred
113120
// (import/export).
114-
'typescript/no-namespace': 'error',
121+
'@typescript-eslint/no-namespace': 'error',
115122

116123
// Disallow non-null assertions using the ! postfix operator
117124
// Using non-null assertions cancels the benefits of the strict null-checking mode.
118-
'typescript/no-non-null-assertion': 'warn',
125+
'@typescript-eslint/no-non-null-assertion': 'warn',
119126

120127
// Disallow the use of parameter properties in class constructors
121128
// This rule disallows the use of parameter properties in constructors, forcing the user to
122129
// explicitly declare all properties in the class.
123-
'typescript/no-parameter-properties': 'warn',
130+
'@typescript-eslint/no-parameter-properties': 'warn',
124131

125132
// Disallow /// <reference path="" /> comments
126133
// Triple-slash reference directive comments should not be used anymore. Use import instead.
127-
'typescript/no-triple-slash-reference': 'error',
134+
'@typescript-eslint/no-triple-slash-reference': 'error',
128135

129136
// Prevent TypeScript-specific constructs from being erroneously flagged as unused
130137
// This rule only has an effect when the no-unused-vars core rule is enabled. It ensures that
131138
// TypeScript-specific constructs, such as implemented interfaces, are not erroneously flagged
132139
// as unused.
133-
'typescript/no-unused-vars': 'error',
140+
'@typescript-eslint/no-unused-vars': 'error',
134141

135142
// Disallow the use of variables before they are defined
136143
// This rule will warn when it encounters a reference to an identifier that has not yet been
137144
// declared.
138-
'typescript/no-use-before-define': ['error', {
145+
'@typescript-eslint/no-use-before-define': ['error', {
139146
functions: false,
140147
classes: false,
141148
typedefs: false,
@@ -144,18 +151,18 @@ module.exports = {
144151
// Disallows the use of require statements except in import statements
145152
// In other words, the use of forms such as var foo = require("foo") are banned. Instead use ES6
146153
// style imports or import foo = require("foo") imports.
147-
'typescript/no-var-requires': 'error',
154+
'@typescript-eslint/no-var-requires': 'error',
148155

149156
// Require the use of the namespace keyword instead of the module keyword to declare custom
150157
// TypeScript modules
151158
// In an effort to prevent further confusion between custom TypeScript modules and the new
152159
// ES2015 modules, starting with TypeScript v1.5 the keyword namespace is now the preferred way
153160
// to declare custom TypeScript modules.
154-
'typescript/prefer-namespace-keyword': 'warn',
161+
'@typescript-eslint/prefer-namespace-keyword': 'warn',
155162

156163
// Require consistent spacing around type annotations
157164
// This rule aims to enforce specific spacing patterns around type annotations and function
158165
// types in type literals.
159-
'typescript/type-annotation-spacing': 'warn',
166+
'@typescript-eslint/type-annotation-spacing': 'warn',
160167
},
161168
}

0 commit comments

Comments
 (0)