Skip to content

Commit

Permalink
save the work
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross committed Dec 1, 2014
0 parents commit 466128d
Show file tree
Hide file tree
Showing 6 changed files with 372 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

npm-debug.log
node_modules
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# stylus-lint

A linter for stylus

# install

With [npm](https://npmjs.org) do:

```
npm install stylus-lint
```

# license

ISC
119 changes: 119 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// modules
const fs = require('fs'),
chalk = require('chalk'),
fileinput = require('fileinput'),
stream = require('stream'),
readline = require('readline'),
_ = require('lodash');


// regexes
const comment = /\/\/\s/, // check for space after comment line
starS = /(\* )/, // check for space after star (inside a docblockr comment)
starO = /(\/\*\*)/ || /(\/\*)/, // check for star selector as opening comment
starE = /(\*\/)/; // finally, check for star selector as closing comment

// other stuff
var errors = [],
warnings = [],
files = [],
count = 0;


fileinput.input('test/test.styl').on('line', function(line) {
var line = line.toString();
count += 1;

// check for comment
if (line.indexOf('//') !== -1) {
// check for space after comment, if no space, return warning
if (!comment.test(line)) {
warnings.push('space after comment is preferred: \n' + count + ': ' + line);
}
}

// check for 0px
if (line.indexOf(' 0px') !== -1) {
warnings.push('0 is preferred over 0px. Found on line: \n' + count + ': ' + line)
}

/**
* check for * selector. (super basic atm, @TODO needs to not trigger on regex selectors)
* technically this is used as part of resets often, for good reason, despite its slowness
* which is why i'm setting it up as a warning as it won't break code but you might prefer to not use it
*/
if (line.indexOf('*') !== -1) {
// check for various places where the * is valid (just comment checks atm)
if (!starO.test(line) && !starE.test(line) && !starS.test(line)) {
warnings.push('* selector is very slow. Found on line: \n' + count + ': ' + line);
}
}

// check for semicolons
if (line.indexOf(';') !== -1) {
errors.push('semicolon found on line: \n' + count + ': ' + line)
}
}).
on('error', function(err) {
throw err;
}).
on('end', function() {
for (var i = 0; i < warnings.length; i++) {
console.log( chalk.yellow('Warning: ' + warnings[i]) );
}
for (var i = 0; i < errors.length; i++) {
console.log( chalk.red('Error: ' + errors[i]) );
}
});


// fs.readFile('test/test.styl', 'utf8', function(err, data) {
// if (err) {
// return console.error(err);
// }

// // console.log(data);
// // console.log(typeof data);
// console.log(semi.exec(data))

// if (!_.isNull(semi.exec(data))) {
// console.log('Match!');
// }
// else {
// console.log('No Match!');
// }
// });

// fileinput.input().on('line', function(line) {
// console.log( fileinput.lineno(), line.toString('utf8') );
// });


// var instream = fs.createReadStream(process.argv[2]);
// var outstream = new stream;
// outstream.readable = true;
// outstream.writable = true;

// var rl = readline.createInterface({
// input: instream,
// output: outstream,
// terminal: false
// });

// rl.on('line', function(line) {
// console.log(line);
// //Do your stuff ...
// //Then write to outstream
// // rl.write(cubestuff);
// }).
// on('error', function(err) {
// throw err;
// });

// fs.readdir(process.argv[2], function(err, contents) {
// if (err) throw err;

// contents.forEach(function(file) {
// files.push(file);
// });
// });
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "stylus-lint",
"version": "1.0.0",
"description": "A linter for stylus",
"main": "index.js",
"scripts": {
"test": "npm test"
},
"repository": {
"type": "git",
"url": "stylus-lint"
},
"keywords": [
"stylus"
],
"author": "Ross Patton",
"license": "ISC",
"devDependencies": {
"chalk": "^0.5.1",
"lodash": "^2.4.1",
"readline": "0.0.5"
}
}
194 changes: 194 additions & 0 deletions test/test.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/**
* universal baseline
* 1 font-smoothing makes our text sharp
* 2 crisper, higher contrast gifs and pngs, on supported browsers
* 3 height of global header at top
* 4 this setting can speed up font rendering significantly, esp on mobile
*/
body
background-color $white
color $dark-gray;
-webkit-font-smoothing antialiased // 1
-webkit-osx-font-smoothing grayscale // 1
-moz-osx-font-smoothing grayscale // 1
image-rendering crisp-edges // 2
-webkit-overflow-scrolling touch
padding-top 60px // 3
text-rendering optimizeSpeed // 4

// gray bg on grid pages
&:not(.single)
background-color *

// hide brand bar on smaller devices by default
+media('med-plus')
*
padding-top 90px


/**
* set link defaults
* 1 Address `outline` inconsistency between Chrome and other browsers.
* 2 Improve readability when focused and also mouse hovered in all browsers
*/
a
transition(color, .15s, false)
color inherit
text-decoration none
&:focus
outline thin dotted // 1

&:active,
&:hover
cursor pointer
outline 0 // 2


// Prevent modern browsers from displaying `audio` without controls.
// Remove excess height in iOS 5 devices.
audio:not([controls])
display none
height 0


// Correct `inline-block` display not defined in IE 8/9.
audio,
canvas,
video
display inline-block


// Address style set to `bolder` in Firefox 4+, Safari 5, and Chrome.
b,
strong
font-weight bold;


// fixes blockquote rendering bugs in older browsers
blockquote
quotes none
&:after,
&:before
content ''
content none // on purpose


// default button stylez
// @TODO so, trying to minimize base styles as much as possible
// button,
// input[type='submit']
// @extends $button-base


/**
* 1. Correct font family not being inherited in all browsers.
* 2. Correct font size not being inherited in all browsers.
* 3. Address margins set differently in Firefox 4+, Safari 5, and Chrome.
*/
button,
input,
select,
textarea
font-family inherit // 1
font-size 100% // 2
margin 0 // 3


/**
* Address Firefox 4+ setting `line-height` on `input` using `!important` in
* the UA stylesheet
*/
button
input
line-height normal


// Remove inner padding and border in Firefox 4+.
button::-moz-focus-inner,
input::-moz-focus-inner
border 0;
padding 0


/**
* Address inconsistent `text-transform` inheritance for `button` and `select`.
* All other form control elements do not inherit `text-transform` values.
* Correct `button` style inheritance in Chrome, Safari 5+, and IE 8+.
* Correct `select` style inheritance in Firefox 4+ and Opera.
*/
button,
select
text-transform none


/**
* 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
and `video` controls.
* 2. Correct inability to style clickable `input` types in iOS.
* 3. Improve usability and consistency of cursor style between image-type
`input` and others.
*/
button,
html input[type='button'], // 1
input[type='reset'],
input[type='submit']
-webkit-appearance button // 2
cursor pointer // 3


// Re-set default cursor for disabled elements.
button[disabled],
html input[disabled]
cursor default


// remove default margin
figure
margin 0


// no underlines on headlines
h1,
h2,
h3,
h4,
h5,
h6
transition(color, .15s, false)
color $black;


//i is reserved for icons, not italic
i
display block
font-style normal


/**
* 1 Remove border when inside `a` element in IE
* 2 no stretchy
* 3 fixes annoying phantom space after images
* 4 default to full width (maybe not the best idea?)
*/
img,
iframe
border 0px //1
height auto //2
display block //3


img,
code,
kbd,
pre,
samp
width 100% //4


// images and video won't break their containers
img,
video,
object,
figure,
iframe
max-width 100%
6 changes: 6 additions & 0 deletions test/test2.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body
margin 0;
padding 0

img
display block

0 comments on commit 466128d

Please sign in to comment.