Skip to content

Commit fba0543

Browse files
author
Kartik Raj
authored
Include pylintrc (microsoft#5369)
1 parent 809b259 commit fba0543

File tree

3 files changed

+16
-49
lines changed

3 files changed

+16
-49
lines changed

src/client/linters/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@ export const LINTERID_BY_PRODUCT = new Map<Product, LinterId>([
1717
[Product.pydocstyle, 'pydocstyle'],
1818
[Product.pylama, 'pylama']
1919
]);
20-
21-
export const PYLINT_CONFIG = '.pylintrc';

src/client/linters/linterAvailability.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ import * as path from 'path';
88
import { Uri } from 'vscode';
99
import { IApplicationShell, IWorkspaceService } from '../common/application/types';
1010
import '../common/extensions';
11-
import { traceError } from '../common/logger';
11+
import { traceDecorators } from '../common/logger';
1212
import { IFileSystem } from '../common/platform/types';
13-
import { IConfigurationService, IPersistentStateFactory, Product } from '../common/types';
13+
import { IConfigurationService, IPersistentStateFactory } from '../common/types';
1414
import { Common, Linters } from '../common/utils/localize';
1515
import { sendTelemetryEvent } from '../telemetry';
1616
import { EventName } from '../telemetry/constants';
17-
import { PYLINT_CONFIG } from './constants';
1817
import { IAvailableLinterActivator, ILinterInfo } from './types';
1918

2019
const doNotDisplayPromptStateKey = 'MESSAGE_KEY_FOR_CONFIGURE_AVAILABLE_LINTER_PROMPT';
@@ -50,7 +49,7 @@ export class AvailableLinterActivator implements IAvailableLinterActivator {
5049
}
5150

5251
// Is the linter available in the current workspace?
53-
if (await this.isLinterAvailable(linterInfo.product, resource)) {
52+
if (await this.isLinterAvailable(linterInfo, resource)) {
5453

5554
// great, it is - ask the user if they'd like to enable it.
5655
return this.promptToConfigureAvailableLinter(linterInfo);
@@ -96,18 +95,18 @@ export class AvailableLinterActivator implements IAvailableLinterActivator {
9695
* @param linterProduct Linter to check in the current workspace environment.
9796
* @param resource Context information for workspace.
9897
*/
99-
public async isLinterAvailable(linterProduct: Product, resource?: Uri): Promise<boolean | undefined> {
98+
@traceDecorators.error('Failed to discover if linter pylint is available')
99+
public async isLinterAvailable(linterInfo: ILinterInfo, resource?: Uri): Promise<boolean | undefined> {
100100
if (!this.workspaceService.hasWorkspaceFolders) {
101101
return false;
102102
}
103103
const workspaceFolder = resource ? this.workspaceService.getWorkspaceFolder(resource)! : this.workspaceService.workspaceFolders![0];
104-
const filePath = path.join(workspaceFolder.uri.fsPath, PYLINT_CONFIG);
105-
return this.fs.fileExists(filePath)
106-
.catch((reason) => {
107-
// report and continue, assume the linter is unavailable.
108-
traceError(`[WARNING]: Failed to discover if linter ${linterProduct} is installed.`, reason);
109-
return false;
110-
});
104+
let isAvailable = false;
105+
for (const configName of linterInfo.configFileNames) {
106+
const configPath = path.join(workspaceFolder.uri.fsPath, configName);
107+
isAvailable = isAvailable || await this.fs.fileExists(configPath);
108+
}
109+
return isAvailable;
111110
}
112111

113112
/**

src/test/linters/linter.availability.unit.test.ts

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ suite('Linter Availability Provider tests', () => {
284284
.verifiable(TypeMoq.Times.once());
285285
fsMock.setup(fs => fs.fileExists(TypeMoq.It.isAny()))
286286
.returns(async () => options.linterIsInstalled)
287-
.verifiable(TypeMoq.Times.once());
287+
.verifiable(TypeMoq.Times.atLeastOnce());
288288

289289
setupConfigurationServiceForJediSettingsTest(options.jediEnabledValue, configServiceMock);
290290
setupWorkspaceMockForLinterConfiguredTests(
@@ -413,7 +413,7 @@ suite('Linter Availability Provider tests', () => {
413413

414414
// perform test
415415
const availabilityProvider = new AvailableLinterActivator(appShellMock.object, fsMock.object, workspaceServiceMock.object, configServiceMock.object, factoryMock.object);
416-
const result = await availabilityProvider.isLinterAvailable(linterInfo.product);
416+
const result = await availabilityProvider.isLinterAvailable(linterInfo);
417417

418418
expect(result).to.equal(expectedResult, 'Expected promptToConfigureAvailableLinter to return true because the configuration was updated.');
419419
fsMock.verifyAll();
@@ -431,37 +431,7 @@ suite('Linter Availability Provider tests', () => {
431431

432432
// perform test
433433
const availabilityProvider = new AvailableLinterActivator(appShellMock.object, fsMock.object, workspaceServiceMock.object, configServiceMock.object, factoryMock.object);
434-
const result = await availabilityProvider.isLinterAvailable(linterInfo.product);
435-
436-
expect(result).to.equal(expectedResult, 'Expected promptToConfigureAvailableLinter to return true because the configuration was updated.');
437-
fsMock.verifyAll();
438-
workspaceServiceMock.verifyAll();
439-
});
440-
441-
test('Discovery of linter is available in the environment returns false when it fails', async () => {
442-
// set expectations
443-
const expectedResult = false;
444-
445-
// arrange
446-
const [appShellMock, fsMock, workspaceServiceMock, configServiceMock, factoryMock, linterInfo] = getDependenciesForAvailabilityTests();
447-
const workspaceFolder = { uri: Uri.parse('full/path/to/workspace'), name: '', index: 0 };
448-
workspaceServiceMock
449-
.setup(c => c.hasWorkspaceFolders)
450-
.returns(() => true)
451-
.verifiable(TypeMoq.Times.once());
452-
workspaceServiceMock
453-
.setup(c => c.workspaceFolders)
454-
.returns(() => [workspaceFolder]);
455-
workspaceServiceMock
456-
.setup(c => c.getWorkspaceFolder(TypeMoq.It.isAny()))
457-
.returns(() => workspaceFolder);
458-
fsMock.setup(fs => fs.fileExists(TypeMoq.It.isAny()))
459-
.returns(async () => Promise.reject('error testfail'))
460-
.verifiable(TypeMoq.Times.once());
461-
462-
// perform test
463-
const availabilityProvider = new AvailableLinterActivator(appShellMock.object, fsMock.object, workspaceServiceMock.object, configServiceMock.object, factoryMock.object);
464-
const result = await availabilityProvider.isLinterAvailable(linterInfo.product);
434+
const result = await availabilityProvider.isLinterAvailable(linterInfo);
465435

466436
expect(result).to.equal(expectedResult, 'Expected promptToConfigureAvailableLinter to return true because the configuration was updated.');
467437
fsMock.verifyAll();
@@ -532,8 +502,8 @@ function setupInstallerForAvailabilityTest(_linterInfo: LinterInfo, linterIsInst
532502
.setup(c => c.getWorkspaceFolder(TypeMoq.It.isAny()))
533503
.returns(() => workspaceFolder);
534504
fsMock.setup(fs => fs.fileExists(TypeMoq.It.isAny()))
535-
.returns(async () => linterIsInstalled)
536-
.verifiable(TypeMoq.Times.once());
505+
.returns(() => Promise.resolve(linterIsInstalled))
506+
.verifiable(TypeMoq.Times.atLeastOnce());
537507

538508
return fsMock;
539509
}

0 commit comments

Comments
 (0)