Skip to content

Commit

Permalink
Remove stdlib setting
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Oct 20, 2023
1 parent 9c03290 commit 36b8e52
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 129 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
A Visual Studio Code extension with support for the `pylint` linter. The extension ships with `pylint=3.0.1`.

Note:

- This extension is supported for all [actively supported versions](https://devguide.python.org/#status-of-python-branches) of the `Python` language (i.e., Python >= 3.8).
- By default, this extension uses the shipped `pylint` version. However, you can use `pylint` from your environment by setting `pylint.importStrategy` to `fromEnvironment`. Alternatively, you can use a custom `pylint` executable by setting `pylint.path`.
- Minimum supported version of `pylint` is `2.12.2`.
Expand All @@ -26,7 +27,6 @@ If you want to disable pylint, you can [disable this extension](https://code.vis
| pylint.showNotification | `off` | Setting to control when a notification is shown. |
| pylint.lintOnChange | `false` | (experimental) Setting to control linting on change feature. |
| pylint.ignorePatterns | `[]` | Glob patterns used to exclude files and directories from being linted. |
| pylint.includeStdLib | `false` | Controls whether to perform linting on Python's standard library files or directories. |

## Commands

Expand Down
7 changes: 2 additions & 5 deletions bundled/tool/lsp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,6 @@ def _get_global_defaults():
"importStrategy": GLOBAL_SETTINGS.get("importStrategy", "useBundled"),
"showNotifications": GLOBAL_SETTINGS.get("showNotifications", "off"),
"extraPaths": GLOBAL_SETTINGS.get("extraPaths", []),
"includeStdLib": False,
}


Expand Down Expand Up @@ -683,13 +682,11 @@ def _run_tool_on_document(
log_warning(f"Skipping notebook cells [Not Supported]: {str(document.uri)}")
return None

if not settings["includeStdLib"] and utils.is_stdlib_file(document.path):
if utils.is_stdlib_file(document.path):
log_warning(
f"Skipping standard library file (stdlib excluded): {document.path}"
)
log_warning(
"You can include stdlib files by setting `pylint.includeStdLib` to true."
)

return None

if utils.is_match(settings["ignorePatterns"], document.path):
Expand Down
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,6 @@
],
"scope": "machine",
"type": "string"
},
"pylint.includeStdLib": {
"default": false,
"description": "%settings.includeStdLib.description%",
"scope": "resource",
"type": "boolean"
}
}
},
Expand Down
3 changes: 1 addition & 2 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
"settings.showNotifications.off.description": "All notifications are turned off, any errors or warning are still available in the logs.",
"settings.showNotifications.onError.description": "Notifications are shown only in the case of an error.",
"settings.showNotifications.onWarning.description": "Notifications are shown for errors and warnings.",
"settings.showNotifications.always.description": "Notifications are shown for anything that the server chooses to show.",
"settings.includeStdLib.description": "Controls whether to filter out files from standard library from being linted."
"settings.showNotifications.always.description": "Notifications are shown for anything that the server chooses to show."
}
4 changes: 0 additions & 4 deletions src/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export interface ISettings {
interpreter: string[];
importStrategy: string;
showNotifications: string;
includeStdLib: boolean;
extraPaths: string[];
}

Expand Down Expand Up @@ -138,7 +137,6 @@ export async function getWorkspaceSettings(
importStrategy: config.get<string>('importStrategy', 'useBundled'),
showNotifications: config.get<string>('showNotifications', 'off'),
extraPaths: resolveVariables(extraPaths, workspace),
includeStdLib: config.get<boolean>('includeStdLib', false),
};
return workspaceSetting;
}
Expand Down Expand Up @@ -170,7 +168,6 @@ export async function getGlobalSettings(namespace: string, includeInterpreter?:
importStrategy: getGlobalValue<string>(config, 'importStrategy', 'fromEnvironment'),
showNotifications: getGlobalValue<string>(config, 'showNotifications', 'off'),
extraPaths: getGlobalValue<string[]>(config, 'extraPaths', []),
includeStdLib: config.get<boolean>('includeStdLib', false),
};
return setting;
}
Expand All @@ -190,7 +187,6 @@ export function checkIfConfigurationChanged(e: ConfigurationChangeEvent, namespa
`${namespace}.importStrategy`,
`${namespace}.showNotifications`,
`${namespace}.ignorePatterns`,
`${namespace}.includeStdLib`,
`${namespace}.lintOnChange`,
'python.analysis.extraPaths',
];
Expand Down
98 changes: 0 additions & 98 deletions src/test/python_tests/test_linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,104 +480,6 @@ def _handler(params):
assert_that(actual, is_(expected))


@pytest.mark.parametrize("value", [True, False], ids=["include-stdlib", "skip-stdlib"])
def test_stdlib_filtering(value: bool):
"""Test to ensure stdlib filtering setting works."""
contents = TEST_FILE_PATH.read_text(encoding="utf-8")

actual = []
with session.LspSession() as ls_session:
default_init = defaults.vscode_initialize_defaults()
init_options = default_init["initializationOptions"]
init_options["settings"][0]["includeStdLib"] = value
init_options["globalSettings"]["includeStdLib"] = value
ls_session.initialize(default_init)

# trick pylint into thinking the file is stdlib file
FAKE_TEST_URI = utils.as_uri(
str(pathlib.Path(pytest.__file__).parent / "sample.py")
)

done = Event()

def _handler(params):
nonlocal actual
actual = params
done.set()

ls_session.set_notification_callback(session.PUBLISH_DIAGNOSTICS, _handler)

ls_session.notify_did_open(
{
"textDocument": {
"uri": FAKE_TEST_URI,
"languageId": "python",
"version": 1,
"text": contents,
}
}
)

# wait for some time to receive all notifications
done.wait(TIMEOUT)

expected = {
"uri": FAKE_TEST_URI,
"diagnostics": [
{
"range": {
"start": {"line": 0, "character": 0},
"end": {"line": 0, "character": 0},
},
"message": "Missing module docstring",
"severity": 3,
"code": "C0114:missing-module-docstring",
"codeDescription": {
"href": f"{DOCUMENTATION_HOME}/convention/missing-module-docstring.html"
},
"source": LINTER["name"],
},
{
"range": {
"start": {"line": 2, "character": 6},
"end": {
"line": 2,
"character": 7,
},
},
"message": "Undefined variable 'x'",
"severity": 1,
"code": "E0602:undefined-variable",
"codeDescription": {
"href": f"{DOCUMENTATION_HOME}/error/undefined-variable.html"
},
"source": LINTER["name"],
},
{
"range": {
"start": {"line": 0, "character": 0},
"end": {
"line": 0,
"character": 10,
},
},
"message": "Unused import sys",
"severity": 2,
"code": "W0611:unused-import",
"codeDescription": {
"href": f"{DOCUMENTATION_HOME}/warning/unused-import.html"
},
"source": LINTER["name"],
},
],
}

if value:
assert_that(actual, is_(expected))
else:
assert_that(actual, is_({"uri": FAKE_TEST_URI, "diagnostics": []}))


@pytest.mark.parametrize(
"patterns",
[
Expand Down
13 changes: 0 additions & 13 deletions src/test/ts_tests/tests/common/settings.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ suite('Settings Tests', () => {
.setup((c) => c.get('ignorePatterns', []))
.returns(() => [])
.verifiable(TypeMoq.Times.atLeastOnce());
configMock
.setup((c) => c.get('includeStdLib', false))
.returns(() => false)
.verifiable(TypeMoq.Times.atLeastOnce());

pythonConfigMock
.setup((c) => c.get('linting.pylintArgs', []))
Expand All @@ -113,7 +109,6 @@ suite('Settings Tests', () => {
assert.deepStrictEqual(settings.workspace, workspace1.uri.toString());
assert.deepStrictEqual(settings.extraPaths, []);
assert.deepStrictEqual(settings.ignorePatterns, []);
assert.deepStrictEqual(settings.includeStdLib, false);

configMock.verifyAll();
pythonConfigMock.verifyAll();
Expand Down Expand Up @@ -163,10 +158,6 @@ suite('Settings Tests', () => {
.setup((c) => c.get('ignorePatterns', []))
.returns(() => [])
.verifiable(TypeMoq.Times.atLeastOnce());
configMock
.setup((c) => c.get('includeStdLib', false))
.returns(() => false)
.verifiable(TypeMoq.Times.atLeastOnce());

pythonConfigMock
.setup((c) => c.get('linting.pylintArgs', []))
Expand Down Expand Up @@ -255,10 +246,6 @@ suite('Settings Tests', () => {
.setup((c) => c.get('ignorePatterns', []))
.returns(() => [])
.verifiable(TypeMoq.Times.atLeastOnce());
configMock
.setup((c) => c.get('includeStdLib', false))
.returns(() => false)
.verifiable(TypeMoq.Times.atLeastOnce());

pythonConfigMock
.setup((c) => c.get<string[]>('linting.pylintArgs', []))
Expand Down

0 comments on commit 36b8e52

Please sign in to comment.