Skip to content

Commit 1c1a16a

Browse files
committed
style(rule): Resolve linter issue
1 parent ad1ddcc commit 1c1a16a

File tree

3 files changed

+66
-66
lines changed

3 files changed

+66
-66
lines changed

src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { type Plugin } from '@commitlint/types';
2-
import { default as scopePattern } from "./rules/scope-pattern";
1+
import { type Plugin } from "@commitlint/types"
2+
import { default as scopePattern } from "./rules/scope-pattern"
33

4-
export const rules: Plugin['rules'] = {
5-
'commitlint-plugin-prevenger/scope-pattern': scopePattern,
6-
};
4+
export const rules: Plugin["rules"] = {
5+
"commitlint-plugin-prevenger/scope-pattern": scopePattern,
6+
}
77

88
export default {
9-
rules,
10-
};
9+
rules
10+
}
Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import type { Commit } from 'conventional-commits-parser';
2-
import type { Rule } from '@commitlint/types';
1+
import type { Commit } from "conventional-commits-parser"
2+
import type { Rule } from "@commitlint/types"
33
import rule from "."
44

5-
describe('scope-pattern', () => {
5+
describe("scope-pattern", () => {
66
const ruleFn = rule as Rule<[string, string?]>
77
const createCommit = (scope?: string): Commit => {
88
return {
9-
type: 'feat',
9+
type: "feat",
1010
scope: scope,
1111
header: `feat(${scope}): some message`,
1212
body: null,
@@ -17,45 +17,45 @@ describe('scope-pattern', () => {
1717
notes: [] as Commit.Note[],
1818
references: [] as Commit.Reference[]
1919
} as Commit
20-
};
21-
22-
it('passes when scope matches pattern and "always" is used', async () => {
23-
const result = await ruleFn(createCommit('core'), 'always', ['^core$']);
24-
expect(result).toEqual([true, '']);
25-
});
26-
27-
it('fails when scope does not match pattern and "always" is used', async () => {
28-
const result = await ruleFn(createCommit('utils'), 'always', ['^core$']);
29-
expect(result).toEqual([false, 'scope must match pattern: ^core$']);
30-
});
31-
32-
it('passes when scope does not match pattern and "never" is used', async () => {
33-
const result = await ruleFn(createCommit('utils'), 'never', ['^core$']);
34-
expect(result).toEqual([true, '']);
35-
});
36-
37-
it('fails when scope matches pattern and "never" is used', async () => {
38-
const result = await ruleFn(createCommit('core'), 'never', ['^core$']);
39-
expect(result).toEqual([false, 'scope must not match pattern: ^core$']);
40-
});
41-
42-
it('passes when scope is undefined', async () => {
43-
const result = await ruleFn(createCommit(undefined), 'always', ['^core$']);
44-
expect(result).toEqual([true, '']);
45-
});
46-
47-
it('uses default "when" and "value" when not provided', async () => {
48-
const result = await ruleFn(createCommit('anyscope'));
49-
expect(result).toEqual([true, '']);
50-
});
51-
52-
it('uses default "value" when only "when" is provided', async () => {
53-
const result = await ruleFn(createCommit('anyscope'), 'always');
54-
expect(result).toEqual([true, '']);
55-
});
56-
57-
it('uses custom message when provided and fails', async () => {
58-
const result = await ruleFn(createCommit('utils'), 'always', ['^core$', 'Custom message']);
59-
expect(result).toEqual([false, 'Custom message']);
60-
});
61-
});
20+
}
21+
22+
it("passes when scope matches pattern and \"always\" is used", async () => {
23+
const result = await ruleFn(createCommit("core"), "always", ["^core$"])
24+
expect(result).toEqual([true, ""])
25+
})
26+
27+
it("fails when scope does not match pattern and \"always\" is used", async () => {
28+
const result = await ruleFn(createCommit("utils"), "always", ["^core$"])
29+
expect(result).toEqual([false, "scope must match pattern: ^core$"])
30+
})
31+
32+
it("passes when scope does not match pattern and \"never\" is used", async () => {
33+
const result = await ruleFn(createCommit("utils"), "never", ["^core$"])
34+
expect(result).toEqual([true, ""])
35+
})
36+
37+
it("fails when scope matches pattern and \"never\" is used", async () => {
38+
const result = await ruleFn(createCommit("core"), "never", ["^core$"])
39+
expect(result).toEqual([false, "scope must not match pattern: ^core$"])
40+
})
41+
42+
it("passes when scope is undefined", async () => {
43+
const result = await ruleFn(createCommit(undefined), "always", ["^core$"])
44+
expect(result).toEqual([true, ""])
45+
})
46+
47+
it("uses default \"when\" and \"value\" when not provided", async () => {
48+
const result = await ruleFn(createCommit("anyscope"))
49+
expect(result).toEqual([true, ""])
50+
})
51+
52+
it("uses default \"value\" when only \"when\" is provided", async () => {
53+
const result = await ruleFn(createCommit("anyscope"), "always")
54+
expect(result).toEqual([true, ""])
55+
})
56+
57+
it("uses custom message when provided and fails", async () => {
58+
const result = await ruleFn(createCommit("utils"), "always", ["^core$", "Custom message"])
59+
expect(result).toEqual([false, "Custom message"])
60+
})
61+
})

src/rules/scope-pattern/index.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import type { Rule } from '@commitlint/types';
2-
import type { Commit } from 'conventional-commits-parser';
1+
import type { Rule } from "@commitlint/types"
2+
import type { Commit } from "conventional-commits-parser"
33

44
const rule: Rule = async (
55
parsed: Commit,
6-
when: 'always' | 'never' = 'always',
7-
value: [string, string?] = ['']
6+
when: "always" | "never" = "always",
7+
value: [string, string?] = [""]
88
) => {
9-
const [pattern, message] = value;
9+
const [pattern, message] = value
1010

11-
if (!parsed.scope) return [true, ''];
11+
if (!parsed.scope) return [true, ""]
1212

13-
const regex = new RegExp(pattern);
14-
const isMatch = regex.test(parsed.scope);
15-
const isNegated = when === 'never';
16-
const pass = isNegated ? !isMatch : isMatch;
13+
const regex = new RegExp(pattern)
14+
const isMatch = regex.test(parsed.scope)
15+
const isNegated = when === "never"
16+
const pass = isNegated ? !isMatch : isMatch
1717

1818
return [
1919
pass,
20-
pass ? '' : (message || `scope must ${isNegated ? 'not ' : ''}match pattern: ${pattern}`)
21-
];
22-
};
20+
pass ? "" : (message || `scope must ${isNegated ? "not " : ""}match pattern: ${pattern}`)
21+
]
22+
}
2323

2424
export default rule

0 commit comments

Comments
 (0)