Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor vf md LS to use arrow functions #5301

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"rules": {
"prefer-arrow/prefer-arrow-functions": ["error", {}],
"@typescript-eslint/no-floating-promises": "warn"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ describe('HTML Completion', () => {
matches.length,
1,
expected.label +
' should only existing once: Actual: ' +
completions.items.map(c => c.label).join(', ')
' should only existing once: Actual: ' +
completions.items.map(c => c.label).join(', ')
);
const match = matches[0];
if (expected.documentation) {
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('HTML Completion', () => {
assert.equal(actual, expected);
};

function run(tests: PromiseLike<void>[], testDone) {
const run = (tests: PromiseLike<void>[], testDone) => {
// tslint:disable-next-line:no-floating-promises
Promise.all(tests).then(
() => {
Expand All @@ -119,7 +119,7 @@ describe('HTML Completion', () => {
testDone(error);
}
);
}
};

it('Complete', testDone => {
run(
Expand Down Expand Up @@ -571,7 +571,7 @@ describe('HTML Completion', () => {
// Visualforce
//////////////

function getCompletionSuggestions(value: string): CompletionList {
const getCompletionSuggestions = (value: string): CompletionList => {
const offset = value.indexOf('|');
value = value.substr(0, offset) + value.substr(offset + 1);

Expand All @@ -587,7 +587,7 @@ describe('HTML Completion', () => {
const vfDoc = ls.parseHTMLDocument(document);
const list = ls.doComplete(document, position, vfDoc);
return list;
}
};

describe('Visualforce Completions', () => {
// This list is from https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_map.htm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { getLanguageService } from '../../src/htmlLanguageService';
import { applyEdits } from './textEditSupport';

describe('JSON Formatter', () => {
function format(unformatted: string, expected: string, insertSpaces = true) {
const format = (
unformatted: string,
expected: string,
insertSpaces = true
) => {
let range: Range = null;
const uri = 'test://test.html';

Expand All @@ -37,7 +41,7 @@ describe('JSON Formatter', () => {
});
const formatted = applyEdits(document, edits);
assert.equal(formatted, expected);
}
};

it('full document', () => {
const content = ['<div class = "foo">', '<br>', ' </div>'].join('\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { TextDocument } from 'vscode-languageserver-types';
import * as htmlLanguageService from '../../src/htmlLanguageService';

describe('HTML Highlighting', () => {
function assertHighlights(
const assertHighlights = (
value: string,
expectedMatches: number[],
elementName: string
): void {
): void => {
const offset = value.indexOf('|');
value = value.substr(0, offset) + value.substr(offset + 1);

Expand Down Expand Up @@ -45,7 +45,7 @@ describe('HTML Highlighting', () => {
elementName
);
}
}
};

it('Single', () => {
assertHighlights('|<html></html>', [], null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { TextDocument } from 'vscode-languageserver-types';
import * as htmlLanguageService from '../../src/htmlLanguageService';

describe('HTML Hover', () => {
function assertHover(
const assertHover = (
value: string,
expectedHoverLabel: string,
expectedHoverOffset
): void {
): void => {
const offset = value.indexOf('|');
value = value.substr(0, offset) + value.substr(offset + 1);

Expand All @@ -35,7 +35,7 @@ describe('HTML Hover', () => {
hover && document.offsetAt(hover.range.start),
expectedHoverOffset
);
}
};

it('Single', () => {
assertHover('|<html></html>', void 0, void 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { TextDocument } from 'vscode-languageserver-types';
import * as htmlLanguageService from '../../src/htmlLanguageService';

describe('HTML Link Detection', () => {
function getDocumentContext(
const getDocumentContext = (
documentUrl: string
): htmlLanguageService.DocumentContext {
): htmlLanguageService.DocumentContext => {
return {
resolveReference: (ref, base) => {
if (base) {
Expand All @@ -22,13 +22,13 @@ describe('HTML Link Detection', () => {
return url.resolve(documentUrl, ref);
}
};
}
};

function testLinkCreation(
const testLinkCreation = (
modelUrl: string,
tokenContent: string,
expected: string
): void {
): void => {
const document = TextDocument.create(
modelUrl,
'html',
Expand All @@ -38,12 +38,12 @@ describe('HTML Link Detection', () => {
const ls = htmlLanguageService.getLanguageService();
const links = ls.findDocumentLinks(document, getDocumentContext(modelUrl));
assert.equal(links[0] && links[0].target, expected);
}
};

function testLinkDetection(
const testLinkDetection = (
value: string,
expectedLinks: { offset: number; target: string }[]
): void {
): void => {
const document = TextDocument.create(
'test://test/test.html',
'html',
Expand All @@ -59,7 +59,7 @@ describe('HTML Link Detection', () => {
links.map(l => ({ offset: l.range.start.character, target: l.target })),
expectedLinks
);
}
};

it('Link creation', () => {
testLinkCreation('http://model/1', 'javascript:void;', null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as assert from 'assert';
import { HTMLDocument, Node, parse } from '../../src/parser/htmlParser';

describe('HTML Parser', () => {
function toJSON(node: Node) {
const toJSON = (node: Node) => {
return {
tag: node.tag,
start: node.start,
Expand All @@ -18,35 +18,35 @@ describe('HTML Parser', () => {
closed: node.closed,
children: node.children.map(toJSON)
};
}
};

function toJSONWithAttributes(node: Node) {
const toJSONWithAttributes = (node: Node) => {
return {
tag: node.tag,
attributes: node.attributes,
children: node.children.map(toJSONWithAttributes)
};
}
};

function assertDocument(input: string, expected: any) {
const assertDocument = (input: string, expected: any) => {
const document = parse(input);
assert.deepEqual(document.roots.map(toJSON), expected);
}
};

function assertNodeBefore(
const assertNodeBefore = (
input: string,
offset: number,
expectedTag: string
) {
) => {
const document = parse(input);
const node = document.findNodeBefore(offset);
assert.equal(node ? node.tag : '', expectedTag, 'offset ' + offset);
}
};

function assertAttributes(input: string, expected: any) {
const assertAttributes = (input: string, expected: any) => {
const document = parse(input);
assert.deepEqual(document.roots.map(toJSONWithAttributes), expected);
}
};

it('Simple', () => {
assertDocument('<html></html>', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('HTML Scanner', () => {
content?: string;
}

function assertTokens(tests: { input: string; tokens: Token[] }[]) {
const assertTokens = (tests: { input: string; tokens: Token[] }[]) => {
let scannerState = ScannerState.WithinContent;
for (const t of tests) {
const scanner = createScanner(t.input, 0, scannerState);
Expand All @@ -47,7 +47,7 @@ describe('HTML Scanner', () => {
assert.deepEqual(actual, t.tokens);
scannerState = scanner.getScannerState();
}
}
};

it('Open Start Tag #1', () => {
assertTokens([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import * as assert from 'assert';
import { TextDocument, TextEdit } from 'vscode-languageserver-types';

export function applyEdits(document: TextDocument, edits: TextEdit[]): string {
export const applyEdits = (document: TextDocument, edits: TextEdit[]): string => {
let text = document.getText();
const sortedEdits = edits.sort(
(a, b) =>
Expand All @@ -27,4 +27,4 @@ export function applyEdits(document: TextDocument, edits: TextEdit[]): string {
lastOffset = startOffset;
});
return text;
}
};
Loading