Skip to content

Commit 05a3cdd

Browse files
committed
Added new eslint rule to enforce that protected class variables and methods should never start with an underscore. We were somewhat inconsistent here. Fixed up the code to honor this rule.
1 parent c06831d commit 05a3cdd

12 files changed

+223
-230
lines changed

.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"accessor"
7878
],
7979
"modifiers": ["protected"],
80-
"leadingUnderscore": "allow",
80+
"leadingUnderscore": "forbid",
8181
"format": ["camelCase"],
8282
"filter": {
8383
"regex": "^(test_| )",

packages/pyright-internal/src/analyzer/backgroundAnalysisProgram.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class BackgroundAnalysisProgram {
3030
private _console: ConsoleInterface,
3131
private _configOptions: ConfigOptions,
3232
private _importResolver: ImportResolver,
33-
protected _backgroundAnalysis?: BackgroundAnalysisBase,
33+
private _backgroundAnalysis?: BackgroundAnalysisBase,
3434
private _maxAnalysisTime?: MaxAnalysisTime,
3535
private _disableChecker?: boolean,
3636
cacheManager?: CacheManager
@@ -65,6 +65,10 @@ export class BackgroundAnalysisProgram {
6565
return this._backgroundAnalysis;
6666
}
6767

68+
set backgroundAnalysis(value: BackgroundAnalysisBase | undefined) {
69+
this._backgroundAnalysis = value;
70+
}
71+
6872
hasSourceFile(filePath: string): boolean {
6973
return !!this._program.getSourceFile(filePath);
7074
}
@@ -147,7 +151,7 @@ export class BackgroundAnalysisProgram {
147151

148152
startAnalysis(token: CancellationToken): boolean {
149153
if (this._backgroundAnalysis) {
150-
this._backgroundAnalysis.startAnalysis(this._getIndices(), token);
154+
this._backgroundAnalysis.startAnalysis(this.getIndices(), token);
151155
return false;
152156
}
153157

@@ -183,7 +187,7 @@ export class BackgroundAnalysisProgram {
183187
}
184188

185189
getIndexing(filePath: string) {
186-
return this._getIndices()?.getIndex(this._configOptions.findExecEnvironment(filePath).root);
190+
return this.getIndices()?.getIndex(this._configOptions.findExecEnvironment(filePath).root);
187191
}
188192

189193
async getDiagnosticsForRange(filePath: string, range: Range, token: CancellationToken): Promise<Diagnostic[]> {
@@ -244,7 +248,7 @@ export class BackgroundAnalysisProgram {
244248
this._backgroundAnalysis?.shutdown();
245249
}
246250

247-
protected _getIndices(): Indices | undefined {
251+
protected getIndices(): Indices | undefined {
248252
return undefined;
249253
}
250254

packages/pyright-internal/src/analyzer/importResolver.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class ImportResolver {
121121
private _stdlibModules: Set<string> | undefined;
122122
protected cachedParentImportResults: ParentDirectoryCache;
123123

124-
constructor(readonly fileSystem: FileSystem, protected _configOptions: ConfigOptions, readonly host: Host) {
124+
constructor(readonly fileSystem: FileSystem, private _configOptions: ConfigOptions, readonly host: Host) {
125125
this.cachedParentImportResults = new ParentDirectoryCache(() => this.getPythonSearchPaths([]));
126126
}
127127

@@ -145,9 +145,9 @@ export class ImportResolver {
145145
execEnv: ExecutionEnvironment,
146146
moduleDescriptor: ImportedModuleDescriptor
147147
): ImportResult {
148-
// Wrap internal call to _resolveImport() to prevent calling any
148+
// Wrap internal call to resolveImportInternal() to prevent calling any
149149
// child class version of resolveImport().
150-
return this._resolveImport(sourceFilePath, execEnv, moduleDescriptor);
150+
return this.resolveImportInternal(sourceFilePath, execEnv, moduleDescriptor);
151151
}
152152

153153
getCompletionSuggestions(
@@ -445,7 +445,7 @@ export class ImportResolver {
445445

446446
// Resolves the import and returns the path if it exists, otherwise
447447
// returns undefined.
448-
protected _resolveImport(
448+
protected resolveImportInternal(
449449
sourceFilePath: string,
450450
execEnv: ExecutionEnvironment,
451451
moduleDescriptor: ImportedModuleDescriptor
@@ -2297,7 +2297,7 @@ export class ImportResolver {
22972297
.isImportFound;
22982298
}
22992299

2300-
return this._resolveImport(sourceFilePath, execEnv, moduleDescriptor).isImportFound;
2300+
return this.resolveImportInternal(sourceFilePath, execEnv, moduleDescriptor).isImportFound;
23012301
}
23022302

23032303
private _isUniqueValidSuggestion(suggestionToAdd: string, suggestions: Map<string, string>) {

packages/pyright-internal/src/backgroundAnalysisBase.ts

+13-21
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase
287287
private _configOptions: ConfigOptions;
288288
private _program: Program;
289289

290-
protected _importResolver: ImportResolver;
291-
protected _logTracker: LogTracker;
290+
protected importResolver: ImportResolver;
291+
protected logTracker: LogTracker;
292292

293293
protected constructor() {
294294
super(workerData as InitializationData);
@@ -298,12 +298,12 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase
298298
this.log(LogLevel.Info, `Background analysis(${threadId}) root directory: ${data.rootDirectory}`);
299299

300300
this._configOptions = new ConfigOptions(data.rootDirectory);
301-
this._importResolver = this.createImportResolver(this.fs, this._configOptions, this.createHost());
301+
this.importResolver = this.createImportResolver(this.fs, this._configOptions, this.createHost());
302302

303303
const console = this.getConsole();
304-
this._logTracker = new LogTracker(console, `BG(${threadId})`);
304+
this.logTracker = new LogTracker(console, `BG(${threadId})`);
305305

306-
this._program = new Program(this._importResolver, this._configOptions, console, this._logTracker);
306+
this._program = new Program(this.importResolver, this._configOptions, console, this.logTracker);
307307

308308
// Create the extensions bound to the program for this background thread
309309
Extensions.createProgramExtensions(this._program, {
@@ -391,22 +391,18 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase
391391
}
392392

393393
case 'setImportResolver': {
394-
this._importResolver = this.createImportResolver(this.fs, this._configOptions, this.createHost());
394+
this.importResolver = this.createImportResolver(this.fs, this._configOptions, this.createHost());
395395

396-
this.program.setImportResolver(this._importResolver);
396+
this.program.setImportResolver(this.importResolver);
397397
break;
398398
}
399399

400400
case 'setConfigOptions': {
401401
this._configOptions = createConfigOptionsFrom(msg.data);
402402

403-
this._importResolver = this.createImportResolver(
404-
this.fs,
405-
this._configOptions,
406-
this._importResolver.host
407-
);
403+
this.importResolver = this.createImportResolver(this.fs, this._configOptions, this.importResolver.host);
408404
this.program.setConfigOptions(this._configOptions);
409-
this.program.setImportResolver(this._importResolver);
405+
this.program.setImportResolver(this.importResolver);
410406
break;
411407
}
412408

@@ -425,7 +421,7 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase
425421
const { executionRoot } = msg.data;
426422
const execEnv = this._configOptions.getExecutionEnvironments().find((e) => e.root === executionRoot);
427423
if (execEnv) {
428-
this._importResolver.ensurePartialStubPackages(execEnv);
424+
this.importResolver.ensurePartialStubPackages(execEnv);
429425
}
430426
break;
431427
}
@@ -470,7 +466,7 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase
470466
case 'invalidateAndForceReanalysis': {
471467
// Make sure the import resolver doesn't have invalid
472468
// cached entries.
473-
this._importResolver.invalidateCache();
469+
this.importResolver.invalidateCache();
474470

475471
// Mark all files with one or more errors dirty.
476472
this.program.markAllFilesDirty(/* evenIfContentsAreSame */ true, /* indexingNeeded */ msg.data);
@@ -479,12 +475,8 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase
479475

480476
case 'restart': {
481477
// recycle import resolver
482-
this._importResolver = this.createImportResolver(
483-
this.fs,
484-
this._configOptions,
485-
this._importResolver.host
486-
);
487-
this.program.setImportResolver(this._importResolver);
478+
this.importResolver = this.createImportResolver(this.fs, this._configOptions, this.importResolver.host);
479+
this.program.setImportResolver(this.importResolver);
488480
break;
489481
}
490482

packages/pyright-internal/src/common/fullAccessHost.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class LimitedAccessHost extends NoAccessHost {
6060
}
6161

6262
export class FullAccessHost extends LimitedAccessHost {
63-
constructor(protected _fs: FileSystem) {
63+
constructor(protected fs: FileSystem) {
6464
super();
6565
}
6666

@@ -84,7 +84,7 @@ export class FullAccessHost extends LimitedAccessHost {
8484
override getPythonSearchPaths(pythonPath?: string, logInfo?: string[]): PythonPathResult {
8585
const importFailureInfo = logInfo ?? [];
8686
let result = this._executePythonInterpreter(pythonPath, (p) =>
87-
this._getSearchPathResultFromInterpreter(this._fs, p, importFailureInfo)
87+
this._getSearchPathResultFromInterpreter(this.fs, p, importFailureInfo)
8888
);
8989

9090
if (!result) {

packages/pyright-internal/src/common/uriParser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import { FileSystem } from './fileSystem';
1515
import { convertUriToPath } from './pathUtils';
1616

1717
export class UriParser {
18-
constructor(protected readonly _fs: FileSystem) {}
18+
constructor(protected readonly fs: FileSystem) {}
1919

2020
decodeTextDocumentPosition(textDocument: TextDocumentIdentifier, position: Position) {
2121
const filePath = this.decodeTextDocumentUri(textDocument.uri);
2222
return { filePath, position };
2323
}
2424

2525
decodeTextDocumentUri(uriString: string) {
26-
return convertUriToPath(this._fs, uriString);
26+
return convertUriToPath(this.fs, uriString);
2727
}
2828

2929
isLocal(uri: URI | string | undefined) {

0 commit comments

Comments
 (0)