View | Details | Raw Unified | Return to bug 512330
Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.client.ui/web/orion/commandRegistry.js (-1 / +1 lines)
Lines 1285-1291 define([ Link Here
1285
								parent.classList.add('quickFixList'); //$NON-NLS-1$
1285
								parent.classList.add('quickFixList'); //$NON-NLS-1$
1286
								var QUICKFIX_ID = 'quickfixDetails'; //$NON-NLS-1$
1286
								var QUICKFIX_ID = 'quickfixDetails'; //$NON-NLS-1$
1287
								var quickfixDetails = parent.childNodes.item(QUICKFIX_ID);
1287
								var quickfixDetails = parent.childNodes.item(QUICKFIX_ID);
1288
								if (command.id === 'ignore.in.file.fix'){
1288
								if (command.id === 'ignore.in.file.fix' || command.id === 'css.ignore.on-line.fix'){
1289
									if (!quickfixDetails){
1289
									if (!quickfixDetails){
1290
										quickfixDetails = document.createElement("div");
1290
										quickfixDetails = document.createElement("div");
1291
										quickfixDetails.id = QUICKFIX_ID;
1291
										quickfixDetails.id = QUICKFIX_ID;
(-)a/bundles/org.eclipse.orion.client.webtools/web/webtools/nls/root/messages.js (+1 lines)
Lines 122-127 define({//Default message bundle Link Here
122
	"zero-units": "Disallow units for 0 values:",   
122
	"zero-units": "Disallow units for 0 values:",   
123
	
123
	
124
	// CSS Quick Fixes
124
	// CSS Quick Fixes
125
	"quickfix-ignore-on-line": "Ignore",
125
	"quickfix-empty-rules": "Remove the rule",
126
	"quickfix-empty-rules": "Remove the rule",
126
	"quickfix-important": "Remove '!important' annotation",
127
	"quickfix-important": "Remove '!important' annotation",
127
	"quickfix-zero-units": "Remove 'px' qualifier",
128
	"quickfix-zero-units": "Remove 'px' qualifier",
(-)a/bundles/org.eclipse.orion.client.webtools/web/webtools/plugins/webToolsPlugin.js (+29 lines)
Lines 191-196 define(['orion/plugin', Link Here
191
    	 * Register quick fixes as editor commands
191
    	 * Register quick fixes as editor commands
192
    	 */
192
    	 */
193
    	var cssQuickFixComputer = new cssQuickFixes.CssQuickFixes();
193
    	var cssQuickFixComputer = new cssQuickFixes.CssQuickFixes();
194
    	
195
    	provider.registerServiceProvider("orion.edit.command", //$NON-NLS-1$
196
		{
197
			/** @callback */
198
			execute: function(editorContext, context) {
199
				context.annotation.fixid = 'ignore-on-line'; //$NON-NLS-1$
200
				return cssQuickFixComputer.execute(editorContext, context);
201
			}
202
		},
203
		{
204
			name: messages["quickfix-ignore-on-line"],
205
			scopeId: "orion.edit.quickfix", //$NON-NLS-1$
206
			id: "css.ignore.on-line.fix", //$NON-NLS-1$
207
			contentType: ['text/css', 'text/html'], //$NON-NLS-1$ //$NON-NLS-2$
208
			validationProperties: [{
209
					source: "annotation:id", //$NON-NLS-1$
210
					match: "^(?:.*\\S.*)$" //$NON-NLS-1$
211
				},
212
				{
213
					source: "annotation:data:ruleSource", //$NON-NLS-1$
214
					match: "css" //$NON-NLS-1$
215
				},
216
				{
217
					source: "readonly", //$NON-NLS-1$
218
					match: false
219
				}
220
			]
221
		}
222
	);
194
223
195
    	provider.registerServiceProvider("orion.edit.command",  //$NON-NLS-1$
224
    	provider.registerServiceProvider("orion.edit.command",  //$NON-NLS-1$
196
    		cssQuickFixComputer,
225
    		cssQuickFixComputer,
(-)a/bundles/org.eclipse.orion.client.webtools/web/webtools/cssQuickFixes.js (-7 / +38 lines)
Lines 31-60 define([ Link Here
31
		 * @param {Object} context The context params
31
		 * @param {Object} context The context params
32
		 */
32
		 */
33
		execute: function(editorContext, context) {
33
		execute: function(editorContext, context) {
34
			var id = context.annotation.id;
34
			var id = context.annotation.fixid;
35
			Metrics.logEvent('language tools', 'quickfix', id, 'text/css');
35
			if (!id){
36
				id = context.annotation.id;
37
			}
38
			Metrics.logEvent('language tools', 'quickfix', id, 'text/css'); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
36
		    var fixes = this[id];
39
		    var fixes = this[id];
37
	        if(fixes) {
40
	        if(fixes) {
38
	            return fixes(editorContext, context.annotation);
41
	            return fixes(editorContext, context.annotation);
39
	        }
42
	        }
40
		    return null;
43
		    return null;
41
		},
44
		},
42
		"empty-rules": function(editorContext, annotation) { //$NON-NLS-0$
45
		"ignore-on-line": function(editorContext, annotation) {
46
			return editorContext.getText().then(function(text) {
47
				// Find end of line
48
				var lineEnd = getLineEnd(text, annotation.end);
49
				return editorContext.setText(" /* csslint allow: " + annotation.id + " */", lineEnd, lineEnd); //$NON-NLS-1$ //$NON-NLS-2$
50
            });
51
		},
52
		"empty-rules": function(editorContext, annotation) {
43
			return editorContext.getText().then(function(text) {
53
			return editorContext.getText().then(function(text) {
44
				// Remove leading space
54
				// Remove leading space
45
				var start = annotation.start;
55
				var start = annotation.start;
46
				while (start >= 0 && (text[start-1] === ' ' || text[start-1] === '\t')){ //$NON-NLS-0$ //$NON-NLS-1$
56
				while (start >= 0 && (text[start-1] === ' ' || text[start-1] === '\t')){
47
					start--;
57
					start--;
48
				}
58
				}
49
				var contents = text.substring(annotation.start);
59
				var contents = text.substring(annotation.start);
50
				contents = contents.match(/.*{\s*}\s*/,''); //$NON-NLS-0$
60
				contents = contents.match(/.*{\s*}\s*/,'');
51
				if (contents){
61
				if (contents){
52
					return editorContext.setText("", start, start+contents[0].length);
62
					return editorContext.setText("", start, start+contents[0].length);
53
				}
63
				}
54
				return null;
64
				return null;
55
            });
65
            });
56
		},
66
		},
57
		"important": function(editorContext, annotation){ //$NON-NLS-0$
67
		"important": function(editorContext, annotation){
58
			return editorContext.getText().then(function(text) {
68
			return editorContext.getText().then(function(text) {
59
				// The annotation will select the property name. Get the complete property.
69
				// The annotation will select the property name. Get the complete property.
60
				var contents = text.substring(annotation.start);
70
				var contents = text.substring(annotation.start);
Lines 68-74 define([ Link Here
68
				return null;
78
				return null;
69
            });
79
            });
70
		},
80
		},
71
		"zero-units": function(editorContext, annotation) { //$NON-NLS-0$
81
		"zero-units": function(editorContext, annotation) {
72
			return editorContext.getText().then(function(text) {
82
			return editorContext.getText().then(function(text) {
73
				var contents = text.substring(annotation.start, annotation.end);
83
				var contents = text.substring(annotation.start, annotation.end);
74
				contents = contents.replace(/0px/gi,'0'); //$NON-NLS-0$
84
				contents = contents.replace(/0px/gi,'0'); //$NON-NLS-0$
Lines 77-82 define([ Link Here
77
		}
87
		}
78
	});
88
	});
79
	
89
	
90
	/**
91
    * @description Finds the end of the line in the given text starting at the given offset
92
    * @param {String} text The text
93
    * @param {Number} offset The offset
94
    * @returns {Number} The offset in the text before the new line or end of file
95
    */
96
   function getLineEnd(text, offset) {
97
       if(!text) {
98
           return 0;
99
       }
100
       if(offset < 0) {
101
           return 0;
102
       }
103
        var off = offset;
104
       var char = text[off];
105
       while(off < text.length && !/[\r\n]/.test(char)) {
106
           char = text[++off];
107
       }
108
       return off;
109
	}
110
	
80
	return {
111
	return {
81
		CssQuickFixes: CssQuickFixes
112
		CssQuickFixes: CssQuickFixes
82
	};
113
	};
(-)a/bundles/org.eclipse.orion.client.webtools/web/webtools/cssValidator.js (-37 / +40 lines)
Lines 23-62 define("webtools/cssValidator", [ Link Here
23
		// Define the default values for the rules
23
		// Define the default values for the rules
24
		// 0:off, 1:warning, 2:error 3:info
24
		// 0:off, 1:warning, 2:error 3:info
25
		rules: {
25
		rules: {
26
			"adjoining-classes" : 3, //$NON-NLS-0$
26
			"adjoining-classes" : 3,
27
			"box-model" : 3, //$NON-NLS-0$
27
			"box-model" : 3,
28
			"box-sizing" : 3, //$NON-NLS-0$
28
			"box-sizing" : 3,
29
			"bulletproof-font-face" : 3, //$NON-NLS-0$
29
			"bulletproof-font-face" : 3,
30
			"compatible-vendor-prefixes" : 3, //$NON-NLS-0$
30
			"compatible-vendor-prefixes" : 3,
31
			"display-property-grouping" : 3, //$NON-NLS-0$
31
			"display-property-grouping" : 3,
32
			"duplicate-background-images" : 3, //$NON-NLS-0$
32
			"duplicate-background-images" : 3,
33
			"duplicate-properties" : 3, //$NON-NLS-0$
33
			"duplicate-properties" : 3,
34
			"empty-rules" : 3, //$NON-NLS-0$
34
			"empty-rules" : 3,
35
			"fallback-colors" : 3, //$NON-NLS-0$
35
			"fallback-colors" : 3,
36
			"floats" : 3, //$NON-NLS-0$
36
			"floats" : 3,
37
			"font-faces" : 3, //$NON-NLS-0$
37
			"font-faces" : 3,
38
			"font-sizes" : 3, //$NON-NLS-0$
38
			"font-sizes" : 3,
39
			"gradients" : 3, //$NON-NLS-0$
39
			"gradients" : 3,
40
			"ids" : 3, //$NON-NLS-0$
40
			"ids" : 3,
41
			"import" : 3, //$NON-NLS-0$
41
			"import" : 3,
42
			"important" : 3, //$NON-NLS-0$
42
			"important" : 3,
43
			"known-properties" : 3, //$NON-NLS-0$
43
			"known-properties" : 3,
44
			"outline-none" : 3, //$NON-NLS-0$
44
			"outline-none" : 3,
45
			"overqualified-elements" : 3, //$NON-NLS-0$
45
			"overqualified-elements" : 3,
46
			"qualified-headings" : 3, //$NON-NLS-0$
46
			"qualified-headings" : 3,
47
			"regex-selectors" : 3, //$NON-NLS-0$
47
			"regex-selectors" : 3,
48
			"rules-count" : 3, //$NON-NLS-0$
48
			"rules-count" : 3,
49
			"selector-max-approaching" : 3, //$NON-NLS-0$
49
			"selector-max-approaching" : 3,
50
			"selector-max" : 3, //$NON-NLS-0$
50
			"selector-max" : 3,
51
			"shorthand" : 3, //$NON-NLS-0$
51
			"shorthand" : 3,
52
			"star-property-hack" : 3, //$NON-NLS-0$
52
			"star-property-hack" : 3,
53
			"text-indent" : 3, //$NON-NLS-0$
53
			"text-indent" : 3,
54
			"underscore-property-hack" : 3, //$NON-NLS-0$
54
			"underscore-property-hack" : 3,
55
			"unique-headings" : 3, //$NON-NLS-0$
55
			"unique-headings" : 3,
56
			"universal-selector" : 3, //$NON-NLS-0$
56
			"universal-selector" : 3,
57
			"unqualified-attributes" : 3, //$NON-NLS-0$
57
			"unqualified-attributes" : 3,
58
			"vendor-prefix" : 3, //$NON-NLS-0$
58
			"vendor-prefix" : 3,
59
			"zero-units" : 3 //$NON-NLS-0$
59
			"zero-units" : 3
60
		},
60
		},
61
		
61
		
62
		/**
62
		/**
Lines 79-85 define("webtools/cssValidator", [ Link Here
79
		 * @param {Object} [key] Optional key to use for complex rule configuration.
79
		 * @param {Object} [key] Optional key to use for complex rule configuration.
80
		 */
80
		 */
81
		setOption: function(ruleId, value, key) {
81
		setOption: function(ruleId, value, key) {
82
			if (typeof value === "number") { //$NON-NLS-0$
82
			if (typeof value === "number") {
83
				if(Array.isArray(this.rules[ruleId])) {
83
				if(Array.isArray(this.rules[ruleId])) {
84
					var ruleConfig = this.rules[ruleId];
84
					var ruleConfig = this.rules[ruleId];
85
					if (key) {
85
					if (key) {
Lines 178-184 define("webtools/cssValidator", [ Link Here
178
						line: message.line,
178
						line: message.line,
179
						start: range[0],
179
						start: range[0],
180
						end: range[1],
180
						end: range[1],
181
						severity: message.type
181
						severity: message.type,
182
						data: {
183
							ruleSource: 'css' //$NON-NLS-1$
184
						}
182
					});
185
					});
183
				}
186
				}
184
			}
187
			}
Lines 231-237 define("webtools/cssValidator", [ Link Here
231
		 * @since 8.0
234
		 * @since 8.0
232
		 */
235
		 */
233
		_getProblemRange: function(message) {
236
		_getProblemRange: function(message) {
234
			if (!message.rule || !message.rule.id || message.rule.id === "errors"){ //$NON-NLS-0$
237
			if (!message.rule || !message.rule.id || message.rule.id === "errors"){
235
				// Parsing errors often don't have a token to select, so instead select the line
238
				// Parsing errors often don't have a token to select, so instead select the line
236
				return [1, message.evidence.length + 1];
239
				return [1, message.evidence.length + 1];
237
			}
240
			}

Return to bug 512330