Skip to content

Commit

Permalink
fixed linter problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakae committed Apr 17, 2024
1 parent 0a53f1f commit a94224d
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
3 changes: 2 additions & 1 deletion extension/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dist",
"**/*.d.ts",
"webpack.config.js",
"pack"
"pack",
"**/generated/"
]
}
14 changes: 7 additions & 7 deletions extension/src-diagram-snippets/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { VNodeData, JsxVNodeChildren, JsxVNodeChild, jsx, FunctionComponent } from "snabbdom";
import { VNodeData, JsxVNodeChildren, JsxVNodeChild, jsx, FunctionComponent, VNode } from "snabbdom";


declare global {
Expand All @@ -30,7 +30,7 @@ declare global {
const modulesNS = ['hook', 'on', 'style', 'class', 'props', 'attrs', 'dataset'];
const SVGNS = 'http://www.w3.org/2000/svg';

function normalizeAttrs(source: VNodeData | null, defNS: string, namespace?: string) {
function normalizeAttrs(source: VNodeData | null, defNS: string, namespace?: string): VNodeData {
const data: VNodeData = {};

if (namespace) {
Expand All @@ -46,24 +46,24 @@ function normalizeAttrs(source: VNodeData | null, defNS: string, namespace?: str
}
});
Object.keys(source).forEach(key => {
if (key === 'key' || key === 'classNames' || key === 'selector') return;
if (key === 'key' || key === 'classNames' || key === 'selector') {return;}
const idx = key.indexOf('-');
if (idx > 0)
addAttr(key.slice(0, idx), key.slice(idx + 1), source[key]);
{addAttr(key.slice(0, idx), key.slice(idx + 1), source[key]);}
else if (!data[key])
addAttr(defNS, key, source[key]);
{addAttr(defNS, key, source[key]);}
});
return data;

function addAttr(modname: string, key: string, val: JsxVNodeChildren) {
function addAttr(modname: string, key: string, val: JsxVNodeChildren): void {
const mod = data[modname] || (data[modname] = {});
mod[key] = val;
}
}

// eslint-disable-next-line @typescript-eslint/naming-convention
function JSX(namespace?: string, defNS: string = 'props') {
return (tag: FunctionComponent | string, attrs: VNodeData | null, ...children: JsxVNodeChild[]) => jsx(tag, normalizeAttrs(attrs, defNS, namespace), children);
return (tag: FunctionComponent | string, attrs: VNodeData | null, ...children: JsxVNodeChild[]) : VNode => jsx(tag, normalizeAttrs(attrs, defNS, namespace), children);
}

const html = JSX();
Expand Down
8 changes: 4 additions & 4 deletions extension/src-diagram-snippets/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Starter {
vscode.postMessage({ readyMessage: 'Template Webview ready' });
console.log('Waiting for diagram identifier...');
// add listener for messages
const eventListener = (message: any) => {
const eventListener = (message: any): void => {
this.handleMessages(message);
};
window.addEventListener('message', eventListener);
Expand Down Expand Up @@ -64,7 +64,7 @@ export class Starter {
/**
* Sends the text in the input field as a AddTemplateAction to the extension.
*/
protected addTemplate() {
protected addTemplate(): void {
const text = document.getElementById(txtID);
if (text) {
const value = (text as HTMLInputElement).value;
Expand All @@ -80,7 +80,7 @@ export class Starter {
* Handles incoming messages from the extension.
* @param message The received Message.
*/
protected handleMessages(message: any) {
protected handleMessages(message: any): void {
if (message.data.identifier) {
this.initHtml(message.data.identifier);
} else if (message.data.templates) {
Expand All @@ -94,7 +94,7 @@ export class Starter {
* Adds the {@code templates} to the webview.
* @param templates The Templates that should be shown.
*/
protected handleTemplates(templates: VNode[]) {
protected handleTemplates(templates: VNode[]): void {
createTemps(templates);
}
}
Expand Down
6 changes: 3 additions & 3 deletions extension/src-diagram-snippets/mouseListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import { ExecuteTemplateAction } from "./actions";

export function click(event: MouseEvent) {
let node = event.target;
let owner = (node as SVGElement).ownerSVGElement;
export function click(event: MouseEvent): ExecuteTemplateAction | undefined {
const node = event.target;
const owner = (node as SVGElement).ownerSVGElement;
if (owner) {
const action = { kind: ExecuteTemplateAction.KIND, id: owner.id } as ExecuteTemplateAction;
return action;
Expand Down
7 changes: 3 additions & 4 deletions extension/src-language-server/diagram-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

import {
Action,
DiagramServer,
DiagramServices,
JsonMap,
RequestAction,
RequestModelAction,
ResponseAction,
ResponseAction
} from "sprotty-protocol";
import { Connection } from "vscode-languageserver";
import { SetSynthesisOptionsAction, UpdateOptionsAction } from "./options/actions";
import { DropDownOption } from "./options/option-models";
import { StpaTemplates } from './stpa-templates';
import { GenerateSVGsAction, RequestSvgAction, SvgAction } from "./stpa/actions";
import { StpaSynthesisOptions, filteringUCAsID } from "./stpa/diagram/stpa-synthesis-options";
import {
Expand Down Expand Up @@ -54,9 +54,8 @@ import {
setSystemConstraintGraphOptions,
} from "./stpa/result-report/svg-generator";
import { SynthesisOptions } from "./synthesis-options";
import { StpaTemplates } from './stpa-templates';
import { LanguageTemplate } from './templates/template-model';
import { TemplateDiagramServer } from './templates/template-diagram-server';
import { LanguageTemplate } from './templates/template-model';

export class PastaDiagramServer extends TemplateDiagramServer {
protected synthesisOptions: SynthesisOptions | undefined;
Expand Down
14 changes: 7 additions & 7 deletions extension/src-language-server/stpa-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class StpaTemplates {
* Creates the default templates.
* @returns A list with the default templates.
*/
protected generateDefaultTemplates() {
protected generateDefaultTemplates(): LanguageTemplate[] {
return [
new SimpleCSTemplate(this.langiumDocuments, "T0"),
new SimpleCSWithAcsTemplate(this.langiumDocuments, "T1"),
Expand All @@ -48,13 +48,13 @@ export class StpaTemplates {
];
}

createTemp(text: string) {
createTemp(text: string): LanguageTemplate {
// TODO: currently only control structure
this.customTempsNumber++;
return new CustomCSTemplate(this.langiumDocuments, text, 'CS' + this.customTempsNumber, text);
}

getTemplates() {
getTemplates(): LanguageTemplate[] {
return this.templates;
}

Expand Down Expand Up @@ -98,10 +98,10 @@ function getPositionForCSTemplate(document: TextDocument, template: LanguageTemp
* @param id The id to append.
* @returns The modified text.
*/
function addNodeIDs(text: string, id: string) {
function addNodeIDs(text: string, id: string): string {
const splits = text.split(/[^a-zA-Z0-9\{\}]/);
// collect node names
const names = [];
const names: string[] = [];
for (let i = 3; i < splits.length; i++) {
if (splits[i] === '{' && !isKeyWord(splits[i - 1])) {
names.push(splits[i - 1]);
Expand All @@ -116,7 +116,7 @@ function addNodeIDs(text: string, id: string) {
return text;
}

function isKeyWord(text: string) {
function isKeyWord(text: string): boolean {
return text === 'hierarchyLevel' || text === 'label' || text === 'processModel' || text === 'controlActions' || text === 'feedback';
}

Expand All @@ -138,7 +138,7 @@ export class CustomCSTemplate implements LanguageTemplate {
/**
* Check whether the CS caption and graph name exists. If not, adds it.
*/
protected checkCaption() {
protected checkCaption(): void {
const splits = this.baseCode.split(/[^a-zA-Z0-9\{\}]/);
const words = splits.filter(child => child !== "");
if (words[0] !== 'ControlStructure') {
Expand Down
14 changes: 7 additions & 7 deletions extension/src-language-server/stpa/diagram/diagram-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
* SPDX-License-Identifier: EPL-2.0
*/

import { GeneratorContext, IdCache, IdCacheImpl, LangiumDiagramGenerator } from "langium-sprotty";
import { AstNode, LangiumDocumentFactory, LangiumParser, ParseResult } from 'langium';
import { GeneratorContext, IdCache, IdCacheImpl } from "langium-sprotty";
import { SModelElement, SModelRoot, SNode } from "sprotty-protocol";
import { CancellationToken } from 'vscode-languageserver';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { Model } from "../../generated/ast";
import { StpaDocumentBuilder } from '../../stpa-document-builder';
import { LanguageTemplate, TemplateGraphGenerator } from '../../templates/template-model';
import { StpaServices } from "../stpa-module";
import { createControlStructure } from "./diagram-controlStructure";
import { createRelationshipGraph } from "./diagram-relationshipGraph";
import { filterModel } from "./filtering";
import { StpaSynthesisOptions } from "./stpa-synthesis-options";
import { LangiumParser, ParseResult, AstNode, LangiumDocumentFactory } from 'langium';
import { CancellationToken } from 'vscode-languageserver';
import { TextDocument } from 'vscode-languageserver-textdocument';
import { StpaDocumentBuilder } from '../../stpa-document-builder';
import { LanguageTemplate } from '../../templates/template-model';

export class StpaDiagramGenerator extends LangiumDiagramGenerator {
export class StpaDiagramGenerator extends TemplateGraphGenerator {
protected readonly options: StpaSynthesisOptions;
protected readonly parser: LangiumParser;
protected readonly docBuilder: StpaDocumentBuilder;
Expand Down
2 changes: 1 addition & 1 deletion extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ function registerTextEditorSync(manager: StpaLspVscodeExtension, context: vscode
}
function registerTemplateWebview(manager: StpaLspVscodeExtension, context: vscode.ExtensionContext): void {
const provider: vscode.WebviewViewProvider = {
resolveWebviewView: function (webviewView: vscode.WebviewView, context: vscode.WebviewViewResolveContext<unknown>, token: vscode.CancellationToken): void | Thenable<void> {
resolveWebviewView: function (webviewView: vscode.WebviewView, _context: vscode.WebviewViewResolveContext<unknown>, _token: vscode.CancellationToken): void | Thenable<void> {
const tWebview = new TemplateWebview(
"templates",
manager,
Expand Down
2 changes: 1 addition & 1 deletion extension/src/language-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class StpaLspVscodeExtension extends LspWebviewPanelManager {
return;
}

let activeEditor = vscode.window.activeTextEditor;
const activeEditor = vscode.window.activeTextEditor;
if (activeEditor) {
// TODO: endPos is not completly correct. maybe \n must be counted too?
const endPos = textDocument.positionAt(textDocument.offsetAt(pos) + msg.text.length);
Expand Down

0 comments on commit a94224d

Please sign in to comment.