diff --git a/package.json b/package.json index 924e55a..3e855f7 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,42 @@ "scope": "resource", "type": "array" }, + "ruff.lint.preview": { + "default": null, + "markdownDescription": "Enable [preview mode](https://docs.astral.sh/ruff/settings/#lint_preview) for the linter; enables unstable rules and fixes.", + "scope": "resource", + "type": "boolean" + }, + "ruff.lint.select": { + "default": null, + "markdownDescription": "Set rule codes to enable. Use `ALL` to enable all rules. See [the documentation](https://docs.astral.sh/ruff/settings/#lint_select) for more details.", + "examples": [ + ["E4", "E7", "E9", "F"] + ], + "items": { + "type": "string" + }, + "scope": "resource", + "type": "array" + }, + "ruff.lint.extendSelect": { + "default": null, + "markdownDescription": "Enable additional rule codes on top of existing configuration, instead of overriding it. Use `ALL` to enable all rules.", + "items": { + "type": "string" + }, + "scope": "resource", + "type": "array" + }, + "ruff.lint.ignore": { + "default": null, + "markdownDescription": "Set rule codes to disable. See [the documentation](https://docs.astral.sh/ruff/settings/#lint_ignore) for more details.", + "items": { + "type": "string" + }, + "scope": "resource", + "type": "array" + }, "ruff.run": { "default": "onType", "markdownDescription": "Run Ruff on every keystroke (`onType`) or on save (`onSave`).", @@ -134,6 +170,12 @@ "scope": "resource", "type": "array" }, + "ruff.format.preview": { + "default": null, + "markdownDescription": "Enable [preview mode](https://docs.astral.sh/ruff/settings/#format_preview) for the formatter; enables unstable formatting.", + "scope": "resource", + "type": "boolean" + }, "ruff.path": { "default": [], "markdownDescription": "Path to a custom `ruff` executable, e.g., `[\"/path/to/ruff\"]`.", @@ -250,6 +292,23 @@ "scope": "window", "type": "string" }, + "ruff.exclude": { + "default": null, + "items": { + "type": "string" + }, + "markdownDescription": "Set paths for the linter and formatter to ignore. See [the documentation](https://docs.astral.sh/ruff/settings/#lint_exclude) for more details.", + "type": "array", + "scope": "resource" + }, + "ruff.lineLength": { + "default": null, + "minimum": 1, + "maximum": 320, + "markdownDescription": "Set the [line length](https://docs.astral.sh/ruff/settings/#line-length) used by the formatter and linter. Must be greater than 0 and less than or equal to 320.", + "scope": "resource", + "type": ["integer", "null"] + }, "ruff.enableExperimentalFormatter": { "default": false, "markdownDescription": "Controls whether Ruff registers as capable of code formatting.", diff --git a/src/common/settings.ts b/src/common/settings.ts index d1125aa..a3c0afa 100644 --- a/src/common/settings.ts +++ b/src/common/settings.ts @@ -26,10 +26,15 @@ type Lint = { enable?: boolean; args?: string[]; run?: Run; + preview?: boolean; + select?: string[]; + extendSelect?: string[]; + ignore?: string[]; }; type Format = { args?: string[]; + preview?: boolean; }; export interface ISettings { @@ -47,6 +52,8 @@ export interface ISettings { fixAll: boolean; lint: Lint; format: Format; + exclude?: string[]; + lineLength?: number; } export function getExtensionSettings(namespace: string): Promise { @@ -111,14 +118,21 @@ export async function getWorkspaceSettings( getPreferredWorkspaceSetting("lint.args", "args", config) ?? [], workspace, ), + preview: config.get("lint.preview"), + select: config.get("lint.select"), + extendSelect: config.get("lint.extendSelect"), + ignore: config.get("lint.ignore"), }, format: { args: resolveVariables(config.get("format.args") ?? [], workspace), + preview: config.get("format.preview"), }, enable: config.get("enable") ?? true, organizeImports: config.get("organizeImports") ?? true, fixAll: config.get("fixAll") ?? true, showNotifications: config.get("showNotifications") ?? "off", + exclude: config.get("exclude"), + lineLength: config.get("lineLength"), }; } @@ -127,6 +141,11 @@ function getGlobalValue(config: WorkspaceConfiguration, key: string, defaultV return inspect?.globalValue ?? inspect?.defaultValue ?? defaultValue; } +function getOptionalGlobalValue(config: WorkspaceConfiguration, key: string): T | undefined { + const inspect = config.inspect(key); + return inspect?.globalValue; +} + export async function getGlobalSettings(namespace: string): Promise { const config = getConfiguration(namespace); return { @@ -142,14 +161,21 @@ export async function getGlobalSettings(namespace: string): Promise { enable: getPreferredGlobalSetting("lint.enable", "enable", config) ?? true, run: getPreferredGlobalSetting("lint.run", "run", config) ?? "onType", args: getPreferredGlobalSetting("lint.args", "args", config) ?? [], + preview: getOptionalGlobalValue(config, "lint.preview"), + select: getOptionalGlobalValue(config, "lint.select"), + extendSelect: getOptionalGlobalValue(config, "lint.extendSelect"), + ignore: getOptionalGlobalValue(config, "lint.ignore"), }, format: { args: getGlobalValue(config, "format.args", []), + preview: getOptionalGlobalValue(config, "format.preview"), }, enable: getGlobalValue(config, "enable", true), organizeImports: getGlobalValue(config, "organizeImports", true), fixAll: getGlobalValue(config, "fixAll", true), showNotifications: getGlobalValue(config, "showNotifications", "off"), + exclude: getOptionalGlobalValue(config, "exclude"), + lineLength: getOptionalGlobalValue(config, "lineLength"), }; } @@ -167,9 +193,16 @@ export function checkIfConfigurationChanged( `${namespace}.interpreter`, `${namespace}.lint.enable`, `${namespace}.lint.run`, + `${namespace}.lint.preview`, + `${namespace}.lint.select`, + `${namespace}.lint.extendSelect`, + `${namespace}.lint.ignore`, `${namespace}.organizeImports`, `${namespace}.path`, `${namespace}.showNotifications`, + `${namespace}.format.preview`, + `${namespace}.exclude`, + `${namespace}.lineLength`, // Deprecated settings (prefer `lint.args`, etc.). `${namespace}.args`, `${namespace}.run`,