Skip to content

Commit 2e73941

Browse files
committed
fix: Spacing
1 parent 24ba5ba commit 2e73941

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@loat-dev/lint-plugins",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"license": "./LICENSE",
55
"exports": {
66
"./colon_spacing": "./src/plugins/colon_spacing.ts"

src/plugins/colon_spacing.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Deno.test('colon-spacing plugin', async (test) => {
77
colonSpacing,
88
'main.ts',
99
`
10-
export function Foo(arg1: string, arg2: number): string {
10+
export function Foo(): string {
1111
return 'Hello World!';
1212
}
1313
`
@@ -19,15 +19,15 @@ Deno.test('colon-spacing plugin', async (test) => {
1919

2020
assertEquals(diagnostic.id, 'colon-spacing/before-colon');
2121
assertEquals(diagnostic.message, 'Wrong colon spacing. Expected 1 space before colon.');
22-
assertEquals(diagnostic.fix, [{range: [54, 54], text: ' '}]);
22+
assertEquals(diagnostic.fix, [{range: [28, 28], text: ' '}]);
2323
});
2424

2525
await test.step('before-colon rule, too many spaces', () => {
2626
const diagnostics = Deno.lint.runPlugin(
2727
colonSpacing,
2828
'main.ts',
2929
`
30-
export function Foo(arg1: string, arg2: number) : string {
30+
export function Foo() : string {
3131
return 'Hello World!';
3232
}
3333
`
@@ -39,15 +39,15 @@ Deno.test('colon-spacing plugin', async (test) => {
3939

4040
assertEquals(diagnostic.id, 'colon-spacing/before-colon');
4141
assertEquals(diagnostic.message, 'Wrong colon spacing. Expected 1 space before colon.');
42-
assertEquals(diagnostic.fix, [{range: [54, 56], text: ' '}]);
42+
assertEquals(diagnostic.fix, [{range: [28, 30], text: ' '}]);
4343
});
4444

4545
await test.step('after-colon rule, no space', () => {
4646
const diagnostics = Deno.lint.runPlugin(
4747
colonSpacing,
4848
'main.ts',
4949
`
50-
export function Foo(prop1: string, prop2: number) :string {
50+
export function Foo() :string {
5151
return 'Hello World!';
5252
}
5353
`
@@ -59,15 +59,15 @@ Deno.test('colon-spacing plugin', async (test) => {
5959

6060
assertEquals(diagnostic.id, 'colon-spacing/after-colon');
6161
assertEquals(diagnostic.message, 'Wrong colon spacing. Expected 1 space after colon.');
62-
assertEquals(diagnostic.fix, [{range: [58, 58], text: ' '}]);
62+
assertEquals(diagnostic.fix, [{range: [30, 30], text: ' '}]);
6363
});
6464

6565
await test.step('after-colon rule, too many spaces', () => {
6666
const diagnostics = Deno.lint.runPlugin(
6767
colonSpacing,
6868
'main.ts',
6969
`
70-
export function Foo(prop1: string, prop2: number) : string {
70+
export function Foo() : string {
7171
return 'Hello World!';
7272
}
7373
`
@@ -79,15 +79,15 @@ Deno.test('colon-spacing plugin', async (test) => {
7979

8080
assertEquals(diagnostic.id, 'colon-spacing/after-colon');
8181
assertEquals(diagnostic.message, 'Wrong colon spacing. Expected 1 space after colon.');
82-
assertEquals(diagnostic.fix, [{range: [58, 60], text: ' '}]);
82+
assertEquals(diagnostic.fix, [{range: [30, 32], text: ' '}]);
8383
});
8484

8585
await test.step('before-colon/after-colon rule, no space, both', () => {
8686
const diagnostics = Deno.lint.runPlugin(
8787
colonSpacing,
8888
'main.ts',
8989
`
90-
export function Foo(prop1: string, prop2: number):string {
90+
export function Foo():string {
9191
return 'Hello World!';
9292
}
9393
`
@@ -100,11 +100,11 @@ Deno.test('colon-spacing plugin', async (test) => {
100100

101101
assertEquals(afterFunctionDiagnostic.id, 'colon-spacing/before-colon');
102102
assertEquals(afterFunctionDiagnostic.message, 'Wrong colon spacing. Expected 1 space before colon.');
103-
assertEquals(afterFunctionDiagnostic.fix, [{range: [56, 56], text: ' '}]);
103+
assertEquals(afterFunctionDiagnostic.fix, [{range: [28, 28], text: ' '}]);
104104

105105
assertEquals(beforeTypeDiagnostic.id, 'colon-spacing/after-colon');
106106
assertEquals(beforeTypeDiagnostic.message, 'Wrong colon spacing. Expected 1 space after colon.');
107-
assertEquals(beforeTypeDiagnostic.fix, [{range: [57, 57], text: ' '}]);
107+
assertEquals(beforeTypeDiagnostic.fix, [{range: [29, 29], text: ' '}]);
108108
});
109109

110110
await test.step('before-colon rule, no space', () => {

src/plugins/colon_spacing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const colonSpacing : Deno.lint.Plugin = {
88
create(context) : Deno.lint.LintVisitor {
99
return {
1010
TSTypeAnnotation(node) : void {
11-
if (['FunctionDeclaration', 'FunctionExpression', 'TSPropertySignature'].includes(node.parent.type)) {
11+
if (['FunctionDeclaration', 'FunctionExpression', 'TSPropertySignature', 'Identifier'].includes(node.parent.type)) {
1212
const functionStart = node.parent.range[0];
1313
const sectionEnd = node.range[0];
1414
const index =
@@ -33,7 +33,7 @@ const colonSpacing : Deno.lint.Plugin = {
3333
create(context) : Deno.lint.LintVisitor {
3434
return {
3535
TSTypeAnnotation(node) : void {
36-
if (['FunctionDeclaration', 'FunctionExpression', 'TSPropertySignature'].includes(node.parent.type)) {
36+
if (['FunctionDeclaration', 'FunctionExpression', 'TSPropertySignature', 'Identifier'].includes(node.parent.type)) {
3737
const sectionStart = node.range[0] + 1;
3838
const sectionEnd = node.typeAnnotation.range[0];
3939

0 commit comments

Comments
 (0)