Skip to content

Commit 3e8c6a4

Browse files
authored
style: enable eslint linting rules (#180)
* Enables eslint linting rules * Fixes linting problems
1 parent ef6bb97 commit 3e8c6a4

File tree

96 files changed

+986
-898
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+986
-898
lines changed

.eslintrc.json

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
"extends": [
88
"eslint:recommended",
99
"plugin:@typescript-eslint/recommended",
10-
// "plugin:@typescript-eslint/recommended-requiring-type-checking", // TODO later too much work currently
10+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
1111
"plugin:unicorn/recommended",
12-
// "plugin:import/recommended", // TODO gives weird errors
12+
"plugin:import/recommended",
1313
"plugin:import/typescript",
1414
"plugin:promise/recommended",
15-
"prettier"//,
16-
// "plugin:sonarjs/recommended" // TODO later too much work currently
15+
"prettier",
16+
"plugin:sonarjs/recommended"
1717
],
18-
// "parser": "@typescript-eslint/parser",
18+
"parser": "@typescript-eslint/parser",
1919
"parserOptions": {
2020
"ecmaVersion": 2021,
21-
"sourceType": "module"//,
22-
// "project": "./tsconfig.json",
23-
// "tsconfigRootDir": "."
21+
"sourceType": "module",
22+
"project": "./tsconfig.json",
23+
"tsconfigRootDir": "."
2424
},
2525
"settings": {
2626
"import/resolver": {
@@ -34,24 +34,24 @@
3434
"unused-imports"
3535
],
3636
"rules": {
37-
// "import/first": "error",
38-
// "import/newline-after-import": "error",
39-
// "import/no-duplicates": "error",
40-
// "import/order": ["error",
41-
// {
42-
// "alphabetize": {
43-
// "order": "asc",
44-
// "caseInsensitive": true
45-
// },
46-
// "newlines-between": "always"
47-
// }
48-
// ],
49-
// "sort-imports": ["error",
50-
// {
51-
// "ignoreDeclarationSort": true,
52-
// "ignoreCase": true
53-
// }
54-
// ],
37+
"import/first": "error",
38+
"import/newline-after-import": "error",
39+
"import/no-duplicates": "error",
40+
"import/order": ["error",
41+
{
42+
"alphabetize": {
43+
"order": "asc",
44+
"caseInsensitive": true
45+
},
46+
"newlines-between": "always"
47+
}
48+
],
49+
"sort-imports": ["error",
50+
{
51+
"ignoreDeclarationSort": true,
52+
"ignoreCase": true
53+
}
54+
],
5555
"notice/notice": [
5656
"error",
5757
{
@@ -60,16 +60,16 @@
6060
}
6161
],
6262
"unicorn/filename-case": "off",
63+
"no-unused-vars": "off",
64+
"@typescript-eslint/no-unused-vars": "off",
65+
"unused-imports/no-unused-imports": "error",
66+
"unused-imports/no-unused-vars": [
67+
"error",
68+
{ "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
69+
],
6370
"unicorn/prefer-ternary": "warn",
64-
65-
// "no-unused-vars": "off",
66-
// "@typescript-eslint/no-unused-vars": "off",
67-
// "unused-imports/no-unused-imports": "error",
68-
// "unused-imports/no-unused-vars": [
69-
// "error",
70-
// { "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
71-
// ],
71+
"unicorn/expiring-todo-comments": "off",
7272
"no-fallthrough": "off",
73-
"unicorn/expiring-todo-comments": "off"
73+
"sonarjs/cognitive-complexity": "warn"
7474
}
7575
}

libraries/analysis-javascript/lib/RootContext.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,27 @@ import { existsSync, lstatSync } from "node:fs";
2020

2121
import * as t from "@babel/types";
2222
import { RootContext as CoreRootContext } from "@syntest/analysis";
23+
import { getLogger, Logger } from "@syntest/logging";
24+
import TypedEmitter from "typed-emitter";
2325

2426
import { AbstractSyntaxTreeFactory } from "./ast/AbstractSyntaxTreeFactory";
2527
import { ControlFlowGraphFactory } from "./cfg/ControlFlowGraphFactory";
28+
import { ConstantPool } from "./constant/ConstantPool";
29+
import { ConstantPoolFactory } from "./constant/ConstantPoolFactory";
30+
import { ConstantPoolManager } from "./constant/ConstantPoolManager";
2631
import { DependencyFactory } from "./dependency/DependencyFactory";
32+
import { Events } from "./Events";
2733
import { Export } from "./target/export/Export";
28-
import { TargetFactory } from "./target/TargetFactory";
29-
import { TypeModelFactory } from "./type/resolving/TypeModelFactory";
30-
import { readFile } from "./utils/fileSystem";
3134
import { ExportFactory } from "./target/export/ExportFactory";
32-
import { TypeExtractor } from "./type/discovery/TypeExtractor";
33-
import { TypeModel } from "./type/resolving/TypeModel";
35+
import { TargetFactory } from "./target/TargetFactory";
3436
import { Element } from "./type/discovery/element/Element";
3537
import { DiscoveredObjectType } from "./type/discovery/object/DiscoveredType";
3638
import { Relation } from "./type/discovery/relation/Relation";
39+
import { TypeExtractor } from "./type/discovery/TypeExtractor";
40+
import { TypeModel } from "./type/resolving/TypeModel";
41+
import { TypeModelFactory } from "./type/resolving/TypeModelFactory";
3742
import { TypePool } from "./type/resolving/TypePool";
38-
import TypedEmitter from "typed-emitter";
39-
import { Events } from "./Events";
40-
import { ConstantPoolManager } from "./constant/ConstantPoolManager";
41-
import { Logger, getLogger } from "@syntest/logging";
42-
import { ConstantPoolFactory } from "./constant/ConstantPoolFactory";
43-
import { ConstantPool } from "./constant/ConstantPool";
43+
import { readFile } from "./utils/fileSystem";
4444

4545
export class RootContext extends CoreRootContext<t.Node> {
4646
protected static LOGGER: Logger;

libraries/analysis-javascript/lib/cfg/ControlFlowGraphFactory.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
import { traverse } from "@babel/core";
1919
import * as t from "@babel/types";
2020
import { ControlFlowGraphFactory as CoreControlFlowGraphFactory } from "@syntest/analysis";
21-
import { ControlFlowProgram, contractControlFlowProgram } from "@syntest/cfg";
21+
import { contractControlFlowProgram, ControlFlowProgram } from "@syntest/cfg";
2222

23-
import { ControlFlowGraphVisitor } from "./ControlFlowGraphVisitor";
2423
import { Factory } from "../Factory";
2524

25+
import { ControlFlowGraphVisitor } from "./ControlFlowGraphVisitor";
26+
2627
export class ControlFlowGraphFactory
2728
extends Factory
2829
implements CoreControlFlowGraphFactory<t.Node>

libraries/analysis-javascript/lib/cfg/ControlFlowGraphVisitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
Node,
2929
NodeType,
3030
} from "@syntest/cfg";
31-
import { Logger, getLogger } from "@syntest/logging";
31+
import { getLogger, Logger } from "@syntest/logging";
3232

3333
export class ControlFlowGraphVisitor extends AbstractSyntaxTreeVisitor {
3434
protected static override LOGGER: Logger;

libraries/analysis-javascript/lib/constant/ConstantPoolFactory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import { traverse } from "@babel/core";
1919
import * as t from "@babel/types";
2020

2121
import { Factory } from "../Factory";
22-
import { ConstantVisitor } from "./ConstantVisitor";
22+
2323
import { ConstantPool } from "./ConstantPool";
24+
import { ConstantVisitor } from "./ConstantVisitor";
2425

2526
export class ConstantPoolFactory extends Factory {
2627
/**

libraries/analysis-javascript/lib/constant/ConstantVisitor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import { NodePath } from "@babel/core";
1919
import * as t from "@babel/types";
2020
import { AbstractSyntaxTreeVisitor } from "@syntest/ast-visitor-javascript";
21+
2122
import { ConstantPool } from "./ConstantPool";
2223

2324
export class ConstantVisitor extends AbstractSyntaxTreeVisitor {

libraries/analysis-javascript/lib/dependency/DependencyFactory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ import { traverse } from "@babel/core";
2020
import * as t from "@babel/types";
2121
import { DependencyFactory as CoreDependencyFactory } from "@syntest/analysis";
2222

23-
import { DependencyVisitor } from "./DependencyVisitor";
2423
import { Factory } from "../Factory";
2524

25+
import { DependencyVisitor } from "./DependencyVisitor";
26+
2627
/**
2728
* Dependency generator for targets.
2829
*

libraries/analysis-javascript/lib/target/Target.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export type Exportable = {
4949

5050
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5151
export function isExported(target: any): target is Exportable {
52+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
5253
return "exported" in target && target.exported === true;
5354
}
5455

libraries/analysis-javascript/lib/target/TargetFactory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import { traverse } from "@babel/core";
2222
import * as t from "@babel/types";
2323
import { TargetFactory as CoreTargetFactory } from "@syntest/analysis";
2424

25+
import { Factory } from "../Factory";
26+
2527
import { ExportVisitor } from "./export/ExportVisitor";
2628
import { Target } from "./Target";
2729
import { TargetVisitor } from "./TargetVisitor";
28-
import { Factory } from "../Factory";
2930

3031
/**
3132
* TargetFactory for Javascript.

libraries/analysis-javascript/lib/target/TargetVisitor.ts

Lines changed: 32 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ import { NodePath } from "@babel/core";
2020
import * as t from "@babel/types";
2121
import { TargetType } from "@syntest/analysis";
2222
import { AbstractSyntaxTreeVisitor } from "@syntest/ast-visitor-javascript";
23+
import { getLogger, Logger } from "@syntest/logging";
24+
25+
import { unsupportedSyntax } from "../utils/diagnostics";
2326

27+
import { Export } from "./export/Export";
2428
import {
2529
Callable,
2630
ClassTarget,
@@ -32,9 +36,6 @@ import {
3236
ObjectTarget,
3337
SubTarget,
3438
} from "./Target";
35-
import { Export } from "./export/Export";
36-
import { unsupportedSyntax } from "../utils/diagnostics";
37-
import { getLogger, Logger } from "@syntest/logging";
3839

3940
const COMPUTED_FLAG = ":computed:";
4041
export class TargetVisitor extends AbstractSyntaxTreeVisitor {
@@ -91,33 +92,6 @@ export class TargetVisitor extends AbstractSyntaxTreeVisitor {
9192
// we always use x as the target name instead of A
9293
const parentNode = path.parentPath.node;
9394
switch (parentNode.type) {
94-
case "ClassProperty": {
95-
// e.g. class A { ? = class {} }
96-
// e.g. class A { ? = function () {} }
97-
// e.g. class A { ? = () => {} }
98-
99-
if (parentNode.key.type === "Identifier") {
100-
// e.g. class A { x = class {} }
101-
// e.g. class A { x = function () {} }
102-
// e.g. class A { x = () => {} }
103-
return parentNode.key.name;
104-
} else if (parentNode.key.type.includes("Literal")) {
105-
// e.g. class A { "x" = class {} }
106-
// e.g. class A { "x" = function () {} }
107-
// e.g. class A { "x" = () => {} }
108-
return "value" in parentNode.key
109-
? parentNode.key.value.toString()
110-
: "null";
111-
} else {
112-
// e.g. const {x} = class {}
113-
// e.g. const {x} = function {}
114-
// e.g. const {x} = () => {}
115-
// Should not be possible
116-
throw new Error(
117-
unsupportedSyntax(path.node.type, this._getNodeId(path))
118-
);
119-
}
120-
}
12195
case "VariableDeclarator": {
12296
// e.g. const ?? = class {}
12397
// e.g. const ?? = function {}
@@ -208,23 +182,39 @@ export class TargetVisitor extends AbstractSyntaxTreeVisitor {
208182
);
209183
}
210184
}
185+
case "ClassProperty":
186+
// e.g. class A { ? = class {} }
187+
// e.g. class A { ? = function () {} }
188+
// e.g. class A { ? = () => {} }
211189
case "ObjectProperty": {
212190
// e.g. {?: class {}}
213191
// e.g. {?: function {}}
214192
// e.g. {?: () => {}}
215193
if (parentNode.key.type === "Identifier") {
194+
// e.g. class A { x = class {} }
195+
// e.g. class A { x = function () {} }
196+
// e.g. class A { x = () => {} }
197+
216198
// e.g. {y: class {}}
217199
// e.g. {y: function {}}
218200
// e.g. {y: () => {}}
219201
return parentNode.key.name;
220202
} else if (parentNode.key.type.includes("Literal")) {
203+
// e.g. class A { "x" = class {} }
204+
// e.g. class A { "x" = function () {} }
205+
// e.g. class A { "x" = () => {} }
206+
221207
// e.g. {1: class {}}
222208
// e.g. {1: function {}}
223209
// e.g. {1: () => {}}
224210
return "value" in parentNode.key
225211
? parentNode.key.value.toString()
226212
: "null";
227213
} else {
214+
// e.g. const {x} = class {}
215+
// e.g. const {x} = function {}
216+
// e.g. const {x} = () => {}
217+
228218
// e.g. {?: class {}}
229219
// e.g. {?: function {}}
230220
// e.g. {?: () => {}}
@@ -348,33 +338,12 @@ export class TargetVisitor extends AbstractSyntaxTreeVisitor {
348338
// call(() => {})
349339
const targetName = this._getTargetNameOfExpression(path);
350340

351-
if (path.parentPath.isVariableDeclarator()) {
352-
const id = this._getNodeId(path);
353-
const export_ = this._getExport(id);
341+
// TODO is there a difference if the parent is a variable declarator?
354342

355-
this._extractFromFunction(
356-
path,
357-
id,
358-
id,
359-
targetName,
360-
export_,
361-
false,
362-
false
363-
);
364-
} else {
365-
const id = this._getNodeId(path);
366-
const export_ = this._getExport(id);
343+
const id = this._getNodeId(path);
344+
const export_ = this._getExport(id);
367345

368-
this._extractFromFunction(
369-
path,
370-
id,
371-
id,
372-
targetName,
373-
export_,
374-
false,
375-
false
376-
);
377-
}
346+
this._extractFromFunction(path, id, id, targetName, export_, false, false);
378347

379348
path.skip();
380349
};
@@ -455,15 +424,13 @@ export class TargetVisitor extends AbstractSyntaxTreeVisitor {
455424
if (object.isIdentifier()) {
456425
// x.? = ?
457426
// x['?'] = ?
458-
if (object.node.name === "exports") {
459-
// exports.? = ?
460-
isObject = false;
461-
id = this._getBindingId(right);
462-
} else if (
463-
object.node.name === "module" &&
464-
property.isIdentifier() &&
465-
property.node.name === "exports"
427+
if (
428+
object.node.name === "exports" ||
429+
(object.node.name === "module" &&
430+
property.isIdentifier() &&
431+
property.node.name === "exports")
466432
) {
433+
// exports.? = ?
467434
// module.exports = ?
468435
isObject = false;
469436
id = this._getBindingId(right);
@@ -704,7 +671,7 @@ export class TargetVisitor extends AbstractSyntaxTreeVisitor {
704671
key.isNumericLiteral() ||
705672
key.isBigIntLiteral()
706673
) {
707-
targetName = `${key.node.value}`;
674+
targetName = String(key.node.value);
708675
}
709676

710677
if (value.isFunction()) {
@@ -791,7 +758,7 @@ export class TargetVisitor extends AbstractSyntaxTreeVisitor {
791758
key.isNumericLiteral() ||
792759
key.isBigIntLiteral()
793760
) {
794-
targetName = `${key.node.value}`;
761+
targetName = String(key.node.value);
795762
}
796763

797764
if (value.isFunction()) {

0 commit comments

Comments
 (0)