@odg/eslint-config 2.0.3 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -34,6 +34,7 @@
34
34
  - [Installation](#installation)
35
35
  - [File Name Convention](#file-name-convention)
36
36
  - [Semi Rule](#semi-rule)
37
+ - [Cond Assign](#cond-assign)
37
38
  - [Quotes Rule](#quotes-rule)
38
39
  - [Indent Rule](#indent-rule)
39
40
  - [Line Break Rule](#line-break-rule)
@@ -42,6 +43,8 @@
42
43
  - [Camel Case Rule](#camel-case-rule)
43
44
  - [Strict](#strict)
44
45
  - [Padded Block Rule](#padded-block-rule)
46
+ - [Object Shorthand](#object-shorthand)
47
+ - [No Unused Labels](#no-unused-labels)
45
48
  - [Lines Between Class Members](#lines-between-class-members)
46
49
  - [No Multi Assign Rule](#no-multi-assign-rule)
47
50
  - [Explicit Member Accessibility Rule](#explicit-member-accessibility-rule)
@@ -125,6 +128,8 @@
125
128
  - [Max Statements Per Line](#max-statements-per-line)
126
129
  - [No Constant Condition](#no-constant-condition)
127
130
  - [No Debugger](#no-debugger)
131
+ - [No Console](#no-console)
132
+ - [No deprecated](#no-deprecated)
128
133
  - [Not Duplicate Case](#not-duplicate-case)
129
134
  - [Regex Block](#regex-block)
130
135
  - [No Overwrite Exception](#no-overwrite-exception)
@@ -156,7 +161,7 @@
156
161
  - [No Undefined declare](#no-undefined-declare)
157
162
  - [No New require](#no-new-require)
158
163
  - [No New Object](#no-new-object)
159
- - [No New Symbol](#no-new-symbol)
164
+ - [No New Native Nonconstructor](#no-new-native-nonconstructor)
160
165
  - [Var Size](#var-size)
161
166
  - [Max Depth](#max-depth)
162
167
  - [Max Params](#max-params)
@@ -448,6 +453,7 @@
448
453
  - [Performance](#performance)
449
454
  - [No Alert](#no-alert)
450
455
  - [No Loop Func](#no-loop-func)
456
+ - [No Sync](#no-sync)
451
457
  - [Errors](#errors)
452
458
  - [Construtor Super Invalid](#construtor-super-invalid)
453
459
  - [Getter Return](#getter-return)
@@ -538,17 +544,20 @@
538
544
  Add dependence to package.json
539
545
 
540
546
  ```bash
541
- npm install eslint @odg/eslint-config
547
+ npm install @odg/eslint-config
542
548
  # or
543
- yarn add -D eslint @odg/eslint-config
549
+ yarn add -D @odg/eslint-config
544
550
  ```
545
551
 
546
- Add extends in your `.eslintrc` file
552
+ Create the `eslint.config.js` file in the root directory of your project.
553
+
554
+ ```js
555
+ import odgLinter from "@odg/eslint-config";
556
+
557
+ export default [
558
+ ...odgLinter,
559
+ ];
547
560
 
548
- ```json
549
- {
550
- "extends": [ "@odg" ]
551
- }
552
561
  ```
553
562
 
554
563
  Add script in your `package.json` file
@@ -556,12 +565,14 @@ Add script in your `package.json` file
556
565
  ```json
557
566
  {
558
567
  "scripts": {
559
- "lint": "eslint --ext .js,.jsx,.ts,.tsx,.json,.jsonc,.json5,.yml,.yaml,.xml,.txt,.svg,.properties,.gradle,.java,.cpp,.c,.cs,.html,.css,.groovy,.gitignore,.npmignore,.toml,.env,.example,.sample,.ini,.php,.bat,.powershell,.ps1,.sh,.bash,.eslintrc",
568
+ "lint": "eslint",
569
+ "lint:fix": "eslint --fix",
560
570
  }
561
571
  }
562
572
  ```
563
573
 
564
- Test: `npm run lint` or `yarn lint`
574
+ Test List: `npm run lint .` or `yarn lint .`
575
+ Start Fix: `npm run lint:fix .` or `yarn lint:fix .`
565
576
 
566
577
  ## File Name Convention
567
578
 
@@ -595,6 +606,7 @@ Requires semicolons at the end of statements
595
606
 
596
607
  <https://eslint.org/docs/rules/semi#semi>
597
608
  <https://eslint.org/docs/rules/semi-style>
609
+ <https://eslint.org/docs/latest/rules/no-unexpected-multiline>
598
610
 
599
611
  👍 Examples of correct code
600
612
 
@@ -625,6 +637,24 @@ class C {
625
637
  foo();
626
638
  }
627
639
  }
640
+
641
+ const foo = bar;
642
+ (1 || 2).baz();
643
+
644
+ const baz = bar
645
+ ;(1 || 2).baz()
646
+
647
+ const hello = 'world';
648
+ [1, 2, 3].forEach(addNumber);
649
+
650
+ const hi = 'world'
651
+ void [1, 2, 3].forEach(addNumber);
652
+
653
+ const x = function() {};
654
+ `hello`
655
+
656
+ const tag = function() {}
657
+ tag `hello`
628
658
  ```
629
659
 
630
660
  👎 Examples of incorrect code
@@ -657,6 +687,71 @@ class C {
657
687
  ;bar()
658
688
  }
659
689
  }
690
+
691
+ const foo = bar
692
+ (1 || 2).baz();
693
+
694
+ const hello = 'world'
695
+ [1, 2, 3].forEach(addNumber);
696
+
697
+ const x = function() {}
698
+ `hello`
699
+
700
+ const y = function() {}
701
+ y
702
+ `hello`
703
+
704
+ const z = foo
705
+ /regex/g.test(bar)
706
+ ```
707
+
708
+ ## Cond Assign
709
+
710
+ ----------
711
+
712
+ In conditional statements, it is very easy to mistype a comparison operator (such as ==) as an assignment operator
713
+ (such as =). For example:
714
+
715
+ <https://eslint.org/docs/latest/rules/no-cond-assign>
716
+
717
+ 👍 Examples of correct code
718
+
719
+ ```typescript
720
+ // Assignment replaced by comparison
721
+ let x;
722
+ if (x === 0) {
723
+ const b = 1;
724
+ }
725
+
726
+ // Practical example that wraps the assignment in parentheses
727
+ const setHeight = function (someNode) {
728
+ do {
729
+ someNode.height = "100px";
730
+ } while ((someNode = someNode.parentNode));
731
+ }
732
+
733
+ // Practical example that wraps the assignment and tests for 'null'
734
+ const set_height = function (someNode) {
735
+ do {
736
+ someNode.height = "100px";
737
+ } while ((someNode = someNode.parentNode) !== null);
738
+ }
739
+ ```
740
+
741
+ 👎 Examples of incorrect code
742
+
743
+ ```typescript
744
+ let x;
745
+ if (x = 0) {
746
+ const b = 1;
747
+ }
748
+
749
+ // Practical example that is similar to an error
750
+ const setHeight = function (someNode) {
751
+ do {
752
+ someNode.height = "100px";
753
+ } while (someNode = someNode.parentNode);
754
+ }
660
755
  ```
661
756
 
662
757
  ## Quotes Rule
@@ -907,6 +1002,78 @@ if (a) {
907
1002
 
908
1003
  ```
909
1004
 
1005
+ ## Object Shorthand
1006
+
1007
+ ----------
1008
+
1009
+ Require or disallow method and property shorthand syntax for object literals
1010
+
1011
+ <https://eslint.org/docs/latest/rules/object-shorthand>
1012
+
1013
+ 👍 Examples of correct code
1014
+
1015
+ ```typescript
1016
+ const foo = {
1017
+ w() {},
1018
+ *x() {},
1019
+ [y]() {},
1020
+ z
1021
+ };
1022
+ ```
1023
+
1024
+ 👎 Examples of incorrect code
1025
+
1026
+ ```typescript
1027
+ const foo = {
1028
+ w: function() {},
1029
+ x: function *() {},
1030
+ [y]: function() {},
1031
+ z: z
1032
+ };
1033
+ ```
1034
+
1035
+ ## No Unused Labels
1036
+
1037
+ ----------
1038
+
1039
+ Labels that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring.
1040
+
1041
+ <https://eslint.org/docs/latest/rules/no-unused-labels>
1042
+
1043
+ 👍 Examples of correct code
1044
+
1045
+ ```typescript
1046
+ A: {
1047
+ if (foo()) {
1048
+ break A;
1049
+ }
1050
+ bar();
1051
+ }
1052
+
1053
+ B:
1054
+ for (let i = 0; i < 10; ++i) {
1055
+ if (foo()) {
1056
+ break B;
1057
+ }
1058
+ bar();
1059
+ }
1060
+ ```
1061
+
1062
+ 👎 Examples of incorrect code
1063
+
1064
+ ```typescript
1065
+ A: var foo = 0;
1066
+
1067
+ B: {
1068
+ foo();
1069
+ }
1070
+
1071
+ C:
1072
+ for (let i = 0; i < 10; ++i) {
1073
+ foo();
1074
+ }
1075
+ ```
1076
+
910
1077
  ## Lines Between Class Members
911
1078
 
912
1079
  ----------
@@ -2371,6 +2538,7 @@ No Unreachable code
2371
2538
 
2372
2539
  <https://eslint.org/docs/rules/no-unreachable>
2373
2540
  <https://sonarsource.github.io/rspec/#/rspec/S6079/javascript>
2541
+ <https://eslint.org/docs/latest/rules/no-useless-assignment>
2374
2542
 
2375
2543
  👍 Examples of correct code
2376
2544
 
@@ -2393,6 +2561,41 @@ switch (foo) {
2393
2561
  case 1:
2394
2562
  break;
2395
2563
  }
2564
+
2565
+ function fn1() {
2566
+ let v = 'used';
2567
+ doSomething(v);
2568
+ v = 'used-2';
2569
+ doSomething(v);
2570
+ }
2571
+
2572
+ function fn2() {
2573
+ let v = 'used';
2574
+ if (condition) {
2575
+ v = 'used-2';
2576
+ doSomething(v);
2577
+ return
2578
+ }
2579
+ doSomething(v);
2580
+ }
2581
+
2582
+ function fn3() {
2583
+ let v = 'used';
2584
+ if (condition) {
2585
+ doSomething(v);
2586
+ } else {
2587
+ v = 'used-2';
2588
+ doSomething(v);
2589
+ }
2590
+ }
2591
+
2592
+ function fn4() {
2593
+ let v = 'used';
2594
+ for (let i = 0; i < 10; i++) {
2595
+ doSomething(v);
2596
+ v = 'used in next iteration';
2597
+ }
2598
+ }
2396
2599
  ```
2397
2600
 
2398
2601
  👎 Examples of incorrect code
@@ -2427,6 +2630,49 @@ function baz() {
2427
2630
 
2428
2631
  for (;;) {}
2429
2632
  console.log("done");
2633
+
2634
+ function fn1() {
2635
+ let v = 'used';
2636
+ doSomething(v);
2637
+ v = 'unused';
2638
+ }
2639
+
2640
+ function fn2() {
2641
+ let v = 'used';
2642
+ if (condition) {
2643
+ v = 'unused';
2644
+ return
2645
+ }
2646
+ doSomething(v);
2647
+ }
2648
+
2649
+ function fn3() {
2650
+ let v = 'used';
2651
+ if (condition) {
2652
+ doSomething(v);
2653
+ } else {
2654
+ v = 'unused';
2655
+ }
2656
+ }
2657
+
2658
+ function fn4() {
2659
+ let v = 'unused';
2660
+ if (condition) {
2661
+ v = 'used';
2662
+ doSomething(v);
2663
+ return
2664
+ }
2665
+ }
2666
+
2667
+ function fn5() {
2668
+ let v = 'used';
2669
+ if (condition) {
2670
+ let v = 'used';
2671
+ console.log(v);
2672
+ v = 'unused';
2673
+ }
2674
+ console.log(v);
2675
+ }
2430
2676
  ```
2431
2677
 
2432
2678
  ## No Multiline String
@@ -4342,6 +4588,63 @@ function isTruthy(x) {
4342
4588
  }
4343
4589
  ```
4344
4590
 
4591
+ ## No Console
4592
+
4593
+ ----------
4594
+
4595
+ Disallow the use of console
4596
+
4597
+ <https://eslint.org/docs/latest/rules/no-console>
4598
+
4599
+ 👍 Examples of correct code
4600
+
4601
+ ```typescript
4602
+ import { ConsoleLogger, Logger } from "@odg/log"
4603
+
4604
+ const log = new Logger();
4605
+ log.pushHandler(new ConsoleLogger());
4606
+
4607
+ log.debug("This is a debug message");
4608
+ ```
4609
+
4610
+ 👎 Examples of incorrect code
4611
+
4612
+ ```typescript
4613
+ console.log("Log a debug level message.");
4614
+ console.warn("Log a warn level message.");
4615
+ console.error("Log an error level message.");
4616
+ console.log = foo();
4617
+ ```
4618
+
4619
+ ## No Deprecated
4620
+
4621
+ ----------
4622
+
4623
+ Node has many deprecated API. The community is going to remove those API from Node in future,
4624
+ so we should not use those.
4625
+
4626
+ <https://github.com/eslint-community/eslint-plugin-n/blob/master/docs/rules/no-deprecated-api.md>
4627
+
4628
+ 👍 Examples of correct code
4629
+
4630
+ ```typescript
4631
+ var fs = require("fs");
4632
+ fs.stat(...);
4633
+ fs.access(...);
4634
+ ```
4635
+
4636
+ 👎 Examples of incorrect code
4637
+
4638
+ ```typescript
4639
+ var fs = require("fs");
4640
+ fs.exists("./foo.js", function() {});
4641
+
4642
+ // Also, it can report the following patterns.
4643
+ var exists = require("fs").exists;
4644
+ const {exists} = require("fs");
4645
+
4646
+ ```
4647
+
4345
4648
  ## Not Duplicate Case
4346
4649
 
4347
4650
  ----------
@@ -5526,29 +5829,34 @@ var myObject = new Object();
5526
5829
  new Object();
5527
5830
  ```
5528
5831
 
5529
- ## No New Symbol
5832
+ ## No New Native Nonconstructor
5530
5833
 
5531
5834
  ----------
5532
5835
 
5533
- Disallow new operators with the Symbol object
5836
+ Disallow new operators with the Symbol and BigInt object
5534
5837
 
5535
- <https://eslint.org/docs/latest/rules/no-new-symbol>
5838
+ <https://eslint.org/docs/latest/rules/no-new-native-nonconstructor>
5536
5839
 
5537
5840
  👍 Examples of correct code
5538
5841
 
5539
5842
  ```typescript
5540
- var foo = Symbol('foo');
5843
+ const foo = Symbol('foo');
5844
+ const bar = BigInt(9007199254740991);
5541
5845
 
5542
5846
  // Ignores shadowed Symbol.
5543
- function bar(Symbol) {
5544
- const baz = new Symbol("baz");
5847
+ function baz(Symbol) {
5848
+ const qux = new Symbol("baz");
5849
+ }
5850
+ function quux(BigInt) {
5851
+ const corge = new BigInt(9007199254740991);
5545
5852
  }
5546
5853
  ```
5547
5854
 
5548
5855
  👎 Examples of incorrect code
5549
5856
 
5550
5857
  ```typescript
5551
- var foo = new Symbol('foo');
5858
+ const foo = new Symbol('foo');
5859
+ const bar = new BigInt(9007199254740991);
5552
5860
  ```
5553
5861
 
5554
5862
  ## Var Size
@@ -5629,6 +5937,7 @@ var { prop: a} = {};
5629
5937
  Enforce a maximum depth that blocks can be nested
5630
5938
 
5631
5939
  <https://eslint.org/docs/latest/rules/max-depth>
5940
+ <https://eslint.org/docs/latest/rules/max-nested-callbacks>
5632
5941
 
5633
5942
  👍 Examples of correct code
5634
5943
 
@@ -5641,6 +5950,14 @@ function foo() {
5641
5950
  }
5642
5951
  }
5643
5952
  }
5953
+
5954
+ foo1(function() { // Nested 1 deep
5955
+ foo2(function() { // Nested 2 deep
5956
+ foo3(function() { // Nested 3 deep
5957
+
5958
+ });
5959
+ });
5960
+ });
5644
5961
  ```
5645
5962
 
5646
5963
  👎 Examples of incorrect code
@@ -5658,6 +5975,16 @@ function foo() {
5658
5975
  }
5659
5976
  }
5660
5977
  }
5978
+
5979
+ foo1(function() { // Nested 1 deep
5980
+ foo2(function() { // Nested 2 deep
5981
+ foo3(function() { // Nested 3 deep
5982
+ foo4(function() { // Nested 4 deep
5983
+ // Do something
5984
+ });
5985
+ });
5986
+ });
5987
+ });
5661
5988
  ```
5662
5989
 
5663
5990
  ## Max Params
@@ -9326,9 +9653,8 @@ import a from './foo.js';
9326
9653
  👎 Examples of incorrect code
9327
9654
 
9328
9655
  ```typescript
9329
- import { } from './foo.js';
9330
- import t, { } from './foo.js';
9331
- import type { } from './foo.js';
9656
+ import t from './foo.js';
9657
+ import type from './foo.js';
9332
9658
  ```
9333
9659
 
9334
9660
  ### Export End File
@@ -9349,8 +9675,7 @@ import a from './foo.js';
9349
9675
  👎 Examples of incorrect code
9350
9676
 
9351
9677
  ```typescript
9352
- import { } from './foo.js';
9353
- import t, { } from './foo.js';
9678
+ import t from './foo.js';
9354
9679
  ```
9355
9680
 
9356
9681
  ### Import First
@@ -10300,6 +10625,7 @@ var foo = /(a?b*)+/; // warns about `+`
10300
10625
  This rule reports control characters that were not escaped using a control escape (\0, t, \n, \v, f, \r).
10301
10626
 
10302
10627
  <https://ota-meshi.github.io/eslint-plugin-regexp/rules/control-character-escape.html>
10628
+ <https://eslint.org/docs/latest/rules/no-control-regex>
10303
10629
 
10304
10630
  👍 Examples of correct code
10305
10631
 
@@ -10307,6 +10633,15 @@ This rule reports control characters that were not escaped using a control escap
10307
10633
  var foo = /[\n\r]/;
10308
10634
  var foo = /\t/;
10309
10635
  var foo = RegExp("\t+\n");
10636
+
10637
+ const pattern1 = /\x20/;
10638
+ const pattern2 = /\u0020/;
10639
+ const pattern3 = /\u{20}/u;
10640
+ const pattern4 = /\t/;
10641
+ const pattern5 = /\n/;
10642
+ const pattern6 = new RegExp("\x20");
10643
+ const pattern7 = new RegExp("\\t");
10644
+ const pattern8 = new RegExp("\\n");
10310
10645
  ```
10311
10646
 
10312
10647
  👎 Examples of incorrect code
@@ -10316,6 +10651,14 @@ var foo = / /;
10316
10651
  var foo = /\u0009/;
10317
10652
  var foo = /\u{a}/u;
10318
10653
  var foo = RegExp("\\u000a");
10654
+
10655
+ const pattern1 = /\x00/;
10656
+ const pattern2 = /\x0C/;
10657
+ const pattern3 = /\x1F/;
10658
+ const pattern4 = /\u000C/;
10659
+ const pattern5 = /\u{C}/u;
10660
+ const pattern6 = new RegExp("\x0C"); // raw U+000C character in the pattern
10661
+ const pattern7 = new RegExp("\\x0C"); // \x0C pattern
10319
10662
  ```
10320
10663
 
10321
10664
  ### Negation
@@ -16549,6 +16892,92 @@ for (let i = 0; i < 10; ++i) {
16549
16892
  foo = 100;
16550
16893
  ```
16551
16894
 
16895
+ ### No Sync
16896
+
16897
+ ----------
16898
+
16899
+ In Node.js, most I/O is done through asynchronous methods. However,
16900
+ there are often synchronous versions of the asynchronous methods. For example, fs.exists() and fs.existsSync()
16901
+
16902
+ <https://github.com/eslint-community/eslint-plugin-n/blob/master/docs/rules/no-sync.md>
16903
+ <https://github.com/eslint-community/eslint-plugin-n/blob/master/docs/rules/prefer-promises/dns.md>
16904
+ <https://github.com/eslint-community/eslint-plugin-n/blob/master/docs/rules/prefer-promises/fs.md>
16905
+
16906
+ 👍 Examples of correct code
16907
+
16908
+ ```typescript
16909
+ fs.exists()
16910
+
16911
+ /*eslint n/prefer-promises/dns: [error]*/
16912
+ const { promises: dns } = require("dns")
16913
+
16914
+ async function lookup(hostname) {
16915
+ const { address, family } = await dns.lookup(hostname)
16916
+ //...
16917
+ }
16918
+
16919
+ import { promises as dns } from "dns"
16920
+
16921
+ async function lookup(hostname) {
16922
+ const { address, family } = await dns.lookup(hostname)
16923
+ //...
16924
+ }
16925
+
16926
+ const { promises: fs } = require("fs")
16927
+
16928
+ async function readData(filePath) {
16929
+ const content = await fs.readFile(filePath, "utf8")
16930
+ //...
16931
+ }
16932
+
16933
+ import { promises as fs } from "fs"
16934
+
16935
+ async function readData(filePath) {
16936
+ const content = await fs.readFile(filePath, "utf8")
16937
+ //...
16938
+ }
16939
+ ```
16940
+
16941
+ 👎 Examples of incorrect code
16942
+
16943
+ ```typescript
16944
+ fs.existsSync()
16945
+
16946
+ /*eslint n/prefer-promises/dns: [error]*/
16947
+ import dns from "dns"
16948
+
16949
+ function lookup(hostname) {
16950
+ dns.lookup(hostname, (error, address, family) => {
16951
+ //...
16952
+ })
16953
+ }
16954
+
16955
+ /*eslint n/prefer-promises/dns: [error]*/
16956
+ const dns = require("dns")
16957
+
16958
+ function lookup(hostname) {
16959
+ dns.lookup(hostname, (error, address, family) => {
16960
+ //...
16961
+ })
16962
+ }
16963
+
16964
+ import fs from "fs"
16965
+
16966
+ function readData(filePath) {
16967
+ fs.readFile(filePath, "utf8", (error, content) => {
16968
+ //...
16969
+ })
16970
+ }
16971
+
16972
+ const fs = require("fs")
16973
+
16974
+ function readData(filePath) {
16975
+ fs.readFile(filePath, "utf8", (error, content) => {
16976
+ //...
16977
+ })
16978
+ }
16979
+ ```
16980
+
16552
16981
  ## Errors
16553
16982
 
16554
16983
  ### Construtor Super Invalid