Skip to content

Commit 223ec13

Browse files
committed
feat: diagnostics modifiers
Implement functionality to configure diagnostic error messages during source code analysis. Lines in the code with the `# robotcode:` marker are now interpreted as modifiers. The full structure of a modifier is `# robotcode: <action>[code(,code)*]*`. **Allowed actions:** - `ignore`: Ignore specified diagnostic codes. - `hint`: Treat specified diagnostic codes as hints. - `warn`: Treat specified diagnostic codes as warnings. - `error`: Treat specified diagnostic codes as errors. - `reset`: Reset the diagnostic codes to their default state. **This implementation allows for the following:** - Custom actions to be performed on specified diagnostic codes. - Enhanced control over which diagnostic messages are shown, ignored, or modified. - Flexibility in managing diagnostic outputs for better code quality and debugging experience. **Usage details:** - A diagnostic modifier can be placed at the end of a line. It modifies only the errors occurring in that line. - A modifier can be placed at the very beginning of a line. It applies from that line to the end of the file. - If a modifier is within a block (e.g., Testcase, Keyword, IF, FOR) and is indented, it applies only to the current block. **Example usage:** - `# robotcode: ignore[variable-not-found, keyword-not-found]` - Ignores the errors for variable not found and keyword not found. - `# robotcode: hint[MultipleKeywords]` - Treats the MultipleKeywords error as a hint. - `# robotcode: warn[variable-not-found]` - Treats the variable-not-found error as a warning. - `# robotcode: error[keyword-not-found]` - Treats the keyword-not-found error as an error. - `# robotcode: reset[MultipleKeywords]` - Resets the MultipleKeywords error to its default state. - `# robotcode: ignore` - Ignores all diagnostic messages . - `# robotcode: reset` - Resets all diagnostic messages to their default. **Example scenarios:** *Modifier at the end of a line:* ```robot *** Keywords *** Keyword Name Log ${arg1} # robotcode: ignore[variable-not-found] ``` This modifier will ignore the `variable-not-found` error for the `Log` keyword in this line only. *Modifier at the beginning of a line:* ```robot # robotcode: ignore[keyword-not-found] *** Test Cases *** Example Test Log Hello Some Undefined Keyword ``` This modifier will ignore `keyword-not-found` errors from the point it is declared to the end of the file. *Modifier within a block:* ```robot *** Keywords *** Example Keyword # robotcode: warn[variable-not-found] Log ${arg1} Another Keyword ``` This modifier will treat `variable-not-found` errors as warnings within the `Example Keyword` block. *Modifier using reset:* ```robot # robotcode: error[variable-not-found] *** Test Cases *** Example Test Log ${undefined_variable} # robotcode: reset[variable-not-found] Log ${undefined_variable} ``` In this example, the `variable-not-found` error is treated as an error until it is reset in the `Another Test` block, where it will return to its default state. *Modifier to ignore all diagnostic messages:* ```robot # robotcode: ignore *** Test Cases *** Example Test Log ${undefined_variable} Some Undefined Keyword ``` This modifier will ignore all diagnostic messages from the point it is declared to the end of the file. *Modifier to reset all diagnostic messages:* ```robot # robotcode: ignore *** Test Cases *** Example Test Log ${undefined_variable} # robotcode: reset Another Test Some Undefined Keyword ``` In this example, all diagnostic messages are ignored until the `reset` modifier, which returns all messages to their default state from that point onward.
1 parent f68b8e3 commit 223ec13

File tree

30 files changed

+817
-324
lines changed

30 files changed

+817
-324
lines changed

.eslintignore

Lines changed: 0 additions & 12 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 113 deletions
This file was deleted.

.vscode/launch.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"module": "robotcode.cli",
2222
"justMyCode": false,
2323
//"cwd": "${workspaceFolder}/tests/robotcode/language_server/robotframework/parts/data/tests",
24-
"cwd": "E:\\tmp\\rfalpha",
24+
"cwd": "${workspaceFolder}",
2525
//"cwd": "C:\\develop\\robot\\robotframework",
2626
// "env": {
2727
// "ROBOTCODE_COLOR": "1",
@@ -45,13 +45,11 @@
4545
// "--no-pager",
4646
//"config", "info", "list",
4747
// "analyze",
48-
"-p",
49-
"ci",
50-
"profiles",
51-
"list",
52-
"-h"
48+
49+
"discover",
50+
"tests",
5351
// "discover", "tests", "--tags"
54-
// "."
52+
"."
5553
]
5654
},
5755
{

eslint.config.mjs

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
import tseslint from "typescript-eslint";
4+
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
5+
6+
export default [
7+
{
8+
ignores: [
9+
"**/node_modules/",
10+
"**/dist/",
11+
"**/out/",
12+
"**/coverage/",
13+
"**/vscode.d.ts",
14+
"**/vscode.proposed.d.ts",
15+
"**/.mypy_cache/",
16+
"**/.pytest_cache/",
17+
"**/site/",
18+
"**/docs/",
19+
],
20+
},
21+
{ files: ["**/*.{js,mjs,cjs,ts}"] },
22+
{ languageOptions: { globals: globals.browser } },
23+
pluginJs.configs.recommended,
24+
...tseslint.configs.recommended,
25+
eslintPluginPrettierRecommended,
26+
{
27+
rules: {
28+
"@typescript-eslint/ban-ts-comment": [
29+
"error",
30+
{
31+
"ts-ignore": "allow-with-description",
32+
},
33+
],
34+
strict: "off",
35+
"@typescript-eslint/explicit-module-boundary-types": "error",
36+
"no-bitwise": "off",
37+
"no-dupe-class-members": "off",
38+
"@typescript-eslint/no-dupe-class-members": "error",
39+
"no-empty-function": "off",
40+
"@typescript-eslint/no-empty-interface": "off",
41+
"@typescript-eslint/no-explicit-any": "error",
42+
"@typescript-eslint/no-non-null-assertion": "off",
43+
"no-unused-vars": "off",
44+
45+
"@typescript-eslint/no-unused-vars": [
46+
"error",
47+
{
48+
args: "after-used",
49+
argsIgnorePattern: "^_",
50+
},
51+
],
52+
53+
"no-use-before-define": "off",
54+
"no-useless-constructor": "off",
55+
"@typescript-eslint/no-useless-constructor": "error",
56+
"@typescript-eslint/no-var-requires": "off",
57+
58+
"class-methods-use-this": [
59+
"error",
60+
{
61+
exceptMethods: ["dispose"],
62+
},
63+
],
64+
65+
"func-names": "off",
66+
"import/extensions": "off",
67+
"import/namespace": "off",
68+
"import/no-extraneous-dependencies": "off",
69+
70+
"import/prefer-default-export": "off",
71+
"linebreak-style": "off",
72+
"no-await-in-loop": "off",
73+
"no-console": "off",
74+
"no-control-regex": "off",
75+
"no-extend-native": "off",
76+
"no-multi-str": "off",
77+
"no-param-reassign": "off",
78+
"no-prototype-builtins": "off",
79+
80+
"no-restricted-syntax": [
81+
"error",
82+
{
83+
selector: "ForInStatement",
84+
message:
85+
"for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.",
86+
},
87+
{
88+
selector: "LabeledStatement",
89+
message: "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.",
90+
},
91+
{
92+
selector: "WithStatement",
93+
message: "`with` is disallowed in strict mode because it makes code impossible to predict and optimize.",
94+
},
95+
],
96+
97+
"no-template-curly-in-string": "off",
98+
"no-underscore-dangle": "off",
99+
"no-useless-escape": "off",
100+
101+
"no-void": [
102+
"error",
103+
{
104+
allowAsStatement: true,
105+
},
106+
],
107+
108+
"operator-assignment": "off",
109+
//"prettier/prettier": ["error"],
110+
},
111+
},
112+
];

0 commit comments

Comments
 (0)