Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/rossPatton/stylint into …
Browse files Browse the repository at this point in the history
…exclude
  • Loading branch information
Lance Miller committed Nov 4, 2015
2 parents 74c47fc + 306af2e commit 2c82c15
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 133 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
}],
"comma-style": [2, "last"],
"consistent-return": 0,
"curly": 1,
"default-case": 1,
"eol-last": 1,
"eqeqeq": 1,
Expand Down
4 changes: 2 additions & 2 deletions .stylintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
// Comments - woooo
"blocks": "always",
"brackets": "always",
"brackets": false,
"colons": "always",
"colors": false,
"commaSpace": "always",
Expand All @@ -13,7 +13,7 @@
"extendPref": false,
"globalDupe": true,
"indentPref": {
"expect": false
"expect": 2
},
"leadingZero": "always",
"maxErrors": false,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## stylint - the stylus linter.

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rossPatton/stylint?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Code Climate](https://codeclimate.com/github/rossPatton/stylint/badges/gpa.svg)](https://codeclimate.com/github/rossPatton/stylint) [![Test Coverage](https://codeclimate.com/github/rossPatton/stylint/badges/coverage.svg)](https://codeclimate.com/github/rossPatton/stylint/coverage)
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rossPatton/stylint?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Code Climate](https://codeclimate.com/github/rossPatton/stylint/badges/gpa.svg)](https://codeclimate.com/github/rossPatton/stylint) [![Test Coverage](https://codeclimate.com/github/rossPatton/stylint/badges/coverage.svg)](https://codeclimate.com/github/rossPatton/stylint/coverage) [![Build Status](https://travis-ci.org/rossPatton/stylint.svg?branch=master)](https://travis-ci.org/rossPatton/stylint)

[![NPM](https://nodei.co/npm/stylint.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/stylint/)

Expand Down
Empty file modified bin/stylint
100644 → 100755
Empty file.
14 changes: 10 additions & 4 deletions src/checks/semicolons.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
'use strict'

// we only want to check semicolons on properties/values
var ignoreRe = /(^[&$=#>.])|{|}|if|for(?!\w)|else|@block|@media|=$|=\s|,$|}$|{$/gm
var ignoreRe = /(^[#.])|[&$=>]|{|}|if|for(?!\w)|else|@block|@media|=$|=\s|(}|{)$/igm
// for some reason the prev regex matches in regexr
// but isn't matching here
var listRe = /,$/m


/**
Expand All @@ -10,9 +13,12 @@ var ignoreRe = /(^[&$=#>.])|{|}|if|for(?!\w)|else|@block|@media|=$|=\s|,$|}$|{$/
* @return {boolean} true if in order, false if not
*/
var semicolons = function( line ) {
if ( ignoreRe.test( line ) || this.state.hashOrCss ) {
return
}
if ( ignoreRe.test( line.trim() ) ) return
if ( listRe.test( line ) ) return
if ( this.state.hashOrCss ) return

// console.log( line.trim() )
// console.log( /,$/.test( line.trim() ) )

var semicolon

Expand Down
5 changes: 4 additions & 1 deletion src/checks/valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
// 4 ignore numbers
// 5 ( from || to ) are only valid inside @keyframe
// 6 the actual JSON property whitelist we will test against
// 7 if interpolated value just give it a pass
var attrOrMixinRe = /^\[\S+\]|({[\S]+})|(\([\S ]+\))|(\(\))/ // 1
var stripRe = /(?=\S)\[\S+\]|(\.|#)(\w|-)+/ // /(?=\S)\[\S+\]/ // 2
var ignoreRe = /^[$.#]|[&=>+~]|if|for|else|return|@block|calc|@extend|@media/ // 3
var numRe = /\d+?(?=px|%|em|rem|v(h|w)|v(min|max)|ex|ch|mm|cm|in|pt|pc|mozmm)/ // 4
var keyRe = /((from)|(to))+(?= $| {| \d|\n|{)/ // 5
var validJSON = require( '../data/valid.json' ) // 6
var interpolatedRe = /( *{\S+} *)/ // 7


/**
Expand All @@ -28,14 +30,15 @@ module.exports = function valid( line ) {
var arr = this.splitAndStrip( new RegExp( /[\s\t,:]/ ), line ) // 1

// if not splittable for some reason
if ( typeof arr[0] === 'undefined' ) { return }
if ( typeof arr[0] === 'undefined' ) return

// in order, let line be considered valid if:
// 1 we are in a hash or css block
// 2 classname, varname, id, or syntax.
// 3 if the selector only consists of an attr or mixin (which can be custom)
// 4 if it's a number
if ( this.state.hashOrCSS || // 1
interpolatedRe.test( this.cache.origLine ) ||
ignoreRe.test( line.trim() ) || // 2
attrOrMixinRe.test( line ) || // 3
numRe.test( arr[0] ) ) { // 3
Expand Down
2 changes: 1 addition & 1 deletion src/utils/trimLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var trimLine = function( line ) {
}

// strip interpolated variables
return line.replace( /({\S+})/, '' ) // /({.+})
return line.replace( /( *{\S+} *)/, '' )
}

module.exports = trimLine
56 changes: 52 additions & 4 deletions test-styl/_ads.styl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* Styling for various ad types
*/

// @stylint off

// &,
// &:hover,
// &:before,
Expand All @@ -12,6 +10,58 @@
// {some_var},
// margin 0

div#my-id #another-id {
// ...
}

.svg {
background: $background;

path,
rect,
polygon,
circle {
fill: $foreground;
}
}

.svg {
background: $background;
path,
circle,
polygon,
rect {
fill: $foreground;
}
}

.module-class
&__anything
padding: 20px;

__anything
margin: 0;

$icon-selector = '.icon'
// warn: trailing white space

.label, {$icon-selector}
font-size: 12px;

button
.label
font-size: 11px;
{$icon-selector} // warn: duplicate property or selector
font-size: 10px;

// warn: property is not valid
{$icon-selector}-user {
color: blue;
}


// @stylint off

div:not([style="display: block;"]) {
display: none;
}
Expand Down Expand Up @@ -62,8 +112,6 @@ $black = #000;
ms-opacity(0.6); // <- gives false epositive
}

// @stylint on

.abcdefghi {
.active { // @stylint ignore
color: red;
Expand Down
Loading

0 comments on commit 2c82c15

Please sign in to comment.