Skip to content

Commit

Permalink
Remove setting linting.lintOnTextChange as it was never implemented (#…
Browse files Browse the repository at this point in the history
…315)

Fixes #313 
The setting linting.lintOnTextChange is deprecated as it was never implemented.
  • Loading branch information
DonJayamanne authored Nov 28, 2017
1 parent c1edd58 commit e2218b1
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 30 deletions.
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const hygiene = exports.hygiene = (some, options) => {
}
};
}
const tsProject = ts.createProject('tsconfig.json', { strict: true, noImplicitAny: false });
const tsProject = ts.createProject('tsconfig.json', { strict: true, noImplicitAny: false, noImplicitThis: false });
const reporter = customReporter();
return tsProject(reporter);
}
Expand Down Expand Up @@ -231,7 +231,7 @@ function run(lintOnlyModifiedFiles, doNotExit) {
if (lintOnlyModifiedFiles && doNotExit) {
console.log('Watching for changes...');
}
}
}
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
exitProcessOnError();
Expand Down
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -957,12 +957,6 @@
"description": "Whether to lint Python files using mypy.",
"scope": "resource"
},
"python.linting.lintOnTextChange": {
"type": "boolean",
"default": true,
"description": "Whether to lint Python files when modified.",
"scope": "resource"
},
"python.linting.lintOnSave": {
"type": "boolean",
"default": true,
Expand Down
3 changes: 1 addition & 2 deletions src/client/common/configSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export interface ILintingSettings {
flake8Args: string[];
pydocstyleEnabled: boolean;
pydocstyleArgs: string[];
lintOnTextChange: boolean;
lintOnSave: boolean;
maxNumberOfProblems: number;
pylintCategorySeverity: IPylintCategorySeverity;
Expand Down Expand Up @@ -242,7 +241,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
enabledWithoutWorkspace: false,
ignorePatterns: [],
flake8Args: [], flake8Enabled: false, flake8Path: 'flake',
lintOnSave: false, lintOnTextChange: false, maxNumberOfProblems: 100,
lintOnSave: false, maxNumberOfProblems: 100,
mypyArgs: [], mypyEnabled: false, mypyPath: 'mypy',
outputWindow: 'python', pep8Args: [], pep8Enabled: false, pep8Path: 'pep8',
pylamaArgs: [], pylamaEnabled: false, pylamaPath: 'pylama',
Expand Down
35 changes: 25 additions & 10 deletions src/client/common/featureDeprecationManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { commands, Disposable, window, workspace } from 'vscode';
import { commands, Disposable, window, workspace, WorkspaceConfiguration } from 'vscode';
import { launch } from './net/browser';
import { IPersistentStateFactory } from './persistentState';

Expand All @@ -10,7 +10,12 @@ type deprecatedFeatureInfo = {
message: string;
moreInfoUrl: string;
commands?: string[];
setting?: string;
setting?: deprecatedSettingAndValue;
};

type deprecatedSettingAndValue = {
setting: string;
values?: {}[];
};

const jupyterDeprecationInfo: deprecatedFeatureInfo = {
Expand All @@ -27,7 +32,13 @@ const deprecatedFeatures: deprecatedFeatureInfo[] = [
doNotDisplayPromptStateKey: 'SHOW_DEPRECATED_FEATURE_PROMPT_FORMAT_ON_SAVE',
message: 'The setting \'python.formatting.formatOnSave\' is deprecated, please use \'editor.formatOnSave\'.',
moreInfoUrl: 'https://github.com/Microsoft/vscode-python/issues/309',
setting: 'formatting.formatOnSave'
setting: { setting: 'formatting.formatOnSave', values: ['true', true] }
},
{
doNotDisplayPromptStateKey: 'SHOW_DEPRECATED_FEATURE_PROMPT_LINT_ON_TEXT_CHANGE',
message: 'The setting \'python.linting.lintOnTextChange\' is deprecated, please enable \'python.linting.lintOnSave\' and \'files.autoSave\'.',
moreInfoUrl: 'https://github.com/Microsoft/vscode-python/issues/313',
setting: { setting: 'linting.lintOnTextChange', values: ['true', true] }
}
];

Expand All @@ -37,7 +48,6 @@ export interface IFeatureDeprecationManager extends Disposable {

export class FeatureDeprecationManager implements IFeatureDeprecationManager {
private disposables: Disposable[] = [];
private settingDeprecationNotified: string[] = [];
constructor(private persistentStateFactory: IPersistentStateFactory, private jupyterExtensionInstalled: boolean) { }
public dispose() {
this.disposables.forEach(disposable => disposable.dispose());
Expand All @@ -59,26 +69,31 @@ export class FeatureDeprecationManager implements IFeatureDeprecationManager {
}
}
private checkAndNotifyDeprecatedSetting(deprecatedInfo: deprecatedFeatureInfo) {
const setting = deprecatedInfo.setting!;
let notify = false;
if (Array.isArray(workspace.workspaceFolders) && workspace.workspaceFolders.length > 0) {
workspace.workspaceFolders.forEach(workspaceFolder => {
if (notify) {
return;
}
const pythonConfig = workspace.getConfiguration('python', workspaceFolder.uri);
notify = pythonConfig.has(setting) && this.settingDeprecationNotified.indexOf(setting) === -1;
notify = this.isDeprecatedSettingAndValueUsed(workspace.getConfiguration('python', workspaceFolder.uri), deprecatedInfo.setting!);
});
} else {
const pythonConfig = workspace.getConfiguration('python');
notify = pythonConfig.has(setting) && this.settingDeprecationNotified.indexOf(setting) === -1;
notify = this.isDeprecatedSettingAndValueUsed(workspace.getConfiguration('python'), deprecatedInfo.setting!);
}

if (notify) {
this.settingDeprecationNotified.push(setting);
this.notifyDeprecation(deprecatedInfo);
}
}
private isDeprecatedSettingAndValueUsed(pythonConfig: WorkspaceConfiguration, deprecatedSetting: deprecatedSettingAndValue) {
if (!pythonConfig.has(deprecatedSetting.setting)) {
return false;
}
if (!Array.isArray(deprecatedSetting.values) || deprecatedSetting.values.length === 0) {
return true;
}
return deprecatedSetting.values.indexOf(pythonConfig.get(deprecatedSetting.setting)!) >= 0;
}
private async notifyDeprecation(deprecatedInfo: deprecatedFeatureInfo) {
const notificationPromptEnabled = this.persistentStateFactory.createGlobalPersistentState(deprecatedInfo.doNotDisplayPromptStateKey, true);
if (!notificationPromptEnabled.value) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const fileInNonRootWorkspace = path.join(__dirname, '..', '..', 'src', 'test', '
export const rootWorkspaceUri = getWorkspaceRoot();

export type PythonSettingKeys = 'workspaceSymbols.enabled' | 'pythonPath' |
'linting.lintOnSave' | 'linting.lintOnTextChange' |
'linting.lintOnSave' |
'linting.enabled' | 'linting.pylintEnabled' |
'linting.flake8Enabled' | 'linting.pep8Enabled' | 'linting.pylamaEnabled' |
'linting.prospectorEnabled' | 'linting.pydocstyleEnabled' | 'linting.mypyEnabled' |
Expand Down
11 changes: 2 additions & 9 deletions src/test/linters/lint.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as assert from 'assert';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as vscode from 'vscode';
import { PythonSettings } from '../../client/common/configSettings';
Expand All @@ -22,7 +21,6 @@ const pep8ConfigPath = path.join(pythoFilesPath, 'pep8config');
const pydocstyleConfigPath27 = path.join(pythoFilesPath, 'pydocstyleconfig27');
const pylintConfigPath = path.join(pythoFilesPath, 'pylintconfig');
const fileToLint = path.join(pythoFilesPath, 'file.py');
let pylintFileToLintLines: string[] = [];

const pylintMessagesToBeReturned: baseLinter.ILintMessage[] = [
{ line: 24, column: 0, severity: baseLinter.LintMessageSeverity.Information, code: 'I0011', message: 'Locally disabling no-member (E1101)', provider: '', type: '' },
Expand Down Expand Up @@ -114,7 +112,6 @@ suite('Linting', () => {
const isPython3Deferred = createDeferred<boolean>();
const isPython3 = isPython3Deferred.promise;
suiteSetup(async () => {
pylintFileToLintLines = fs.readFileSync(fileToLint).toString('utf-8').split(/\r?\n/g);
await initialize();
const version = await execPythonFile(fileToLint, PythonSettings.getInstance(vscode.Uri.file(fileToLint)).pythonPath, ['--version'], __dirname, true);
isPython3Deferred.resolve(version.indexOf('3.') >= 0);
Expand All @@ -135,7 +132,6 @@ suite('Linting', () => {
await updateSetting('linting.enabled', true, rootWorkspaceUri, vscode.ConfigurationTarget.WorkspaceFolder);
}
await updateSetting('linting.lintOnSave', false, rootWorkspaceUri, vscode.ConfigurationTarget.Workspace);
await updateSetting('linting.lintOnTextChange', false, rootWorkspaceUri, vscode.ConfigurationTarget.Workspace);
await updateSetting('linting.pylintEnabled', false, rootWorkspaceUri, vscode.ConfigurationTarget.Workspace);
await updateSetting('linting.flake8Enabled', false, rootWorkspaceUri, vscode.ConfigurationTarget.Workspace);
await updateSetting('linting.pep8Enabled', false, rootWorkspaceUri, vscode.ConfigurationTarget.Workspace);
Expand All @@ -146,7 +142,6 @@ suite('Linting', () => {

if (IS_MULTI_ROOT_TEST) {
await updateSetting('linting.lintOnSave', false, rootWorkspaceUri, vscode.ConfigurationTarget.WorkspaceFolder);
await updateSetting('linting.lintOnTextChange', false, rootWorkspaceUri, vscode.ConfigurationTarget.WorkspaceFolder);
await updateSetting('linting.pylintEnabled', false, rootWorkspaceUri, vscode.ConfigurationTarget.WorkspaceFolder);
await updateSetting('linting.flake8Enabled', false, rootWorkspaceUri, vscode.ConfigurationTarget.WorkspaceFolder);
await updateSetting('linting.pep8Enabled', false, rootWorkspaceUri, vscode.ConfigurationTarget.WorkspaceFolder);
Expand All @@ -164,8 +159,7 @@ suite('Linting', () => {
const messages = await linter.lint(editor.document, cancelToken.token);
if (enabled) {
assert.notEqual(messages.length, 0, `No linter errors when linter is enabled, Output - ${output.output}`);
}
else {
} else {
assert.equal(messages.length, 0, `Errors returned when linter is disabled, Output - ${output.output}`);
}
}
Expand Down Expand Up @@ -217,8 +211,7 @@ suite('Linting', () => {
const messages = await linter.lint(editor.document, cancelToken.token);
if (messagesToBeReceived.length === 0) {
assert.equal(messages.length, 0, `No errors in linter, Output - ${outputChannel.output}`);
}
else {
} else {
if (outputChannel.output.indexOf('ENOENT') === -1) {
// Pylint for Python Version 2.7 could return 80 linter messages, where as in 3.5 it might only return 1.
// Looks like pylint stops linting as soon as it comes across any ERRORS.
Expand Down

0 comments on commit e2218b1

Please sign in to comment.