Address review comments

This commit is contained in:
Mats Larsen
2022-06-01 14:17:36 +02:00
parent 7a395f47d5
commit 2bd978fad9
7 changed files with 19 additions and 20 deletions
+3 -2
View File
@@ -8,7 +8,8 @@
- Add a `lib/formatters/<formatter>.ts` file using the template below, replacing `Type` and `type` as appropriate
```js
import {BaseFormatter, ExecResult} from './base';
import {UnprocessedExecResult} from '../../types/execution/execution.interfaces';
import {BaseFormatter} from './base';
import {FormatOptions} from './base.interfaces';
export class TypeFormatter extends BaseFormatter {
@@ -20,7 +21,7 @@
- The value returned by `key` above corresponds to the `type` property you set in the compiler-explorer properties
configuration file.
- Tweak `format(source: string, options: FormatOptions): Promise<ExecResult>` and
- Tweak `format(source: string, options: FormatOptions): Promise<UnprocessedExecResult>` and
`isValidStyle(style: string): boolean` as necessary. See the JSDoc for `format` and the implementations for other
formatters to get a further understanding of how to implement `format(source, options)`.
+2 -2
View File
@@ -32,8 +32,8 @@ export interface FormatterInfo {
versionReExp?: string;
}
export interface FormatOptions {
export type FormatOptions = {
useSpaces: boolean;
tabWidth: number;
baseStyle: string;
}
};
+2 -8
View File
@@ -22,17 +22,11 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import {UnprocessedExecResult} from '../../types/execution/execution.interfaces';
import * as exec from '../exec';
import {FormatOptions, FormatterInfo} from './base.interfaces';
// TODO(supergrecko): initial type for ../exec.js exec method
export type ExecResult = {
code: number;
stdout: string;
stderr: string;
};
export abstract class BaseFormatter {
public formatterInfo: FormatterInfo;
@@ -46,7 +40,7 @@ export abstract class BaseFormatter {
* This method should construct the command line arguments and call the formatter executable with the constructed
* arguments, returning the execution result
*/
async format(source: string, options: FormatOptions): Promise<ExecResult> {
async format(source: string, options: FormatOptions): Promise<UnprocessedExecResult> {
const args = [`--style=${options.baseStyle}`];
return await exec.execute(this.formatterInfo.exe, args, {input: source});
}
+3 -2
View File
@@ -22,9 +22,10 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import {UnprocessedExecResult} from '../../types/execution/execution.interfaces';
import * as exec from '../exec';
import {BaseFormatter, ExecResult} from './base';
import {BaseFormatter} from './base';
import {FormatOptions} from './base.interfaces';
export class ClangFormatFormatter extends BaseFormatter {
@@ -32,7 +33,7 @@ export class ClangFormatFormatter extends BaseFormatter {
return 'clangformat';
}
override async format(source: string, options: FormatOptions): Promise<ExecResult> {
override async format(source: string, options: FormatOptions): Promise<UnprocessedExecResult> {
const tabText = options.useSpaces ? 'Never' : 'AlignWithSpaces';
const arg = `{BasedOnStyle: ${options.baseStyle}, IndentWidth: ${options.tabWidth}, UseTab: ${tabText}}`;
return await exec.execute(this.formatterInfo.exe, [`--style=${arg}`], {input: source});
+3 -2
View File
@@ -22,9 +22,10 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import {UnprocessedExecResult} from '../../types/execution/execution.interfaces';
import * as exec from '../exec';
import {BaseFormatter, ExecResult} from './base';
import {BaseFormatter} from './base';
import {FormatOptions} from './base.interfaces';
export class DartFormatFormatter extends BaseFormatter {
@@ -32,7 +33,7 @@ export class DartFormatFormatter extends BaseFormatter {
return 'dartformat';
}
override async format(source: string, options: FormatOptions): Promise<ExecResult> {
override async format(source: string, options: FormatOptions): Promise<UnprocessedExecResult> {
return await exec.execute(this.formatterInfo.exe, ['format'], {input: source});
}
+3 -2
View File
@@ -22,9 +22,10 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import {UnprocessedExecResult} from '../../types/execution/execution.interfaces';
import * as exec from '../exec';
import {BaseFormatter, ExecResult} from './base';
import {BaseFormatter} from './base';
import {FormatOptions} from './base.interfaces';
export class GoFmtFormatter extends BaseFormatter {
@@ -38,7 +39,7 @@ export class GoFmtFormatter extends BaseFormatter {
* This function does not use any options, because gofmt does not have any
* options.
*/
override async format(source: string, options: FormatOptions): Promise<ExecResult> {
override async format(source: string, options: FormatOptions): Promise<UnprocessedExecResult> {
return await exec.execute(this.formatterInfo.exe, [], {input: source});
}
+3 -2
View File
@@ -22,9 +22,10 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
import {UnprocessedExecResult} from '../../types/execution/execution.interfaces';
import * as exec from '../exec';
import {BaseFormatter, ExecResult} from './base';
import {BaseFormatter} from './base';
import {FormatOptions} from './base.interfaces';
export class RustFmtFormatter extends BaseFormatter {
@@ -32,7 +33,7 @@ export class RustFmtFormatter extends BaseFormatter {
return 'rustfmt';
}
override async format(source: string, options: FormatOptions): Promise<ExecResult> {
override async format(source: string, options: FormatOptions): Promise<UnprocessedExecResult> {
const args = [
'--emit',
'stdout',