Skip to content

Commit

Permalink
Merge pull request #60 from zowe/fix-linter
Browse files Browse the repository at this point in the history
fixed linter error
  • Loading branch information
1000TurquoisePogs authored Oct 18, 2023
2 parents b9679f3 + 1755390 commit dc338b1
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 37 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/test-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Lint TypeScript

on:
push:
branches:
- v2.x/staging
pull_request:
types: [opened, reopened, synchronize]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install Dependencies
run: npm ci

- name: Lint TypeScript
run: npm run lint
5 changes: 3 additions & 2 deletions src/actions/HomeActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

import { ConnectionStore } from "../storage/ConnectionStore";
import { IResponse } from '../types/interfaces';
import * as util from 'node:util';
import { execFile as execFileCallback } from 'node:child_process';

export class HomeActions {

public static async checkZoweCLI(): Promise<IResponse> {
const version = await ConnectionStore.get('zowe-cli-version');
if (!version) {
const util = require('node:util');
const execFile = util.promisify(require('node:child_process').execFile);
const execFile = util.promisify(execFileCallback);
// TODO: Verify not just Zowe CLI version, but get list of profiles available with host names
// and check ssh commands are operational to verify it set up correctly.
try {
Expand Down
3 changes: 1 addition & 2 deletions src/actions/InstallationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { stringify } from 'yaml';
import { IIpcConnectionArgs, IResponse } from '../types/interfaces';
import { ConfigurationStore } from "../storage/ConfigurationStore";
import { ProgressStore } from "../storage/ProgressStore";
import * as fs from 'fs';

class Installation {

Expand Down Expand Up @@ -73,7 +74,6 @@ class Installation {

async generateYamlFile() {
const zoweYaml: any = ConfigurationStore.getConfig();
const fs = require('fs');
const filePath = path.join(app.getPath('temp'), 'zowe.yaml')
await fs.writeFile(filePath, stringify(zoweYaml), (err: any) => {
if (err) {
Expand Down Expand Up @@ -135,7 +135,6 @@ export class FTPInstallation extends Installation {
const filePath = path.join(installDir, "zowe.pax");
console.log(`Uploading ${tempPath} to ${filePath}`)
const result = await new FileTransfer().upload(connectionArgs, tempPath, filePath, DataType.BINARY);
const fs = require('fs');
try {
fs.unlink(tempPath, () => {
console.log("Deleted zowe.pax successfully.");
Expand Down
2 changes: 1 addition & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ app.on('window-all-closed', async () => {
});

app.on('activate', () => {

// Intentionally left empty
});
2 changes: 1 addition & 1 deletion src/renderer/components/common/EditorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { selectYaml, selectSchema, setNextStepEnabled } from '../configuration-w
import { setConfiguration, setZoweConfig, getZoweConfig } from '../../../services/ConfigService';
import Ajv2019 from "ajv/dist/2019"
import MonacoEditorComponent from "../common/MonacoEditor";
import draft7MetaSchema from "ajv/dist/refs/json-schema-draft-07.json";

const EditorDialog = ({isEditorVisible, toggleEditorVisibility, onChange} : any) => {

Expand All @@ -31,7 +32,6 @@ const EditorDialog = ({isEditorVisible, toggleEditorVisibility, onChange} : any)

const ajv = new Ajv2019()
ajv.addKeyword("$anchor");
const draft7MetaSchema = require("ajv/dist/refs/json-schema-draft-07.json")
ajv.addMetaSchema(draft7MetaSchema)
const validate = ajv.compile(schema);

Expand Down
14 changes: 12 additions & 2 deletions src/renderer/components/common/MonacoEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

import React, { useEffect, useRef, useState } from 'react';
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
import { load } from 'js-yaml';
Expand Down Expand Up @@ -39,8 +49,8 @@ const MonacoEditorComponent = ({initialContent, onContentChange, isSchemaValid,
setError(false, '');
onContentChange(code, false);
} catch(error) {
let errorDesc = error.message ? error.message : "Invalid Yaml";
let errorMsg = error.reason ? error.reason : errorDesc;
const errorDesc = error.message ? error.message : "Invalid Yaml";
const errorMsg = error.reason ? error.reason : errorDesc;
setError(true, errorMsg);
onContentChange(code, true);
}
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/stages/Planning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const serverSchema = {
"$anchor": "zoweDatasetMember",
"type": "string",
"description": "A 1-8-char all caps dataset member name",
"pattern": "^([A-Z\$\#\@]){1}([A-Z0-9\$\#\@]){0,7}$",
"pattern": "^([A-Z$#@]){1}([A-Z0-9$#@]){0,7}$",
"minLength": 1,
"maxLength": 8
},
Expand Down Expand Up @@ -154,15 +154,15 @@ const Planning = () => {
schema.properties.zowe.properties.setup.properties.certificate.properties.pkcs12.properties.directory = serverSchema.$defs.path;
schema.$id = serverSchema.$id;
dispatch(setSchema(schema));
let installationDir = '', javaHome, nodeHome;
let installationDir = '';
if (res.details.config?.zowe?.runtimeDirectory && res.details.config?.zowe?.workspaceDirectory) {
const getParentDir = (path: string): string => path.split('/').filter((i: string, ind: number) => i || !ind).slice(0, -1).join('/');
const runtimeParent = getParentDir(res.details.config.zowe.runtimeDirectory);
const workspaceParent = getParentDir(res.details.config.zowe.workspaceDirectory);
if (runtimeParent === workspaceParent) installationDir = runtimeParent;
}
javaHome = (res.details.config?.java?.home) ? res.details.config.java.home : '';
nodeHome = (res.details.config?.node?.home) ? res.details.config.node.home : '';
const javaHome = (res.details.config?.java?.home) ? res.details.config.java.home : '';
const nodeHome = (res.details.config?.node?.home) ? res.details.config.node.home : '';
dispatch(setInstallationArgs({...installationArgs, installationDir, javaHome, nodeHome}));
} else {
window.electron.ipcRenderer.getExampleZowe().then((res: IResponse) => {
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/jsonFormsTheme.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

import { createTheme } from '@mui/material/styles';

const jsonFormTheme = createTheme({
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Copyright Contributors to the Zowe Project.
*/

const { contextBridge, ipcRenderer } = require('electron');
import { contextBridge, ipcRenderer } from 'electron';
import { IIpcConnectionArgs } from '../types/interfaces';

contextBridge.exposeInMainWorld('electron', {
Expand Down
11 changes: 10 additions & 1 deletion src/services/ConfigService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { flatten, unflatten } from 'flat';
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

import { flatten, unflatten } from 'flat';
// To set the subsection of the configuration
export const setConfiguration = (section: string, data: any, setZconfig?: boolean) => {
if(!data) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/FileTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {IncomingMessage} from "http";
import {connectFTPServer} from "./utils";
import {IIpcConnectionArgs} from "../types/interfaces";

const fs = require('fs');
const https = require('https');
import * as fs from 'fs';
import * as https from 'https';

export enum DataType {
ASCII = 'ascii',
Expand Down
39 changes: 21 additions & 18 deletions src/services/SubmitJcl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,31 @@
import {connectFTPServer} from "./utils";
import {IIpcConnectionArgs, IJobResults, JobOutput} from "../types/interfaces";

export async function submitJcl(config: IIpcConnectionArgs, jcl: string, returnDDs: string[]): Promise<IJobResults> {
export function submitJcl(config: IIpcConnectionArgs, jcl: string, returnDDs: string[]): Promise<IJobResults> {

return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {
let jobOutput: IJobResults;
let client
try {
client = await connectFTPServer(config);
console.log('About to submit jcl=',jcl);
const jobId = await client.submitJCL(jcl);
console.log(`jobId: ${jobId}`);
jobOutput = await waitForjobToFinish(client, jobId, returnDDs)

client.close();
console.log(`job result=`,jobOutput);
resolve(jobOutput);
let client: any;

} catch (err) {
console.error(err)
client.close()
reject(err)
async function submitAndResolve() {
try {
client = await connectFTPServer(config);
console.log('About to submit jcl=', jcl);
const jobId = await client.submitJCL(jcl);
console.log(`jobId: ${jobId}`);
jobOutput = await waitForjobToFinish(client, jobId, returnDDs);
client.close();
console.log(`job result=`, jobOutput);
resolve(jobOutput);
} catch (err) {
console.error(err);
client.close();
reject(err);
}
}
})

submitAndResolve();
});
}

async function waitForjobToFinish(client: any, jobId: string, returnDDs: string[]): Promise<IJobResults> {
Expand Down
2 changes: 1 addition & 1 deletion src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import {IIpcConnectionArgs} from "../types/interfaces";
import Header from "../renderer/components/Header"
import { AlertColor } from "@mui/material/Alert";
const zos = require('zos-node-accessor');
import zos from 'zos-node-accessor';

export async function connectFTPServer(config: IIpcConnectionArgs): Promise<any> {

Expand Down
2 changes: 1 addition & 1 deletion src/storage/ConfigurationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ConfigurationStore {
const schema = store.get('schema') as any;
let schemaPart: any = schema.properties;
for (const key of keys) {
if (!schemaPart.hasOwnProperty(key)) {
if (!Object.prototype.hasOwnProperty.call(schemaPart, key)) {
return false;
}
schemaPart = schemaPart[key].properties;
Expand Down
2 changes: 1 addition & 1 deletion src/storage/ConnectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const validateWithSchema = (key: string): boolean => {
const keys = key.split('.');
let schemaPart: any = storeSchema;
for (const key of keys) {
if (!schemaPart.hasOwnProperty(key)) {
if (!Object.prototype.hasOwnProperty.call(schemaPart, key)) {
return false;
}
schemaPart = schemaPart[key].properties;
Expand Down
11 changes: 11 additions & 0 deletions src/types/zos-node-accessor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

declare module 'zos-node-accessor';

0 comments on commit dc338b1

Please sign in to comment.