Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS-470 Update DEV.md #4971

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions docs/DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,33 @@ When using this for the ruling tests, make sure that you run them in series (and
java -jar <location of rule-api jar> generate -rule S1234 [-branch <RSPEC branch>]
```

2. Generate other files required for a new rule. If the rule is already covered by ESLint or its plugins, use the existing <ESLint-style rulekey> 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 <ESLint-style rulekey>
// 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": [
Expand Down
Loading