Skip to content

Commit 5779f7a

Browse files
committed
Addressed all eslint warnings in code and CI now also runs npm run lint
1 parent 3f0969e commit 5779f7a

File tree

14 files changed

+22
-23
lines changed

14 files changed

+22
-23
lines changed

.eslintrc.cjs

+1-5
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ module.exports = {
3838
"react-refresh/only-export-components": [
3939
"warn",
4040
{ allowConstantExport: true },
41-
],
42-
"@typescript-eslint/restrict-template-expressions": [
43-
"warn",
44-
{},
45-
],
41+
]
4642
},
4743
};

.github/workflows/ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
cache: 'npm'
3333
- run: npm ci
3434
- run: npm run build
35+
- run: npm run lint
3536
- run: npm run coverage
3637
- if: ${{ matrix.node-version == '18.x' }}
3738
name: Upload coverage reports to Codecov

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
`import { Logger, LogLevel } from "@forman2/extendit/util"`.
1111
* Fixed and enhanced API doc of `compileWhenClause` function. [#16]
1212
* Clarified effect of `extensionDependencies` in `README.md`.
13+
* Addressed all `eslint` warnings in code and CI now also runs `npm run lint`.
1314

1415
# 0.1.0 (from 18.11.2023)
1516

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"scripts": {
5353
"dev": "vite",
5454
"build": "tsc && vite build",
55-
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
55+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives",
5656
"preview": "vite preview",
5757
"test": "vitest",
5858
"coverage": "vitest run --coverage",

src/framework/core/extension/activate.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ test("activateExtension fails for missing main.js file", async () => {
9898
expect(extension.status).toEqual("rejected");
9999
expect(Array.isArray(extension.reasons)).toBe(true);
100100
expect(extension.reasons).toHaveLength(1);
101-
expect(`${extension.reasons![0]}`).toMatch("Failed to load url main.js");
101+
expect(extension.reasons![0] + "").toMatch("Failed to load url main.js");
102102
disposable.dispose();
103103
});
104104

@@ -112,7 +112,7 @@ test("activateExtension fails on activation", async () => {
112112
expect(Array.isArray(extension.reasons)).toBe(true);
113113
expect(extension.reasons).toHaveLength(1);
114114
expect(extension.reasons![0]).toBeInstanceOf(Error);
115-
expect(`${extension.reasons![0]}`).toMatch(
115+
expect(extension.reasons![0] + "").toMatch(
116116
"Failed by intention: pippo.will-fail-on-activation"
117117
);
118118
disposable.dispose();
@@ -133,10 +133,10 @@ test("activateExtension fails for failing dependency", async () => {
133133
expect(extension.status).toEqual("rejected");
134134
expect(Array.isArray(extension.reasons)).toBe(true);
135135
expect(extension.reasons).toHaveLength(2);
136-
expect(`${extension.reasons![0]}`).toMatch(
136+
expect(extension.reasons![0] + "").toMatch(
137137
"Extension 'pippo.requires-failing' rejected because dependencies could not be resolved."
138138
);
139-
expect(`${extension.reasons![1]}`).toMatch(
139+
expect(extension.reasons![1] + "").toMatch(
140140
"Failed by intention: pippo.will-fail-on-activation"
141141
);
142142
disposable1.dispose();

src/framework/core/extension/deactivate.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ test("deactivateExtension with failing deactivate()", async () => {
5757
expect(Array.isArray(extension.reasons)).toBe(true);
5858
expect(extension.reasons).toHaveLength(1);
5959
expect(extension.reasons![0]).toBeInstanceOf(Error);
60-
expect(`${extension.reasons![0]}`).toMatch(
60+
expect(extension.reasons![0] + "").toMatch(
6161
"Failed by intention: pippo.will-fail-on-deactivation"
6262
);
6363
disposable.dispose();

src/framework/core/extension/set.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ export function setExtensionStatus(
6969
? r
7070
: typeof r === "string"
7171
? new Error(r)
72-
: // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
73-
new Error(`${r})`)
72+
: new Error(r + "")
7473
);
7574
nextExtension = {
7675
...nextExtension,

src/framework/util/assert.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function assertDefined<T>(
5151
): asserts value is NonNullable<T> {
5252
if (value === undefined || value === null) {
5353
throw AssertionError.fromMessage(
54-
message ?? `Expected 'value' to be defined, but received ${value}`
54+
message ?? `Expected 'value' to be defined, but received ${value + ""}`
5555
);
5656
}
5757
}

src/framework/util/expr/node.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export class Literal<T> extends Node<T> {
4747
}
4848

4949
toString(): string {
50-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
5150
return `${typeof this.value}(${this.value})`;
5251
}
5352
}
@@ -236,7 +235,7 @@ export class Assign extends Node {
236235
} else {
237236
throw new Error(
238237
'An array index must have type "number" or "string", ' +
239-
`was type "${typeof indexValue}": ${indexValue}`
238+
`was type "${typeof indexValue}": ${indexValue + ""}`
240239
);
241240
}
242241
}

src/framework/util/expr/ops.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { BinaryOp, UnaryOp } from "./ops";
1111
describe("unary ops", () => {
1212
function assertUnaryOps<T>(x: unknown, expected: [UnaryOp, T][]) {
1313
expected.forEach(([op, result]) => {
14-
expect(op(x), `${op.name}(${x})`).toEqual(result);
14+
expect(op(x), `${op.name}(${String(x)})`).toEqual(result);
1515
});
1616
}
1717

@@ -35,7 +35,9 @@ describe("binary ops", () => {
3535
expected: [BinaryOp, T][]
3636
) {
3737
expected.forEach(([op, result]) => {
38-
expect(op(x, y), `${op.name}(${x}, ${y})`).toEqual(result);
38+
expect(op(x, y), `${op.name}(${String(x)}, ${String(y)})`).toEqual(
39+
result
40+
);
3941
});
4042
}
4143

src/framework/util/expr/parser.ts

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export class Parser {
8787
} else {
8888
throw this.error(
8989
`Missing ":" after "?" of conditional` +
90-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
9190
` near "${this.token().value}".`
9291
);
9392
}

src/framework/util/expr/scanner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type TokenType =
1717

1818
export interface Token {
1919
type: TokenType;
20-
value: unknown;
20+
value: string | number;
2121
}
2222

2323
// End-of-token-stream marker

src/framework/util/key.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
export function keyFromValue(value: unknown): string {
1212
return typeof value === "string"
1313
? value
14+
: value === null
15+
? "null"
1416
: Array.isArray(value)
1517
? keyFromArray(value)
16-
: typeof value === "object" && value !== null
18+
: typeof value === "object"
1719
? keyFromObject(value)
18-
: `${value}`;
20+
: value + "";
1921
}
2022

2123
/**

src/framework/util/log/logger.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class Logger {
2222
* @returns A global logger instance.
2323
*/
2424
static getLogger(name?: string): Logger {
25-
let key = name ?? "";
25+
const key = name ?? "";
2626
let logger = Logger.instances.get(key);
2727
if (!logger) {
2828
logger = new Logger(key);

0 commit comments

Comments
 (0)