Skip to content
This repository was archived by the owner on Feb 2, 2026. It is now read-only.

Commit 5cf3cb4

Browse files
committed
Fix #84 Validation issue when value contains an SCSS list
1 parent c1f00ec commit 5cf3cb4

145 files changed

Lines changed: 1126 additions & 947 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

css-checks/src/main/java/org/sonar/css/checks/RuleDescriptionsGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public class RuleDescriptionsGenerator {
4444
private static final String UTF_8 = "UTF-8";
4545

4646
private static final Map<String, String> CSS_OBJECT_LINKS = ImmutableMap.<String, String>builder()
47-
.put("|", "https://developer.mozilla.org/en-US/docs/Web/CSS/Value_definition_syntax#Single_bar")
4847
.put("||", "https://developer.mozilla.org/en-US/docs/Web/CSS/Value_definition_syntax#Double_bar")
48+
.put("|", "https://developer.mozilla.org/en-US/docs/Web/CSS/Value_definition_syntax#Single_bar")
4949
.put("&&", "https://developer.mozilla.org/en-US/docs/Web/CSS/Value_definition_syntax#Double_ampersand")
5050
.put("?", "https://developer.mozilla.org/en-US/docs/Web/CSS/Value_definition_syntax#Question_mark_()")
5151
.put("+", "https://developer.mozilla.org/en-US/docs/Web/CSS/Value_definition_syntax#Plus_()")

css-checks/src/main/java/org/sonar/css/checks/common/FontFaceBrowserCompatibilityCheck.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,24 @@
2222
import com.google.common.annotations.VisibleForTesting;
2323
import com.google.common.collect.ImmutableList;
2424
import com.google.common.collect.ImmutableMap;
25-
26-
import java.util.List;
27-
import java.util.Optional;
28-
import java.util.regex.Pattern;
29-
import java.util.stream.Collectors;
30-
3125
import org.sonar.check.Priority;
3226
import org.sonar.check.Rule;
3327
import org.sonar.check.RuleProperty;
3428
import org.sonar.css.checks.CheckList;
3529
import org.sonar.css.checks.CheckUtils;
3630
import org.sonar.css.checks.Tags;
3731
import org.sonar.css.model.property.standard.Src;
32+
import org.sonar.plugins.css.api.tree.Tree;
3833
import org.sonar.plugins.css.api.tree.css.*;
3934
import org.sonar.plugins.css.api.visitors.DoubleDispatchVisitorCheck;
4035
import org.sonar.squidbridge.annotations.SqaleConstantRemediation;
4136

37+
import java.util.ArrayList;
38+
import java.util.List;
39+
import java.util.Optional;
40+
import java.util.regex.Pattern;
41+
import java.util.stream.Collectors;
42+
4243
/*
4344
* https://css-tricks.com/snippets/css/using-font-face/
4445
* http://blog.fontspring.com/2011/02/further-hardening-of-the-bulletproof-syntax/
@@ -102,7 +103,7 @@ private boolean isFontFaceRuleToBeChecked(AtRuleTree tree) {
102103
private boolean definesScrPropertyWithUrl(List<PropertyDeclarationTree> declarations) {
103104
for (PropertyDeclarationTree declaration : declarations)
104105
if (declaration.property().standardProperty() instanceof Src
105-
&& !declaration.value().valueElementsOfType(UriTree.class).isEmpty()) {
106+
&& !getUris(declaration).isEmpty()) {
106107
return true;
107108
}
108109
return false;
@@ -161,9 +162,7 @@ private void checkSecondToLastSrcPropertyDeclaration(PropertyDeclarationTree dec
161162
}
162163

163164
private void checkLastSrcProperty(PropertyDeclarationTree declaration) {
164-
List<UriTree> uris = declaration.value().valueElementsOfType(UriTree.class).stream()
165-
.filter(t -> t.uriContent() != null && !t.uriContent().text().isEmpty())
166-
.collect(Collectors.toList());
165+
List<UriTree> uris = getUris(declaration);
167166

168167
if (uris.isEmpty()) {
169168
addPreciseIssue(declaration.property(), "URL for \"" + FORMAT.get(browserSupportLevel).get(0) + "\" format is expected.");
@@ -220,6 +219,22 @@ private void checkLastSrcProperty(PropertyDeclarationTree declaration) {
220219
}
221220
}
222221

222+
private List<UriTree> getUris(PropertyDeclarationTree declaration) {
223+
List<UriTree> uris = new ArrayList<>();
224+
if (declaration.value().valueElements().get(0).is(Tree.Kind.VALUE_COMMA_SEPARATED_LIST)) {
225+
for (ValueTree v : ((ValueCommaSeparatedListTree) declaration.value().valueElements().get(0)).values()) {
226+
uris.addAll(v.valueElementsOfType(UriTree.class).stream()
227+
.filter(t -> t.uriContent() != null && !t.uriContent().text().isEmpty())
228+
.collect(Collectors.toList()));
229+
}
230+
} else {
231+
uris = declaration.value().valueElementsOfType(UriTree.class).stream()
232+
.filter(t -> t.uriContent() != null && !t.uriContent().text().isEmpty())
233+
.collect(Collectors.toList());
234+
}
235+
return uris;
236+
}
237+
223238
@Override
224239
public void validateParameters() {
225240
if (!BASIC_LEVEL.equals(browserSupportLevel) && !DEEP_LEVEL.equals(browserSupportLevel) && !DEEPEST_LEVEL.equals(browserSupportLevel)) {

css-checks/src/main/java/org/sonar/css/checks/common/FormattingCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public void visitAtRule(AtRuleTree tree) {
163163
private void checkAtRuleOpeningCurlyBrace(AtRuleTree tree) {
164164
Preconditions.checkNotNull(tree.block());
165165

166-
Tree tree1 = tree.preludes() != null ? tree.preludes().get(tree.preludes().size() - 1) : tree.atKeyword();
166+
Tree tree1 = tree.preludes() != null ? tree.preludes() : tree.atKeyword();
167167
Tree tree2 = tree.block().openCurlyBrace();
168168

169169
if (!isOnSameLine(tree1, tree2)) {

css-checks/src/main/java/org/sonar/css/checks/common/SingleQuotesCheck.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ private void checkForDoubleQuotes(StringTree tree) {
6262
}
6363

6464
private boolean isEncodingOfCharsetAtRule(StringTree tree) {
65-
return tree.parent() instanceof AtRuleTree && ((AtRuleTree) tree.parent()).standardAtRule() instanceof Charset;
65+
return tree.parent() != null
66+
&& tree.parent().parent() instanceof AtRuleTree
67+
&& ((AtRuleTree) tree.parent().parent()).standardAtRule() instanceof Charset;
6668
}
6769

6870
private boolean containsQuote(String text) {

css-checks/src/test/resources/checks/common/fontface/basic.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
}
33

44
@font-face {
5-
font-family: 'MyFontFamily';
5+
font-family: 'MyFontFamily';
66
}
77

88
@font-face {
9-
font-family: 'MyFontFamily';
10-
src: url('myfont.woff2') format('woff2'),
11-
url('myfont.woff') format('woff');
9+
font-family: 'MyFontFamily';
10+
src: url('myfont.woff2') format('woff2'),
11+
url('myfont.woff') format('woff');
1212
}
1313

1414
@font-face {

css-checks/src/test/resources/checks/common/properties/css/background-attachment.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
background-attachment: local;
66
background-attachment: local, fixed;
77
background-attachment: local, fixed, fixed;
8-
background-attachment: 10; /* Noncompliant !{Update the invalid value of property "background-attachment". Expected format: scroll | fixed | local [, scroll | fixed | local]*}! */
8+
background-attachment: 10; /* Noncompliant !{Update the invalid value of property "background-attachment". Expected format: [ scroll | fixed | local ]#}! */
99
background-attachment: 10, 10; /* Noncompliant */
1010
}

css-checks/src/test/resources/checks/common/properties/css/background-blend-mode.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
background-blend-mode: inherit;
33
background-blend-mode: normal;
44
background-blend-mode: multiply;
5+
background-blend-mode: multiply !important;
56
background-blend-mode: screen;
67
background-blend-mode: overlay;
78
background-blend-mode: darken;
@@ -21,7 +22,7 @@
2122
background-blend-mode: 10; /* Noncompliant */
2223
background-blend-mode: normal, multiply;
2324
background-blend-mode: normal, multiply, multiply;
25+
background-blend-mode: normal, multiply, multiply !important;
2426
background-blend-mode: normal, multiply, multiply, color-burn;
2527
background-blend-mode: normal, multiply, multiply, zzz; /* Noncompliant */
26-
background-blend-mode: normal, multiply, , multiply; /* Noncompliant */
2728
}

css-checks/src/test/resources/checks/common/properties/css/background-clip.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
background-clip: border-box;
44
background-clip: padding-box;
55
background-clip: content-box;
6-
background-clip: 10px; /* Noncompliant !{Update the invalid value of property "background-clip". Expected format: <box> [, <box>]*}! */
6+
background-clip: 10px; /* Noncompliant !{Update the invalid value of property "background-clip". Expected format: <box>#}! */
77
background-clip: 10; /* Noncompliant */
88
background-clip: border-box, padding-box
99

css-checks/src/test/resources/checks/common/properties/css/background-image.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
.mybox {
22
background-image: inherit;
33
background-image: none;
4+
background-image: none !important;
45
background-image: url(http://mybox);
6+
background-image: url(http://mybox) !important;
57
background-image: url(http://mybox), url(http://mybox);
68
background-image: url(http://mybox), url(http://mybox), url(http://mybox);
7-
background-image: 10; /* Noncompliant !{Update the invalid value of property "background-image". Expected format: none | <image> [, <image>]*}! */
9+
background-image: 10; /* Noncompliant !{Update the invalid value of property "background-image". Expected format: none | <image>#}! */
810
background-image: 10, 10; /* Noncompliant */
911
background-image: image();
1012
background-image: image-set();

css-checks/src/test/resources/checks/common/properties/css/background-origin.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
background-origin: border-box;
44
background-origin: padding-box;
55
background-origin: content-box;
6-
background-origin: 10px; /* Noncompliant !{Update the invalid value of property "background-origin". Expected format: <box> [, <box>]*}! */
6+
background-origin: 10px; /* Noncompliant !{Update the invalid value of property "background-origin". Expected format: <box>#}! */
77
background-origin: 10; /* Noncompliant */
88
background-origin: border-box, padding-box
99

0 commit comments

Comments
 (0)