Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: CSSLint/csslint
base: master
...
head fork: pguelpa/csslint
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 87 additions and 0 deletions.
  1. +52 −0 src/formatters/stats.js
  2. +35 −0 src/rules/selectors-count.js
View
52 src/formatters/stats.js
@@ -0,0 +1,52 @@
+/*global CSSLint*/
+CSSLint.addFormatter({
+ //format information
+ id: "stats",
+ name: "Only output statistics",
+
+ /**
+ * Return content to be printed before all file results.
+ * @return {String} to prepend before all results
+ */
+ startFormat: function() {
+ return "";
+ },
+
+ /**
+ * Return content to be printed after all file results.
+ * @return {String} to append after all results
+ */
+ endFormat: function() {
+ return "";
+ },
+
+ /**
+ * Given CSS Lint results for a file, return output for this format.
+ * @param results {Object} with error and warning messages
+ * @param filename {String} relative file path
+ * @param options {Object} (Optional) specifies special handling of output
+ * @return {String} output for results
+ */
+ formatResults: function(results, filename, options) {
+ var stats = results.stats,
+ output = "";
+ options = options || {};
+
+ var pos = filename.lastIndexOf("/"),
+ shortFilename = filename;
+
+ if (pos === -1){
+ pos = filename.lastIndexOf("\\");
+ }
+ if (pos > -1){
+ shortFilename = filename.substring(pos+1);
+ }
+
+ output = "\n\n" + shortFilename;
+ for(var stat in stats) {
+ output += "\n" + stat + " = " + stats[stat];
+ }
+
+ return output;
+ }
+});
View
35 src/rules/selectors-count.js
@@ -0,0 +1,35 @@
+/*global CSSLint*/
+/*
+ * Rule: Metric to see how many selectors you have
+ */
+CSSLint.addRule({
+
+ //rule information
+ id: "selectors-count",
+ name: "Selectors Count",
+ desc: "Track how many selectors there are",
+ browsers: "All",
+
+ //initialization
+ init: function(parser, reporter){
+ var rule = this,
+ counter = 0;
+
+ function startStylesheet() {
+ counter = 0;
+ }
+
+ function endStylesheet() {
+ reporter.stat("selector-count", counter);
+ }
+
+ function startRule(event) {
+ counter += event.selectors.length;
+ }
+
+ parser.addListener("startstylesheet", startStylesheet);
+ parser.addListener("endstylesheet", endStylesheet);
+ parser.addListener("startrule", startRule);
+ }
+
+});

No commit comments for this range

Something went wrong with that request. Please try again.