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-478 Upgrade to ESLint 9 #5010

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 4 additions & 10 deletions docs/DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ The contents of the test code have the following structure:

```javascript
some.clean.code();
some.faulty.code(); // Noncompliant N [[qf1,qf2,...]] {{Optional message to assert}}
some.faulty.code(); // Noncompliant [[qf1,qf2,...]] {{Message to assert}}
// ^^^^^^
// fix@qf1 {{Optional suggestion description}}
// fix@qf1 {{Suggestion description}}
// edit@qf1 [[sc=1;ec=5]] {{text to replace line from [sc] column to [ec] column}}
faulty.setFaultyParam(true);
// ^^^^^^^^^^^^^^< {{Optional secondary message to assert}}
Expand Down Expand Up @@ -196,18 +196,12 @@ You can find an example at [the bottom of this document](#examples).

#### Tests syntax

Given the above test snippet: the issue primary location (`// ^^^^`), issue messages (`{{...}}`), secondary location(s) (`// ^^^<`), issues count (`N`) and quick fixes are optional.

`N` is an integer defining the amount of issues will be reported in the line.

Only one of the methods (`{{messageN}}+` OR `N`) to define the expected issues can be used in a `Noncompliant` line. If you set both `N` and messages, the framework will throw an error.

If no `N` nor messages are provided, the engine will expect one issue to be raised. Meaning, `//Noncompliant` is equivalent to `//Noncompliant 1`.
Given the above test snippet, issue messages (`{{...}}`) and quick fixes (if the rule provides them) are mandatory. The issue primary location (`// ^^^^`) and secondary location(s) (`// ^^^<`) are optional.

`Noncompliant` lines will be associated by default to the line of code where they are writen. The syntax `@line_number` allows for an issue to be associated to another line:

```javascript
// Noncompliant@2 N [[qf1,qf2,...]] {{Optional message to assert}}
// Noncompliant@2 [[qf1,qf2,...]] {{Optional message to assert}}
some.faulty.code();
```

Expand Down
2 changes: 1 addition & 1 deletion esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ await esbuild.build({
// we mark this file as external because it does not exist on EsLint any more and in any case
// the code never reaches this dynamic require as this is a fallback if 'eslint/use-at-your-own-risk'
// does not exist. we need to keep an eye on this in the future.
external: ['eslint/lib/util/glob-util'],
external: ['eslint/lib/util/glob-util', 'jiti'],
platform: 'node',
minify: true,
plugins: [
Expand Down
12 changes: 6 additions & 6 deletions its/eslint8-plugin-sonarjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"test": "node index.test.js"
},
"devDependencies": {
"eslint-plugin-sonarjs": "file:../../lib/eslint-plugin-sonarjs-0.0.0-SNAPSHOT.tgz",
"@types/eslint": "^8.56.12",
"@types/eslint": "^8",
"cross-spawn": "7.0.6",
"eslint": "8.57.1",
"eslint-plugin-import": "2.31.0",
"typescript": "5.6.3",
"typescript-eslint": "7.18.0"
"eslint": "^8",
"eslint-plugin-sonarjs": "file:../../lib/eslint-plugin-sonarjs-0.0.0-SNAPSHOT.tgz",
"typescript": "^5",
"typescript-eslint": "^7",
"@typescript-eslint/parser": "^7"
kebetsi marked this conversation as resolved.
Show resolved Hide resolved
}
}
7 changes: 4 additions & 3 deletions its/eslint9-plugin-sonarjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"devDependencies": {
"eslint-plugin-sonarjs": "file:../../lib/eslint-plugin-sonarjs-0.0.0-SNAPSHOT.tgz",
"cross-spawn": "7.0.6",
"eslint": "9 - 9.14",
"typescript": "5.6.3",
"typescript-eslint": "^8.5.0"
"eslint": "^9",
"typescript": "^5",
"typescript-eslint": "^8",
"@typescript-eslint/parser": "^8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
import static org.assertj.core.api.Assertions.tuple;

import com.sonar.orchestrator.Orchestrator;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
Expand All @@ -33,12 +30,12 @@
import org.sonarqube.ws.Issues.Issue;

@ExtendWith(OrchestratorStarter.class)
public class HtmlAnalysisTest {
class HtmlAnalysisTest {

private static final Orchestrator orchestrator = OrchestratorStarter.ORCHESTRATOR;

@Test
void should_raise_issues_in_html_files() throws IOException {
void should_raise_issues_in_html_files() {
var projectKey = "html-project";
var uniqueProjectKey = projectKey + UUID.randomUUID();
var build = getSonarScanner()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ void test() throws Exception {
extractArchive(fileToExtract, temp);
bridge.start(temp);
assertStatus(bridge);
bridge.request(gson.toJson(InitLinter.build("S1481")), "init-linter");
bridge.request(
gson.toJson(InitLinter.build("S1481", temp.toAbsolutePath().toString())),
"init-linter"
);
assertAnalyzeJs(bridge);
} finally {
bridge.stop();
Expand All @@ -91,8 +94,7 @@ void test() throws Exception {

private void assertAnalyzeJs(Bridge bridge) throws IOException, InterruptedException {
AnalysisRequest r = new AnalysisRequest();
r.fileContent =
"function foo() { \n" + " var a; \n" + " var c; // NOSONAR\n" + " var b = 42; \n" + "} \n";
r.fileContent = "function foo() { \n var a; \n var c; // NOSONAR\n var b = 42; \n} \n";
r.filePath = temp.resolve("file.js").toAbsolutePath().toString();
String response = bridge.request(gson.toJson(r), "analyze-js");
JsonObject jsonObject = gson.fromJson(response, JsonObject.class);
Expand Down Expand Up @@ -231,12 +233,14 @@ static class InitLinter {
List<Rule> rules = new ArrayList<>();
List<String> environments = new ArrayList<>();
List<String> globals = new ArrayList<>();
String baseDir;

static InitLinter build(String rule) {
static InitLinter build(String rule, String baseDir) {
InitLinter initLinter = new InitLinter();
Rule rule1 = new Rule();
rule1.key = rule;
initLinter.rules.add(rule1);
initLinter.baseDir = baseDir;
return initLinter;
}
}
Expand Down
Loading