Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fixes from CodeFactor #29

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/apexlink/src/ApexDepedencyCheckImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ export default class ApexDepedencyCheckImpl {

public async execute() {

let apexLinkProcessExecutor = new ExecuteCommand(this.logger, LoggerLevel.INFO, false);
let generatedCommand = await this.getGeneratedCommandWithParams();
const apexLinkProcessExecutor = new ExecuteCommand(this.logger, LoggerLevel.INFO, false);
const generatedCommand = await this.getGeneratedCommandWithParams();

await apexLinkProcessExecutor.execCommand(
generatedCommand,
process.cwd()
);
let result = fs.readJSONSync(`${this.projectDirectory}/apexlink.json`)
const result = fs.readJSONSync(`${this.projectDirectory}/apexlink.json`)
return result;
}

private async getGeneratedCommandWithParams() {
let javaHome:string = await this.getJavaHome();
//Replace Program Files with Progra~1 in Windows
javaHome = javaHome.replace(/Program Files/, "Progra~1");
let command = `${path.join(javaHome, 'bin', 'java')} -jar ${jarFile} -depends -json ${
const command = `${path.join(javaHome, 'bin', 'java')} -jar ${jarFile} -depends -json ${
this.projectDirectory } > ${this.projectDirectory}/apexlink.json`;
return command;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/apexlink/tests/ApexDependencyCheckImpl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import path from 'path';
describe('Given a directory with apex classes, ', () => {
it('it should provide the dependendencies of apex class', async () => {

let apexLinkImpl = new ApexDepedencyCheckImpl(new ConsoleLogger(), path.join(__dirname,`/resources/feature-mgmt`));
let result = await apexLinkImpl.execute();
const apexLinkImpl = new ApexDepedencyCheckImpl(new ConsoleLogger(), path.join(__dirname,`/resources/feature-mgmt`));
const result = await apexLinkImpl.execute();
expect(result.dependencies).toContainEqual({ "name": "AlwaysEnabledFeature", "dependencies": ["Feature"]});

},30000);
Expand All @@ -16,8 +16,8 @@ describe('Given a directory with apex classes, ', () => {
describe('Given a directory with no apex classes, ', () => {
it('it should provide an empty array', async () => {

let apexLinkImpl = new ApexDepedencyCheckImpl(new ConsoleLogger(), path.join(__dirname,`/resources/core-crm`));
let result = await apexLinkImpl.execute();
const apexLinkImpl = new ApexDepedencyCheckImpl(new ConsoleLogger(), path.join(__dirname,`/resources/core-crm`));
const result = await apexLinkImpl.execute();
expect(result.dependencies.length).toEqual(0);

},50000);
Expand Down
4 changes: 2 additions & 2 deletions packages/sfdx-process-wrapper/src/SFDXCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export abstract class SFDXCommand {
command += ' ' + this.getGeneratedParams();

SFPLogger.log('Generated Command:' + command, LoggerLevel.TRACE, this.logger);
let executor: ExecuteCommand = new ExecuteCommand(this.logger, this.logLevel, showProgress);
const executor: ExecuteCommand = new ExecuteCommand(this.logger, this.logLevel, showProgress);
//CLI writes errors to Output Stream during errors in JSON Mode, so if quiet is true, use swap output for error
let output = await executor.execCommand(command, this.project_directory, timeout, quiet);
const output = await executor.execCommand(command, this.project_directory, timeout, quiet);
if (quiet) {
return JSON.parse(output).result;
}
Expand Down
20 changes: 10 additions & 10 deletions packages/sfp-cli/src/BuildBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export default abstract class BuildBase extends SfpCommand {
failedPackages: string[];
};
let totalElapsedTime: number;
let artifactCreationErrors: string[] = [];
const artifactCreationErrors: string[] = [];

let tags = {
const tags = {
is_diffcheck_enabled: String(flags.diffcheck),
stage: this.getStage(),
branch: flags.branch,
Expand All @@ -113,7 +113,7 @@ export default abstract class BuildBase extends SfpCommand {
const buildOnlyPackages: string[] = flags.buildOnly;

// Read Manifest
let projectConfig = ProjectConfig.getSFDXProjectConfig(process.cwd());
const projectConfig = ProjectConfig.getSFDXProjectConfig(process.cwd());

SFPLogger.log(COLOR_HEADER(`command: ${COLOR_KEY_MESSAGE(this.getStage())}`));
SFPLogger.log(COLOR_HEADER(`Build Packages Only Changed: ${flags.diffcheck}`));
Expand All @@ -128,7 +128,7 @@ export default abstract class BuildBase extends SfpCommand {
}
SFPLogger.log(COLOR_HEADER(`Artifact Directory: ${flags.artifactdir}`));
SFPLogger.printHeaderLine('', COLOR_HEADER, LoggerLevel.INFO);
let executionStartTime = Date.now();
const executionStartTime = Date.now();

if (!(flags.tag == null || flags.tag == undefined)) {
tags['tag'] = flags.tag;
Expand Down Expand Up @@ -164,7 +164,7 @@ export default abstract class BuildBase extends SfpCommand {
SFPLogger.log(`${EOL}${EOL}`);
SFPLogger.log('Generating Artifacts and Tags....');

for (let generatedPackage of buildExecResult.generatedPackages) {
for (const generatedPackage of buildExecResult.generatedPackages) {
try {
await ArtifactGenerator.generateArtifact(generatedPackage, process.cwd(), artifactDirectory);
} catch (error) {
Expand Down Expand Up @@ -216,7 +216,7 @@ export default abstract class BuildBase extends SfpCommand {
},
};

for (let generatedPackage of buildExecResult.generatedPackages) {
for (const generatedPackage of buildExecResult.generatedPackages) {
buildResult.packages.push({
name: generatedPackage.packageName,
version: generatedPackage.package_version_number,
Expand All @@ -227,7 +227,7 @@ export default abstract class BuildBase extends SfpCommand {

}

for (let failedPackage of buildExecResult.failedPackages) {
for (const failedPackage of buildExecResult.failedPackages) {
buildResult.packages.push({
name: failedPackage,
version: null,
Expand All @@ -239,8 +239,8 @@ export default abstract class BuildBase extends SfpCommand {
//try to understad which release configs was successfull
buildResult.summary.sucessfullReleaseConfigs=[];
for (const releaseConfig in this.releaseConfigMap) {
let packages = this.releaseConfigMap[releaseConfig];
let failedPackages = packages.filter((x) => buildExecResult.failedPackages.includes(x));
const packages = this.releaseConfigMap[releaseConfig];
const failedPackages = packages.filter((x) => buildExecResult.failedPackages.includes(x));
if (failedPackages.length === 0) {
buildResult.summary.sucessfullReleaseConfigs.push(releaseConfig);
}
Expand Down Expand Up @@ -287,7 +287,7 @@ export default abstract class BuildBase extends SfpCommand {

if (releaseConfigFilePaths?.length > 0) {
buildProps.includeOnlyPackages = [];
let releaseConfigAggregatedLoader = new ReleaseConfigAggregator(logger);
const releaseConfigAggregatedLoader = new ReleaseConfigAggregator(logger);
releaseConfigAggregatedLoader.addReleaseConfigs(releaseConfigFilePaths);
buildProps.includeOnlyPackages = releaseConfigAggregatedLoader.getAllPackages();
printIncludeOnlyPackages(buildProps.includeOnlyPackages);
Expand Down
2 changes: 1 addition & 1 deletion packages/sfp-cli/src/InstallPackageCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default abstract class InstallPackageCommand extends SfpCommand {
* the primary install
*/
private async preInstall(): Promise<void> {
let artifacts = ArtifactFetcher.fetchArtifacts(this.flags.artifactdir, this.flags.package, null);
const artifacts = ArtifactFetcher.fetchArtifacts(this.flags.artifactdir, this.flags.package, null);
if (artifacts.length === 0) {
if (!this.flags.skiponmissingartifact) {
throw new Error(
Expand Down
16 changes: 8 additions & 8 deletions packages/sfp-cli/src/PackageCreateCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ export default abstract class PackageCreateCommand extends SfpCommand {
*
*/
async execute(): Promise<any> {
let isToCreatePackage = await this.preCreate();
const isToCreatePackage = await this.preCreate();
if (isToCreatePackage) {
try {
let packageMetadata = await this.create();
const packageMetadata = await this.create();
await this.postCreate(packageMetadata);
} catch (err) {
console.log(err);
Expand All @@ -88,16 +88,16 @@ export default abstract class PackageCreateCommand extends SfpCommand {
let isToRunBuild;

if (this.flags.diffcheck) {
let packageDiffImpl = new PackageDiffImpl(new ConsoleLogger(), this.sfdxPackage, null);
const packageDiffImpl = new PackageDiffImpl(new ConsoleLogger(), this.sfdxPackage, null);

let isToRunBuild = (await packageDiffImpl.exec()).isToBeBuilt;
const isToRunBuild = (await packageDiffImpl.exec()).isToBeBuilt;

if (isToRunBuild) console.log(`Detected changes to ${this.sfdxPackage} package...proceeding\n`);
else console.log(`No changes detected for ${this.sfdxPackage} package...skipping\n`);
} else isToRunBuild = true;

if (isToRunBuild) {
let git = await Git.initiateRepo(new ConsoleLogger());
const git = await Git.initiateRepo(new ConsoleLogger());
this.repositoryURL = await git.getRemoteOriginUrl(this.flags.repourl);
this.commitId = await git.getHeadCommit();
}
Expand All @@ -113,15 +113,15 @@ export default abstract class PackageCreateCommand extends SfpCommand {

if (this.flags.gittag) {

let git = await Git.initiateRepo(new ConsoleLogger());
let tagname = `${this.sfdxPackage}_v${sfpPackage.package_version_number}`;
const git = await Git.initiateRepo(new ConsoleLogger());
const tagname = `${this.sfdxPackage}_v${sfpPackage.package_version_number}`;
await git.addAnnotatedTag(tagname, `${sfpPackage.packageName} sfp package ${sfpPackage.package_version_number}`)

sfpPackage.tag = tagname;
}

//Generate Artifact
let artifactFilepath: string = await ArtifactGenerator.generateArtifact(
const artifactFilepath: string = await ArtifactGenerator.generateArtifact(
sfpPackage,
process.cwd(),
this.artifactDirectory
Expand Down
12 changes: 6 additions & 6 deletions packages/sfp-cli/src/ProjectValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export default class ProjectValidation {
}

public validateSFDXProjectJSON() {
let schema = fs.readJSONSync(path.join(this.resourcesDir, `sfdx-project.schema.json`), { encoding: 'UTF-8' });
let validator = this.ajv.compile(schema);
let isSchemaValid = validator(this.projectConfig);
const schema = fs.readJSONSync(path.join(this.resourcesDir, `sfdx-project.schema.json`), { encoding: 'UTF-8' });
const validator = this.ajv.compile(schema);
const isSchemaValid = validator(this.projectConfig);
if (!isSchemaValid) {
let errorMsg: string = `The sfdx-project.json is invalid, Please fix the following errors\n`;

Expand All @@ -39,7 +39,7 @@ export default class ProjectValidation {

public validatePackageNames() {
ProjectConfig.getAllPackageDirectoriesFromConfig(this.projectConfig).forEach((pkg) => {
let name = pkg.package;
const name = pkg.package;
if ( name.length > 38) {
throw new Error(
'sfdx-project.json validation failed for package "' +
Expand All @@ -61,9 +61,9 @@ export default class ProjectValidation {

public validatePackageBuildNumbers() {
ProjectConfig.getAllPackageDirectoriesFromConfig(this.projectConfig).forEach((pkg) => {
let packageType = ProjectConfig.getPackageType(this.projectConfig, pkg.package);
const packageType = ProjectConfig.getPackageType(this.projectConfig, pkg.package);

let pattern: RegExp = /NEXT$|LATEST$/i;
const pattern: RegExp = /NEXT$|LATEST$/i;
if (
pkg.versionNumber.match(pattern) &&
(packageType === PackageType.Source || packageType === PackageType.Data)
Expand Down
2 changes: 1 addition & 1 deletion packages/sfp-cli/src/SfpCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default abstract class SfpCommand extends Command {
}

if (this.statics.requiresProject) {
let projectValidation = new ProjectValidation();
const projectValidation = new ProjectValidation();
projectValidation.validateSFDXProjectJSON();
projectValidation.validatePackageNames();
}
Expand Down
6 changes: 3 additions & 3 deletions packages/sfp-cli/src/commands/apextests/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ export default class TriggerApexTest extends SfpCommand {

let testOptions: TestOptions;
let coverageOptions: CoverageOptions;
let outputdir = path.join('.testresults');
const outputdir = path.join('.testresults');

if (this.flags.testlevel === TestLevel.RunAllTestsInOrg.toString()) {
testOptions = new RunAllTestsInOrg(this.flags.waittime, outputdir, this.flags.synchronous);
} else if (this.flags.testlevel === TestLevel.RunAllTestsInPackage.toString()) {
if (this.flags.package === null) {
throw new Error('Package name must be specified when test level is RunAllTestsInPackage');
}
let pkg: SfpPackage = await SfpPackageBuilder.buildPackageFromProjectDirectory(
const pkg: SfpPackage = await SfpPackageBuilder.buildPackageFromProjectDirectory(
new ConsoleLogger(),
null,
this.flags.package,
Expand Down Expand Up @@ -146,7 +146,7 @@ export default class TriggerApexTest extends SfpCommand {
null,
null
);
let result = await triggerApexTests.exec();
const result = await triggerApexTests.exec();

if (!result.result) {
throw new Error(`Error: ${result.message}`);
Expand Down
8 changes: 4 additions & 4 deletions packages/sfp-cli/src/commands/artifacts/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ export default class Fetch extends SfpCommand {
public async execute() {
this.validateFlags();

let releaseDefinition = await ReleaseDefinitionLoader.loadReleaseDefinition(this.flags.releasedefinition);
const releaseDefinition = await ReleaseDefinitionLoader.loadReleaseDefinition(this.flags.releasedefinition);
let result: {
success: ArtifactVersion[];
failed: ArtifactVersion[];
};

let executionStartTime = Date.now();
const executionStartTime = Date.now();
try {
let fetchImpl: FetchImpl = new FetchImpl(
const fetchImpl: FetchImpl = new FetchImpl(
this.flags.artifactdir,
this.flags.scriptpath,
this.flags.scope,
Expand All @@ -84,7 +84,7 @@ export default class Fetch extends SfpCommand {

process.exitCode = 1;
} finally {
let totalElapsedTime: number = Date.now() - executionStartTime;
const totalElapsedTime: number = Date.now() - executionStartTime;

if (result) this.printSummary(result, totalElapsedTime);
}
Expand Down
14 changes: 7 additions & 7 deletions packages/sfp-cli/src/commands/artifacts/promote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ export default class Promote extends SfpCommand {
//Refresh HubOrg Authentication
await this.hubOrg.refreshAuth();

let unpromotedPackages: { name: string; error: string }[] = [];
const unpromotedPackages: { name: string; error: string }[] = [];
try {
let artifacts = ArtifactFetcher.fetchArtifacts(this.flags.artifactdir);
const artifacts = ArtifactFetcher.fetchArtifacts(this.flags.artifactdir);

if (artifacts.length === 0) {
throw new Error(`No artifacts found at ${this.flags.artifactdir}`);
}

let result: boolean = true;
let promotedPackages: string[] = [];
for (let artifact of artifacts) {
let sfpPackage = await SfpPackageBuilder.buildPackageFromArtifact(artifact, new ConsoleLogger());
const promotedPackages: string[] = [];
for (const artifact of artifacts) {
const sfpPackage = await SfpPackageBuilder.buildPackageFromArtifact(artifact, new ConsoleLogger());
try {
if (sfpPackage.package_type === PackageType.Unlocked) {
let promoteUnlockedPackageImpl = new PromoteUnlockedPackageImpl(
const promoteUnlockedPackageImpl = new PromoteUnlockedPackageImpl(
artifact.sourceDirectoryPath,
sfpPackage.package_version_id,
this.hubOrg.getUsername()
Expand Down Expand Up @@ -103,7 +103,7 @@ export default class Promote extends SfpCommand {
}

private substituteBuildNumberWithPreRelease(packageVersionNumber: string) {
let segments = packageVersionNumber.split('.');
const segments = packageVersionNumber.split('.');

if (segments.length === 4) {
packageVersionNumber = segments.reduce((version, segment, segmentsIdx) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/sfp-cli/src/commands/artifacts/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export default class Query extends SfpCommand {
public async execute() {
await this.org.refreshAuth();

let sfpOrg: SFPOrg = await SFPOrg.create({ connection: this.org.getConnection() });
let installedArtifacts = await sfpOrg.getAllInstalledArtifacts();
const sfpOrg: SFPOrg = await SFPOrg.create({ connection: this.org.getConnection() });
const installedArtifacts = await sfpOrg.getAllInstalledArtifacts();
if (!this.flags.json) {
let minTable = new Table({
const minTable = new Table({
head: [
'Package',
'Version in org',
Expand Down
4 changes: 2 additions & 2 deletions packages/sfp-cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class Build extends BuildBase {
}

getBuildProps(): BuildProps {
let buildProps: BuildProps = {
const buildProps: BuildProps = {
configFilePath: this.flags.configfilepath,
devhubAlias: this.flags.devhubalias,
repourl: this.flags.repourl,
Expand All @@ -40,7 +40,7 @@ export default class Build extends BuildBase {
}

getBuildImplementer(buildProps: BuildProps): BuildImpl {
let buildImpl = new BuildImpl(buildProps);
const buildImpl = new BuildImpl(buildProps);
return buildImpl;
}
}
4 changes: 2 additions & 2 deletions packages/sfp-cli/src/commands/changelog/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class GenerateChangelog extends SfpCommand {

async execute() {
try {
let changelogImpl: ChangelogImpl = new ChangelogImpl(
const changelogImpl: ChangelogImpl = new ChangelogImpl(
new ConsoleLogger(),
this.flags.artifactdir,
this.flags.releasename,
Expand All @@ -98,7 +98,7 @@ export default class GenerateChangelog extends SfpCommand {
} catch (err) {
let errorMessage: string = '';
if (err instanceof Array) {
for (let e of err) {
for (const e of err) {
errorMessage += e.message + `\n`;
}
} else {
Expand Down
Loading
Loading