Skip to content

Commit

Permalink
feat: remove unused types
Browse files Browse the repository at this point in the history
  • Loading branch information
kokororin committed Sep 4, 2023
1 parent 09f782c commit 87d999e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 37 deletions.
28 changes: 22 additions & 6 deletions src/PHPFmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,31 @@ import detectIndent from 'detect-indent';
import findUp from 'find-up';
import * as semver from 'semver';
import phpfmt, { type PHPFmt as IPHPFmt } from 'phpfmt';
import type { PHPFmtConfig } from './types';
import { type Widget, PHPFmtStatus } from './Widget';
import { Transformation } from './Transformation';
import { PHPFmtError, PHPFmtSkipError } from './PHPFmtError';
import { exec } from './utils';

export interface PHPFmtConfig {
php_bin: string;
use_old_phpfmt: boolean;
detect_indent: boolean;
psr1: boolean;
psr1_naming: boolean;
psr2: boolean;
wp: boolean;
indent_with_space: number | boolean;
enable_auto_align: boolean;
visibility_order: boolean;
ignore: string[];
passes: string[];
exclude: string[];
smart_linebreak_after_curly: boolean;
yoda: boolean;
cakephp: boolean;
custom_arguments: string;
}

export class PHPFmt {
private config: PHPFmtConfig;
private transformation: Transformation;
Expand Down Expand Up @@ -64,7 +83,7 @@ export class PHPFmt {
const spaces = this.config.indent_with_space;
if (spaces === true) {
this.args.push('--indent_with_space');
} else if (spaces > 0) {
} else if (typeof spaces === 'number' && spaces > 0) {
this.args.push(`--indent_with_space=${spaces}`);
}
}
Expand Down Expand Up @@ -287,9 +306,6 @@ export class PHPFmt {
this.widget.logError('Remove temp file failed', err);
}

if (formatted.length > 0) {
return formatted;
}
return '';
return formatted;
}
}
4 changes: 2 additions & 2 deletions src/PHPFmtProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class PHPFmtProvider {

const text = await this.phpfmt.format(originalText);
this.widget.updateStatusBarItem(PHPFmtStatus.Success);
if (text !== originalText) {
if (text && text !== originalText) {
return [new TextEdit(range, text)];
}
} catch (err) {
Expand Down Expand Up @@ -267,7 +267,7 @@ export class PHPFmtProvider {
text = text.replace(/^<\?php\r?\n/, '');
}
this.widget.updateStatusBarItem(PHPFmtStatus.Success);
if (text !== originalText) {
if (text && text !== originalText) {
return [new TextEdit(range, text)];
}
} catch (err) {
Expand Down
6 changes: 5 additions & 1 deletion src/Transformation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import os from 'os';
import mem from 'mem';
import phpfmt, { type PHPFmt as IPHPFmt } from 'phpfmt';
import type { TransformationItem } from './types';
import { exec } from './utils';

export interface TransformationItem {
key: string;
description: string;
}

export class Transformation {
public constructor(
private readonly phpBin: string,
Expand Down
3 changes: 2 additions & 1 deletion src/Widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ThemeColor
} from 'vscode';
import dayjs from 'dayjs';
import { type LogLevel } from './types';

export enum PHPFmtStatus {
Ready = 'check-all',
Expand All @@ -18,6 +17,8 @@ export enum PHPFmtStatus {
Disabled = 'circle-slash'
}

export type LogLevel = 'INFO' | 'WARN' | 'ERROR' | 'NONE';

export class Widget {
private logLevel: LogLevel = 'INFO';
private readonly outputChannel: OutputChannel;
Expand Down
27 changes: 0 additions & 27 deletions src/types.d.ts

This file was deleted.

0 comments on commit 87d999e

Please sign in to comment.