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

Commit 8bc7f7d

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

File tree

4 files changed

+108
-41
lines changed

4 files changed

+108
-41
lines changed

environments/typescript/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ 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
1515
```
1616

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

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

3132
extends: [
3233
'@strv/javascript/environments/nodejs/v10',

environments/typescript/recommended.js

Lines changed: 27 additions & 22 deletions
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,98 @@ 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+
},
82+
singleline: {
83+
delimiter: 'comma',
84+
},
8085
}],
8186

8287
// Require a consistent member declaration order
8388
// A consistent ordering of fields, methods and constructors can make interfaces, type literals,
8489
// classes and class expressions easier to read, navigate and edit.
85-
'typescript/member-ordering': 'warn',
90+
'@typescript-eslint/member-ordering': 'warn',
8691

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

9196
// Disallow generic Array constructors
9297
// Use of the Array constructor to construct a new array is generally discouraged in favor of
9398
// array literal notation because of the single-argument pitfall and because the Array global
9499
// may be redefined.
95-
'typescript/no-array-constructor': 'error',
100+
'@typescript-eslint/no-array-constructor': 'error',
96101

97102
// Disallow the declaration of empty interfaces
98103
// An empty interface is equivalent to its supertype. If the interface does not implement a
99104
// supertype, then the interface is equivalent to an empty object ({}). In both cases it can be
100105
// omitted.
101-
'typescript/no-empty-interface': 'warn',
106+
'@typescript-eslint/no-empty-interface': 'warn',
102107

103108
// Disallows explicit type declarations for variables or parameters initialized to a number,
104109
// string, or boolean
105110
// This rule disallows explicit type declarations on parameters, variables and properties where
106111
// the type can be easily inferred from its value.
107-
'typescript/no-explicit-any': 'warn',
112+
'@typescript-eslint/no-explicit-any': 'warn',
108113

109114

110115
// Disallow the use of custom TypeScript modules and namespaces
111116
// Custom TypeScript modules (module foo {}) and namespaces (namespace foo {}) are considered
112117
// outdated ways to organize TypeScript code. ES2015 module syntax is now preferred
113118
// (import/export).
114-
'typescript/no-namespace': 'error',
119+
'@typescript-eslint/no-namespace': 'error',
115120

116121
// Disallow non-null assertions using the ! postfix operator
117122
// Using non-null assertions cancels the benefits of the strict null-checking mode.
118-
'typescript/no-non-null-assertion': 'warn',
123+
'@typescript-eslint/no-non-null-assertion': 'warn',
119124

120125
// Disallow the use of parameter properties in class constructors
121126
// This rule disallows the use of parameter properties in constructors, forcing the user to
122127
// explicitly declare all properties in the class.
123-
'typescript/no-parameter-properties': 'warn',
128+
'@typescript-eslint/no-parameter-properties': 'warn',
124129

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

129134
// Prevent TypeScript-specific constructs from being erroneously flagged as unused
130135
// This rule only has an effect when the no-unused-vars core rule is enabled. It ensures that
131136
// TypeScript-specific constructs, such as implemented interfaces, are not erroneously flagged
132137
// as unused.
133-
'typescript/no-unused-vars': 'error',
138+
'@typescript-eslint/no-unused-vars': 'error',
134139

135140
// Disallow the use of variables before they are defined
136141
// This rule will warn when it encounters a reference to an identifier that has not yet been
137142
// declared.
138-
'typescript/no-use-before-define': ['error', {
143+
'@typescript-eslint/no-use-before-define': ['error', {
139144
functions: false,
140145
classes: false,
141146
typedefs: false,
@@ -144,18 +149,18 @@ module.exports = {
144149
// Disallows the use of require statements except in import statements
145150
// In other words, the use of forms such as var foo = require("foo") are banned. Instead use ES6
146151
// style imports or import foo = require("foo") imports.
147-
'typescript/no-var-requires': 'error',
152+
'@typescript-eslint/no-var-requires': 'error',
148153

149154
// Require the use of the namespace keyword instead of the module keyword to declare custom
150155
// TypeScript modules
151156
// In an effort to prevent further confusion between custom TypeScript modules and the new
152157
// ES2015 modules, starting with TypeScript v1.5 the keyword namespace is now the preferred way
153158
// to declare custom TypeScript modules.
154-
'typescript/prefer-namespace-keyword': 'warn',
159+
'@typescript-eslint/prefer-namespace-keyword': 'warn',
155160

156161
// Require consistent spacing around type annotations
157162
// This rule aims to enforce specific spacing patterns around type annotations and function
158163
// types in type literals.
159-
'typescript/type-annotation-spacing': 'warn',
164+
'@typescript-eslint/type-annotation-spacing': 'warn',
160165
},
161166
}

0 commit comments

Comments
 (0)