From 510ac865875fcd1ed4475a50f74fd3ed5f0de3d5 Mon Sep 17 00:00:00 2001 From: Amaury Levé Date: Tue, 26 Jun 2018 15:24:29 +0200 Subject: Rule S4664: Selectors of lower specificity should come before overriding selectors of higher specificity --- .../org/sonar/l10n/css/rules/css/S4664.html | 28 ++++++++++++++++++++++ .../org/sonar/l10n/css/rules/css/S4664.json | 16 +++++++++++++ .../l10n/css/rules/css/Sonar_way_profile.json | 1 + 3 files changed, 45 insertions(+) create mode 100644 sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4664.html create mode 100644 sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4664.json (limited to 'sonar-css-plugin/src/main/resources') diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4664.html b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4664.html new file mode 100644 index 0000000..6f501e2 --- /dev/null +++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4664.html @@ -0,0 +1,28 @@ +
Order of instructions in CSS is important: instructions that occur last in the file take the priority. When a selector with high specificity (eg
+#container a top: 10px; ) comes before the selector it overrides (eg: a top: 0; ), the priority is given to the high
+specificity definition which violates the principle of the last instruction takes the priority.
CSS are most legible when overriding selectors always come after the selectors they override. That way both mechanisms, source order and +specificity, work together nicely.
+
+b a {}
+a {}
+
+
+@media print {
+ #c a {}
+ a {}
+}
+
+
+a {}
+b a {}
+
+
+@media print {
+ a {}
+ #c a {}
+}
+
+
diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4664.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4664.json
new file mode 100644
index 0000000..ebcea71
--- /dev/null
+++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/S4664.json
@@ -0,0 +1,16 @@
+{
+ "title": "Selectors of lower specificity should come before overriding selectors of higher specificity",
+ "type": "BUG",
+ "status": "ready",
+ "remediation": {
+ "func": "Constant\/Issue",
+ "constantCost": "5min"
+ },
+ "tags": [
+
+ ],
+ "defaultSeverity": "Critical",
+ "ruleSpecification": "RSPEC-4664",
+ "sqKey": "S4664",
+ "scope": "Main"
+}
diff --git a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/Sonar_way_profile.json b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/Sonar_way_profile.json
index adbe829..ce1c647 100644
--- a/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/Sonar_way_profile.json
+++ b/sonar-css-plugin/src/main/resources/org/sonar/l10n/css/rules/css/Sonar_way_profile.json
@@ -20,6 +20,7 @@
"S4661",
"S4662",
"S4663",
+ "S4664",
"S4666",
"S4667",
"S4668",
--
cgit v1.2.3