Skip to content

Commit 6ae25a2

Browse files
authored
fix: Change ruff errors to warnings and fix config saving (#2246)
Changed all except syntax errors to warning underlines instead of error underline since they are not actual errors. Also changed redux to not save if the config matches the default. This should fix an edge case where a user opens the settings editor just to see what the config is, then hits "Save". Previously, this would save the current defaults as their settings and then if the defaults changed they would not get updated settings. This way, if a user was on defaults and the default changes they will get the new default. Also added a little bit of debug logging for Ruff.
1 parent 92b133b commit 6ae25a2

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/code-studio/src/settings/EditorSectionContent.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,24 @@ export function EditorSectionContent(): JSX.Element {
5151
(newValue: Record<string, unknown>) => {
5252
dispatch(
5353
updateNotebookSettings({
54-
python: { linter: { ...ruffSettings, config: newValue } },
54+
python: {
55+
linter: {
56+
...ruffSettings,
57+
config:
58+
JSON.stringify(newValue) ===
59+
JSON.stringify(RUFF_DEFAULT_SETTINGS)
60+
? undefined
61+
: newValue,
62+
},
63+
},
5564
})
5665
);
5766
MonacoProviders.setRuffSettings(newValue);
5867
},
5968
[dispatch, ruffSettings]
6069
);
6170

62-
const [val, setVal] = useState(JSON.stringify(ruffConfig, null, 2));
71+
const val = JSON.stringify(ruffConfig, null, 2);
6372

6473
const [isRuffSettingsOpen, setIsRuffSettingsOpen] = useState(false);
6574

@@ -70,7 +79,6 @@ export function EditorSectionContent(): JSX.Element {
7079
const handleRuffSettingsSave = useCallback(
7180
(v: Record<string, unknown>) => {
7281
handleRuffConfigChange(v);
73-
setVal(JSON.stringify(v, null, 2));
7482
handleRuffSettingsClose();
7583
},
7684
[handleRuffConfigChange, handleRuffSettingsClose]

packages/console/src/monaco/MonacoProviders.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,25 @@ class MonacoProviders extends PureComponent<
108108
return;
109109
}
110110

111+
const diagnostics = MonacoProviders.getDiagnostics(model);
112+
log.debug(`Linting Python document: ${model.uri.toString()}`, diagnostics);
113+
111114
monaco.editor.setModelMarkers(
112115
model,
113116
'ruff',
114-
MonacoProviders.getDiagnostics(model).map((d: Diagnostic) => {
115-
// Unused variable or import. Mark as warning and unnecessary to fade the text
117+
diagnostics.map((d: Diagnostic) => {
118+
// Unused variable or import. Mark as unnecessary to fade the text
116119
const isUnnecessary = d.code === 'F401' || d.code === 'F841';
120+
const isSyntaxError = d.code == null; // SyntaxError has no error code
117121
return {
118122
startLineNumber: d.location.row,
119123
startColumn: d.location.column,
120124
endLineNumber: d.end_location.row,
121125
endColumn: d.end_location.column,
122-
message: d.code != null ? `${d.code}: ${d.message}` : d.message, // SyntaxError has no code
123-
severity: isUnnecessary
124-
? monaco.MarkerSeverity.Warning
125-
: monaco.MarkerSeverity.Error,
126+
message: isSyntaxError ? d.message : `${d.code}: ${d.message}`,
127+
severity: isSyntaxError
128+
? monaco.MarkerSeverity.Error
129+
: monaco.MarkerSeverity.Warning,
126130
tags: isUnnecessary ? [monaco.MarkerTag.Unnecessary] : [],
127131
};
128132
})
@@ -374,6 +378,8 @@ class MonacoProviders extends PureComponent<
374378
return;
375379
}
376380

381+
log.debug(`Formatting Python document: ${model.uri.toString}`);
382+
377383
return [
378384
{
379385
range: model.getFullModelRange(),

0 commit comments

Comments
 (0)