Skip to content

Commit

Permalink
chore: refactor to arrow function vscode lightning (#5282)
Browse files Browse the repository at this point in the history
* chore: vs lightning to arrow

@W-14564471@

* chore: fix tests
  • Loading branch information
peternhale authored Dec 18, 2023
1 parent 4bd60fe commit 9e98633
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 45 deletions.
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",
"@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-unsafe-assignment": "warn",
Expand Down
37 changes: 18 additions & 19 deletions packages/salesforcedx-vscode-lightning/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ import {
import { nls } from './messages';

// See https://github.com/Microsoft/vscode-languageserver-node/issues/105
export function code2ProtocolConverter(value: Uri): string {
export const code2ProtocolConverter = (value: Uri): string => {
if (/^win32/.test(process.platform)) {
// The *first* : is also being encoded which is not the standard for URI on Windows
// Here we transform it back to the standard way
return value.toString().replace('%3A', ':');
} else {
return value.toString();
}
}
};

function protocol2CodeConverter(value: string): Uri {
const protocol2CodeConverter = (value: string): Uri => {
return Uri.parse(value);
}
};

function getActivationMode(): string {
const getActivationMode = (): string => {
const config = workspace.getConfiguration('salesforcedx-vscode-lightning');
return config.get('activationMode') || 'autodetect'; // default to autodetect
}
};

export async function activate(extensionContext: ExtensionContext) {
export const activate = async (extensionContext: ExtensionContext) => {
const extensionHRStart = process.hrtime();
console.log('Activation Mode: ' + getActivationMode());
// Run our auto detection routine before we activate
Expand Down Expand Up @@ -179,23 +179,22 @@ export async function activate(extensionContext: ExtensionContext) {

// Notify telemetry that our extension is now active
TelemetryService.getInstance().sendExtensionActivationEvent(extensionHRStart);
}
};

let indexingResolve: any;

function startIndexing(): void {
const startIndexing = (): void => {
const indexingPromise: Promise<void> = new Promise(resolve => {
indexingResolve = resolve;
});
reportIndexing(indexingPromise);
}
void reportIndexing(indexingPromise);
};

function endIndexing(): void {
const endIndexing = (): void => {
indexingResolve(undefined);
}

function reportIndexing(indexingPromise: Promise<void>) {
window.withProgress(
};
const reportIndexing = async (indexingPromise: Promise<void>) => {
void window.withProgress(
{
location: ProgressLocation.Window,
title: nls.localize('index_components_text'),
Expand All @@ -205,9 +204,9 @@ function reportIndexing(indexingPromise: Promise<void>) {
return indexingPromise;
}
);
}
};

export function deactivate() {
export const deactivate = () => {
console.log('Aura Components Extension Deactivated');
TelemetryService.getInstance().sendExtensionDeactivationEvent();
}
};
4 changes: 2 additions & 2 deletions packages/salesforcedx-vscode-lightning/src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { messages as enMessages } from './i18n';
import { messages as jaMessages } from './i18n.ja';
const supportedLocales = [DEFAULT_LOCALE, LOCALE_JA];

function loadMessageBundle(config?: Config): Message {
const loadMessageBundle = (config?: Config): Message => {
const base = new Message(enMessages);

const localeConfig = config ? config.locale : DEFAULT_LOCALE;
Expand All @@ -30,7 +30,7 @@ function loadMessageBundle(config?: Config): Message {
}

return base;
}
};

export const nls = new Localization(
loadMessageBundle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const checkedPackagePatterns: RegExp[] = [
/^@salesforce\/salesforcedx/i
];

function readJsonFile(jsonFilePath: string) {
const readJsonFile = (jsonFilePath: string): any => {
try {
return JSON.parse(fs.readFileSync(jsonFilePath, 'utf8'));
} catch (e) {
throw new Error(`Error reading json file from ${jsonFilePath}: ${e}`);
}
}
};

const packageJsonPath = path.join(
__dirname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import * as vscode from 'vscode';

const PERFECT_MATCH = 10;

async function matchExtensionAsHtml(extension: string) {
const matchExtensionAsHtml = async (extension: string) => {
const doc = await vscode.workspace.openTextDocument(
vscode.Uri.parse(`untitled:fake/path/doc.${extension}`)
);
expect(vscode.languages.match({ language: 'html' }, doc)).to.equal(
PERFECT_MATCH
);
}
};

describe('Lightning file association', () => {
it('Should support .app association', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Aura Hovers', function() {

let auraDir: string;

beforeEach(async function() {
beforeEach(async () => {
auraDir = path.join(
workspace.workspaceFolders![0].uri.fsPath,
'force-app',
Expand All @@ -33,10 +33,11 @@ describe('Aura Hovers', function() {
await new Promise(r => setTimeout(r, 1000));
});

afterEach(async function() {
afterEach(async () => {
await commands.executeCommand('workbench.action.closeActiveEditor');
});

// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
it('Should provide additional details when hovering over an aura tag', async function() {
const doc = await workspace.openTextDocument(
path.join(auraDir, 'auraPubsubSubscriber', 'auraPubsubSubscriber.cmp')
Expand Down Expand Up @@ -64,6 +65,7 @@ describe('Aura Hovers', function() {
expect(content!.value).to.include('View in Component Library');
});

// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
it('Should provide additional details when hovering over an aura attribute', async function() {
const doc = await workspace.openTextDocument(
path.join(auraDir, 'auraPubsubSubscriber', 'auraPubsubSubscriber.cmp')
Expand Down Expand Up @@ -100,7 +102,7 @@ describe('Aura Hovers', function() {
* @param expectedContent - content that is being searched for
* @returns the first content which includes the expected value || undefined
*/
function findContentFromInstances(instances: Hover[], expectedContent: string) {
const findContentFromInstances = (instances: Hover[], expectedContent: string) => {
for (const instance of instances) {
// type assertion to prevent using a deprecated type
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
Expand All @@ -115,4 +117,4 @@ function findContentFromInstances(instances: Hover[], expectedContent: string) {
return content;
}
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { assert, expect } from 'chai';
import * as path from 'path';
import * as vscode from 'vscode';

describe('Aura Intellisense Test Suite', function () {
describe('Aura Intellisense Test Suite', () => {
let auraDir: string;

beforeEach(async () => {
Expand Down Expand Up @@ -159,11 +159,11 @@ describe('Aura Intellisense Test Suite', function () {
// NOTE: Because the completion providers always returns all possible results and then VSCode
// does the filtering based on what is typed, we have no good way of testing what vscode is
// actually displaying to the user based on what we typed
async function testCompletion(
const testCompletion = async (
docUri: vscode.Uri,
position: vscode.Position,
expectedCompletionList: vscode.CompletionList
) {
) => {
// Simulate triggering a completion
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const actualCompletionList = (await vscode.commands.executeCommand(
Expand All @@ -172,8 +172,8 @@ async function testCompletion(
position
)) as vscode.CompletionList;

expectedCompletionList.items.forEach(function (expectedItem) {
const actualItem = actualCompletionList.items.find(function (obj) {
expectedCompletionList.items.forEach(expectedItem => {
const actualItem = actualCompletionList.items.find(obj => {
if (obj.label) {
return obj.label === expectedItem.label;
}
Expand Down Expand Up @@ -211,4 +211,4 @@ async function testCompletion(
);
}
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import * as path from 'path';
import { Location, Position, commands, window, workspace } from 'vscode';
import URI from 'vscode-uri';

describe('Aura Definition Linking', function() {
describe('Aura Definition Linking', () => {
let auraDir: string;
let lwcDir: string;

beforeEach(async function() {
beforeEach(async () => {
auraDir = path.join(
workspace.workspaceFolders![0].uri.fsPath,
'force-app',
Expand All @@ -34,22 +34,22 @@ describe('Aura Definition Linking', function() {
await new Promise(r => setTimeout(r, 1500));
});

afterEach(async function() {
afterEach(async () => {
await commands.executeCommand('workbench.action.closeActiveEditor');
});

it('Should provide navigation to a selected Aura tag', function() {
it('Should provide navigation to a selected Aura tag', async () => {
// select the 'c:DemoComponent' Aura tag
testDefinitionNavigation(
await testDefinitionNavigation(
path.join(auraDir, 'DemoApp', 'DemoApp.app'),
path.join(auraDir, 'DemoComponent', 'DemoComponent.cmp'),
new Position(1, 12)
);
});

it('Should provide navigation to a selected LWC tag', function() {
it('Should provide navigation to a selected LWC tag', async () => {
// select the 'c:contactList' LWC tag
testDefinitionNavigation(
await testDefinitionNavigation(
path.join(auraDir, 'auraEmbeddedLWC', 'auraEmbeddedLWC.cmp'),
path.join(lwcDir, 'contactList', 'contactList.js'),
new Position(20, 28)
Expand All @@ -63,11 +63,11 @@ describe('Aura Definition Linking', function() {
* @param endLocation - expected definition location given the position
* @param position - position to initiate the definition lookup
*/
async function testDefinitionNavigation(
const testDefinitionNavigation = async (
startLocation: string,
endLocation: string,
position: Position
) {
) => {
const doc = await workspace.openTextDocument(startLocation);
const editor = await window.showTextDocument(doc);

Expand All @@ -88,4 +88,4 @@ async function testDefinitionNavigation(
const expectedURI = URI.file(endLocation);

expect(location.uri.toString()).to.equal(expectedURI.toString());
}
};

0 comments on commit 9e98633

Please sign in to comment.