Skip to content

Commit

Permalink
Adds no-use-before-define eslint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Feb 28, 2023
1 parent af24943 commit 8e8bdc0
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 180 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.base.json
Expand Up @@ -131,7 +131,7 @@
"error",
{
"destructuring": "all",
"ignoreReadBeforeAssign": false
"ignoreReadBeforeAssign": true
}
],
"prefer-numeric-literals": "error",
Expand All @@ -140,7 +140,6 @@
"prefer-spread": "error",
"prefer-template": "error",
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
// Turn off until fix for: https://github.com/eslint/eslint/issues/11899
"require-atomic-updates": "off",
"semi": ["error", "always"],
"semi-style": ["error", "last"],
Expand Down Expand Up @@ -301,6 +300,7 @@
"varsIgnorePattern": "^_$"
}
],
"@typescript-eslint/no-use-before-define": ["error", { "functions": false, "classes": false }],
"@typescript-eslint/non-nullable-type-assertion-style": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-includes": "warn",
Expand Down
6 changes: 3 additions & 3 deletions src/avatars.ts
Expand Up @@ -14,6 +14,9 @@ import type { ContactPresenceStatus } from './vsls/vsls';

const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)

let avatarCache: Map<string, Avatar> | undefined;
const avatarQueue = new Map<string, Promise<Uri>>();

const _onDidFetchAvatar = new EventEmitter<{ email: string }>();
_onDidFetchAvatar.event(
debounce(() => {
Expand Down Expand Up @@ -48,9 +51,6 @@ interface Avatar {
retries: number;
}

let avatarCache: Map<string, Avatar> | undefined;
const avatarQueue = new Map<string, Promise<Uri>>();

const missingGravatarHash = '00000000000000000000000000000000';

const presenceCache = new Map<ContactPresenceStatus, string>();
Expand Down
17 changes: 9 additions & 8 deletions src/configuration.ts
Expand Up @@ -16,6 +16,7 @@ interface ConfigurationOverrides {
export class Configuration {
static configure(context: ExtensionContext): void {
context.subscriptions.push(
// eslint-disable-next-line @typescript-eslint/no-use-before-define
workspace.onDidChangeConfiguration(configuration.onConfigurationChanged, configuration),
);
}
Expand Down Expand Up @@ -121,7 +122,7 @@ export class Configuration {
}

isUnset<T extends ConfigPath>(section: T, scope?: ConfigurationScope | null): boolean {
const inspect = configuration.inspect(section, scope)!;
const inspect = this.inspect(section, scope)!;
if (inspect.workspaceFolderValue !== undefined) return false;
if (inspect.workspaceValue !== undefined) return false;
if (inspect.globalValue !== undefined) return false;
Expand All @@ -134,7 +135,7 @@ export class Configuration {
to: T,
options: { fallbackValue?: ConfigPathValue<T>; migrationFn?(value: any): ConfigPathValue<T> },
): Promise<boolean> {
const inspection = configuration.inspect(from as any);
const inspection = this.inspect(from as any);
if (inspection === undefined) return false;

let migrated = false;
Expand Down Expand Up @@ -203,10 +204,10 @@ export class Configuration {
to: T,
options: { migrationFn?(value: any): ConfigPathValue<T> },
): Promise<void> {
const fromInspection = configuration.inspect(from as any);
const fromInspection = this.inspect(from as any);
if (fromInspection === undefined) return;

const toInspection = configuration.inspect(to);
const toInspection = this.inspect(to);
if (fromInspection.globalValue !== undefined) {
if (toInspection === undefined || toInspection.globalValue === undefined) {
await this.update(
Expand Down Expand Up @@ -293,24 +294,24 @@ export class Configuration {
}

updateEffective<T extends ConfigPath>(section: T, value: ConfigPathValue<T> | undefined): Thenable<void> {
const inspect = configuration.inspect(section)!;
const inspect = this.inspect(section)!;
if (inspect.workspaceFolderValue !== undefined) {
if (value === inspect.workspaceFolderValue) return Promise.resolve(undefined);

return configuration.update(section, value, ConfigurationTarget.WorkspaceFolder);
return this.update(section, value, ConfigurationTarget.WorkspaceFolder);
}

if (inspect.workspaceValue !== undefined) {
if (value === inspect.workspaceValue) return Promise.resolve(undefined);

return configuration.update(section, value, ConfigurationTarget.Workspace);
return this.update(section, value, ConfigurationTarget.Workspace);
}

if (inspect.globalValue === value || (inspect.globalValue === undefined && value === inspect.defaultValue)) {
return Promise.resolve(undefined);
}

return configuration.update(
return this.update(
section,
areEqual(value, inspect.defaultValue) ? undefined : value,
ConfigurationTarget.Global,
Expand Down
15 changes: 9 additions & 6 deletions src/extension.ts
Expand Up @@ -108,12 +108,6 @@ export async function activate(context: ExtensionContext): Promise<GitLensApi |

if (!workspace.isTrusted) {
void setContext(ContextKeys.Untrusted, true);
context.subscriptions.push(
workspace.onDidGrantWorkspaceTrust(() => {
void setContext(ContextKeys.Untrusted, undefined);
container.telemetry.setGlobalAttribute('workspace.isTrusted', workspace.isTrusted);
}),
);
}

setKeysForSync(context);
Expand Down Expand Up @@ -161,6 +155,15 @@ export async function activate(context: ExtensionContext): Promise<GitLensApi |
registerBuiltInActionRunners(container);
registerPartnerActionRunners(context);

if (!workspace.isTrusted) {
context.subscriptions.push(
workspace.onDidGrantWorkspaceTrust(() => {
void setContext(ContextKeys.Untrusted, undefined);
container.telemetry.setGlobalAttribute('workspace.isTrusted', workspace.isTrusted);
}),
);
}

void showWelcomeOrWhatsNew(container, gitlensVersion, previousVersion);

void storage.store(prerelease && !insiders ? 'preVersion' : 'version', gitlensVersion);
Expand Down
234 changes: 117 additions & 117 deletions src/plus/github/github.ts
Expand Up @@ -59,6 +59,123 @@ import { GitHubDetailedIssue, GitHubPullRequest } from './models';
const emptyPagedResult: PagedResult<any> = Object.freeze({ values: [] });
const emptyBlameResult: GitHubBlame = Object.freeze({ ranges: [] });

const prNodeProperties = `
assignees(first: 10) {
nodes {
login
avatarUrl
url
}
}
author {
login
avatarUrl
url
}
baseRefName
baseRefOid
baseRepository {
name
owner {
login
}
}
checksUrl
isDraft
isCrossRepository
isReadByViewer
headRefName
headRefOid
headRepository {
name
owner {
login
}
}
permalink
number
title
state
additions
deletions
updatedAt
closedAt
mergeable
mergedAt
mergedBy {
login
}
repository {
isFork
owner {
login
}
}
repository {
isFork
owner {
login
}
}
reviewDecision
reviewRequests(first: 10) {
nodes {
asCodeOwner
id
requestedReviewer {
... on User {
login
avatarUrl
url
}
}
}
}
totalCommentsCount
`;

const issueNodeProperties = `
... on Issue {
assignees(first: 100) {
nodes {
login
url
avatarUrl
}
}
author {
login
avatarUrl
url
}
comments {
totalCount
}
number
title
url
createdAt
closedAt
closed
updatedAt
labels(first: 20) {
nodes {
color
name
}
}
reactions(content: THUMBS_UP) {
totalCount
}
repository {
name
owner {
login
}
}
}
`;

export class GitHubApi implements Disposable {
private readonly _onDidReauthenticate = new EventEmitter<void>();
get onDidReauthenticate(): Event<void> {
Expand Down Expand Up @@ -2475,120 +2592,3 @@ function uniqueWithReasons<T extends { reasons: string[] }>(items: T[], lookup:
return original;
});
}

const prNodeProperties = `
assignees(first: 10) {
nodes {
login
avatarUrl
url
}
}
author {
login
avatarUrl
url
}
baseRefName
baseRefOid
baseRepository {
name
owner {
login
}
}
checksUrl
isDraft
isCrossRepository
isReadByViewer
headRefName
headRefOid
headRepository {
name
owner {
login
}
}
permalink
number
title
state
additions
deletions
updatedAt
closedAt
mergeable
mergedAt
mergedBy {
login
}
repository {
isFork
owner {
login
}
}
repository {
isFork
owner {
login
}
}
reviewDecision
reviewRequests(first: 10) {
nodes {
asCodeOwner
id
requestedReviewer {
... on User {
login
avatarUrl
url
}
}
}
}
totalCommentsCount
`;

const issueNodeProperties = `
... on Issue {
assignees(first: 100) {
nodes {
login
url
avatarUrl
}
}
author {
login
avatarUrl
url
}
comments {
totalCount
}
number
title
url
createdAt
closedAt
closed
updatedAt
labels(first: 20) {
nodes {
color
name
}
}
reactions(content: THUMBS_UP) {
totalCount
}
repository {
name
owner {
login
}
}
}
`;

0 comments on commit 8e8bdc0

Please sign in to comment.