From e2218b1b4a00402e777a966b0cde4fb438df52b1 Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Tue, 28 Nov 2017 15:38:51 -0800 Subject: [PATCH] Remove setting linting.lintOnTextChange as it was never implemented (#315) Fixes #313 The setting linting.lintOnTextChange is deprecated as it was never implemented. --- gulpfile.js | 4 +-- package.json | 6 ---- src/client/common/configSettings.ts | 3 +- .../common/featureDeprecationManager.ts | 35 +++++++++++++------ src/test/common.ts | 2 +- src/test/linters/lint.test.ts | 11 ++---- 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 6ddd833657d5..514c619a004c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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); } @@ -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(); diff --git a/package.json b/package.json index 35ee03f90a03..d97c4fe8f15f 100644 --- a/package.json +++ b/package.json @@ -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, diff --git a/src/client/common/configSettings.ts b/src/client/common/configSettings.ts index bc1a15e2f037..c21649159419 100644 --- a/src/client/common/configSettings.ts +++ b/src/client/common/configSettings.ts @@ -84,7 +84,6 @@ export interface ILintingSettings { flake8Args: string[]; pydocstyleEnabled: boolean; pydocstyleArgs: string[]; - lintOnTextChange: boolean; lintOnSave: boolean; maxNumberOfProblems: number; pylintCategorySeverity: IPylintCategorySeverity; @@ -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', diff --git a/src/client/common/featureDeprecationManager.ts b/src/client/common/featureDeprecationManager.ts index 1a139b53647a..2e72a6fee614 100644 --- a/src/client/common/featureDeprecationManager.ts +++ b/src/client/common/featureDeprecationManager.ts @@ -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'; @@ -10,7 +10,12 @@ type deprecatedFeatureInfo = { message: string; moreInfoUrl: string; commands?: string[]; - setting?: string; + setting?: deprecatedSettingAndValue; +}; + +type deprecatedSettingAndValue = { + setting: string; + values?: {}[]; }; const jupyterDeprecationInfo: deprecatedFeatureInfo = { @@ -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] } } ]; @@ -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()); @@ -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) { diff --git a/src/test/common.ts b/src/test/common.ts index 15d2a4727ea7..fef6a58aa34b 100644 --- a/src/test/common.ts +++ b/src/test/common.ts @@ -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' | diff --git a/src/test/linters/lint.test.ts b/src/test/linters/lint.test.ts index 6eaa262f398e..80bbf8be4578 100644 --- a/src/test/linters/lint.test.ts +++ b/src/test/linters/lint.test.ts @@ -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'; @@ -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: '' }, @@ -114,7 +112,6 @@ suite('Linting', () => { const isPython3Deferred = createDeferred(); 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); @@ -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); @@ -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); @@ -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}`); } } @@ -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.