diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/commandRegistry.js b/bundles/org.eclipse.orion.client.ui/web/orion/commandRegistry.js index b006f72..730494a 100644 --- a/bundles/org.eclipse.orion.client.ui/web/orion/commandRegistry.js +++ b/bundles/org.eclipse.orion.client.ui/web/orion/commandRegistry.js @@ -1285,7 +1285,7 @@ define([ parent.classList.add('quickFixList'); //$NON-NLS-1$ var QUICKFIX_ID = 'quickfixDetails'; //$NON-NLS-1$ var quickfixDetails = parent.childNodes.item(QUICKFIX_ID); - if (command.id === 'ignore.in.file.fix'){ + if (command.id === 'ignore.in.file.fix' || command.id === 'css.ignore.on-line.fix'){ if (!quickfixDetails){ quickfixDetails = document.createElement("div"); quickfixDetails.id = QUICKFIX_ID; diff --git a/bundles/org.eclipse.orion.client.webtools/web/webtools/nls/root/messages.js b/bundles/org.eclipse.orion.client.webtools/web/webtools/nls/root/messages.js index 1396de9..1db8bb7 100644 --- a/bundles/org.eclipse.orion.client.webtools/web/webtools/nls/root/messages.js +++ b/bundles/org.eclipse.orion.client.webtools/web/webtools/nls/root/messages.js @@ -122,6 +122,7 @@ define({//Default message bundle "zero-units": "Disallow units for 0 values:", // CSS Quick Fixes + "quickfix-ignore-on-line": "Ignore", "quickfix-empty-rules": "Remove the rule", "quickfix-important": "Remove '!important' annotation", "quickfix-zero-units": "Remove 'px' qualifier", diff --git a/bundles/org.eclipse.orion.client.webtools/web/webtools/plugins/webToolsPlugin.js b/bundles/org.eclipse.orion.client.webtools/web/webtools/plugins/webToolsPlugin.js index 6aedb65..8c19403 100644 --- a/bundles/org.eclipse.orion.client.webtools/web/webtools/plugins/webToolsPlugin.js +++ b/bundles/org.eclipse.orion.client.webtools/web/webtools/plugins/webToolsPlugin.js @@ -191,6 +191,35 @@ define(['orion/plugin', * Register quick fixes as editor commands */ var cssQuickFixComputer = new cssQuickFixes.CssQuickFixes(); + + provider.registerServiceProvider("orion.edit.command", //$NON-NLS-1$ + { + /** @callback */ + execute: function(editorContext, context) { + context.annotation.fixid = 'ignore-on-line'; //$NON-NLS-1$ + return cssQuickFixComputer.execute(editorContext, context); + } + }, + { + name: messages["quickfix-ignore-on-line"], + scopeId: "orion.edit.quickfix", //$NON-NLS-1$ + id: "css.ignore.on-line.fix", //$NON-NLS-1$ + contentType: ['text/css', 'text/html'], //$NON-NLS-1$ //$NON-NLS-2$ + validationProperties: [{ + source: "annotation:id", //$NON-NLS-1$ + match: "^(?:.*\\S.*)$" //$NON-NLS-1$ + }, + { + source: "annotation:data:ruleSource", //$NON-NLS-1$ + match: "css" //$NON-NLS-1$ + }, + { + source: "readonly", //$NON-NLS-1$ + match: false + } + ] + } + ); provider.registerServiceProvider("orion.edit.command", //$NON-NLS-1$ cssQuickFixComputer, diff --git a/bundles/org.eclipse.orion.client.webtools/web/webtools/cssQuickFixes.js b/bundles/org.eclipse.orion.client.webtools/web/webtools/cssQuickFixes.js index bd7087e..550c746 100644 --- a/bundles/org.eclipse.orion.client.webtools/web/webtools/cssQuickFixes.js +++ b/bundles/org.eclipse.orion.client.webtools/web/webtools/cssQuickFixes.js @@ -31,30 +31,40 @@ define([ * @param {Object} context The context params */ execute: function(editorContext, context) { - var id = context.annotation.id; - Metrics.logEvent('language tools', 'quickfix', id, 'text/css'); + var id = context.annotation.fixid; + if (!id){ + id = context.annotation.id; + } + Metrics.logEvent('language tools', 'quickfix', id, 'text/css'); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ var fixes = this[id]; if(fixes) { return fixes(editorContext, context.annotation); } return null; }, - "empty-rules": function(editorContext, annotation) { //$NON-NLS-0$ + "ignore-on-line": function(editorContext, annotation) { + return editorContext.getText().then(function(text) { + // Find end of line + var lineEnd = getLineEnd(text, annotation.end); + return editorContext.setText(" /* csslint allow: " + annotation.id + " */", lineEnd, lineEnd); //$NON-NLS-1$ //$NON-NLS-2$ + }); + }, + "empty-rules": function(editorContext, annotation) { return editorContext.getText().then(function(text) { // Remove leading space var start = annotation.start; - while (start >= 0 && (text[start-1] === ' ' || text[start-1] === '\t')){ //$NON-NLS-0$ //$NON-NLS-1$ + while (start >= 0 && (text[start-1] === ' ' || text[start-1] === '\t')){ start--; } var contents = text.substring(annotation.start); - contents = contents.match(/.*{\s*}\s*/,''); //$NON-NLS-0$ + contents = contents.match(/.*{\s*}\s*/,''); if (contents){ return editorContext.setText("", start, start+contents[0].length); } return null; }); }, - "important": function(editorContext, annotation){ //$NON-NLS-0$ + "important": function(editorContext, annotation){ return editorContext.getText().then(function(text) { // The annotation will select the property name. Get the complete property. var contents = text.substring(annotation.start); @@ -68,7 +78,7 @@ define([ return null; }); }, - "zero-units": function(editorContext, annotation) { //$NON-NLS-0$ + "zero-units": function(editorContext, annotation) { return editorContext.getText().then(function(text) { var contents = text.substring(annotation.start, annotation.end); contents = contents.replace(/0px/gi,'0'); //$NON-NLS-0$ @@ -77,6 +87,27 @@ define([ } }); + /** + * @description Finds the end of the line in the given text starting at the given offset + * @param {String} text The text + * @param {Number} offset The offset + * @returns {Number} The offset in the text before the new line or end of file + */ + function getLineEnd(text, offset) { + if(!text) { + return 0; + } + if(offset < 0) { + return 0; + } + var off = offset; + var char = text[off]; + while(off < text.length && !/[\r\n]/.test(char)) { + char = text[++off]; + } + return off; + } + return { CssQuickFixes: CssQuickFixes }; diff --git a/bundles/org.eclipse.orion.client.webtools/web/webtools/cssValidator.js b/bundles/org.eclipse.orion.client.webtools/web/webtools/cssValidator.js index dcd928e..0ebee6a 100644 --- a/bundles/org.eclipse.orion.client.webtools/web/webtools/cssValidator.js +++ b/bundles/org.eclipse.orion.client.webtools/web/webtools/cssValidator.js @@ -23,40 +23,40 @@ define("webtools/cssValidator", [ // Define the default values for the rules // 0:off, 1:warning, 2:error 3:info rules: { - "adjoining-classes" : 3, //$NON-NLS-0$ - "box-model" : 3, //$NON-NLS-0$ - "box-sizing" : 3, //$NON-NLS-0$ - "bulletproof-font-face" : 3, //$NON-NLS-0$ - "compatible-vendor-prefixes" : 3, //$NON-NLS-0$ - "display-property-grouping" : 3, //$NON-NLS-0$ - "duplicate-background-images" : 3, //$NON-NLS-0$ - "duplicate-properties" : 3, //$NON-NLS-0$ - "empty-rules" : 3, //$NON-NLS-0$ - "fallback-colors" : 3, //$NON-NLS-0$ - "floats" : 3, //$NON-NLS-0$ - "font-faces" : 3, //$NON-NLS-0$ - "font-sizes" : 3, //$NON-NLS-0$ - "gradients" : 3, //$NON-NLS-0$ - "ids" : 3, //$NON-NLS-0$ - "import" : 3, //$NON-NLS-0$ - "important" : 3, //$NON-NLS-0$ - "known-properties" : 3, //$NON-NLS-0$ - "outline-none" : 3, //$NON-NLS-0$ - "overqualified-elements" : 3, //$NON-NLS-0$ - "qualified-headings" : 3, //$NON-NLS-0$ - "regex-selectors" : 3, //$NON-NLS-0$ - "rules-count" : 3, //$NON-NLS-0$ - "selector-max-approaching" : 3, //$NON-NLS-0$ - "selector-max" : 3, //$NON-NLS-0$ - "shorthand" : 3, //$NON-NLS-0$ - "star-property-hack" : 3, //$NON-NLS-0$ - "text-indent" : 3, //$NON-NLS-0$ - "underscore-property-hack" : 3, //$NON-NLS-0$ - "unique-headings" : 3, //$NON-NLS-0$ - "universal-selector" : 3, //$NON-NLS-0$ - "unqualified-attributes" : 3, //$NON-NLS-0$ - "vendor-prefix" : 3, //$NON-NLS-0$ - "zero-units" : 3 //$NON-NLS-0$ + "adjoining-classes" : 3, + "box-model" : 3, + "box-sizing" : 3, + "bulletproof-font-face" : 3, + "compatible-vendor-prefixes" : 3, + "display-property-grouping" : 3, + "duplicate-background-images" : 3, + "duplicate-properties" : 3, + "empty-rules" : 3, + "fallback-colors" : 3, + "floats" : 3, + "font-faces" : 3, + "font-sizes" : 3, + "gradients" : 3, + "ids" : 3, + "import" : 3, + "important" : 3, + "known-properties" : 3, + "outline-none" : 3, + "overqualified-elements" : 3, + "qualified-headings" : 3, + "regex-selectors" : 3, + "rules-count" : 3, + "selector-max-approaching" : 3, + "selector-max" : 3, + "shorthand" : 3, + "star-property-hack" : 3, + "text-indent" : 3, + "underscore-property-hack" : 3, + "unique-headings" : 3, + "universal-selector" : 3, + "unqualified-attributes" : 3, + "vendor-prefix" : 3, + "zero-units" : 3 }, /** @@ -79,7 +79,7 @@ define("webtools/cssValidator", [ * @param {Object} [key] Optional key to use for complex rule configuration. */ setOption: function(ruleId, value, key) { - if (typeof value === "number") { //$NON-NLS-0$ + if (typeof value === "number") { if(Array.isArray(this.rules[ruleId])) { var ruleConfig = this.rules[ruleId]; if (key) { @@ -178,7 +178,10 @@ define("webtools/cssValidator", [ line: message.line, start: range[0], end: range[1], - severity: message.type + severity: message.type, + data: { + ruleSource: 'css' //$NON-NLS-1$ + } }); } } @@ -231,7 +234,7 @@ define("webtools/cssValidator", [ * @since 8.0 */ _getProblemRange: function(message) { - if (!message.rule || !message.rule.id || message.rule.id === "errors"){ //$NON-NLS-0$ + if (!message.rule || !message.rule.id || message.rule.id === "errors"){ // Parsing errors often don't have a token to select, so instead select the line return [1, message.evidence.length + 1]; }