Skip to content

Commit 76632d0

Browse files
committed
Added: linter
1 parent b8e71dc commit 76632d0

File tree

4 files changed

+55
-21
lines changed

4 files changed

+55
-21
lines changed

deno.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@
7070
]
7171
},
7272
"lint": {
73+
"include": [ "./src/components/toggle_switch/" ],
74+
"plugins": [
75+
"./lint/plugins/colon_spacing.ts"
76+
],
7377
"rules": {
7478
"tags": [
7579
"recommended"
@@ -101,10 +105,9 @@
101105
}
102106
},
103107
"fmt": {
104-
"options": {
105-
"singleQuote": true,
106-
"lineWidth": 120
107-
}
108+
"trailingCommas": "never",
109+
"singleQuote": true,
110+
"lineWidth": 120
108111
},
109112
"imports": {
110113
"@deno/esbuild-plugin": "jsr:@deno/esbuild-plugin@^1.2.0",

lint/plugins/colon_spacing.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/// <reference lib="deno.ns" />
2+
/// <reference lib="deno.unstable" />
3+
4+
export default {
5+
name: "colon-spacing",
6+
rules: {
7+
"after-function": {
8+
create(context) : Deno.lint.LintVisitor {
9+
return {
10+
TSTypeAnnotation(node) : void {
11+
if (node.parent.type === 'FunctionDeclaration') {
12+
const functionStart = node.parent.range[0];
13+
const sectionEnd = node.range[0]
14+
const index = context.sourceCode.getText(node.parent).substring(0, sectionEnd - functionStart).search(/\) *$/) + 1
15+
const sectionStart = functionStart + index;
16+
17+
if (index !== -1 && sectionEnd - sectionStart !== 1) {
18+
context.report({
19+
message: `Wrong colon spacing. [${sectionStart}, ${sectionEnd}]`,
20+
range: [sectionStart - 1, sectionEnd + 1],
21+
fix(fixer) {
22+
return fixer.replaceTextRange([sectionStart, sectionEnd], ' ')
23+
},
24+
})
25+
}
26+
}
27+
}
28+
}
29+
}
30+
}
31+
}
32+
} satisfies Deno.lint.Plugin

src/components/button/button.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import { mergeProps, type JSXElement } from '@solid-js'
2-
import { buttonTypes, type ButtonType } from './button_types.ts';
3-
import './index.css'
4-
1+
import { type JSXElement, mergeProps } from '@solid-js';
2+
import { type ButtonType, buttonTypes } from './button_types.ts';
3+
import './index.css';
54

65
export function Button(props: {
7-
type?: ButtonType,
8-
children: JSXElement
9-
}) : JSXElement {
6+
type?: ButtonType;
7+
children: JSXElement;
8+
}): JSXElement {
109
const properties = mergeProps({ type: buttonTypes.DEFAULT }, props);
1110

1211
return (
1312
<button
1413
type='button'
1514
class={`ui button button--${properties.type}`}
1615
data-type={properties.type}
17-
>{properties.children}</button>
18-
)
16+
>
17+
{properties.children}
18+
</button>
19+
);
1920
}
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
import { type JSXElement, createSignal } from '@solid-js'
1+
import { createSignal, type JSXElement } from '@solid-js';
22

3-
import './index.css'
4-
5-
6-
export function ToggleSwitch() : JSXElement {
3+
import './index.css';
74

5+
export default function ToggleSwitch(_foo: string, _bar: string): JSXElement {
86
const [state, setState] = createSignal(false);
97

108
const toggle = () => {
119
setState((v) => !v);
1210
console.log('State is now:', state());
13-
}
11+
};
1412

1513
return (
1614
<button
1715
type='button'
18-
class={`ui toggle-switch`}
16+
class='ui toggle-switch'
1917
classList={{
2018
'toggle-switch--active': state()
2119
}}
@@ -24,5 +22,5 @@ export function ToggleSwitch() : JSXElement {
2422
>
2523
{state() ? 'ON' : 'OFF'}
2624
</button>
27-
)
25+
);
2826
}

0 commit comments

Comments
 (0)