Skip to content

Commit 4a2f0cb

Browse files
committed
Merge pull request #3 from stefmikhail/master
Changed module from `sys` to `util` and the variable name to match, to remove error notification in bundle output
2 parents e58226d + d9767e3 commit 4a2f0cb

File tree

4 files changed

+135
-75
lines changed

4 files changed

+135
-75
lines changed

README.md

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
CSSLint TextMate Bundle
22

3-
Forked orignally from [JSHint TM Bundle](https://github.com/fgnass/jshint.tmbundle) and updated to use CSSLint
3+
Forked from jcfant's [CSSLint Textmate Bundle](https://github.com/jcfant/csslint.tmbundle), who originally forked it from [JSHint TM Bundle](https://github.com/fgnass/jshint.tmbundle) and updated it to use CSSLint.
44

55
TextMate bundle for [CSSLint](http://csslint.net/)
66

7-
![Screenshot](https://github.com/jcfant/images/raw/master/CSSLintTMBundle.jpg)
7+
8+
9+
This Fork differs in several ways from jcfant's:
10+
11+
* First, the window stays open after double clicking on an entry. This way, even though you will be brought to the line in your document the entry is referring to, you will still be able to return to the lint window to see the next entry.
12+
* Second, the window is a set 800px by 800px making it easier to manage.
13+
* Third, I preferred the old design of the window, so I merged the two styles into what IMHO is a much better lint window:
14+
* For errors, the background is now red.
15+
* The line number and column number of the error is displayed.
16+
* An underline is placed under the character in the code preview where the issue is found.
17+
* And a description of the rule in question is also displayed.
18+
19+
20+
![Screenshot](https://github.com/stefmikhail/csslint.tmbundle/raw/master/cssLintTMBundle.png)
21+
822

923
Features:
1024

@@ -15,17 +29,18 @@ Features:
1529

1630
## Installation
1731

18-
Download the [zip file](http://github.com/jcfant/csslint.tmbundle/zipball/master) and rename the
19-
extracted folder to `csslint.tmbundle`. Double-click.
32+
cd ~/Library/Application\ Support/TextMate/Bundles
33+
git clone git://github.com/stefmikhail/csslint.tmbundle.git "CSSLint.tmbundle"
34+
osascript -e 'tell app "TextMate" to reload bundles'
35+
2036

2137
## Prerequisites
2238

2339
You need [Node.js](http://nodejs.org/) and TextMate, that's all.
2440

25-
If you don't have Node.js installed on your system you can also use [Pierre Bertet's fork](https://github.com/bpierre/jshint.tmbundle) which uses [WebKit's JavaScriptCore](http://trac.webkit.org/wiki/JSC) instead.
26-
2741
This bundle uses `#!/usr/local/bin/node` to launch the node process. If you get a *node - not found* error,the `PATH` variable is probably not setup in TextMate.
2842

2943
## Contributors
3044

3145
* [JC Fant](http://www.scriptble.com)
46+
* Stefan Melnychenko

Support/csslint-tm.js

+48-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var env = process.env || process.ENV,
33
http = require('https'),
44
fs = require('fs'),
5-
sys = require('sys'),
5+
util = require('util'),
66
port = "443",
77
stdout = process.stdout,
88
showVersionMessage = false,
@@ -55,7 +55,7 @@ function versionsMatch(tmContents, tempContents, callback){
5555
cssTMContents = String(cssTMContents).replace(/^\s+|\s+$/, '');
5656
if (error)
5757
callback(false);
58-
58+
5959
fs.stat(cssTempFile, function(error, stats){
6060
if (error){
6161
callback(false);
@@ -97,7 +97,7 @@ function hasLatestJS(callback){
9797
getLatest(callback, cssPath + cssFile, cssLintFile);
9898
return;
9999
}
100-
100+
101101
var aDate = Date.parse(stats.atime);
102102
var mDate = Date.parse(stats.mtime);
103103
var lDate = aDate < mDate ? aDate : mDate;
@@ -112,18 +112,18 @@ function hasLatestJS(callback){
112112
function hasLatestVersion(callback){
113113
fs.stat(cssTMFile, function(error, stats){
114114
if (error){
115-
//sys.puts(error);
115+
//util.puts(error);
116116
versionUpdate.callback = callback;
117117
getLatest(version, cssPath + cssVersion, cssTempFile);
118118
return;
119119
}
120-
120+
121121
versionUpdate.callback = callback;
122122
fs.stat(cssTempFile, function(error){
123123
if (error){
124124
getLatest(version, cssPath + cssVersion, cssTempFile);
125125
}
126-
126+
127127
var aDate = Date.parse(stats.atime);
128128
var mDate = Date.parse(stats.mtime);
129129
var lDate = aDate < mDate ? aDate : mDate;
@@ -143,24 +143,24 @@ module.exports = function(options) {
143143
hasLatestJS(function(error){
144144
if (options === undefined)
145145
options = {};
146-
146+
147147
var file = env.TM_FILEPATH;
148148
var input = fs.readFileSync(file, 'utf8');
149149
var CSSLint = require(cssLintFile).CSSLint;
150150

151151
var result = CSSLint.verify(input);
152152
var messages = result.messages;
153-
153+
154154
var body = "";
155-
155+
156156
if (messages.length){
157157
if (showVersionMessage){
158158
body += '<div class="cssHeader">' + versionMessage + '</div>';
159159
}
160-
if (error){
161-
body += '<div class="cssHeader">' + error + '</div>';
162-
}
163-
160+
if (error){
161+
body += '<div class="cssHeader">' + error + '</div>';
162+
}
163+
164164
if (options.rollup){
165165
//rollups at the bottom
166166
messages.sort(function(a, b){
@@ -175,23 +175,49 @@ module.exports = function(options) {
175175
}
176176

177177
messages.forEach(function(message,i){
178-
var link = 'txmt://open?url=file://' + escape(file) + '&line=' + message.line;
179-
body += "<div class=\"entry " + message.type + "\"><a href=\"" + link + "\">";
180-
body += "<div class=\"header " + message.type + "\">" + message.type + "</div>";
181-
body += "<div class=\"message\">" + html(message.message) + "</div>";
182-
body += "<div class=\"evidence\">" + html(message.evidence) + "</div>";
183-
body += '</a>';
184-
body += "</div>";
178+
var temp = '',
179+
link = 'txmt://open?url=file://' + escape(file) + '&line=' + message.line + '&column=' + message.col;
180+
if (message && message.line && message.col && message.message) {
181+
temp += '<div class="entry ' + message.type + '"><a href="' + link + '">';
182+
temp += '<div class="header ' + message.type + '">' + message.message;
183+
temp += '<span class="line"> Line ' + message.line + ' Char ' + message.col + '</span></div>';
184+
if (message.evidence && !isNaN(message.col)) {
185+
temp += '<div class="evidence">';
186+
temp += html(message.evidence.substring(0, message.col-1));
187+
temp += '<em>';
188+
temp += (message.col <= message.evidence.length) ? html(message.evidence.substring(message.col-1, message.col)) : '&nbsp;';
189+
temp += '</em>';
190+
temp += html(message.evidence.substring(message.col));
191+
temp += '</div>';
192+
};
193+
temp += '<div class="desc">' + message.rule.desc + '</div>';
194+
temp += '</a>';
195+
temp += '</div>';
196+
// Insert our 'error' messages at the top of the list
197+
if(message.type === "error"){
198+
body = temp + body;
199+
} else {
200+
body += temp;
201+
}
202+
// For sections that only contain a message - e.g general suggestion errors
203+
} else if (message.message) {
204+
temp += '<div class="entry ' + message.type + '"><a href="txmt://open?url=file://' + escape(file) + '">';
205+
temp += '<div class="header ' + message.type + '">' + message.message + '</div>';
206+
temp += '<div class="desc">' + message.rule.desc + '</div>';
207+
temp += '</a>';
208+
temp += '</div>';
209+
body += temp;
210+
};
185211
});
186212
}
187213

188-
214+
189215
/*
190216
* Original version of writing the error messages to TextMate from jshint.tmbundle
191217
*/
192218
if (body.length > 0) {
193219
fs.readFile(__dirname + '/output.html', 'utf8', function(e, html) {
194-
sys.puts(html.replace('{body}', body));
220+
util.puts(html.replace('{body}', body));
195221
process.exit(205); //show_html
196222
});
197223
}

Support/output.html

+66-47
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,77 @@
11
<html>
2-
<head>
3-
<style type="text/css">
4-
body {
5-
background-color: #cecccc;
6-
padding: 0;
7-
margin: 0;
8-
font-family: Monaco;
9-
}
10-
a {
11-
display: block;
12-
text-decoration: none;
13-
color: #444;
14-
background: -webkit-gradient(linear, 0 100%, 0 0, from(#CACACA), to(#DCDCDC));
15-
border-style: solid;
16-
border-width: 1px 0;
17-
border-color: #fff #000 #afafaf #000;
18-
padding: 10px 20px;
19-
text-shadow: 0 1px #fff;
20-
}
21-
a:hover {
22-
background: -webkit-gradient(linear, 0 100%, 0 0, from(#8191B0), to(#B5C0D5));
23-
color: #fff;
24-
text-shadow: none;
25-
}
26-
.cssHeader {
27-
padding: 10px 20px;
28-
background: -webkit-gradient(linear, 0 100%, 0 0, from(#f9eba5), to(#fdf4c5));
29-
border-bottom: 1px solid #999;
30-
font-size: 13px;
31-
font-weight: bold;
32-
}
2+
<head>
333

34-
.header {
4+
<style type="text/css">
5+
body {
6+
background-color: #e8e8e8;
7+
padding: 0;
8+
margin: 0;
9+
font-family: "Times New Roman";
10+
font-size: 16px;
11+
}
12+
a {
13+
display: block;
14+
text-decoration: none;
15+
color: #444;
16+
background: -webkit-gradient(linear, 0 100%, 0 0, from(#CACACA), to(#DCDCDC));
17+
border-style: solid;
18+
border-width: 1px 0;
19+
border-color: #fff #000 #afafaf #000;
20+
padding: 10px 20px;
21+
text-shadow: 0 1px #fff;
22+
}
23+
a:hover {
24+
background: -webkit-gradient(linear, 0 100%, 0 0, from(#8191B0), to(#B5C0D5));
25+
color: #fff;
26+
text-shadow: none;
27+
}
28+
.error a {
29+
background: -webkit-gradient(linear, 0 100%, 0 0, from(#512114), to(#A53627));
30+
color: #fff;
31+
text-shadow: 0 1px #300800;
32+
border-top: #A54937;
33+
border-bottom: #2C0700;
34+
}
35+
.error a:hover {
36+
background: -webkit-gradient(linear, 0 100%, 0 0, from(#510D00), to(#A51909));
37+
}
38+
.cssHeader {
39+
padding: 10px 20px;
40+
background: -webkit-gradient(linear, 0 100%, 0 0, from(#f9eba5), to(#fdf4c5));
41+
border-bottom: 1px solid #999;
42+
font-size: 13px;
3543
font-weight: bold;
36-
font-size: 15px;
37-
text-transform: capitalize;
3844
}
39-
40-
.message, .evidence {
41-
padding-left: 10px;
45+
span.line {
46+
float: right;
47+
font-size: 9px;
4248
}
43-
44-
.header.error {
45-
color: #a80810;
49+
span, .evidence {
50+
display: block;
51+
font-size: 12px;
52+
font-family: Monaco;
53+
margin: 5px 0;
4654
}
47-
.header.warning {
48-
color: #0fa808;
55+
em {
56+
font-style: normal;
57+
border-bottom: 2px solid red;
4958
}
5059
.evidence {
5160
color: #0811a8;
5261
}
53-
</style>
54-
</head>
55-
<body onload="window.resizeTo(800,document.getElementById('output').offsetHeight+22)" onblur="window.close()">
56-
<div id="output">{body}</div>
57-
</body>
62+
.error .evidence {
63+
color: #8E8BFF;
64+
}
65+
.desc {
66+
font-size: 0.8em;
67+
padding: 0;
68+
margin: 0;
69+
font-style: italic;
70+
}
71+
</style>
72+
</head>
73+
74+
<body onload="window.resizeTo(800,800)">
75+
<div id="output">{body}</div>
76+
</body>
5877
</html>

cssLintTMBundle.png

135 KB
Loading

0 commit comments

Comments
 (0)