Skip to content

Commit

Permalink
(cake-buildGH-475) fixed all linting errors
Browse files Browse the repository at this point in the history
mostly that is correcting var/let to const...
  • Loading branch information
nils-a committed Nov 30, 2020
1 parent 5cdfdd1 commit b942ece
Show file tree
Hide file tree
Showing 26 changed files with 143 additions and 86 deletions.
46 changes: 46 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -710,12 +710,14 @@
"xml2js": "^0.4.23"
},
"devDependencies": {
"@types/adm-zip": "^0.4.33",
"@types/byline": "^4.2.32",
"@types/glob": "^7.1.3",
"@types/ini": "^1.3.30",
"@types/mocha": "^8.0.4",
"@types/node": "^14.14.10",
"@types/node-fetch": "^2.5.7",
"@types/request": "^2.48.5",
"@types/vscode": "^1.24.0",
"@types/xml2js": "^0.4.7",
"@typescript-eslint/eslint-plugin": "^4.9.0",
Expand Down
2 changes: 1 addition & 1 deletion src/addPackage/actions/handleDirectiveWithContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function _getFileContentWithDirective(
encoding: 'utf8'
});
const stream = byline(fileStream, { keepEmptyLines: true });
let content: Array<string> = [];
const content: Array<string> = [];
let containDirective = false;
stream.on('data', line => {
if (
Expand Down
19 changes: 11 additions & 8 deletions src/bakery/cakeBakery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var request = require('request');
var AdmZip = require('adm-zip');
import * as request from 'request';
import * as AdmZip from 'adm-zip';
import * as path from 'path';
import * as fs from 'fs';
import { window, workspace } from 'vscode';
Expand Down Expand Up @@ -48,7 +48,10 @@ export class CakeBakery {
public downloadAndExtract(): Thenable<boolean> {
return new Promise((resolve, reject) => {
// Download the NuGet Package
let vm = this;

// TODO: check if the next statement is really needed!
// eslint-disable-next-line @typescript-eslint/no-this-alias
const vm = this;
try {
if (!fs.existsSync(vm.getToolFolderPath())) {
fs.mkdirSync(vm.getToolFolderPath());
Expand All @@ -57,8 +60,8 @@ export class CakeBakery {
window.showErrorMessage('Unable to create directory');
}

var data: any[] = [],
dataLen = 0;
const data: any[] = [];
let dataLen = 0;

request
.get(CAKE_BAKERY_PACKAGE_URL, {
Expand All @@ -69,14 +72,14 @@ export class CakeBakery {
dataLen += chunk.length;
})
.on('end', function() {
var buf = new Buffer(dataLen);
const buf = new Buffer(dataLen);

for (var i = 0, len = data.length, pos = 0; i < len; i++) {
for (let i = 0, len = data.length, pos = 0; i < len; i++) {
data[i].copy(buf, pos);
pos += data[i].length;
}

var zip = new AdmZip(buf);
const zip = new AdmZip(buf);
zip.extractAllTo(vm.getNupkgDestinationPath());
resolve(true);
})
Expand Down
8 changes: 4 additions & 4 deletions src/bakery/cakeBakeryCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { commands, window, workspace } from 'vscode';
import * as fs from 'fs';
import { CakeBakery } from './cakeBakery';

export async function installCakeBakeryCommand() {
export async function installCakeBakeryCommand(): Promise<void> {
// Make sure that we're in the correct place.
if (workspace.rootPath === undefined) {
window.showErrorMessage('You have not yet opened a folder.');
return;
}

// Install Cake Bakery
var result = await installCakeDebug();
const result = await installCakeDebug();
if (result) {
commands.executeCommand('o.restart');
window.showInformationMessage(
Expand All @@ -24,9 +24,9 @@ export async function installCakeBakeryCommand() {
}

export async function installCakeDebug(): Promise<boolean> {
let bakery = new CakeBakery();
const bakery = new CakeBakery();

var targetPath = bakery.getTargetPath();
const targetPath = bakery.getTargetPath();
if (fs.existsSync(targetPath)) {
window.showWarningMessage(
'Intellisense support for Cake files has already been installed.'
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrapper/cakeBootstrapper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var request = require('request');
import * as request from 'request';
import vscode = require('vscode');
import * as path from 'path';
import { CakeBootstrapperInfo } from './cakeBootstrapperInfo';
Expand Down Expand Up @@ -75,22 +75,22 @@ export class CakeBootstrapper {
}

public static getBootstrappersByType(bootstrapperType: enums.RunnerType): CakeBootstrapperInfo[] {
var filteredBootstrappers = CakeBootstrapper.bootstrappers.filter(bootstrapper => bootstrapper.type === bootstrapperType);
const filteredBootstrappers = CakeBootstrapper.bootstrappers.filter(bootstrapper => bootstrapper.type === bootstrapperType);

return filteredBootstrappers;
}

public download(stream: NodeJS.WritableStream): Thenable<boolean> {
return new Promise((resolve, reject) => {
// Get the Cake configuration.
var config = vscode.workspace.getConfiguration('cake');
const config = vscode.workspace.getConfiguration('cake');
if (!config) {
reject('Could not resolve bootstrapper configuration.');
return;
}

// Get the bootstrapper URI from the configuration.
var uri = config['bootstrappers'][this._info.id];
const uri = config['bootstrappers'][this._info.id];
if (!uri) {
reject(
'Could not resolve bootstrapper URI from configuration.'
Expand Down
18 changes: 9 additions & 9 deletions src/bootstrapper/cakeBootstrapperCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CakeBootstrapperInfo } from './cakeBootstrapperInfo';

export async function installCakeBootstrapperCommand() {
// Let the user select the bootstrapper.
var info = await window.showQuickPick(CakeBootstrapper.getBootstrappers(), {
const info = await window.showQuickPick(CakeBootstrapper.getBootstrappers(), {
placeHolder: 'Select the bootstrapper that you want to install',
matchOnDetail: true,
matchOnDescription: true
Expand All @@ -26,28 +26,28 @@ export async function installCakeBootstrapperCommand() {

export async function installCakeBootstrapperFile(
info: CakeBootstrapperInfo,
notifyOnCompletion: boolean = true
notifyOnCompletion = true
) {
// Create the bootstrapper from the platform.
let bootstrapper = new CakeBootstrapper(info);
const bootstrapper = new CakeBootstrapper(info);

// Does the bootstrapper already exist?
var buildFilePath = bootstrapper.getTargetPath();
const buildFilePath = bootstrapper.getTargetPath();

if (fs.existsSync(buildFilePath)) {
var message = `Overwrite the existing \'${
const message = `Overwrite the existing '${
info.fileName
}\' file in this folder?`;
var option = await window.showWarningMessage(message, 'Overwrite');
}' file in this folder?`;
const option = await window.showWarningMessage(message, 'Overwrite');

if (option !== 'Overwrite') {
return;
}
}

// Download the bootstrapper and save it to disk.
var file = fs.createWriteStream(buildFilePath);
var result = await bootstrapper.download(file);
const file = fs.createWriteStream(buildFilePath);
const result = await bootstrapper.download(file);

if (result) {
if (process.platform !== 'win32' && info.posix) {
Expand Down
2 changes: 1 addition & 1 deletion src/buildFile/cakeBuildFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CakeBuildFile {
public create(): Thenable<boolean> {
return new Promise((resolve, reject) => {
try {
let buildFile = fs.createWriteStream(this.getTargetPath(), {
const buildFile = fs.createWriteStream(this.getTargetPath(), {
flags: 'a'
});

Expand Down
12 changes: 6 additions & 6 deletions src/buildFile/cakeBuildFileCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function installBuildFileCommand() {
return;
}

var name = await window.showInputBox({
const name = await window.showInputBox({
placeHolder: messages.PROMPT_SCRIPT_NAME,
value: DEFAULT_SCRIPT_NAME
});
Expand All @@ -22,7 +22,7 @@ export async function installBuildFileCommand() {
return;
}

var result = await installBuildFile(name);
const result = await installBuildFile(name);

if (result) {
window.showInformationMessage(
Expand All @@ -35,15 +35,15 @@ export async function installBuildFileCommand() {

export async function installBuildFile(fileName: string): Promise<boolean> {
// Create the buildFile object
let buildFile = new CakeBuildFile(fileName);
const buildFile = new CakeBuildFile(fileName);

var targetPath = buildFile.getTargetPath();
var ready = await utils.checkForExisting(targetPath);
const targetPath = buildFile.getTargetPath();
const ready = await utils.checkForExisting(targetPath);

if (!ready) {
Promise.reject(CANCEL);
}

var result = await buildFile.create();
const result = await buildFile.create();
return result;
}
10 changes: 5 additions & 5 deletions src/cakeMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ function _verifyTasksRunner(config: ITaskRunnerSettings,
}

async function _getCakeScriptsAsTasks(context: vscode.ExtensionContext): Promise<vscode.Task[]> {
let workspaceRoot = vscode.workspace.rootPath;
let emptyTasks: vscode.Task[] = [];
const workspaceRoot = vscode.workspace.rootPath;
const emptyTasks: vscode.Task[] = [];

if (!workspaceRoot) {
return emptyTasks;
}

try {
const config = getExtensionSettings().taskRunner;
let files = await vscode.workspace.findFiles(
const files = await vscode.workspace.findFiles(
config.scriptsIncludePattern,
config.scriptsExcludePattern
);
Expand All @@ -161,13 +161,13 @@ async function _getCakeScriptsAsTasks(context: vscode.ExtensionContext): Promise
files.forEach(file => {
const contents = fs.readFileSync(file.fsPath).toString();

let taskRegularExpression = new RegExp(
const taskRegularExpression = new RegExp(
config.taskRegularExpression,
'g'
);

let matches: RegExpExecArray | null;
let taskNames: string[] = [];
const taskNames: string[] = [];

while ((matches = taskRegularExpression.exec(contents))) {
taskNames.push(matches[1]);
Expand Down
11 changes: 6 additions & 5 deletions src/codeLens/cakeCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class CakeDebugTaskCodeLens extends CodeLens {
export class CakeCodeLensProvider implements CodeLensProvider {
private _onDidChangeCodeLensesEmitter = new EventEmitter<void>();
private _taskNameRegExp: RegExp;
public showCodeLens: boolean = false;
public showCodeLens = false;

public constructor(taskRegExp: string) {
this._taskNameRegExp = new RegExp(taskRegExp, 'g');
Expand All @@ -49,8 +49,8 @@ export class CakeCodeLensProvider implements CodeLensProvider {
const symbols: SymbolInformation[] = [];

for (let i = 0; i < document.lineCount; i++) {
let line = document.lineAt(i);
let matches = this._taskNameRegExp.exec(line.text);
const line = document.lineAt(i);
const matches = this._taskNameRegExp.exec(line.text);
if (matches) {
symbols.push(
new SymbolInformation(
Expand Down Expand Up @@ -124,6 +124,7 @@ export class CakeCodeLensProvider implements CodeLensProvider {
return codeLens;
}

public dispose() {
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
public dispose(): void { }
}
2 changes: 1 addition & 1 deletion src/codeLens/cakeRunTaskCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function installCakeRunTaskCommand(
await installCakeToolIfNeeded(settings, context);

let buildCommand = getPlatformSettingsValue(settings.taskRunner.launchCommand);
buildCommand = `${buildCommand} \"${fileName}\" --target=\"${taskName}\" --verbosity=${settings.taskRunner.verbosity}`;
buildCommand = `${buildCommand} "${fileName}" --target="${taskName}" --verbosity=${settings.taskRunner.verbosity}`;

TerminalExecutor.runInTerminal(buildCommand);
}
6 changes: 3 additions & 3 deletions src/configuration/cakeConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var request = require('request');
import * as request from 'request';
import vscode = require('vscode');
import * as path from 'path';

Expand All @@ -14,15 +14,15 @@ export class CakeConfiguration {
public download(stream: NodeJS.WritableStream): Thenable<boolean> {
return new Promise((resolve, reject) => {
// Get the Cake configuration.
var config = vscode.workspace.getConfiguration('cake');
const config = vscode.workspace.getConfiguration('cake');

if (!config) {
reject('Could not resolve configuration configuration.');
return;
}

// Get the bootstrapper URI from the configuration.
var uri = config['configuration']['config'];
const uri = config['configuration']['config'];

if (!uri) {
reject(
Expand Down
Loading

0 comments on commit b942ece

Please sign in to comment.