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

Only accept supported web languages for CSS analysis (and activate SASS by default) #4308

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This SonarSource project is a [static code analyzer](https://en.wikipedia.org/wi
- [25 CSS rules](https://rules.sonarsource.com/css)
- Compatible with ECMAScript 2015-2020
- React JSX, Flow, Vue, and AWS lambda functions support for JavaScript and TypeScript
- CSS, SCSS, Less, also 'style' inside PHP, HTML, and VueJS files
- CSS, SCSS, SASS, Less, also 'style' inside HTML and VueJS files
- Metrics (complexity, number of lines, etc.)
- Import of test coverage reports
- Import of ESLint, TSLint, and Stylelint issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</style>
</head>
<body>
<?= "Hello World!" ?>
"Hello World!
</body>
</html>
12 changes: 12 additions & 0 deletions its/plugin/projects/css-metrics-project/src/file4.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$firstValue: 62.5%

$firstValue: 24px !default

body
font-size: $firstValue
foo: "some text"


// body font size = 62.5%

/* some comment */
6 changes: 6 additions & 0 deletions its/plugin/projects/css-metrics-project/src/file6.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!doctype html>
<title>Example</title>
<style>
p { }
</style>
<p>Hello World!</p>
15 changes: 15 additions & 0 deletions its/plugin/projects/css-metrics-project/src/file7.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Example</title>
<style>
p {
font-size: 5vw;
padding: 0 5vw;
line-height: 1.8em;
}
</style>
</head>
</html>
9 changes: 9 additions & 0 deletions its/plugin/projects/css-metrics-project/src/ignored/file8.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public static void prepare() {

SonarScanner scanner = CssTestsUtils.createScanner(PROJECT_KEY);
scanner.setProperty("sonar.exclusions", "**/file-with-parsing-error-excluded.css");
scanner.setProperty("sonar.html.file.suffixes", ".htm");
buildResult = orchestrator.executeBuild(scanner);
}

Expand Down Expand Up @@ -168,7 +167,8 @@ void issue_list() {
tuple("css:S1116", "css-issues-project:src/file6.vue"),
tuple("css:S5362", "css-issues-project:src/file1.css"),
tuple("css:S5362", "css-issues-project:src/file2.less"),
tuple("css:S5362", "css-issues-project:src/file3.scss")
tuple("css:S5362", "css-issues-project:src/file3.scss"),
tuple("css:S1116", "css-issues-project:src/file5-1.html")
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public static void prepare() {

@Test
void test() {
assertThat(getMeasureAsDouble(PROJECT_KEY, "lines")).isEqualTo(43);
assertThat(getMeasureAsDouble(PROJECT_KEY, "ncloc")).isEqualTo(32);
assertThat(getMeasureAsDouble(PROJECT_KEY, "lines")).isEqualTo(89);
assertThat(getMeasureAsDouble(PROJECT_KEY, "ncloc")).isEqualTo(52);
assertThat(getMeasure(PROJECT_KEY, "ncloc_language_distribution").getValue())
.isEqualTo("css=22;web=10");
assertThat(getMeasureAsDouble(PROJECT_KEY, "comment_lines")).isEqualTo(4);
.isEqualTo("css=27;php=1;web=24");
assertThat(getMeasureAsDouble(PROJECT_KEY, "comment_lines")).isEqualTo(6);

assertThat(getMeasure(PROJECT_KEY + ":src/file1.css", "ncloc_data").getValue())
.contains("1=1;", "2=1;", "3=1;", "4=1;", "5=1;", "6=1;", "7=1");
Expand All @@ -56,5 +56,31 @@ void test() {

assertThat(getMeasure(PROJECT_KEY + ":src/file3.scss", "ncloc_data").getValue())
.contains("1=1;", "3=1;", "5=1;", "6=1;", "7=1;", "8=1");

assertThat(getMeasure(PROJECT_KEY + ":src/file4.sass", "ncloc_data").getValue())
.contains("1=1", "3=1", "5=1", "6=1", "7=1");

assertThat(getMeasure(PROJECT_KEY + ":src/file5.html", "ncloc_data").getValue())
.contains("1=1", "2=1", "3=1", "4=1", "5=1", "6=1", "7=1", "8=1", "9=1", "10=1");

// .htm is not part of sonar-HTML languages. When it is, an assertion should be added for file6.htm
ilia-kebets-sonarsource marked this conversation as resolved.
Show resolved Hide resolved

assertThat(getMeasure(PROJECT_KEY + ":src/file7.xhtml", "ncloc_data").getValue())
.contains(
"1=1",
"2=1",
"4=1",
"5=1",
"6=1",
"7=1",
"8=1",
"9=1",
"10=1",
"11=1",
"12=1",
"13=1",
"14=1",
"15=1"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@ExtendWith(OrchestratorStarter.class)
class CssNoCssFileProjectTest {

private static final String PROJECT_KEY = "css-php-project";
private static final String PROJECT_KEY = "css-html-project";

private static final Orchestrator orchestrator = OrchestratorStarter.ORCHESTRATOR;

Expand All @@ -62,6 +62,6 @@ void test() {

assertThat(issuesList)
.extracting(Issues.Issue::getRule, Issues.Issue::getLine, Issues.Issue::getComponent)
.containsExactlyInAnyOrder(tuple("css:S4658", 7, "css-php-project:src/index.php"));
.containsExactlyInAnyOrder(tuple("css:S4658", 7, PROJECT_KEY + ":src/index.html"));
}
}