Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d6f9f76

Browse files
committed
chore: enable strictNullChecks for codebase
1 parent 14cb05d commit d6f9f76

File tree

6 files changed

+34
-29
lines changed

6 files changed

+34
-29
lines changed

‎jest.config.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ module.exports = {
33
testEnvironment: 'node',
44
globals: {
55
'ts-jest': {
6-
tsConfig: {
7-
resolveJsonModule: true
8-
}
9-
}
10-
}
6+
tsConfig: 'tsconfig.spec.json',
7+
},
8+
},
119
};

‎src/board.ts‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ interface ICoordinates {
4646
}
4747

4848
interface IParentTransform extends ICoordinates {
49-
angle: number;
49+
angle: number|null;
5050
}
5151

5252
function kiUnits(value: string | number) {
@@ -56,10 +56,12 @@ function kiUnits(value: string | number) {
5656
return value * 10 * 0.0254;
5757
}
5858

59-
function kiAngle(value: string, parentAngle?: number) {
60-
const angle = parseFloat(value) + (parentAngle || 0);
61-
if (!isNaN(angle)) {
62-
return angle > 180 ? -(360 - angle) : angle;
59+
function kiAngle(value?: string, parentAngle?: number) {
60+
if (value) {
61+
const angle = parseFloat(value) + (parentAngle || 0);
62+
if (!isNaN(angle)) {
63+
return angle > 180 ? -(360 - angle) : angle;
64+
}
6365
}
6466
return null;
6567
}
@@ -130,7 +132,7 @@ function convertVia(
130132
const [x, y, diameter, net, drill, id, locked] = args;
131133
return [
132134
'via',
133-
kiAt(x, y, null, parentCoords),
135+
kiAt(x, y, undefined, parentCoords),
134136
['size', kiUnits(diameter)],
135137
['drill', kiUnits(drill) * 2],
136138
['layers', 'F.Cu', 'B.Cu'],
@@ -164,7 +166,6 @@ function convertPadToVia(
164166

165167
const size = kiUnits(holeRadius);
166168
const drillHoleLength = holeLength === '0' ? null : kiUnits(holeLength);
167-
const slotted = drillHoleLength > 0 ? 'oval' : null;
168169

169170
if (shape !== 'ELLIPSE') {
170171
return [
@@ -182,7 +183,7 @@ function convertPadToVia(
182183

183184
return [
184185
'via',
185-
kiAt(x, y, null, parentCoords),
186+
kiAt(x, y, undefined, parentCoords),
186187
['size', kiUnits(holeRadius)],
187188
['drill', kiUnits(drill) * 2],
188189
['layers', 'F.Cu', 'B.Cu'],
@@ -291,9 +292,13 @@ function convertArc(
291292
transform?: IParentTransform
292293
) {
293294
const [width, layer, net, path, _, id, locked] = args;
294-
const [match, startPoint, arcParams] = /^M\s*([-\d.\s]+)A\s*([-\d.\s]+)$/.exec(
295-
path.replace(/[,\s]+/g, ' ')
296-
);
295+
const pathMatch = /^M\s*([-\d.\s]+)A\s*([-\d.\s]+)$/.exec(path.replace(/[,\s]+/g, ' '));
296+
if (!pathMatch) {
297+
console.warn(`Invalid arc path: ${path}`);
298+
return null;
299+
}
300+
301+
const [match, startPoint, arcParams] = pathMatch;
297302
const [startX, startY] = startPoint.split(' ');
298303
const [svgRx, svgRy, xAxisRotation, largeArc, sweep, endX, endY] = arcParams.split(' ');
299304
const start = kiCoords(startX, startY, transform);
@@ -438,7 +443,7 @@ function convertLibHole(args: string[], transform: IParentTransform) {
438443
'',
439444
'np_thru_hole',
440445
'circle',
441-
kiAt(x, y, null, transform),
446+
kiAt(x, y, undefined, transform),
442447
['size', size, size],
443448
['drill', size],
444449
['layers', '*.Cu', '*.Mask'],
@@ -687,7 +692,7 @@ export function convertShape(shape: string, conversionState: IConversionState) {
687692
}
688693

689694
function flatten<T>(arr: T[]) {
690-
return [].concat(...arr);
695+
return ([]asT[]).concat(...arr);
691696
}
692697

693698
export function convertBoardToArray(input: IEasyEDABoard): ISpectraList {

‎src/schematic.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function kiUnits(value: string | number) {
99
}
1010

1111
function flatten<T>(arr: T[]) {
12-
return [].concat(...arr);
12+
return ([]asT[]).concat(...arr);
1313
}
1414

1515
function convertNoConnect(args: string[]) {

‎src/spectra.ts‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ export interface ISpectraList extends Array<ISpectraList | string | number | nul
22

33
const WHITESPACE = [' ', '\t', '\r', '\n'];
44

5+
function notNull<TValue>(value: TValue | null): value is TValue {
6+
return value !== null;
7+
}
8+
59
export function encodeString(str: string) {
610
if (/^[a-z][a-z0-9_]+$/.test(str)) {
711
return str;
@@ -24,15 +28,9 @@ export function encodeValue(value: ISpectraList | string | number) {
2428
}
2529

2630
export function encodeObject(object: ISpectraList): string {
27-
return (
28-
'(' +
29-
object
30-
.filter((it) => it !== null)
31-
.map(encodeValue)
32-
.join(' ') +
33-
')'
34-
);
31+
return '(' + object.filter(notNull).map(encodeValue).join(' ') + ')';
3532
}
33+
3634
function parseElement(input: string): [ISpectraList | string | number, number] {
3735
let idx = 0;
3836
while (WHITESPACE.includes(input[idx])) {

‎tsconfig.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"target": "es5",
44
"module": "commonjs",
55
"moduleResolution": "node",
6-
"noImplicitAny": true,
6+
"strict": true,
77
"removeComments": false,
88
"sourceMap": true,
99
"declaration": true,

‎tsconfig.spec.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"extends": "./tsconfig.json",
33
"exclude": [],
4-
"compilerOptions": { "resolveJsonModule": true }
4+
"compilerOptions": {
5+
"resolveJsonModule": true,
6+
"strictNullChecks": false,
7+
"noEmitOnError": false
8+
}
59
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /