Skip to content

Commit

Permalink
Add eslint rule: Require let or const instead of var
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomura committed Feb 14, 2025
1 parent 78234a2 commit 4cb18de
Show file tree
Hide file tree
Showing 27 changed files with 43 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ module.exports = {
},
],
'brace-style': 'off',
'no-throw-literal': 'error',
'no-var': 'error',
curly: 'error',
eqeqeq: ['error', 'always'],
semi: 'off',
'@stylistic/js/semi': ['error', 'always'],
'no-throw-literal': 'error',
},
settings: {
react: {
Expand Down
2 changes: 1 addition & 1 deletion src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ async function tenantTrackEvent(
}

function event(action: string, actionSubject: string, attributes: any): any {
var event = {
let event = {
origin: 'desktop',
platform: AnalyticsPlatform.for(process.platform),
action: action,
Expand Down
2 changes: 1 addition & 1 deletion src/jira/jira-client/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Container } from '../../container';
import { Resources } from '../../resources';
import { ConnectionTimeout } from '../../util/time';

var tunnel = require('tunnel');
let tunnel = require('tunnel');

export function getAxiosInstance(): AxiosInstance {
const instance = axios.create({
Expand Down
2 changes: 1 addition & 1 deletion src/jira/newIssueMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class NewIssueMonitor {
}

const issueNames = newIssues.map((issue) => `[${issue.key}] "${issue.summary}"`);
var message = '';
let message = '';
if (newIssues.length === 1) {
message = `${issueNames[0]} added to explorer`;
} else if (newIssues.length <= 3) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
rules: {
'no-var': 'error',
'no-restricted-imports': [
'error',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class ConfigWebviewController implements WebviewController<SectionChangeM
break;
}
case ConfigActionType.Login: {
var isCloud = true;
let isCloud = true;
if (isBasicAuthInfo(msg.authInfo) || isPATAuthInfo(msg.authInfo)) {
isCloud = false;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class OnboardingWebviewController implements WebviewController<SectionCha
break;
}
case OnboardingActionType.Login: {
var isCloud = true;
let isCloud = true;
if (isBasicAuthInfo(msg.authInfo)) {
isCloud = false;
try {
Expand Down
4 changes: 2 additions & 2 deletions src/pipelines/pipelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ export class PipelineApiImpl {
}

cleanPipelineData(site: BitbucketSite, pipeline: any): Pipeline {
var name = undefined;
var avatar = undefined;
let name = undefined;
let avatar = undefined;
if (pipeline.creator) {
name = pipeline.creator.display_name;
if (pipeline.creator.links && pipeline.creator.links.avatar) {
Expand Down
2 changes: 1 addition & 1 deletion src/pipelines/yaml/pipelinesYamlHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function addPipelinesSchemaToConfigAtScope(
newValue = Object.assign({}, valueAtScope);
}
Object.keys(newValue).forEach((configKey) => {
var configValue = newValue[configKey];
let configValue = newValue[configKey];
if (value === configValue) {
delete newValue[configKey];
}
Expand Down
1 change: 1 addition & 0 deletions src/react/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
rules: {
'no-var': 'error',
'no-restricted-imports': [
'error',
{
Expand Down
2 changes: 1 addition & 1 deletion src/react/atlascode/bbissue/bitbucketIssueController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export function useBitbucketIssueController(): [BitbucketIssueState, BitbucketIs
return new Promise<User[]>((resolve, reject) => {
(async () => {
try {
var abortKey: string = '';
let abortKey: string = '';

if (abortSignal) {
abortKey = v4();
Expand Down
4 changes: 2 additions & 2 deletions src/react/atlascode/common/editor/MarkdownEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const buildInputRules = (schema: any) => {
return rules;
};

var schema = new Schema({
let schema = new Schema({
nodes: addMentionNodes(markdownSchema.spec.nodes),
marks: markdownSchema.spec.marks,
});
Expand All @@ -105,7 +105,7 @@ const mdParser = new MarkdownParser(schema, defaultMarkdownParser.tokenizer, {
* IMPORTANT: outer div's "suggestion-item-list" class is mandatory. The plugin uses this class for querying.
* IMPORTANT: inner div's "suggestion-item" class is mandatory too for the same reasons
*/
var getMentionSuggestionsHTML = (items: any[]) =>
let getMentionSuggestionsHTML = (items: any[]) =>
'<div class="suggestion-item-list">' +
items.map((i) => '<div class="suggestion-item">' + i.name + '</div>').join('') +
'</div>';
Expand Down
6 changes: 3 additions & 3 deletions src/react/atlascode/config/configController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export function useConfigController(): [ConfigState, ConfigControllerApi] {
return new Promise<Suggestion[]>((resolve, reject) => {
(async () => {
try {
var abortKey: string = '';
let abortKey: string = '';

if (abortSignal) {
abortKey = v4();
Expand Down Expand Up @@ -402,7 +402,7 @@ export function useConfigController(): [ConfigState, ConfigControllerApi] {
return new Promise<FilterSearchResults>((resolve, reject) => {
(async () => {
try {
var abortKey: string = '';
let abortKey: string = '';

if (abortSignal) {
abortKey = v4();
Expand Down Expand Up @@ -442,7 +442,7 @@ export function useConfigController(): [ConfigState, ConfigControllerApi] {
return new Promise<JQLErrors>((resolve, reject) => {
(async () => {
try {
var abortKey: string = '';
let abortKey: string = '';

if (abortSignal) {
abortKey = v4();
Expand Down
6 changes: 3 additions & 3 deletions src/react/atlascode/config/jira/jql/JQLEditDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ export const JQLEditDialog: React.FunctionComponent<JQLEditDialogProps> = ({

const handleSave = useCallback(
(data: FormFields) => {
var entry: JQLEntry = jqlEntry
let entry: JQLEntry = jqlEntry
? jqlEntry
: { id: v4(), siteId: '', name: '', query: '', enabled: true, monitor: true };

var newEntry = Object.assign({}, entry, {
let newEntry = Object.assign({}, entry, {
siteId: data.site,
name: data.name,
// [VSCODE-1282] Having to revert to jqlEntry as there's a bug with how default values are handled currently
Expand All @@ -113,7 +113,7 @@ export const JQLEditDialog: React.FunctionComponent<JQLEditDialogProps> = ({

useEffect(() => {
if (jqlEntry) {
var foundSite = sites.find((s) => s.id === jqlEntry.siteId);
let foundSite = sites.find((s) => s.id === jqlEntry.siteId);
if (foundSite) {
setSite(foundSite);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function useCreatePullRequestController(): [CreatePullRequestState, Creat
return new Promise<User[]>((resolve, reject) => {
(async () => {
try {
var abortKey: string = '';
let abortKey: string = '';

if (abortSignal) {
abortKey = v4();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export function usePullRequestDetailsController(): [PullRequestDetailsState, Pul
return new Promise<User[]>((resolve, reject) => {
(async () => {
try {
var abortKey: string = '';
let abortKey: string = '';

if (abortSignal) {
abortKey = v4();
Expand Down
4 changes: 2 additions & 2 deletions src/react/index-dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createVSCodeTheme } from './vscode/theme/vscodeTheme';

// @ts-ignore
// __webpack_public_path__ is used to set the public path for the js files - https://webpack.js.org/guides/public-path/
declare var __webpack_public_path__: string;
declare let __webpack_public_path__: string;
__webpack_public_path__ = `${document.baseURI!}build/`;

const routes = {
Expand Down Expand Up @@ -71,7 +71,7 @@ class VsCodeApi {
// most important part - incoming messages
this.conn.onmessage = function (message): void {
try {
var json = JSON.parse(message.data);
let json = JSON.parse(message.data);
window.postMessage(json.data, '*');
} catch (e) {
console.error('Invalid JSON: ', message.data);
Expand Down
2 changes: 1 addition & 1 deletion src/react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { createVSCodeTheme } from './vscode/theme/vscodeTheme';

// @ts-ignore
// __webpack_public_path__ is used to set the public path for the js files - https://webpack.js.org/guides/public-path/
declare var __webpack_public_path__: string;
declare let __webpack_public_path__: string;
__webpack_public_path__ = `${document.baseURI!}build/`;

const routes = {
Expand Down
2 changes: 1 addition & 1 deletion src/views/pipelines/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function descriptionForState(
pipeline_state_completed_stopped: 'has been stopped',
};

var words = 'has done something';
let words = 'has done something';
switch (result.state!.type) {
case 'pipeline_state_completed':
words = descriptionForResult[result.state!.result!.type];
Expand Down
8 changes: 4 additions & 4 deletions src/views/pipelines/PipelinesMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class PipelinesMonitor implements BitbucketActivityMonitor {
if (!Container.config.bitbucket.pipelines.monitorEnabled) {
return;
}
for (var i = 0; i < this._repositories.length; i++) {
for (let i = 0; i < this._repositories.length; i++) {
const wsRepo = this._repositories[i];
const previousResults = this._previousResults[wsRepo.rootUri];

Expand All @@ -30,7 +30,7 @@ export class PipelinesMonitor implements BitbucketActivityMonitor {
}

bbApi.pipelines.getRecentActivity(site).then((newResults) => {
var diffs = this.diffResults(previousResults, newResults);
let diffs = this.diffResults(previousResults, newResults);
diffs = diffs.filter((p) => this.shouldDisplayTarget(p.target));
const buttonText = diffs.length === 1 ? 'View' : 'View Pipeline Explorer';
if (diffs.length > 0) {
Expand Down Expand Up @@ -61,8 +61,8 @@ export class PipelinesMonitor implements BitbucketActivityMonitor {
const changes: Pipeline[] = [];
const previousLength = oldResults.length;
const newLength = newResults.length;
var i = 0;
var j = 0;
let i = 0;
let j = 0;
while (true) {
if (i === previousLength || j === newLength) {
return changes;
Expand Down
2 changes: 1 addition & 1 deletion src/webview/bbIssue/vscBitbucketIssueActionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class VSCBitbucketIssueActionApi implements BitbucketIssueActionApi {
async fetchUsers(issue: BitbucketIssue, query: string, abortKey?: string): Promise<User[]> {
const bbApi = await clientForSite(issue.site);

var cancelToken: CancelToken | undefined = undefined;
let cancelToken: CancelToken | undefined = undefined;

if (abortKey) {
const signal: CancelTokenSource = axios.CancelToken.source();
Expand Down
6 changes: 3 additions & 3 deletions src/webview/config/vscConfigActionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class VSCConfigActionApi implements ConfigActionApi {
): Promise<AutocompleteSuggestion[]> {
const client = await Container.clientManager.jiraClient(site);

var cancelToken: CancelToken | undefined = undefined;
let cancelToken: CancelToken | undefined = undefined;

if (abortKey) {
const signal: CancelTokenSource = axios.CancelToken.source();
Expand All @@ -86,7 +86,7 @@ export class VSCConfigActionApi implements ConfigActionApi {
): Promise<FilterSearchResults> {
const client = await Container.clientManager.jiraClient(site);

var cancelToken: CancelToken | undefined = undefined;
let cancelToken: CancelToken | undefined = undefined;

if (abortKey) {
const signal: CancelTokenSource = axios.CancelToken.source();
Expand All @@ -100,7 +100,7 @@ export class VSCConfigActionApi implements ConfigActionApi {
public async validateJql(site: DetailedSiteInfo, jql: string, abortKey?: string): Promise<JQLErrors> {
const client = await Container.clientManager.jiraClient(site);

var cancelToken: CancelToken | undefined = undefined;
let cancelToken: CancelToken | undefined = undefined;

if (abortKey) {
const signal: CancelTokenSource = axios.CancelToken.source();
Expand Down
2 changes: 1 addition & 1 deletion src/webview/pullrequest/vscCreatePullRequestActionImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class VSCCreatePullRequestActionApi implements CreatePullRequestActionApi
async fetchUsers(site: BitbucketSite, query: string, abortKey?: string | undefined): Promise<User[]> {
const client = await Container.clientManager.bbClient(site.details);

var cancelToken: CancelToken | undefined = undefined;
let cancelToken: CancelToken | undefined = undefined;

if (abortKey) {
const signal: CancelTokenSource = axios.CancelToken.source();
Expand Down
2 changes: 1 addition & 1 deletion src/webview/pullrequest/vscPullRequestDetailsActionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class VSCPullRequestDetailsActionApi implements PullRequestDetailsActionA
async fetchUsers(site: BitbucketSite, query: string, abortKey?: string | undefined): Promise<User[]> {
const client = await Container.clientManager.bbClient(site.details);

var cancelToken: CancelToken | undefined = undefined;
let cancelToken: CancelToken | undefined = undefined;

if (abortKey) {
const signal: CancelTokenSource = axios.CancelToken.source();
Expand Down
4 changes: 2 additions & 2 deletions src/webviews/components/index-dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import './App.css';

// @ts-ignore
// __webpack_public_path__ is used to set the public path for the js files - https://webpack.js.org/guides/public-path/
declare var __webpack_public_path__: string;
declare let __webpack_public_path__: string;
__webpack_public_path__ = `${document.baseURI!}build/`;

const routes = {
Expand All @@ -33,7 +33,7 @@ class VsCodeApi {
// most important part - incoming messages
this.conn.onmessage = function (message) {
try {
var json = JSON.parse(message.data);
let json = JSON.parse(message.data);
window.postMessage(json.data, '*');
} catch (e) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/webviews/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './App.css';

// @ts-ignore
// __webpack_public_path__ is used to set the public path for the js files - https://webpack.js.org/guides/public-path/
declare var __webpack_public_path__: string;
declare let __webpack_public_path__: string;
__webpack_public_path__ = `${document.baseURI!}build/`;

const routes = {
Expand Down
6 changes: 3 additions & 3 deletions src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export class UIWebsocket implements Disposable {

this._ws.on('request', function (request) {
console.log(new Date() + ` Connection from origin ${request.origin}.`);
var connection = request.accept(undefined, request.origin);
let connection = request.accept(undefined, request.origin);
// we need to know client index to remove them on 'close' event
var index = clients.push(connection) - 1;
let index = clients.push(connection) - 1;
console.log(new Date() + ' Connection accepted.');

// user sent some message
Expand All @@ -54,7 +54,7 @@ export class UIWebsocket implements Disposable {
}

public send(message: any) {
var json = JSON.stringify({ type: 'message', data: message });
let json = JSON.stringify({ type: 'message', data: message });
this._clients.forEach((client) => {
client.sendUTF(json);
});
Expand Down

0 comments on commit 4cb18de

Please sign in to comment.