Skip to content

Commit bdcbd76

Browse files
committed
Fixing TSLint errors in WBT projects.
1 parent 4f05010 commit bdcbd76

File tree

15 files changed

+192
-187
lines changed

15 files changed

+192
-187
lines changed

apps/rush-lib/src/data/PinnedVersionsConfiguration.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ export class PinnedVersionsConfiguration {
3737
return new PinnedVersionsConfiguration(pinnedVersionJson, jsonFilename);
3838
}
3939

40+
/**
41+
* Preferred to use PinnedVersionsConfiguration.loadFromFile()
42+
*/
43+
private constructor(pinnedVersionJson: IPinnedVersionsJson, private _filename: string) {
44+
this._data = new Map<string, string>();
45+
Object.keys(pinnedVersionJson || {}).forEach((dep: string) => {
46+
this.set(dep, pinnedVersionJson[dep]);
47+
});
48+
}
49+
4050
/** Set a pinned version. Checks that the version is a valid semver. */
4151
public set(dependency: string, version: string): this {
4252
if (!semver.valid(version) && !semver.validRange(version)) {
@@ -84,14 +94,4 @@ export class PinnedVersionsConfiguration {
8494
});
8595
return rawJson;
8696
}
87-
88-
/**
89-
* Preferred to use PinnedVersionsConfiguration.loadFromFile()
90-
*/
91-
private constructor(pinnedVersionJson: IPinnedVersionsJson, private _filename: string) {
92-
this._data = new Map<string, string>();
93-
Object.keys(pinnedVersionJson || {}).forEach((dep: string) => {
94-
this.set(dep, pinnedVersionJson[dep]);
95-
});
96-
}
9797
}

apps/rush-lib/src/data/RushConfiguration.ts

Lines changed: 125 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,131 @@ export default class RushConfiguration {
253253
}
254254
}
255255

256+
/**
257+
* Use RushConfiguration.loadFromConfigurationFile() or Use RushConfiguration.loadFromDefaultLocation()
258+
* instead.
259+
*/
260+
private constructor(rushConfigurationJson: IRushConfigurationJson, rushJsonFilename: string) {
261+
if (rushConfigurationJson.nodeSupportedVersionRange) {
262+
if (!semver.validRange(rushConfigurationJson.nodeSupportedVersionRange)) {
263+
throw new Error('Error parsing the node-semver expression in the "nodeSupportedVersionRange"'
264+
+ ` field from rush.json: "${rushConfigurationJson.nodeSupportedVersionRange}"`);
265+
}
266+
if (!semver.satisfies(process.version, rushConfigurationJson.nodeSupportedVersionRange)) {
267+
throw new Error(`Your dev environment is running Node.js version ${process.version} which does`
268+
+ ` not meet the requirements for building this repository. (The rush.json configuration`
269+
+ ` requires nodeSupportedVersionRange="${rushConfigurationJson.nodeSupportedVersionRange}")`);
270+
}
271+
}
272+
273+
this._rushJsonFolder = path.dirname(rushJsonFilename);
274+
275+
this._commonFolder = path.resolve(path.join(this._rushJsonFolder, RushConstants.commonFolderName));
276+
277+
this._commonRushConfigFolder = path.join(this._commonFolder, 'config', 'rush');
278+
RushConfiguration._validateCommonRushConfigFolder(this._commonRushConfigFolder);
279+
280+
this._commonTempFolder = path.join(this._commonFolder, RushConstants.rushTempFolderName);
281+
this._npmCacheFolder = path.resolve(path.join(this._commonTempFolder, 'npm-cache'));
282+
this._npmTmpFolder = path.resolve(path.join(this._commonTempFolder, 'npm-tmp'));
283+
284+
this._committedShrinkwrapFilename = path.join(this._commonRushConfigFolder, RushConstants.npmShrinkwrapFilename);
285+
this._tempShrinkwrapFilename = path.join(this._commonTempFolder, RushConstants.npmShrinkwrapFilename);
286+
287+
const unresolvedUserFolder: string = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
288+
this._homeFolder = path.resolve(unresolvedUserFolder);
289+
if (!fsx.existsSync(this._homeFolder)) {
290+
throw new Error('Unable to determine the current user\'s home directory');
291+
}
292+
293+
this._rushLinkJsonFilename = path.join(this._commonTempFolder, 'rush-link.json');
294+
295+
this._npmToolVersion = rushConfigurationJson.npmVersion;
296+
this._npmToolFilename = path.resolve(path.join(this._commonTempFolder,
297+
'npm-local', 'node_modules', '.bin', 'npm'));
298+
299+
this._projectFolderMinDepth = rushConfigurationJson.projectFolderMinDepth !== undefined
300+
? rushConfigurationJson.projectFolderMinDepth : 1;
301+
if (this._projectFolderMinDepth < 1) {
302+
throw new Error('Invalid projectFolderMinDepth; the minimum possible value is 1');
303+
}
304+
305+
this._projectFolderMaxDepth = rushConfigurationJson.projectFolderMaxDepth !== undefined
306+
? rushConfigurationJson.projectFolderMaxDepth : 2;
307+
if (this._projectFolderMaxDepth < this._projectFolderMinDepth) {
308+
throw new Error('The projectFolderMaxDepth cannot be smaller than the projectFolderMinDepth');
309+
}
310+
311+
this._approvedPackagesPolicy = new ApprovedPackagesPolicy(this, rushConfigurationJson);
312+
313+
this._gitAllowedEmailRegExps = [];
314+
this._gitSampleEmail = '';
315+
if (rushConfigurationJson.gitPolicy) {
316+
if (rushConfigurationJson.gitPolicy.sampleEmail) {
317+
this._gitSampleEmail = rushConfigurationJson.gitPolicy.sampleEmail;
318+
}
319+
320+
if (rushConfigurationJson.gitPolicy.allowedEmailRegExps) {
321+
this._gitAllowedEmailRegExps = rushConfigurationJson.gitPolicy.allowedEmailRegExps;
322+
323+
if (this._gitSampleEmail.trim().length < 1) {
324+
throw new Error('The rush.json file is missing the "sampleEmail" option, ' +
325+
'which is required when using "allowedEmailRegExps"');
326+
}
327+
}
328+
}
329+
330+
this._telemetryEnabled = !!rushConfigurationJson.telemetryEnabled;
331+
if (rushConfigurationJson.eventHooks) {
332+
this._eventHooks = new EventHooks(rushConfigurationJson.eventHooks);
333+
}
334+
335+
const versionPolicyConfigFile: string = path.join(this._commonRushConfigFolder,
336+
RushConstants.versionPoliciesFileName);
337+
this._versionPolicyConfiguration = new VersionPolicyConfiguration(versionPolicyConfigFile);
338+
339+
this._projects = [];
340+
this._projectsByName = new Map<string, RushConfigurationProject>();
341+
342+
// We sort the projects array in alphabetical order. This ensures that the packages
343+
// are processed in a deterministic order by the various Rush algorithms.
344+
const sortedProjectJsons: IRushConfigurationProjectJson[] = rushConfigurationJson.projects.slice(0);
345+
sortedProjectJsons.sort(
346+
(a: IRushConfigurationProjectJson, b: IRushConfigurationProjectJson) => a.packageName.localeCompare(b.packageName)
347+
);
348+
349+
const tempNamesByProject: Map<IRushConfigurationProjectJson, string>
350+
= RushConfiguration._generateTempNamesForProjects(sortedProjectJsons);
351+
352+
for (const projectJson of sortedProjectJsons) {
353+
const tempProjectName: string = tempNamesByProject.get(projectJson);
354+
const project: RushConfigurationProject = new RushConfigurationProject(projectJson, this, tempProjectName);
355+
this._projects.push(project);
356+
if (this._projectsByName.get(project.packageName)) {
357+
throw new Error(`The project name "${project.packageName}" was specified more than once`
358+
+ ` in the rush.json configuration file.`);
359+
}
360+
this._projectsByName.set(project.packageName, project);
361+
}
362+
363+
for (const project of this._projects) {
364+
project.cyclicDependencyProjects.forEach((cyclicDependencyProject: string) => {
365+
if (!this.getProjectByName(cyclicDependencyProject)) {
366+
throw new Error(`In rush.json, the "${cyclicDependencyProject}" project does not exist,`
367+
+ ` but was referenced by the cyclicDependencyProjects for ${project.packageName}`);
368+
}
369+
});
370+
371+
// Compute the downstream dependencies within the list of Rush projects.
372+
this._populateDownstreamDependencies(project.packageJson.dependencies, project.packageName);
373+
this._populateDownstreamDependencies(project.packageJson.devDependencies, project.packageName);
374+
}
375+
376+
// Example: "./common/config/rush/pinnedVersions.json"
377+
const pinnedVersionsFile: string = path.join(this.commonRushConfigFolder, RushConstants.pinnedVersionsFilename);
378+
this._pinnedVersions = PinnedVersionsConfiguration.tryLoadFromFile(pinnedVersionsFile);
379+
}
380+
256381
/**
257382
* The folder that contains rush.json for this project.
258383
*/
@@ -517,129 +642,4 @@ export default class RushConfiguration {
517642
}
518643
});
519644
}
520-
521-
/**
522-
* Use RushConfiguration.loadFromConfigurationFile() or Use RushConfiguration.loadFromDefaultLocation()
523-
* instead.
524-
*/
525-
private constructor(rushConfigurationJson: IRushConfigurationJson, rushJsonFilename: string) {
526-
if (rushConfigurationJson.nodeSupportedVersionRange) {
527-
if (!semver.validRange(rushConfigurationJson.nodeSupportedVersionRange)) {
528-
throw new Error('Error parsing the node-semver expression in the "nodeSupportedVersionRange"'
529-
+ ` field from rush.json: "${rushConfigurationJson.nodeSupportedVersionRange}"`);
530-
}
531-
if (!semver.satisfies(process.version, rushConfigurationJson.nodeSupportedVersionRange)) {
532-
throw new Error(`Your dev environment is running Node.js version ${process.version} which does`
533-
+ ` not meet the requirements for building this repository. (The rush.json configuration`
534-
+ ` requires nodeSupportedVersionRange="${rushConfigurationJson.nodeSupportedVersionRange}")`);
535-
}
536-
}
537-
538-
this._rushJsonFolder = path.dirname(rushJsonFilename);
539-
540-
this._commonFolder = path.resolve(path.join(this._rushJsonFolder, RushConstants.commonFolderName));
541-
542-
this._commonRushConfigFolder = path.join(this._commonFolder, 'config', 'rush');
543-
RushConfiguration._validateCommonRushConfigFolder(this._commonRushConfigFolder);
544-
545-
this._commonTempFolder = path.join(this._commonFolder, RushConstants.rushTempFolderName);
546-
this._npmCacheFolder = path.resolve(path.join(this._commonTempFolder, 'npm-cache'));
547-
this._npmTmpFolder = path.resolve(path.join(this._commonTempFolder, 'npm-tmp'));
548-
549-
this._committedShrinkwrapFilename = path.join(this._commonRushConfigFolder, RushConstants.npmShrinkwrapFilename);
550-
this._tempShrinkwrapFilename = path.join(this._commonTempFolder, RushConstants.npmShrinkwrapFilename);
551-
552-
const unresolvedUserFolder: string = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
553-
this._homeFolder = path.resolve(unresolvedUserFolder);
554-
if (!fsx.existsSync(this._homeFolder)) {
555-
throw new Error('Unable to determine the current user\'s home directory');
556-
}
557-
558-
this._rushLinkJsonFilename = path.join(this._commonTempFolder, 'rush-link.json');
559-
560-
this._npmToolVersion = rushConfigurationJson.npmVersion;
561-
this._npmToolFilename = path.resolve(path.join(this._commonTempFolder,
562-
'npm-local', 'node_modules', '.bin', 'npm'));
563-
564-
this._projectFolderMinDepth = rushConfigurationJson.projectFolderMinDepth !== undefined
565-
? rushConfigurationJson.projectFolderMinDepth : 1;
566-
if (this._projectFolderMinDepth < 1) {
567-
throw new Error('Invalid projectFolderMinDepth; the minimum possible value is 1');
568-
}
569-
570-
this._projectFolderMaxDepth = rushConfigurationJson.projectFolderMaxDepth !== undefined
571-
? rushConfigurationJson.projectFolderMaxDepth : 2;
572-
if (this._projectFolderMaxDepth < this._projectFolderMinDepth) {
573-
throw new Error('The projectFolderMaxDepth cannot be smaller than the projectFolderMinDepth');
574-
}
575-
576-
this._approvedPackagesPolicy = new ApprovedPackagesPolicy(this, rushConfigurationJson);
577-
578-
this._gitAllowedEmailRegExps = [];
579-
this._gitSampleEmail = '';
580-
if (rushConfigurationJson.gitPolicy) {
581-
if (rushConfigurationJson.gitPolicy.sampleEmail) {
582-
this._gitSampleEmail = rushConfigurationJson.gitPolicy.sampleEmail;
583-
}
584-
585-
if (rushConfigurationJson.gitPolicy.allowedEmailRegExps) {
586-
this._gitAllowedEmailRegExps = rushConfigurationJson.gitPolicy.allowedEmailRegExps;
587-
588-
if (this._gitSampleEmail.trim().length < 1) {
589-
throw new Error('The rush.json file is missing the "sampleEmail" option, ' +
590-
'which is required when using "allowedEmailRegExps"');
591-
}
592-
}
593-
}
594-
595-
this._telemetryEnabled = !!rushConfigurationJson.telemetryEnabled;
596-
if (rushConfigurationJson.eventHooks) {
597-
this._eventHooks = new EventHooks(rushConfigurationJson.eventHooks);
598-
}
599-
600-
const versionPolicyConfigFile: string = path.join(this._commonRushConfigFolder,
601-
RushConstants.versionPoliciesFileName);
602-
this._versionPolicyConfiguration = new VersionPolicyConfiguration(versionPolicyConfigFile);
603-
604-
this._projects = [];
605-
this._projectsByName = new Map<string, RushConfigurationProject>();
606-
607-
// We sort the projects array in alphabetical order. This ensures that the packages
608-
// are processed in a deterministic order by the various Rush algorithms.
609-
const sortedProjectJsons: IRushConfigurationProjectJson[] = rushConfigurationJson.projects.slice(0);
610-
sortedProjectJsons.sort(
611-
(a: IRushConfigurationProjectJson, b: IRushConfigurationProjectJson) => a.packageName.localeCompare(b.packageName)
612-
);
613-
614-
const tempNamesByProject: Map<IRushConfigurationProjectJson, string>
615-
= RushConfiguration._generateTempNamesForProjects(sortedProjectJsons);
616-
617-
for (const projectJson of sortedProjectJsons) {
618-
const tempProjectName: string = tempNamesByProject.get(projectJson);
619-
const project: RushConfigurationProject = new RushConfigurationProject(projectJson, this, tempProjectName);
620-
this._projects.push(project);
621-
if (this._projectsByName.get(project.packageName)) {
622-
throw new Error(`The project name "${project.packageName}" was specified more than once`
623-
+ ` in the rush.json configuration file.`);
624-
}
625-
this._projectsByName.set(project.packageName, project);
626-
}
627-
628-
for (const project of this._projects) {
629-
project.cyclicDependencyProjects.forEach((cyclicDependencyProject: string) => {
630-
if (!this.getProjectByName(cyclicDependencyProject)) {
631-
throw new Error(`In rush.json, the "${cyclicDependencyProject}" project does not exist,`
632-
+ ` but was referenced by the cyclicDependencyProjects for ${project.packageName}`);
633-
}
634-
});
635-
636-
// Compute the downstream dependencies within the list of Rush projects.
637-
this._populateDownstreamDependencies(project.packageJson.dependencies, project.packageName);
638-
this._populateDownstreamDependencies(project.packageJson.devDependencies, project.packageName);
639-
}
640-
641-
// Example: "./common/config/rush/pinnedVersions.json"
642-
const pinnedVersionsFile: string = path.join(this.commonRushConfigFolder, RushConstants.pinnedVersionsFilename);
643-
this._pinnedVersions = PinnedVersionsConfiguration.tryLoadFromFile(pinnedVersionsFile);
644-
}
645645
}

apps/rush-lib/src/data/VersionPolicy.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ export abstract class VersionPolicy {
4444
public static load(versionPolicyJson: IVersionPolicyJson): VersionPolicy {
4545
const definition: VersionPolicyDefinitionName = VersionPolicyDefinitionName[versionPolicyJson.definitionName];
4646
if (definition === VersionPolicyDefinitionName.lockStepVersion) {
47+
// tslint:disable-next-line:no-use-before-declare
4748
return new LockStepVersionPolicy(versionPolicyJson as ILockStepVersionJson);
4849
} else if (definition === VersionPolicyDefinitionName.individualVersion) {
50+
// tslint:disable-next-line:no-use-before-declare
4951
return new IndividualVersionPolicy(versionPolicyJson as IIndividualVersionJson);
5052
}
53+
5154
return undefined;
5255
}
5356

apps/rush-lib/src/data/test/RushConfiguration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import RushConfigurationProject from '../RushConfigurationProject';
1010
import * as path from 'path';
1111
import Utilities from '../../utilities/Utilities';
1212

13-
function normalizePathForComparison(path: string): string {
14-
return Utilities.getAllReplaced(path, '\\', '/').toUpperCase();
13+
function normalizePathForComparison(pathToNormalize: string): string {
14+
return Utilities.getAllReplaced(pathToNormalize, '\\', '/').toUpperCase();
1515
}
1616

1717
function assertPathProperty(validatedPropertyName: string, absolutePath: string, relativePath: string): void {

apps/rush-lib/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export {
4141

4242
export {
4343
VersionMismatchFinder
44-
} from './data/VersionMismatchFinder'
44+
} from './data/VersionMismatchFinder';
4545

4646
export {
4747
ErrorDetectionMode,

apps/rush-lib/src/utilities/JsonSchemaValidator.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,19 @@ export default class JsonSchemaValidator {
4343
buffer = JsonSchemaValidator._formatErrorDetails(errorDetail.inner, indent + ' ', buffer);
4444
}
4545
}
46+
4647
return buffer;
4748
}
4849

49-
public validateObject(jsonObject: Object, errorCallback: ValidateErrorCallback): void {
50+
private constructor(schemaObject: Object) {
51+
this._schemaObject = schemaObject;
52+
this._validator = new Validator({
53+
breakOnFirstError: true,
54+
noTypeless: true
55+
});
56+
}
5057

58+
public validateObject(jsonObject: Object, errorCallback: ValidateErrorCallback): void {
5159
// Remove the $schema reference that appears in the configuration object (used for IntelliSense),
5260
// since we are replacing it with the precompiled version. The validator.setRemoteReference()
5361
// API is a better way to handle this, but we'd first need to publish the schema file
@@ -63,12 +71,4 @@ export default class JsonSchemaValidator {
6371
errorCallback(buffer);
6472
}
6573
}
66-
67-
private constructor(schemaObject: Object) {
68-
this._schemaObject = schemaObject;
69-
this._validator = new Validator({
70-
breakOnFirstError: true,
71-
noTypeless: true
72-
});
73-
}
7474
}

apps/rush/src/utilities/Package.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ export default class Package {
197197
return Package.createFromNpm(npmPackage);
198198
}
199199

200+
private constructor(name: string, version: string, dependencies: IPackageDependency[], folderPath: string) {
201+
this.name = name;
202+
this.version = version;
203+
this.dependencies = dependencies.slice(0); // clone the array
204+
this.folderPath = folderPath;
205+
this.parent = undefined;
206+
this.children = [];
207+
this._childrenByName = new Map<string, Package>();
208+
}
209+
200210
public get nameAndVersion(): string {
201211
let result: string = '';
202212

@@ -292,16 +302,6 @@ export default class Package {
292302
child.printTree(indent + ' ');
293303
}
294304
}
295-
296-
private constructor(name: string, version: string, dependencies: IPackageDependency[], folderPath: string) {
297-
this.name = name;
298-
this.version = version;
299-
this.dependencies = dependencies.slice(0); // clone the array
300-
this.folderPath = folderPath;
301-
this.parent = undefined;
302-
this.children = [];
303-
this._childrenByName = new Map<string, Package>();
304-
}
305305
}
306306

307307
/**

0 commit comments

Comments
 (0)