Skip to content

Commit

Permalink
refactor: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Feb 6, 2022
1 parent 142983c commit 3111c46
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,13 @@ export default {

### config.vls

VLS configuration accepts the same values that can be configured in VS code with keys that start with `vetur`.
These are configured with nested objects rather than dotted string notation. Typescript intellisense is available.
VLS configuration accepts the same values that can be configured in VS code with keys that start with `vetur`.
These are configured with nested objects rather than dotted string notation. TypeScript intellisense is available.

See [`initParams.ts`](https://github.com/fi3ework/vite-plugin-checker/blob/8fc5d7f4a908a4c80d1cb978e0acf1d4e5700e6a/packages/vite-plugin-checker/src/checkers/vls/initParams.ts#L33) for a comprehensive list of the defaults that can be overridden. Vetur unfortunately does not provide a single comprehensive document of all its options.

For example, to performing checking only the `<script>` block:

```ts
checker({
vls: {
Expand Down
13 changes: 9 additions & 4 deletions packages/vite-plugin-checker/src/checkers/vls/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ function validateLogLevel(logLevelInput: unknown): logLevelInput is LogLevel {
.command('diagnostics [workspace]')
.description('Print all diagnostics')
.addOption(
new Option('-c, --checker-config <checkerConfig>', 'Option overrides to pass to VTI')
.default('{}')
new Option('-c, --checker-config <checkerConfig>', 'Option overrides to pass to VTI').default(
'{}'
)
)
.addOption(
new Option('-l, --log-level <logLevel>', 'Log level to print')
Expand All @@ -39,14 +40,18 @@ function validateLogLevel(logLevelInput: unknown): logLevelInput is LogLevel {
throw new Error(`Invalid log level: ${logLevelOption}`)
}

let parsedConfig;
let parsedConfig
try {
parsedConfig = JSON.parse(options.checkerConfig) as any
} catch {
throw new Error(`Unable to parse checker-config JSON: ${options.checkerConfig}`)
}

await diagnostics(workspace, logLevelOption, { watch: false, verbose: false, config: parsedConfig })
await diagnostics(workspace, logLevelOption, {
watch: false,
verbose: false,
config: parsedConfig,
})
})

program.parse(process.argv)
Expand Down
15 changes: 7 additions & 8 deletions packages/vite-plugin-checker/src/checkers/vls/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ async function prepareClientConnection(workspaceUri: URI, options: DiagnosticOpt

if (options.config) {
// Merge in used-provided VLS settings if present
mergeDeep(init.initializationOptions.config, options.config);
mergeDeep(init.initializationOptions.config, options.config)
}

await clientConnection.sendRequest(InitializeRequest.type, init)
Expand Down Expand Up @@ -323,22 +323,21 @@ async function getDiagnostics(
return initialErrCount
}


function isObject(item: any): item is {} {
return item && typeof item === 'object' && !Array.isArray(item);
return item && typeof item === 'object' && !Array.isArray(item)
}

function mergeDeep<T>(target: T, source: DeepPartial<T> | undefined) {
if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (!target[key]) Object.assign(target, { [key]: {} });
mergeDeep(target[key], source[key]);
if (!target[key]) Object.assign(target, { [key]: {} })
mergeDeep(target[key], source[key])
} else {
Object.assign(target, { [key]: source[key] });
Object.assign(target, { [key]: source[key] })
}
}
}

return target;
}
return target
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { URI } from 'vscode-uri'

import type { InitializeParams } from 'vscode-languageserver/node'

export type VlsOptions = ReturnType<typeof getDefaultVLSConfig>;
export type VlsOptions = ReturnType<typeof getDefaultVLSConfig>

export function getInitParams(workspaceUri: URI): InitializeParams {
const defaultVLSConfig = getDefaultVLSConfig()
Expand Down
2 changes: 1 addition & 1 deletion packages/vite-plugin-checker/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function spawnChecker(
// Command line args constructed by checkers therefore need to escape double quotes
// to have them not striped out by cmd.exe. Using shell on all platforms lets us avoid
// having to perform platform-specific logic around escaping quotes since all platform
// shells will strip out unescaped double quotes. E.g. shell=false on linux only would
// shells will strip out unescaped double quotes. E.g. shell=false on linux only would
// result in escaped quotes not being unescaped.
shell: true,
})
Expand Down

0 comments on commit 3111c46

Please sign in to comment.