Skip to content

Commit

Permalink
Eslint fixes returning types and variables types (forcedotcom#214)
Browse files Browse the repository at this point in the history
* Set eslint configuration, delete tslint configs, first pass at fixing eslint errors and warnings

* temporarily remove pre push and pre commit tasks

* Lint lsp common, still work to do here

* Fixed some eslint problems

* Delete package-lock.json

* Not used variables, and duplicated imports

* Remove package-lock

* Deleted unused functions, and minor eslint fixes

* Moved code for used after declaration, and some minor eslint fixes

* Not infereable types fixed

* Exporting ternerror

* Deleted import ternError and copied function

* No inferreable fixed, and interfaces that were starting with I prefix, removed

* Moved check if file outside of promise

* Changed logger to use args instead of arguments, for eslint rules

* Deleted functions that code will never run

* Rever changes for yarn.lock

* Missing await async function

* Yarn.lock re-added, so the circle ci can run, as its running with freeze lock files

* Added returning types to some functions

* Eslint retrun types, and types of variables

Co-authored-by: Luis Campos <[email protected]>
  • Loading branch information
2 people authored and sfsholden committed Sep 10, 2020
1 parent 2671838 commit 8128b4b
Show file tree
Hide file tree
Showing 25 changed files with 114 additions and 112 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
], // non-complete list of globals that are easy to access unintentionally
"no-var": "error",
"jsdoc/no-types": "warn",
"@typescript-eslint/semi": "warn"
"@typescript-eslint/semi": "warn",
"@typescript-eslint/no-explicit-any": "off"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import glob from 'glob';

const checkedPackagePatterns: RegExp[] = [/^@salesforce/i, /^@lwc/i];

function readJsonFile(jsonFilePath: string) {
function readJsonFile(jsonFilePath: string): any {
try {
return JSON.parse(fs.readFileSync(jsonFilePath, 'utf8'));
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AuraIndexer from '../indexer';
import * as path from 'path';
import URI from 'vscode-uri';

function normalize(start: string, p: string) {
function normalize(start: string, p: string): string {
// Fix relative paths on windows
if (start.indexOf('\\') !== -1) {
start = start.replace(/\\/g, '/');
Expand Down
22 changes: 11 additions & 11 deletions packages/aura-language-server/src/aura-indexer/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class AuraIndexer implements Indexer {
this.context.addIndexingProvider({ name: 'aura', indexer: this });
}

public async configureAndIndex() {
public async configureAndIndex(): Promise<any> {
const indexingTasks: Promise<void>[] = [];

indexingTasks.push(this.loadStandardComponents());
Expand All @@ -35,11 +35,11 @@ export default class AuraIndexer implements Indexer {
return this.indexingTasks;
}

public async waitForIndexing() {
public async waitForIndexing(): Promise<void> {
return this.indexingTasks;
}

public resetIndex() {
public resetIndex(): void {
this.eventEmitter.emit('clear');
this.AURA_TAGS.clear();
this.AURA_EVENTS.clear();
Expand All @@ -57,7 +57,7 @@ export default class AuraIndexer implements Indexer {
return this.getAuraTags().get(tag);
}

public clearTagsforDirectory(directory: string, sfdxProject: boolean) {
public clearTagsforDirectory(directory: string, sfdxProject: boolean): void {
const name = componentUtil.componentFromDirectory(directory, sfdxProject);
this.deleteCustomTag(name);
}
Expand Down Expand Up @@ -121,7 +121,7 @@ export default class AuraIndexer implements Indexer {
return tagInfo;
}

private async indexCustomComponents() {
private async indexCustomComponents(): Promise<void> {
const startTime = process.hrtime();
const markupfiles = await this.context.findAllAuraMarkup();

Expand All @@ -135,31 +135,31 @@ export default class AuraIndexer implements Indexer {
console.info(`Indexed ${markupfiles.length} files in ${utils.elapsedMillis(startTime)} ms`);
}

private clearTagsforFile(file: string, sfdxProject: boolean) {
private clearTagsforFile(file: string, sfdxProject: boolean): void {
const name = componentUtil.componentFromFile(file, sfdxProject);
this.deleteCustomTag(name);
}

private deleteCustomTag(tag: string) {
private deleteCustomTag(tag: string): void {
this.AURA_TAGS.delete(tag);
this.AURA_EVENTS.delete(tag);

this.eventEmitter.emit('delete', tag);
}
private setAuraNamespaceTag(namespace: string) {
private setAuraNamespaceTag(namespace: string): void {
if (!this.AURA_NAMESPACES.has(namespace)) {
this.AURA_NAMESPACES.add(namespace);
this.eventEmitter.emit('set-namespace', namespace);
}
}

private setCustomEventTag(info: TagInfo) {
private setCustomEventTag(info: TagInfo): void {
this.setAuraNamespaceTag(info.namespace);
this.AURA_EVENTS.set(info.name, info);
this.eventEmitter.emit('set', info);
}

private setCustomTag(info: TagInfo) {
private setCustomTag(info: TagInfo): void {
this.setAuraNamespaceTag(info.namespace);
this.AURA_TAGS.set(info.name, info);
this.eventEmitter.emit('set', info);
Expand Down Expand Up @@ -229,7 +229,7 @@ export default class AuraIndexer implements Indexer {
return results;
}

private trimQuotes(str: string) {
private trimQuotes(str: string): string {
if (!str) {
return '';
}
Expand Down
4 changes: 2 additions & 2 deletions packages/aura-language-server/src/aura-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export function isAuraMarkup(textDocument: TextDocument): boolean {
return AURA_EXTENSIONS.includes(fileExt);
}

export function getAuraStandardResourcePath() {
export function getAuraStandardResourcePath(): string {
return join(__dirname, RESOURCES_DIR, AURA_STANDARD);
}

export function getAuraSystemResourcePath() {
export function getAuraSystemResourcePath(): string {
return join(__dirname, RESOURCES_DIR, AURA_SYSTEM);
}
22 changes: 11 additions & 11 deletions packages/aura-language-server/src/markup/auraTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ function getAuraByTag(tag: string): TagInfo {
return undefined;
}

export function setIndexer(idx: AuraIndexer) {
export function setIndexer(idx: AuraIndexer): void {
indexer = idx;
}

export function getAuraTagProvider(): IHTMLTagProvider {
function addTags(collector: (tag: string, label: string, info: TagInfo) => void) {
function addTags(collector: (tag: string, label: string, info: TagInfo) => void): void {
for (const [tag, tagInfo] of getAuraTags()) {
collector(tag, tagInfo.getHover(), tagInfo);
}
}

function addAttributes(tag: string, collector: (attribute: string, info: AttributeInfo, type?: string) => void) {
function addAttributes(tag: string, collector: (attribute: string, info: AttributeInfo, type?: string) => void): void {
const cTag = getAuraByTag(tag);
if (cTag) {
for (const info of cTag.attributes) {
Expand All @@ -36,7 +36,7 @@ export function getAuraTagProvider(): IHTMLTagProvider {
}
}

function addExpressions(templateTag: string, collector: (attribute: string, info: AttributeInfo, type: string) => void) {
function addExpressions(templateTag: string, collector: (attribute: string, info: AttributeInfo, type: string) => void): void {
const cTag = getAuraByTag(templateTag);
if (cTag) {
cTag.attributes.forEach(attribute => {
Expand All @@ -49,25 +49,25 @@ export function getAuraTagProvider(): IHTMLTagProvider {
}

return {
getId: () => 'aura',
isApplicable: languageId => languageId === 'html',
collectTags: (collector: (tag: string, label: string, info: TagInfo) => void) => {
getId: (): string => 'aura',
isApplicable: (languageId): boolean => languageId === 'html',
collectTags: (collector: (tag: string, label: string, info: TagInfo) => void): void => {
addTags(collector);
},
collectAttributes: (tag: string, collector: (attribute: string, info: AttributeInfo, type?: string) => void) => {
collectAttributes: (tag: string, collector: (attribute: string, info: AttributeInfo, type?: string) => void): void => {
if (tag) {
addAttributes(tag, collector);
}
},
collectValues: (/*tag: string, attribute: string, collector: (value: string) => void*/) => {
collectValues: (/*tag: string, attribute: string, collector: (value: string) => void*/): void => {
// TODO provide suggestions by consulting shapeService
},

// TODO move this to ICompletionParticipant
collectExpressionValues: (templateTag: string, collector: (value: string) => void): void => {
addExpressions(templateTag, collector);
},
getTagInfo: (tag: string) => getAuraByTag(tag),
getGlobalAttributes: () => [],
getTagInfo: (tag: string): TagInfo => getAuraByTag(tag),
getGlobalAttributes: (): [] => [],
};
}
3 changes: 2 additions & 1 deletion packages/aura-language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ documents.listen(connection);
let htmlLS: LanguageService;
let context: WorkspaceContext;

function startIndexing() {
function startIndexing(): void {
setTimeout(async () => {
const indexer = context.getIndexingProvider('aura') as AuraIndexer;
connection.sendNotification('salesforce/indexingStarted');
Expand Down Expand Up @@ -282,6 +282,7 @@ connection.onRequest('salesforce/listNamespaces', () => {
return result;
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
connection.onRequest((method: string, ...params: any[]) => {
// debugger
console.log(method);
Expand Down
10 changes: 5 additions & 5 deletions packages/aura-language-server/src/tern-server/string-util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function isAlphaNumberic(code: number) {
function isAlphaNumberic(code: number): boolean {
if (code > 47 && code < 58) {
// numeric
return true;
Expand All @@ -14,7 +14,7 @@ function isAlphaNumberic(code: number) {
return false;
}

export function findWord(str: string, offset: number) {
export function findWord(str: string, offset: number): { start: number; end: number } {
let start = -1;
let end = -1;

Expand Down Expand Up @@ -56,7 +56,7 @@ export function findWord(str: string, offset: number) {
};
}
}
export function countPreviousCommas(str: string, offset: number) {
export function countPreviousCommas(str: string, offset: number): number {
let commas = 0;
let pos: number = offset;
let c: number;
Expand All @@ -73,7 +73,7 @@ export function countPreviousCommas(str: string, offset: number) {
}
return commas;
}
export function findPreviousLeftParan(str: string, offset: number) {
export function findPreviousLeftParan(str: string, offset: number): number {
let start = -1;
let pos: number = offset;
let c: number;
Expand All @@ -91,7 +91,7 @@ export function findPreviousLeftParan(str: string, offset: number) {
return start;
}

export function findPreviousWord(str: string, offset: number) {
export function findPreviousWord(str: string, offset: number): { start: number; end: number } {
let start = -1;
let end = -1;

Expand Down
Loading

0 comments on commit 8128b4b

Please sign in to comment.