diff --git a/lib/ace/mode/css.js b/lib/ace/mode/css.js index 7d6fcb42..447a8181 100644 --- a/lib/ace/mode/css.js +++ b/lib/ace/mode/css.js @@ -74,25 +74,19 @@ oop.inherits(Mode, TextMode); this.autoOutdent = function(state, doc, row) { this.$outdent.autoOutdent(doc, row); }; - + this.createWorker = function(session) { var worker = new WorkerClient(["ace"], "ace/mode/css_worker", "Worker"); worker.attachToDocument(session.getDocument()); - + worker.on("csslint", function(e) { - var errors = []; - e.data.forEach(function(message) { - errors.push({ - row: message.line - 1, - column: message.col - 1, - text: message.message, - type: message.type, - lint: message - }); - }); - - session.setAnnotations(errors); + session.setAnnotations(e.data); }); + + worker.on("terminate", function() { + session.clearAnnotations(); + }); + return worker; }; diff --git a/lib/ace/mode/css/csslint.js b/lib/ace/mode/css/csslint.js index d5d05a98..11fa7e8e 100644 --- a/lib/ace/mode/css/csslint.js +++ b/lib/ace/mode/css/csslint.js @@ -8752,374 +8752,6 @@ CSSLint.addRule({ }); /*global CSSLint*/ -(function() { - - /** - * Replace special characters before write to output. - * - * Rules: - * - single quotes is the escape sequence for double-quotes - * - & is the escape sequence for & - * - < is the escape sequence for < - * - > is the escape sequence for > - * - * @param {String} message to escape - * @return escaped message as {String} - */ - var xmlEscape = function(str) { - if (!str || str.constructor !== String) { - return ""; - } - - return str.replace(/[\"&><]/g, function(match) { - switch (match) { - case "\"": - return """; - case "&": - return "&"; - case "<": - return "<"; - case ">": - return ">"; - } - }); - }; - - CSSLint.addFormatter({ - //format information - id: "checkstyle-xml", - name: "Checkstyle XML format", - - /** - * Return opening root XML tag. - * @return {String} to prepend before all results - */ - startFormat: function(){ - return ""; - }, - - /** - * Return closing root XML tag. - * @return {String} to append after all results - */ - endFormat: function(){ - return ""; - }, - - /** - * Returns message when there is a file read error. - * @param {String} filename The name of the file that caused the error. - * @param {String} message The error message - * @return {String} The error message. - */ - readError: function(filename, message) { - 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} (UNUSED for now) specifies special handling of output - * @return {String} output for results - */ - formatResults: function(results, filename, options) { - var messages = results.messages, - output = []; - - /** - * Generate a source string for a rule. - * Checkstyle source strings usually resemble Java class names e.g - * net.csslint.SomeRuleName - * @param {Object} rule - * @return rule source as {String} - */ - var generateSource = function(rule) { - if (!rule || !('name' in rule)) { - return ""; - } - return 'net.csslint.' + rule.name.replace(/\s/g,''); - }; - - - - if (messages.length > 0) { - output.push(""); - CSSLint.Util.forEach(messages, function (message, i) { - //ignore rollups for now - if (!message.rollup) { - output.push(""); - } - }); - output.push(""); - } - - return output.join(""); - } - }); - -}()); -/*global CSSLint*/ -CSSLint.addFormatter({ - //format information - id: "compact", - name: "Compact, 'porcelain' format", - - /** - * 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 messages = results.messages, - output = ""; - options = options || {}; - - /** - * Capitalize and return given string. - * @param str {String} to capitalize - * @return {String} capitalized - */ - var capitalize = function(str) { - return str.charAt(0).toUpperCase() + str.slice(1); - }; - - if (messages.length === 0) { - return options.quiet ? "" : filename + ": Lint Free!"; - } - - CSSLint.Util.forEach(messages, function(message, i) { - if (message.rollup) { - output += filename + ": " + capitalize(message.type) + " - " + message.message + "\n"; - } else { - output += filename + ": " + "line " + message.line + - ", col " + message.col + ", " + capitalize(message.type) + " - " + message.message + "\n"; - } - }); - - return output; - } -}); -/*global CSSLint*/ -CSSLint.addFormatter({ - //format information - id: "csslint-xml", - name: "CSSLint XML format", - - /** - * Return opening root XML tag. - * @return {String} to prepend before all results - */ - startFormat: function(){ - return ""; - }, - - /** - * Return closing root XML tag. - * @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} (UNUSED for now) specifies special handling of output - * @return {String} output for results - */ - formatResults: function(results, filename, options) { - var messages = results.messages, - output = []; - - /** - * Replace special characters before write to output. - * - * Rules: - * - single quotes is the escape sequence for double-quotes - * - & is the escape sequence for & - * - < is the escape sequence for < - * - > is the escape sequence for > - * - * @param {String} message to escape - * @return escaped message as {String} - */ - var escapeSpecialCharacters = function(str) { - if (!str || str.constructor !== String) { - return ""; - } - return str.replace(/\"/g, "'").replace(/&/g, "&").replace(//g, ">"); - }; - - if (messages.length > 0) { - output.push(""); - CSSLint.Util.forEach(messages, function (message, i) { - if (message.rollup) { - output.push(""); - } else { - output.push(""); - } - }); - output.push(""); - } - - return output.join(""); - } -}); -/*global CSSLint*/ -CSSLint.addFormatter({ - //format information - id: "lint-xml", - name: "Lint XML format", - - /** - * Return opening root XML tag. - * @return {String} to prepend before all results - */ - startFormat: function(){ - return ""; - }, - - /** - * Return closing root XML tag. - * @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} (UNUSED for now) specifies special handling of output - * @return {String} output for results - */ - formatResults: function(results, filename, options) { - var messages = results.messages, - output = []; - - /** - * Replace special characters before write to output. - * - * Rules: - * - single quotes is the escape sequence for double-quotes - * - & is the escape sequence for & - * - < is the escape sequence for < - * - > is the escape sequence for > - * - * @param {String} message to escape - * @return escaped message as {String} - */ - var escapeSpecialCharacters = function(str) { - if (!str || str.constructor !== String) { - return ""; - } - return str.replace(/\"/g, "'").replace(/&/g, "&").replace(//g, ">"); - }; - - if (messages.length > 0) { - - output.push(""); - CSSLint.Util.forEach(messages, function (message, i) { - if (message.rollup) { - output.push(""); - } else { - output.push(""); - } - }); - output.push(""); - } - - return output.join(""); - } -}); -/*global CSSLint*/ -CSSLint.addFormatter({ - //format information - id: "text", - name: "Plain Text", - - /** - * 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 messages = results.messages, - output = ""; - options = options || {}; - - if (messages.length === 0) { - return options.quiet ? "" : "\n\ncsslint: No errors in " + filename + "."; - } - - output = "\n\ncsslint: There are " + messages.length + " problems in " + filename + "."; - var pos = filename.lastIndexOf("/"), - shortFilename = filename; - - if (pos === -1){ - pos = filename.lastIndexOf("\\"); - } - if (pos > -1){ - shortFilename = filename.substring(pos+1); - } - - CSSLint.Util.forEach(messages, function (message, i) { - output = output + "\n\n" + shortFilename; - if (message.rollup) { - output += "\n" + (i+1) + ": " + message.type; - output += "\n" + message.message; - } else { - output += "\n" + (i+1) + ": " + message.type + " at line " + message.line + ", col " + message.col; - output += "\n" + message.message; - output += "\n" + message.evidence; - } - }); - - return output; - } -}); exports.CSSLint = CSSLint; diff --git a/lib/ace/mode/css_worker.js b/lib/ace/mode/css_worker.js index 9644ffec..09802cad 100644 --- a/lib/ace/mode/css_worker.js +++ b/lib/ace/mode/css_worker.js @@ -27,33 +27,68 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ***** END LICENSE BLOCK ***** */ - + define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); +var lang = require("../lib/lang"); var Mirror = require("../worker/mirror").Mirror; var CSSLint = require("./css/csslint").CSSLint; var Worker = exports.Worker = function(sender) { Mirror.call(this, sender); - this.setTimeout(200); + this.setTimeout(400); + this.ruleset = null; + this.setDisabledRules("ids"); + this.setInfoRules("adjoining-classes|qualified-headings|zero-units|gradients|import|outline-none"); }; oop.inherits(Worker, Mirror); (function() { - + this.setInfoRules = function(ruleNames) { + if (typeof ruleNames == "string") + ruleNames = ruleNames.split("|"); + this.infoRules = lang.arrayToMap(ruleNames); + this.doc.getValue() && this.deferredUpdate.schedule(100); + }; + + this.setDisabledRules = function(ruleNames) { + if (!ruleNames) { + this.ruleset = null; + } else { + if (typeof ruleNames == "string") + ruleNames = ruleNames.split("|"); + var all = {}; + + CSSLint.getRules().forEach(function(x){ + all[x.id] = true; + }); + ruleNames.forEach(function(x) { + delete all[x]; + }); + console.log(all) + this.ruleset = all; + } + this.doc.getValue() && this.deferredUpdate.schedule(100); + }; + this.onUpdate = function() { var value = this.doc.getValue(); - - var result = CSSLint.verify(value); + var infoRules = this.infoRules; + + var result = CSSLint.verify(value, this.ruleset); this.sender.emit("csslint", result.messages.map(function(msg) { - delete msg.rule; - return msg; + return { + row: msg.line - 1, + column: msg.col - 1, + text: msg.message, + type: infoRules[msg.rule.id] ? "info" : msg.type + } })); }; - + }).call(Worker.prototype); });