Skip to content

Commit b028246

Browse files
committed
Update ESLint configuration
1 parent c19d018 commit b028246

File tree

4 files changed

+301
-137
lines changed

4 files changed

+301
-137
lines changed

etc/eslint/rules/best_practices.js

Lines changed: 127 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,29 @@ rules[ 'curly' ] = 'error';
218218
*/
219219
rules[ 'default-case' ] = 'error';
220220

221+
/**
222+
* Always require default parameters to be last.
223+
*
224+
* @name default-param-last
225+
* @memberof rules
226+
* @type {string}
227+
* @default 'error'
228+
* @see [default-param-last]{@link http://eslint.org/docs/rules/default-param-last}
229+
*
230+
* @example
231+
* // Bad...
232+
* function foo( a = 1, b ) {
233+
* // No-op...
234+
* }
235+
*
236+
* @example
237+
* // Good...
238+
* function foo( b, a = 1 ) {
239+
* // No-op...
240+
* }
241+
*/
242+
rules[ 'default-param-last' ] = 'error';
243+
221244
/**
222245
* Require that a dot be on the same line as a property.
223246
*
@@ -856,6 +879,25 @@ rules[ 'no-multi-spaces' ] = [ 'error', {
856879
*/
857880
rules[ 'no-multi-str' ] = 'error';
858881

882+
/**
883+
* Never allow use the `new` operator without assignment.
884+
*
885+
* @name no-new
886+
* @memberof rules
887+
* @type {string}
888+
* @default 'error'
889+
* @see [no-new]{@link http://eslint.org/docs/rules/no-new}
890+
*
891+
* @example
892+
* // Bad...
893+
* new Foo();
894+
*
895+
* @example
896+
* // Good...
897+
* var f = new Foo();
898+
*/
899+
rules[ 'no-new' ] = 'error';
900+
859901
/**
860902
* Never allow using the `Function` constructor to create functions.
861903
*
@@ -897,23 +939,23 @@ rules[ 'no-new-func' ] = 'error';
897939
rules[ 'no-new-wrappers' ] = 'error';
898940

899941
/**
900-
* Never allow use the `new` operator without assignment.
942+
* Never allow octal literals that begin with a leading zero; e.g., 071 (=> 57).
901943
*
902-
* @name no-new
944+
* @name no-octal
903945
* @memberof rules
904946
* @type {string}
905947
* @default 'error'
906-
* @see [no-new]{@link http://eslint.org/docs/rules/no-new}
948+
* @see [no-octal]{@link http://eslint.org/docs/rules/no-octal}
907949
*
908950
* @example
909951
* // Bad...
910-
* new Foo();
952+
* var num = 071;
911953
*
912954
* @example
913955
* // Good...
914-
* var f = new Foo();
956+
* var num = '071';
915957
*/
916-
rules[ 'no-new' ] = 'error';
958+
rules[ 'no-octal' ] = 'error';
917959

918960
/**
919961
* Never allow octal escape sequences, which are deprecated.
@@ -934,25 +976,6 @@ rules[ 'no-new' ] = 'error';
934976
*/
935977
rules[ 'no-octal-escape' ] = 'error';
936978

937-
/**
938-
* Never allow octal literals that begin with a leading zero; e.g., 071 (=> 57).
939-
*
940-
* @name no-octal
941-
* @memberof rules
942-
* @type {string}
943-
* @default 'error'
944-
* @see [no-octal]{@link http://eslint.org/docs/rules/no-octal}
945-
*
946-
* @example
947-
* // Bad...
948-
* var num = 071;
949-
*
950-
* @example
951-
* // Good...
952-
* var num = '071';
953-
*/
954-
rules[ 'no-octal' ] = 'error';
955-
956979
/**
957980
* Allow parameter reassignment (although bugs can arise when doing so).
958981
*
@@ -1233,6 +1256,36 @@ rules[ 'no-unused-labels' ] = 'error';
12331256
*/
12341257
rules[ 'no-useless-call' ] = 'error';
12351258

1259+
/**
1260+
* Never allow unnecessary catch clauses.
1261+
*
1262+
* @name no-useless-catch
1263+
* @memberof rules
1264+
* @type {string}
1265+
* @default 'error'
1266+
* @see [no-useless-catch]{@link http://eslint.org/docs/rules/no-useless-catch}
1267+
*
1268+
* @example
1269+
* // Bad...
1270+
* try {
1271+
* throw new Error( 'beep' );
1272+
* } catch ( err ) {
1273+
* // Catch is unnecessary if we are just rethrowing...
1274+
* throw err;
1275+
* }
1276+
*
1277+
* @example
1278+
* // Good...
1279+
* try {
1280+
* throw new Error( 'beep' );
1281+
* } catch ( err ) {
1282+
* if ( err instanceof TypeError) {
1283+
* throw err;
1284+
* }
1285+
* }
1286+
*/
1287+
rules[ 'no-useless-catch' ] = 'error';
1288+
12361289
/**
12371290
* Never allow concatenation of two string literals which can be combined as a single literal.
12381291
*
@@ -1347,6 +1400,17 @@ rules[ 'no-warning-comments' ] = [ 'warn', {
13471400
*/
13481401
rules[ 'no-with' ] = 'error';
13491402

1403+
/**
1404+
* Do not require the use of ES2018 named capture groups.
1405+
*
1406+
* @name prefer-named-capture-group
1407+
* @memberof rules
1408+
* @type {string}
1409+
* @default 'off'
1410+
* @see [prefer-named-capture-group]{@link http://eslint.org/docs/rules/prefer-named-capture-group}
1411+
*/
1412+
rules[ 'prefer-named-capture-group' ] = 'off';
1413+
13501414
/**
13511415
* Always require that promises are rejected with `Error` objects.
13521416
*
@@ -1359,6 +1423,25 @@ rules[ 'prefer-promise-reject-errors' ] = [ 'error', {
13591423
'allowEmptyReject': false
13601424
}];
13611425

1426+
/**
1427+
* Always require regular expression literals when not dynamically generating a regular expression.
1428+
*
1429+
* @name prefer-regex-literals
1430+
* @memberof rules
1431+
* @type {string}
1432+
* @default 'error'
1433+
* @see [prefer-regex-literals]{@link https://eslint.org/docs/rules/prefer-regex-literals}
1434+
*
1435+
* @example
1436+
* // Bad...
1437+
* var re = new RegExp( 'foo' );
1438+
*
1439+
* @example
1440+
* // Good...
1441+
* var re = /foo/;
1442+
*/
1443+
rules[ 'prefer-regex-literals' ] = 'error';
1444+
13621445
/**
13631446
* Always require a `radix` parameter to `parseInt()`.
13641447
*
@@ -1405,6 +1488,25 @@ rules[ 'require-await' ] = 'error';
14051488

14061489
/* eslint-enable stdlib/jsdoc-doctest-marker, stdlib/jsdoc-doctest-quote-props */
14071490

1491+
/**
1492+
* Always require the `u` flag when a regular expression involves UTF-16 surrogate pairs.
1493+
*
1494+
* @name require-unicode-regexp
1495+
* @memberof rules
1496+
* @type {string}
1497+
* @default 'error'
1498+
* @see [require-unicode-regexp]{@link http://eslint.org/docs/rules/require-unicode-regexp}
1499+
*
1500+
* @example
1501+
* // Bad...
1502+
* var re = /^[👍]$/;
1503+
*
1504+
* @example
1505+
* // Good...
1506+
* var re = /^[👍]$/u;
1507+
*/
1508+
rules[ 'require-unicode-regexp' ] = 'error';
1509+
14081510
/**
14091511
* Always declare variables at the top of their scope to represent hoisting.
14101512
*

etc/eslint/rules/programmer_errors.js

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ rules[ 'for-direction' ] = 'error';
7777
*/
7878
rules[ 'getter-return' ] = 'error';
7979

80+
/**
81+
* Never allow using an async function as a `Promise` executor.
82+
*
83+
* @name no-async-promise-executor)
84+
* @memberof rules
85+
* @type {string}
86+
* @default 'error'
87+
* @see [no-async-promise-executor)]{@link https://eslint.org/docs/rules/no-async-promise-executor}
88+
*/
89+
rules[ 'no-async-promise-executor' ] = 'error';
90+
8091
/**
8192
* Warn when using `await` inside of loops.
8293
*
@@ -310,25 +321,6 @@ rules[ 'no-dupe-keys' ] = 'error';
310321
*/
311322
rules[ 'no-duplicate-case' ] = 'error';
312323

313-
/**
314-
* Never allow empty character classes in regular expression literals.
315-
*
316-
* @name no-empty-character-class
317-
* @memberof rules
318-
* @type {string}
319-
* @default 'error'
320-
* @see [no-empty-character-class]{@link http://eslint.org/docs/rules/no-empty-character-class}
321-
*
322-
* @example
323-
* // Bad...
324-
* var re = /^abc[]/;
325-
*
326-
* @example
327-
* // Good...
328-
* var re = /^abc[a-z]/;
329-
*/
330-
rules[ 'no-empty-character-class' ] = 'error';
331-
332324
/**
333325
* Never allow empty block statements, including when using `try/catch`.
334326
*
@@ -364,6 +356,25 @@ rules[ 'no-empty-character-class' ] = 'error';
364356
*/
365357
rules[ 'no-empty' ] = 'error';
366358

359+
/**
360+
* Never allow empty character classes in regular expression literals.
361+
*
362+
* @name no-empty-character-class
363+
* @memberof rules
364+
* @type {string}
365+
* @default 'error'
366+
* @see [no-empty-character-class]{@link http://eslint.org/docs/rules/no-empty-character-class}
367+
*
368+
* @example
369+
* // Bad...
370+
* var re = /^abc[]/;
371+
*
372+
* @example
373+
* // Good...
374+
* var re = /^abc[a-z]/;
375+
*/
376+
rules[ 'no-empty-character-class' ] = 'error';
377+
367378
/**
368379
* Never allow reassignment of an exception parameter in a `catch` block.
369380
*
@@ -484,6 +495,17 @@ rules[ 'no-extra-semi' ] = 'error';
484495
*/
485496
rules[ 'no-func-assign' ] = 'error';
486497

498+
/**
499+
* Never allow assigning to imported bindings.
500+
*
501+
* @name no-import-assign
502+
* @memberof rules
503+
* @type {string}
504+
* @default 'error'
505+
* @see [no-import-assign]{@link http://eslint.org/docs/rules/no-import-assign}
506+
*/
507+
rules[ 'no-import-assign' ] = 'error';
508+
487509
/**
488510
* Never allow either function or variable declarations within inner block scopes.
489511
*
@@ -557,6 +579,25 @@ rules[ 'no-invalid-regexp' ] = 'error';
557579
*/
558580
rules[ 'no-irregular-whitespace' ] = 'error';
559581

582+
/**
583+
* Never allow characters which are made with multiple code points in character class syntax.
584+
*
585+
* @name no-misleading-character-class
586+
* @memberof rules
587+
* @type {string}
588+
* @default 'error'
589+
* @see [no-misleading-character-class]{@link http://eslint.org/docs/rules/no-misleading-character-class}
590+
*
591+
* @example
592+
* // Bad...
593+
* var re = /^[👍]$/;
594+
*
595+
* @example
596+
* // Good...
597+
* var re = /^[👍]$/u;
598+
*/
599+
rules[ 'no-misleading-character-class' ] = 'error';
600+
560601
/**
561602
* Never allow calling of global objects as functions.
562603
*
@@ -762,6 +803,17 @@ rules[ 'no-unsafe-finally' ] = 'error';
762803
*/
763804
rules[ 'no-unsafe-negation' ] = 'error';
764805

806+
/**
807+
* Never allow assignments that can lead to race conditions due to usage of await or yield.
808+
*
809+
* @name require-atomic-updates
810+
* @memberof rules
811+
* @type {string}
812+
* @default 'error'
813+
* @see [require-atomic-updates]{@link http://eslint.org/docs/rules/require-atomic-updates}
814+
*/
815+
rules[ 'require-atomic-updates' ] = 'error';
816+
765817
/**
766818
* Never allow direct comparison with `NaN`.
767819
*

0 commit comments

Comments
 (0)