Skip to content

Commit

Permalink
chore(repo): add lint action (#64)
Browse files Browse the repository at this point in the history
* chore(repo): add lint action

* chore: eslint

* chore: release v0.0.3-alpha.33
  • Loading branch information
enzonotario authored Sep 29, 2024
1 parent 87bcd87 commit 957918e
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 98 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*

- run: pnpm install

- name: Lint
run: pnpm run lint
5 changes: 4 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export default antfu(
formatters: true,
lessOpinionated: true,
rules: {
'brace-style': ['error', '1tbs', { allowSingleLine: false }],
'style/brace-style': 'off',
},
stylistic: {
'style/brace-style': ['error', '1tbs', { allowSingleLine: true }],
},
},
)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vitepress-theme-openapi",
"type": "module",
"version": "0.0.3-alpha.32",
"version": "0.0.3-alpha.33",
"packageManager": "[email protected]",
"homepage": "https://vitepress-theme-openapi.vercel.app/",
"repository": {
Expand Down
4 changes: 3 additions & 1 deletion src/components/Common/OAFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
href="https://github.com/enzonotario/vitepress-theme-openapi"
target="_blank"
class="text-blue-700 dark:text-blue-300"
>VitePress Theme OpenAPI</a>
>
VitePress Theme OpenAPI
</a>
</span>
</template>
2 changes: 2 additions & 0 deletions src/components/Common/OAHeading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function getSlotChildrenText(children) {
} else if (node.children.default) {
return getSlotChildrenText(node.children.default())
}
return ''
}).join('')
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Common/OAOperation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ function hasSlot(name) {
v-else-if="!hideDefaultFooter"
#footer="footer"
>
<OAFooter />
<OAFooter v-bind="footer" />
</template>
</OAPath>
</template>
2 changes: 1 addition & 1 deletion src/components/Playground/OAPlaygroundResponse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const url = computed(() => {
if (isAudio) {
try {
return window.URL ? URL.createObjectURL(response.body) : ''
} catch (error) {}
} catch { }
}
return ''
Expand Down
2 changes: 1 addition & 1 deletion src/components/Sample/OACodeSamples.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const samples = generateCodeSamples(url, props.method)
<template>
<div class="vp-code-group vp-adaptive-theme">
<div class="tabs">
<template v-for="(sample, key) in samples">
<template v-for="(sample, key) in samples" :key="key">
<input
:id="`tab-${props.operationId}-${key}`"
type="radio"
Expand Down
8 changes: 4 additions & 4 deletions src/components/Schema/OASchemaPropertyAttributes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const keysToIgnore = ['type', 'description', 'properties', 'required', 'items',

<template>
<div
v-for="(key, idx) in Object.keys(props.property).filter(k => !keysToIgnore.includes(k))"
:key="idx"
v-for="(key, propertyIdx) in Object.keys(props.property).filter(k => !keysToIgnore.includes(k))"
:key="propertyIdx"
class="flex flex-row flex-wrap items-center gap-2"
>
<span class="text-xs text-gray-600 dark:text-gray-300">
Expand All @@ -23,8 +23,8 @@ const keysToIgnore = ['type', 'description', 'properties', 'required', 'items',

<template v-if="Array.isArray(props.property[key])">
<code
v-for="(value, idx) in props.property[key]"
:key="idx"
v-for="(value, attributeIdx) in props.property[key]"
:key="attributeIdx"
class="!text-xs"
>
{{ value }}
Expand Down
3 changes: 1 addition & 2 deletions src/components/Try/OATryItButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ function trackTryIt() {
event_category: 'api',
event_label: props.operationId,
})
}
catch (error) { }
} catch { }
}
function setLoading(value) {
Expand Down
2 changes: 1 addition & 1 deletion src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare module '*.vue' {
import type { DefineComponent } from 'vue'
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-empty-object-type
// eslint-disable-next-line ts/no-empty-object-type
const component: DefineComponent<{}, {}, any>
export default component
}
164 changes: 83 additions & 81 deletions src/json.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
--jse-theme: light;

/* Over all fonts, sizes, and colors */
--jse-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
--jse-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell,
'Helvetica Neue', sans-serif;
--jse-font-family-mono: consolas, menlo, monaco, 'Ubuntu Mono', 'source-code-pro', monospace;
--jse-font-size-mono: 14px;
--jse-theme-color: var(--vp-c-bg-alt);
Expand Down Expand Up @@ -158,86 +159,87 @@
}

.oa-jse-theme-dark {
--jse-theme: dark;

/* Over all fonts, sizes, and colors */
--jse-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
--jse-font-family-mono: consolas, menlo, monaco, 'Ubuntu Mono', 'source-code-pro', monospace;
--jse-font-size-mono: 14px;
--jse-theme-color: var(--vp-c-bg-alt);
--jse-theme-color-highlight: var(--vp-c-bg);
--jse-background-color: var(--vp-code-block-bg);
--jse-text-color: var(--vp-c-text-1);
--jse-text-color-inverse: var(--vp-c-neutral-inverse);
--jse-text-readonly: var(--vp-c-text-3);
--jse-error-color: var(--vp-c-danger-1);
--jse-warning-color: var(--vp-c-warning-1);
--jse-info-color: var(--vp-c-brand-1);

/* Main, menu, modal */
--jse-main-border: 0 solid var(--vp-c-border);
--jse-menu-color: var(--vp-c-text-3);
--jse-modal-background: var(--vp-c-bg-alt);
--jse-modal-overlay-background: rgba(0, 0, 0, 0.3);
--jse-modal-code-background: var(--vp-c-bg-soft);

/* Tooltip in text mode */
--jse-tooltip-color: var(--vp-c-text-1);
--jse-tooltip-background: var(--vp-c-bg-alt);
--jse-tooltip-border: 1px solid var(--vp-c-border);
--jse-tooltip-action-button-color: var(--vp-c-neutral-inverse);
--jse-tooltip-action-button-background: var(--vp-c-text-1);

/* Panels: navigation bar, gutter, search box */
--jse-panel-background: var(--vp-c-bg-alt);
--jse-panel-color: var(--vp-c-text-1);
--jse-panel-color-readonly: var(--vp-c-text-3);
--jse-panel-border: 1px solid var(--vp-c-border);
--jse-panel-button-color-highlight: var(--vp-c-text-1);
--jse-panel-button-background-highlight: var(--vp-c-bg-soft);

/* Navigation bar */
--jse-navigation-bar-background: var(--vp-c-bg);
--jse-navigation-bar-background-highlight: var(--vp-c-bg-alt);
--jse-navigation-bar-dropdown-color: var(--vp-c-text-1);

/* Context menu */
--jse-context-menu-background: var(--vp-c-bg-alt);
--jse-context-menu-background-highlight: var(--vp-c-bg-soft);
--jse-context-menu-color: var(--vp-c-text-1);
--jse-context-menu-separator-color: var(--vp-c-border);
--jse-context-menu-pointer-background: var(--vp-c-bg-alt);
--jse-context-menu-pointer-background-highlight: var(--vp-c-bg-soft);
--jse-context-menu-pointer-color: var(--vp-c-text-1);

/* Contents: JSON key and values */
--jse-key-color: var(--vjs-key-color);
--jse-value-color: var(--vjs-value-string-color);
--jse-value-color-number: var(--vjs-value-number-color);
--jse-value-color-boolean: var(--vjs-value-boolean-color);
--jse-value-color-null: var(--vjs-value-null-color);
--jse-value-color-string: var(--vjs-value-string-color);
--jse-value-color-url: var(--vjs-value-string-color);
--jse-delimiter-color: var(--vjs-caret-color);
--jse-edit-outline: 2px solid var(--vjs-border-color);

/* Selected or hovered */
--jse-selection-background-color: var(--vjs-hover-background-color);
--jse-hover-background-color: var(--vjs-hover-background-color);

/* Controls in modals: inputs, buttons, and `a` */
--jse-input-background: var(--vp-c-bg);
--jse-input-color: var(--vp-c-text-1);
--jse-input-border: 1px solid var(--vp-c-border);
--jse-button-background: var(--vp-c-default-3);
--jse-button-primary-background: var(--vp-c-brand-3);
--jse-button-primary-color: var(--vp-c-white);
--jse-button-secondary-background: var(--vp-c-default-3);
--jse-a-color: var(--vp-c-brand-1);
--jse-a-color-highlight: var(--vp-c-brand-2);
}

.oa-jse .jse-main {
--jse-theme: dark;

/* Over all fonts, sizes, and colors */
--jse-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell,
'Helvetica Neue', sans-serif;
--jse-font-family-mono: consolas, menlo, monaco, 'Ubuntu Mono', 'source-code-pro', monospace;
--jse-font-size-mono: 14px;
--jse-theme-color: var(--vp-c-bg-alt);
--jse-theme-color-highlight: var(--vp-c-bg);
--jse-background-color: var(--vp-code-block-bg);
--jse-text-color: var(--vp-c-text-1);
--jse-text-color-inverse: var(--vp-c-neutral-inverse);
--jse-text-readonly: var(--vp-c-text-3);
--jse-error-color: var(--vp-c-danger-1);
--jse-warning-color: var(--vp-c-warning-1);
--jse-info-color: var(--vp-c-brand-1);

/* Main, menu, modal */
--jse-main-border: 0 solid var(--vp-c-border);
--jse-menu-color: var(--vp-c-text-3);
--jse-modal-background: var(--vp-c-bg-alt);
--jse-modal-overlay-background: rgba(0, 0, 0, 0.3);
--jse-modal-code-background: var(--vp-c-bg-soft);

/* Tooltip in text mode */
--jse-tooltip-color: var(--vp-c-text-1);
--jse-tooltip-background: var(--vp-c-bg-alt);
--jse-tooltip-border: 1px solid var(--vp-c-border);
--jse-tooltip-action-button-color: var(--vp-c-neutral-inverse);
--jse-tooltip-action-button-background: var(--vp-c-text-1);

/* Panels: navigation bar, gutter, search box */
--jse-panel-background: var(--vp-c-bg-alt);
--jse-panel-color: var(--vp-c-text-1);
--jse-panel-color-readonly: var(--vp-c-text-3);
--jse-panel-border: 1px solid var(--vp-c-border);
--jse-panel-button-color-highlight: var(--vp-c-text-1);
--jse-panel-button-background-highlight: var(--vp-c-bg-soft);

/* Navigation bar */
--jse-navigation-bar-background: var(--vp-c-bg);
--jse-navigation-bar-background-highlight: var(--vp-c-bg-alt);
--jse-navigation-bar-dropdown-color: var(--vp-c-text-1);

/* Context menu */
--jse-context-menu-background: var(--vp-c-bg-alt);
--jse-context-menu-background-highlight: var(--vp-c-bg-soft);
--jse-context-menu-color: var(--vp-c-text-1);
--jse-context-menu-separator-color: var(--vp-c-border);
--jse-context-menu-pointer-background: var(--vp-c-bg-alt);
--jse-context-menu-pointer-background-highlight: var(--vp-c-bg-soft);
--jse-context-menu-pointer-color: var(--vp-c-text-1);

/* Contents: JSON key and values */
--jse-key-color: var(--vjs-key-color);
--jse-value-color: var(--vjs-value-string-color);
--jse-value-color-number: var(--vjs-value-number-color);
--jse-value-color-boolean: var(--vjs-value-boolean-color);
--jse-value-color-null: var(--vjs-value-null-color);
--jse-value-color-string: var(--vjs-value-string-color);
--jse-value-color-url: var(--vjs-value-string-color);
--jse-delimiter-color: var(--vjs-caret-color);
--jse-edit-outline: 2px solid var(--vjs-border-color);

/* Selected or hovered */
--jse-selection-background-color: var(--vjs-hover-background-color);
--jse-hover-background-color: var(--vjs-hover-background-color);

/* Controls in modals: inputs, buttons, and `a` */
--jse-input-background: var(--vp-c-bg);
--jse-input-color: var(--vp-c-text-1);
--jse-input-border: 1px solid var(--vp-c-border);
--jse-button-background: var(--vp-c-default-3);
--jse-button-primary-background: var(--vp-c-brand-3);
--jse-button-primary-color: var(--vp-c-white);
--jse-button-secondary-background: var(--vp-c-default-3);
--jse-a-color: var(--vp-c-brand-1);
--jse-a-color-highlight: var(--vp-c-brand-2);
}

.oa-jse .jse-main {
@apply rounded p-2;
background-color: var(--vp-code-block-bg);
}
Expand Down
14 changes: 11 additions & 3 deletions src/lib/OpenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export function OpenApi({ spec }: { spec: any } = { spec: null }) {
if (pathServers && pathServers.length > 0) {
try {
const firstUrl = pathServers[0].url
new URL(firstUrl)

const isValid = new URL(firstUrl)
if (!isValid) {
throw new Error('Invalid URL')
}

return firstUrl
} catch {
console.warn('Invalid server URL in path servers:', pathServers)
Expand All @@ -69,7 +74,10 @@ export function OpenApi({ spec }: { spec: any } = { spec: null }) {
try {
const firstUrl = spec.servers[0].url

new URL(firstUrl)
const isValid = new URL(firstUrl)
if (!isValid) {
throw new Error('Invalid URL')
}

return firstUrl
} catch {
Expand Down Expand Up @@ -136,7 +144,7 @@ export function OpenApi({ spec }: { spec: any } = { spec: null }) {

Object.entries(securitySchemes)
.filter(([key]) => operation.security.some(security => security[key]))
.map(([key, value]) => {
.forEach(([key, value]) => {
output[key] = value
})

Expand Down
2 changes: 1 addition & 1 deletion src/lib/fetchToCurl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const generateHeadersArgument = (headers?: any): HeaderParams => {
}
})
} else if (headers) {
Object.keys(headers).map((name) => {
Object.keys(headers).forEach((name) => {
if (name.toLocaleLowerCase() !== 'content-length') {
headerParam += `${getHeaderString(name, headers[name])} \\\n`
}
Expand Down

0 comments on commit 957918e

Please sign in to comment.