Skip to content

Commit a5053a6

Browse files
Use clearer labels for the enable/disable linting command. (#15162)
(for #8800)
1 parent 4d539ba commit a5053a6

4 files changed

Lines changed: 28 additions & 16 deletions

File tree

news/2 Fixes/8800.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Refactored the Enable Linting command to provide the user with a choice of "Enable" or "Disable" linting to make it more intuitive. (thanks [henryboisdequin](https://github.com/henryboisdequin))

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"python.command.python.execSelectionInDjangoShell.title": "Run Selection/Line in Django Shell",
3131
"python.command.python.goToPythonObject.title": "Go to Python Object",
3232
"python.command.python.setLinter.title": "Select Linter",
33-
"python.command.python.enableLinting.title": "Enable Linting",
33+
"python.command.python.enableLinting.title": "Enable/Disable Linting",
3434
"python.command.python.runLinting.title": "Run Linting",
3535
"python.command.python.enableSourceMapSupport.title": "Enable Source Map Support For Extension Debugging",
3636
"python.command.python.startPage.open.title": "Open Start Page",

src/client/linters/linterCommands.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class LinterCommands implements IDisposable {
8181
}
8282

8383
public async enableLintingAsync(): Promise<void> {
84-
const options = ['on', 'off'];
84+
const options = ['Enable', 'Disable'];
8585
const current = (await this.linterManager.isLintingEnabled(true, this.settingsUri)) ? options[0] : options[1];
8686

8787
const quickPickOptions: QuickPickOptions = {
@@ -91,8 +91,9 @@ export class LinterCommands implements IDisposable {
9191
};
9292

9393
const selection = await this.appShell.showQuickPick(options, quickPickOptions);
94+
9495
if (selection !== undefined) {
95-
const enable = selection === options[0];
96+
const enable: boolean = selection === options[0];
9697
await this.linterManager.enableLintingAsync(enable, this.settingsUri);
9798
}
9899
}

src/test/linters/linterCommands.unit.test.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@ suite('Linting - Linter Commands', () => {
5353
expect(result).to.be.equal('Hello');
5454
});
5555

56-
async function testEnableLintingWithCurrentState(currentState: boolean, selectedState: 'on' | 'off' | undefined) {
56+
async function testEnableLintingWithCurrentState(
57+
currentState: boolean,
58+
selectedState: 'Enable' | 'Disable' | undefined,
59+
) {
5760
when(manager.isLintingEnabled(true, anything())).thenResolve(currentState);
5861
const expectedQuickPickOptions = {
5962
matchOnDetail: true,
6063
matchOnDescription: true,
61-
placeHolder: `current: ${currentState ? 'on' : 'off'}`,
64+
placeHolder: `current: ${currentState ? 'Enable' : 'Disable'}`,
6265
};
6366
when(shell.showQuickPick(anything(), anything())).thenResolve(selectedState as any);
6467

@@ -67,29 +70,33 @@ suite('Linting - Linter Commands', () => {
6770
verify(shell.showQuickPick(anything(), anything())).once();
6871
const options = capture(shell.showQuickPick).last()[0];
6972
const quickPickOptions = capture(shell.showQuickPick).last()[1];
70-
expect(options).to.deep.equal(['on', 'off']);
73+
expect(options).to.deep.equal(['Enable', 'Disable']);
7174
expect(quickPickOptions).to.deep.equal(expectedQuickPickOptions);
7275

7376
if (selectedState) {
74-
verify(manager.enableLintingAsync(selectedState === 'on', anything())).once();
77+
verify(manager.enableLintingAsync(selectedState === 'Enable', anything())).once();
7578
} else {
7679
verify(manager.enableLintingAsync(anything(), anything())).never();
7780
}
7881
}
79-
test("Enable linting should check if linting is enabled, and display current state of 'on' and select nothing", async () => {
82+
test("Enable linting should check if linting is enabled, and display current state of 'Enable' and select nothing", async () => {
8083
await testEnableLintingWithCurrentState(true, undefined);
8184
});
82-
test("Enable linting should check if linting is enabled, and display current state of 'on' and select 'on'", async () => {
83-
await testEnableLintingWithCurrentState(true, 'on');
85+
86+
test("Enable linting should check if linting is enabled, and display current state of 'Enable' and select 'Enable'", async () => {
87+
await testEnableLintingWithCurrentState(true, 'Enable');
8488
});
85-
test("Enable linting should check if linting is enabled, and display current state of 'on' and select 'off'", async () => {
86-
await testEnableLintingWithCurrentState(true, 'off');
89+
90+
test("Enable linting should check if linting is enabled, and display current state of 'Enable' and select 'Disable'", async () => {
91+
await testEnableLintingWithCurrentState(true, 'Disable');
8792
});
88-
test("Enable linting should check if linting is enabled, and display current state of 'off' and select 'on'", async () => {
89-
await testEnableLintingWithCurrentState(true, 'on');
93+
94+
test("Enable linting should check if linting is enabled, and display current state of 'Disable' and select 'Enable'", async () => {
95+
await testEnableLintingWithCurrentState(true, 'Enable');
9096
});
91-
test("Enable linting should check if linting is enabled, and display current state of 'off' and select 'off'", async () => {
92-
await testEnableLintingWithCurrentState(true, 'off');
97+
98+
test("Enable linting should check if linting is enabled, and display current state of 'Disable' and select 'Disable'", async () => {
99+
await testEnableLintingWithCurrentState(true, 'Disable');
93100
});
94101

95102
test('Set Linter should display a quickpick', async () => {
@@ -108,6 +115,7 @@ suite('Linting - Linter Commands', () => {
108115
const quickPickOptions = capture(shell.showQuickPick).last()[1];
109116
expect(quickPickOptions).to.deep.equal(expectedQuickPickOptions);
110117
});
118+
111119
test('Set Linter should display a quickpick and currently active linter when only one is enabled', async () => {
112120
const linterId = 'Hello World';
113121
const activeLinters: ILinterInfo[] = [{ id: linterId } as any];
@@ -126,6 +134,7 @@ suite('Linting - Linter Commands', () => {
126134
const quickPickOptions = capture(shell.showQuickPick).last()[1];
127135
expect(quickPickOptions).to.deep.equal(expectedQuickPickOptions);
128136
});
137+
129138
test('Set Linter should display a quickpick and with message about multiple linters being enabled', async () => {
130139
const activeLinters: ILinterInfo[] = [{ id: 'linterId' } as any, { id: 'linterId2' } as any];
131140
when(manager.getAllLinterInfos()).thenReturn([]);
@@ -143,6 +152,7 @@ suite('Linting - Linter Commands', () => {
143152
const quickPickOptions = capture(shell.showQuickPick).last()[1];
144153
expect(quickPickOptions).to.deep.equal(expectedQuickPickOptions);
145154
});
155+
146156
test('Selecting a linter should display warning message about multiple linters', async () => {
147157
const linters: ILinterInfo[] = [{ id: '1' }, { id: '2' }, { id: '3', product: 'Three' }] as any;
148158
const activeLinters: ILinterInfo[] = [{ id: '1' }, { id: '3' }] as any;

0 commit comments

Comments
 (0)