From 55aeb21ffd740c74e4ccbe90b17aaed2b63566ae Mon Sep 17 00:00:00 2001 From: Victor Diez Date: Fri, 29 Nov 2024 16:38:24 +0100 Subject: [PATCH] Update DEV.md --- docs/DEV.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/DEV.md b/docs/DEV.md index 4516f132094..4a47793bc4c 100644 --- a/docs/DEV.md +++ b/docs/DEV.md @@ -107,30 +107,33 @@ When using this for the ruling tests, make sure that you run them in series (and java -jar generate -rule S1234 [-branch ] ``` -2. Generate other files required for a new rule. If the rule is already covered by ESLint or its plugins, use the existing and add the `eslint` option. +2. Generate other files required for a new rule. Just choose your options in the prompt of the `new-rule` script ```sh -npm run new-rule S1234 -// e.g. -npm run new-rule S1234 no-invalid-something [eslint] +npm run new-rule ``` This script: -- generates a Java check class for the rule `NoInvalidSomethingCheck.java` +- generates a Java check class for the rule `S1234.java` +- generates a Java check test class for the rule `S1234Test.java` - generates a `rules/S1234` folder - generates a `rules/S1234/index.ts` rule index file - generates a `rules/S1234/rule.ts` file for the rule implementation - generates a `rules/S1234/cb.fixture.js` comment-based test file (empty) - generates a `rules/S1234/cb.test.js` test launcher -- updates the `rules/index.ts` file to include the new rule -- updates the `CheckList.java` to include the new rule + +It will also update some files which are not tracked by Git as they are automatically generated: + +- updates the `rules/rules.ts` file to include the new rule +- updates the `rules/plugin-rules.ts` file to include the new rule +- updates the `AllRules.java` to include the new rule 3. Update generated files - Make sure annotations in the Java class specify languages to cover (`@JavaScriptRule` and/or `@TypeScriptRule`) - - If your rule has configurations or you are using some from an ESLint rule, override the `configurations()` method of the Java check class + - If your rule has configurations, or you are using some from an ESLint rule, override the `configurations()` method of the Java check class - You can use a `MyRuleCheckTest.java` test case to verify how the configurations will be serialized to JSON as shown [here](https://github.com/SonarSource/SonarJS/blob/master/sonar-plugin/javascript-checks/src/test/java/org/sonar/javascript/checks/NoEmptyClassCheckTest.java#L30) - - If writing a rule for the test files, replace `implements EslintBasedCheck` with `extends TestFileCheck` in the Java class + - If writing a rule for the test files, replace `extends Check` with `extends TestFileCheck` in the Java class. This will be done by the `new-rule` script, but make sure you are extending the right base class. - In the generated metadata JSON file `javascript-checks/src/main/resources/org/sonar/l10n/javascript/rules/javascript/S1234.json`, add (one or both): ```json "compatibleLanguages": [