Skip to content

Commit ea4bfbb

Browse files
committed
chore: add commit guards
1 parent 2a236bb commit ea4bfbb

File tree

13 files changed

+4445
-478
lines changed

13 files changed

+4445
-478
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ node_modules
33
*.map
44
*.d.ts
55
*.tsbuildinfo
6+
!commitlint.config.js
67

78
## editors
89
/.idea

.husky/commit-msg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx --no -- commitlint --edit $1

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx lint-staged

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Release](https://github.com/OMICRONEnergyOSS/oscd-api/actions/workflows/release-please.yml/badge.svg)](https://github.com/OMICRONEnergyOSS/oscd-api/actions/workflows/release-please.yml)
1+
[![Tests](https://github.com/OMICRONEnergyOSS/oscd-api/actions/workflows/test.yml/badge.svg)](https://github.com/OMICRONEnergyOSS/oscd-api/actions/workflows/test.yml) ![NPM Version](https://img.shields.io/npm/v/@omicronenergy/oscd-api)
22

33
# OpenSCD API
44

commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default { extends: ['@commitlint/config-conventional'] };

edit-event.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EditV2 } from "./editv2.js";
1+
import { EditV2 } from './editv2.js';
22

33
export type EditDetailV2<E extends EditV2 = EditV2> = {
44
edit: E;
@@ -19,7 +19,7 @@ export function newEditEventV2<E extends EditV2>(
1919
edit: E,
2020
options?: EditEventOptions,
2121
): EditEventV2<E> {
22-
return new CustomEvent<EditDetailV2<E>>("oscd-edit-v2", {
22+
return new CustomEvent<EditDetailV2<E>>('oscd-edit-v2', {
2323
composed: true,
2424
bubbles: true,
2525
detail: { ...options, edit },
@@ -28,6 +28,6 @@ export function newEditEventV2<E extends EditV2>(
2828

2929
declare global {
3030
interface ElementEventMap {
31-
["oscd-edit-v2"]: EditEventV2;
31+
['oscd-edit-v2']: EditEventV2;
3232
}
3333
}

editv1.spec.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { expect } from "@open-wc/testing";
1+
import { expect } from '@open-wc/testing';
22

3-
import { isEdit, Update } from "./editv1.js";
4-
import { Insert, Remove, SetAttributes, SetTextContent } from "./editv2.js";
3+
import { isEdit, Update } from './editv1.js';
4+
import { Insert, Remove, SetAttributes, SetTextContent } from './editv2.js';
55

66
const element = new DOMParser().parseFromString(
7-
"<SCL />",
8-
"application/xml",
7+
'<SCL />',
8+
'application/xml',
99
)!.documentElement;
1010

1111
const update: Update = { element, attributes: {} };
@@ -16,31 +16,31 @@ const setAttributes: SetAttributes = {
1616
attributes: {},
1717
attributesNS: {},
1818
};
19-
const setTextContent: SetTextContent = { element, textContent: "" };
19+
const setTextContent: SetTextContent = { element, textContent: '' };
2020

21-
describe("type guard functions for editv1", () => {
22-
it("returns false on invalid Edit type", () =>
23-
expect("invalid edit").to.not.satisfy(isEdit));
21+
describe('type guard functions for editv1', () => {
22+
it('returns false on invalid Edit type', () =>
23+
expect('invalid edit').to.not.satisfy(isEdit));
2424

25-
it("returns false on Update", () => expect(update).to.satisfy(isEdit));
25+
it('returns false on Update', () => expect(update).to.satisfy(isEdit));
2626

27-
it("returns true for Insert", () => expect(insert).to.satisfy(isEdit));
27+
it('returns true for Insert', () => expect(insert).to.satisfy(isEdit));
2828

29-
it("returns true for Remove", () => expect(remove).to.satisfy(isEdit));
29+
it('returns true for Remove', () => expect(remove).to.satisfy(isEdit));
3030

31-
it("returns false for SetAttributes", () =>
31+
it('returns false for SetAttributes', () =>
3232
expect(setAttributes).to.not.satisfy(isEdit));
3333

34-
it("returns true for SetTextContent", () =>
34+
it('returns true for SetTextContent', () =>
3535
expect(setTextContent).to.not.satisfy(isEdit));
3636

37-
it("returns false on mixed edit and editV2 array", () =>
37+
it('returns false on mixed edit and editV2 array', () =>
3838
expect([update, setAttributes]).to.not.satisfy(isEdit));
3939

40-
it("returns true on edit array", () =>
40+
it('returns true on edit array', () =>
4141
expect([update, remove, insert]).to.satisfy(isEdit));
4242

43-
it("returns false on editV2 array", () =>
43+
it('returns false on editV2 array', () =>
4444
expect([setAttributes, remove, insert, setTextContent]).to.not.satisfy(
4545
isEdit,
4646
));

editv1.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isSetAttributes } from "./editv2";
1+
import { isSetAttributes } from './editv2';
22

33
/** Intent to `parent.insertBefore(node, reference)` */
44
export type Insert = {
@@ -37,7 +37,7 @@ export function isInsert(edit: Edit): edit is Insert {
3737
export function isNamespaced(
3838
value: AttributeValue,
3939
): value is NamespacedAttributeValue {
40-
return value !== null && typeof value !== "string";
40+
return value !== null && typeof value !== 'string';
4141
}
4242

4343
export function isUpdate(edit: Edit): edit is Update {
@@ -57,7 +57,7 @@ export type EditEvent<E extends Edit = Edit> = CustomEvent<E>;
5757

5858
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5959
export function isEdit(edit: any): edit is Edit {
60-
if (isComplex(edit)) return !edit.some((e) => !isEdit(e));
60+
if (isComplex(edit)) return !edit.some(e => !isEdit(e));
6161

6262
return (
6363
!isSetAttributes(edit) &&

editv2.spec.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import { expect } from "@open-wc/testing";
1+
import { expect } from '@open-wc/testing';
22

3-
import { Update } from "./editv1.js";
3+
import { Update } from './editv1.js';
44
import {
55
Insert,
66
isEditV2,
77
Remove,
88
SetAttributes,
99
SetTextContent,
10-
} from "./editv2.js";
10+
} from './editv2.js';
1111

1212
const element = new DOMParser().parseFromString(
13-
"<SCL />",
14-
"application/xml",
13+
'<SCL />',
14+
'application/xml',
1515
)!.documentElement;
1616

1717
const update: Update = { element, attributes: {} };
@@ -22,31 +22,31 @@ const setAttributes: SetAttributes = {
2222
attributes: {},
2323
attributesNS: {},
2424
};
25-
const setTextContent: SetTextContent = { element, textContent: "" };
25+
const setTextContent: SetTextContent = { element, textContent: '' };
2626

27-
describe("type guard functions for editv2", () => {
28-
it("returns false on invalid Edit type", () =>
29-
expect("invalid edit").to.not.satisfy(isEditV2));
27+
describe('type guard functions for editv2', () => {
28+
it('returns false on invalid Edit type', () =>
29+
expect('invalid edit').to.not.satisfy(isEditV2));
3030

31-
it("returns false on Update", () => expect(update).to.not.satisfy(isEditV2));
31+
it('returns false on Update', () => expect(update).to.not.satisfy(isEditV2));
3232

33-
it("returns true for Insert", () => expect(insert).to.satisfy(isEditV2));
33+
it('returns true for Insert', () => expect(insert).to.satisfy(isEditV2));
3434

35-
it("returns true for Remove", () => expect(remove).to.satisfy(isEditV2));
35+
it('returns true for Remove', () => expect(remove).to.satisfy(isEditV2));
3636

37-
it("returns true for SetAttributes", () =>
37+
it('returns true for SetAttributes', () =>
3838
expect(setAttributes).to.satisfy(isEditV2));
3939

40-
it("returns true for SetTextContent", () =>
40+
it('returns true for SetTextContent', () =>
4141
expect(setTextContent).to.satisfy(isEditV2));
4242

43-
it("returns false on mixed edit and editV2 array", () =>
43+
it('returns false on mixed edit and editV2 array', () =>
4444
expect([update, setAttributes]).to.not.satisfy(isEditV2));
4545

46-
it("returns false on edit array", () =>
46+
it('returns false on edit array', () =>
4747
expect([update, update]).to.not.satisfy(isEditV2));
4848

49-
it("returns true on editV2 array", () =>
49+
it('returns true on editV2 array', () =>
5050
expect([setAttributes, remove, insert, setTextContent]).to.satisfy(
5151
isEditV2,
5252
));

editv2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function isInsert(edit: EditV2): edit is Insert {
6666

6767
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6868
export function isEditV2(edit: any): edit is EditV2 {
69-
if (isComplex(edit)) return !edit.some((e) => !isEditV2(e));
69+
if (isComplex(edit)) return !edit.some(e => !isEditV2(e));
7070

7171
return (
7272
isSetAttributes(edit) ||

0 commit comments

Comments
 (0)